[SOLVED]Window handles change values at runtime?

Started by
4 comments, last by VanillaSnake21 15 years, 4 months ago
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]

You didn't come into this world. You came out of it, like a wave from the ocean. You are not a stranger here. -Alan Watts

Advertisement
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 ("=").
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man
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.
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?

You didn't come into this world. You came out of it, like a wave from the ocean. You are not a stranger here. -Alan Watts

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 thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man
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.

You didn't come into this world. You came out of it, like a wave from the ocean. You are not a stranger here. -Alan Watts

This topic is closed to new replies.

Advertisement