Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DLL Talk / How do i change the WndProc of a dbc app?

Author
Message
Caleb1994
15
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 10th Apr 2009 01:47
the title says it all.

I was trying to make a menus dll so i could have menus in my and still be able to get the menu item selected. (since that's ussually handled in the WndProc in c++) and was trying to use GetMessage() to get it.

I was thinking about it. won't it be easier to change the wndproc then add in the Menu Procedure?

2 questions.

1 i know this is possible ( With SetClassLong ) but how do i do it?
2. does db have anything thats "Needed" in the WndProc that would be erased?

New Site! Check it out \/
Benjamin
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 10th Apr 2009 03:23 Edited at: 10th Apr 2009 19:17
Well what you first have to do is get the handle to the window (which I assume you have already done), store the current window procedure, set a new window procedure, and inside this function you need to call the original window procedure. This will allow you to process messages as you wish and then pass on any unhandled messages to the old window procedure.

Caleb1994
15
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 10th Apr 2009 06:35
Oh! ok. but how do i Set the Window Procedure? that's what i'm wondering. do i use set class long and use the pointer to the function?

New Site! Check it out \/
Benjamin
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 10th Apr 2009 07:05
Caleb1994
15
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 10th Apr 2009 18:03
lol ok i'll read up

New Site! Check it out \/
Caleb1994
15
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 10th Apr 2009 18:13 Edited at: 10th Apr 2009 19:27
**Deleted because i''m dumb**



just need to knowh ow to get the address to the new window procedure to pass to setclasslong?

New Site! Check it out \/
Benjamin
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 10th Apr 2009 19:17
Oops, it's been quite a while since I did window subclassing. I'm not sure where I pulled CallWndProc from but you can just call the old window procedure like a normal function. Your window procedure should look something like this:



You can obtain the old address using GetClassLong.

Caleb1994
15
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 10th Apr 2009 19:30 Edited at: 10th Apr 2009 19:32
how do i call a function with the address? i have only done it with the name before.

and see above question^ i edited itbefore i saw this.


btw there is a CallWindowProc() function and you use that to with the address of the function. but the only thing i need is how to get the address of the new one to pass to setclasslong

New Site! Check it out \/
Diggsey
17
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 10th Apr 2009 20:58 Edited at: 11th Apr 2009 12:16
To declare a variable as a function pointer, do this:

<return type> (*<variable name> )( <parameter type list> )

eg.

int (*myFunctionPointer)(float, float);

Then to call it, you can just write:
int result = myFunctionPointer(1.0f,2.0f);

[b]Yuor signutare was aresed by a deslyxic mud...
BOX2D V2 HAS HELP FILES! AND A WIKI!
Caleb1994
15
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 10th Apr 2009 21:13 Edited at: 10th Apr 2009 21:33
sweet thanks!

But what about this
Quote: "
int result = myFunctionPointer(1.0f,2.0f);"


whats the f for?

New Site! Check it out \/
Caleb1994
15
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 10th Apr 2009 23:37
Wait!


How does the program know what function it is? i don't specify anything but the parameters so how does that work?

and why isn't this code working?

this is the source to my dll. i have a wndproc function and a ChangeWindowProcedure(hWnd) function. i'm getting a error



at line 28

heres the code



New Site! Check it out \/
Benjamin
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 11th Apr 2009 03:47 Edited at: 11th Apr 2009 03:49
Quote: "How does the program know what function it is?"

Which function? You tell it the address of the new window procedure by passing it in SetWindowLong. Also, I remember now that this function will also return the previous value of the one you are changing, so you can store the old address at the same time.

There are a few problems with your code. The first one is that you are declaring a function pointer for what looks like the new window procedure, when the idea of it is to use it to store the old procedure (OK this isn't exactly a problem, but it's counter-intuitive). Secondly, your syntax is wrong, it should be this:



Thirdly, you're setting 'NewProc' as the new window procedure even though it doesn't point to anything. You should be passing 'WndProc' instead. You'll need to prototype the function at the top of your code, in order to specify it before where it is defined, like this:



Lastly, for best practice you should never cast a function pointer.

Caleb1994
15
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 11th Apr 2009 04:13
Quote: "Quote: "How does the program know what function it is?""


I ment for the function pointer. but i realize now that what i was doing was wrong and how to do it.

i was getting the pointer so i could pass it to SetClassLong but i just realized i just need the name

Heres my updated code. I'm about to test it thanks for all your help.



New Site! Check it out \/

Login to post a reply

Server time is: 2024-04-18 01:44:51
Your offset time is: 2024-04-18 01:44:51