Jump to content
  • Advertisement
Sign in to follow this  
VanillaSnake21

[SOLVED]WindowProc for multiple windows?

This topic is 3476 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I totally forgot how to handle multiple windows within the WinProc. I'm doing something like if(hWnd == MyWindow) { switch(uMsg) ... } but it's not working. [Edited by - VanillaSnake21 on December 15, 2008 1:42:43 PM]

Share this post


Link to post
Share on other sites
Advertisement
Why would you handle two different windows with the same WndProc? Common sense would suggest to me that if the windows are different, use a different WndProc...

Share this post


Link to post
Share on other sites
Quote:
Original post by Codeka
Why would you handle two different windows with the same WndProc? Common sense would suggest to me that if the windows are different, use a different WndProc...


What if I have a window created at runtime (which I do, an error message dialog box)?

Share this post


Link to post
Share on other sites
Quote:
Original post by VanillaSnake21
What if I have a window created at runtime (which I do, an error message dialog box)?


Oh, I see what you mean. You might have multiple instances of the same window sharing the same WndProc. That makes sense.

The way I implement such things (and I think this is a common pattern) is you have a C++ class that encapsulates your window so you have one instance of this class per visible window, right?

You simply use the SetWindowLongPtr function to set the GWLP_USERDATA property to a pointer to your class. Then in the WndProc, use GetWindowLongPtr to get that pointer back and call the methods on your class to handle the message.

Share this post


Link to post
Share on other sites
Quote:
Original post by Codeka
Quote:
Original post by VanillaSnake21
What if I have a window created at runtime (which I do, an error message dialog box)?


Oh, I see what you mean. You might have multiple instances of the same window sharing the same WndProc. That makes sense.

The way I implement such things (and I think this is a common pattern) is you have a C++ class that encapsulates your window so you have one instance of this class per visible window, right?

You simply use the SetWindowLongPtr function to set the GWLP_USERDATA property to a pointer to your class. Then in the WndProc, use GetWindowLongPtr to get that pointer back and call the methods on your class to handle the message.



Maybe I wasn't clear of what I'm trying to do. I want multiple windows created from the same WINDOWCLASS structure (meaning WndProc handles all of their messages) to be able to lets say paint in their client area.

So inside WindowProc I have

switch(uMsg)
{
case WM_PAINT: TextOut(...)
}

but this outputs the Text on all the windows, and even if I specify the correct window in TextOut(m_MyDialog...) that would still be called even when don't want to draw to this window.

I remeber doing this and it was pretty easy. What I basically want to know is which window the message is being passed to (this is contained in the first param of WindowProc) and then compare that handle to the handle of the window that I have, if they are the same paint in the client of that window.

Share this post


Link to post
Share on other sites
Quote:
Original post by godsenddeath
if it's a dialog box, they have their own type of window procedure


I'm implementing my own dialgog box so I'm registering it as a normal window. How can no-one know how this could be done, this is beyond trivial.

Share this post


Link to post
Share on other sites
Quote:
Original post by VanillaSnake21
How can no-one know how this could be done, this is beyond trivial.
You just check the hWnd parameter. I don't quite follow how this isn't working - a HWND refers to one window, unless you're updating all windows with the same data, there shouldn't be a problem.

If you have:

switch(uMsg)
{
case WM_PAINT: TextOut(...)
}


then that will work fine, provided you pass the HDC from BeginPaint() or the HDC from GetDC(hWnd). If that's not working, we'll need to see more code.

EDIT:
Quote:
Original post by VanillaSnake21
What I basically want to know is which window the message is being passed to (this is contained in the first param of WindowProc) and then compare that handle to the handle of the window that I have, if they are the same paint in the client of that window.
If you get a WM_PAINT, you need to paint something. If you ignore it and only handle particular window handles, your windows won't update properly (Not sure if you're doing this already though).

The way I'd do this is by using the method Codeka suggests. That should work fine. Here's some example code that works fine with multiple windows for one class.

Share this post


Link to post
Share on other sites
Might be guessing here but read up on how messages are propagated to child windows. I think Windows will keep pasing the "paste" message to all child windows and the parent until it figures out that one of the child windows handled the event (so you'll need to return the correct value from the WinProc once you find the window that handled the message.)

Also, how are you keeping track of that "MyWindow" variable?

Share this post


Link to post
Share on other sites
@EvilSteve

LRESULT CALLBACK WindowManagerExtension::m_MessageProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{
case WM_CLOSE: PostQuitMessage(0); break;

case WM_PAINT:
{
//*******
//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);

} break;

}

return DefWindowProc(hwnd, uMsg, wParam, lParam);
}

Thats my code. Basically when I use m_Dialog (window for the dialog stored in my class) to get the DC there is no output. When I use the window that is passed to WinProc (hWnd) then it works but outputs on both the dialog window and the main window.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!