Sign in to follow this  
VanillaSnake21

[SOLVED]Window handles change values at runtime?

Recommended Posts

VanillaSnake21    175
In my MessageProc I'm checking which window the message is designated to by doing this: if(hwnd == m_Window1 { Wnd1Function(); ... return DefWndProc(); } if(hwnd == m_Window2) { Wnd2Function(); ... return DefWndProc(); } When I debug, and set the breakpoint at Wnd1Fucntion, I check the values of m_Window1 and 2 and they are the same (why?, they are created with two distinct calls to CreateWindow, and none of them are children of each other). Whats more weirder is that when I set the breakpoint at Wnd2Function() and check the values of Wnd1 and 2, they are now different!. When the program goes back to Wnd1 they are the same again. Why is this happening? [Edited by - VanillaSnake21 on December 16, 2008 11:30:04 PM]

Share this post


Link to post
Share on other sites
LessBread    1415
I can only guess, but perhaps at some point your assigning the hwnd to the variable you're examining. Check that the condition statements use double equals ("==") rather single equal ("=").

Share this post


Link to post
Share on other sites
Nypyren    12074
Time for a data breakpoint!

Actually, nevermind. Sounds exactly like a variable overriding one in an outer scope.

i.e. say you have a member variable of a class "m_ptr", and then inside that class you have a member function where you accidentally say "void *m_ptr = whatever;". For the rest of that function, you'll have a different variable, yet it's named the same thing (especially for purposes of debugging, this can be hard to spot).

Either that, or you're debugging optimized code which is notorious for not showing correct contents of variables.

Share this post


Link to post
Share on other sites
VanillaSnake21    175
Quote:
Original post by LessBread
I can only guess, but perhaps at some point your assigning the hwnd to the variable you're examining. Check that the condition statements use double equals ("==") rather single equal ("=").


There's no assignement, but my WndProc is in a class so I'm using a technique that EvilSteve suggested, I have two WndProcs one is static the other is not, the static one is passing the control to the non-static one. And it does an assignment to the m_Window at the end. I don't exactly understand why I'm assigning the window in the first place, but this is how I was shown to do it. Heres the code:



LRESULT CALLBACK WindowManagerExtension::m_StandinMessageProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{

WindowManagerExtension* wme;


if(uMsg == WM_CREATE)
{
wme = (WindowManagerExtension*)((LPCREATESTRUCT)lParam )->lpCreateParams;
SetWindowLong(hwnd, GWL_USERDATA, (LONG_PTR) wme);
}
else
{
wme = (WindowManagerExtension*)GetWindowLong(hwnd, GWL_USERDATA);
if(!wme) return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
//***
// THIS IS THE ASSIGNMENT
//*****
wme->m_Window = hwnd;

return wme->m_MessageProc( hwnd, uMsg, wParam, lParam);

}





Can that be the reason ? By the way why is it there?

Share this post


Link to post
Share on other sites
LessBread    1415
That's a good candidate for the problem. Try moving that assignment into the WM_CREATE block either before or after SetWindowLong and see if that resolves the issue. The hwnd is assigned to the object instance so that the object can access it as needed.

Also, you probably should check this pointer before dereferencing it too, just in case lParam is null (i.e. 0).

wme = (WindowManagerExtension*)((LPCREATESTRUCT)lParam )->lpCreateParams;

Share this post


Link to post
Share on other sites
VanillaSnake21    175
Quote:
Original post by LessBread
That's a good candidate for the problem. Try moving that assignment into the WM_CREATE block either before or after SetWindowLong and see if that resolves the issue. The hwnd is assigned to the object instance so that the object can access it as needed.

Also, you probably should check this pointer before dereferencing it too, just in case lParam is null (i.e. 0).

wme = (WindowManagerExtension*)((LPCREATESTRUCT)lParam )->lpCreateParams;


I just removed the assignment alltogether and it fixed the problem, Thanks.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this