[SOLVED]WindowProc for multiple windows?
Quote:Original post by rethan
How are you setting m_Dialog?
I'm creating it with the function from my class. Basically with a CreateWindowEx
Also, the WinAPI docs from MSDN mention this:
"An application returns zero if it processes this message." which you seem to not do. In the "Works" case, since you have multiple windows using that same function, each window that gets a paint message will paint "Hello". If you know all your window handles (and get them from CreateWindow() or CreateWindowEx()), then you can switch on that within the WM_PAINT case like so:
case WM_PAINT:
{
switch (hWnd)
{
case m_Dialog:
hDC = GetDC(hWnd);
TextOut(hDC, 20, 20, "Hello", 5);
ReleaseDC(hWnd, hDC);
return 0;
case m_Main:
...
return 0;
}
break;
}
(Or better yet put the drawing code in a function that you can call to make the code cleaner.)
I also noticed that you release on m_hWnd and not hWnd here:ReleaseDC(m_hWnd, hDC);, m_hWnd should be hWnd since you GetDC(hWnd).
"An application returns zero if it processes this message." which you seem to not do. In the "Works" case, since you have multiple windows using that same function, each window that gets a paint message will paint "Hello". If you know all your window handles (and get them from CreateWindow() or CreateWindowEx()), then you can switch on that within the WM_PAINT case like so:
case WM_PAINT:
{
switch (hWnd)
{
case m_Dialog:
hDC = GetDC(hWnd);
TextOut(hDC, 20, 20, "Hello", 5);
ReleaseDC(hWnd, hDC);
return 0;
case m_Main:
...
return 0;
}
break;
}
(Or better yet put the drawing code in a function that you can call to make the code cleaner.)
I also noticed that you release on m_hWnd and not hWnd here:ReleaseDC(m_hWnd, hDC);, m_hWnd should be hWnd since you GetDC(hWnd).
Quote:Original post by rethan
switch (hWnd)
(Or better yet put the drawing code in a function that you can call to make the code cleaner.)
Thats what I'm talking about, if you read my OP I tried it. I said
if(hWnd == m_Dialog)
but that doesn't work, thats what led me to this question, how do I compare window handles correctly?
Quote:
I also noticed that you release on m_hWnd and not hWnd here:ReleaseDC(m_hWnd, hDC);, m_hWnd should be hWnd since you GetDC(hWnd).
typo
Quote:Original post by VanillaSnake21That means that hWnd is not the same as m_Dialog, which means something is getting screwed up and m_Dialog doesn't refer to "this" window.
@EvilSteve//******* //DOESNT WORK //********** HDC hDC = GetDC(m_Dialog); TextOut(hDC, 20, 20, "Hello", 5); ReleaseDC(m_Dialog, hDC); //WORKS*** hDC = GetDC(hWnd); TextOut(hDC, 20, 20, "Hello", 5); ReleaseDC(m_hWnd, hDC);
Quote:Original post by VanillaSnake21That does work. But m_Dialog probably doesn't contain the correct handle.
Thats what I'm talking about, if you read my OP I tried it. I said
if(hWnd == m_Dialog)
but that doesn't work, thats what led me to this question, how do I compare window handles correctly?
Can we see the full source where you assign m_Dialog? The code I linked in my last post works fine.
Quote:Original post by Evil Steve
Can we see the full source where you assign m_Dialog? The code I linked in my last post works fine.
Wow, thanks, it's a pretty stupid mistake. My dialog assignement had m_Window (which is my main window) insetad of m_Dialog to the left of CreateWindow... Fixed it, everything works :). Thats what happens when you copy and paste code... Thanks everyone.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement