Jump to content
  • Advertisement
Sign in to follow this  
nuclear123

WM_SHOWWINDOW question

This topic is 2611 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

currently started some win32 programming and i am reading a tutorial located on functionx.com It strates the following about WM_SHOWWINDOW message

WM_SHOWWINDOW: After a window has been created, it needs to be displayed, that is, the window needs to be shown. Also, if the window was previously hidden, you can decide to show it. On the other hand, if a window is displaying, you may want to hide it, for any reason you judge necessary. To take any of these actions, that is, to show or hide a window, you must send the WM_SHOWWINDOW message. The syntax of this message is:

OnCreate(HWND hWnd, [color="#ff0000"]WM_SHOWWINDOW, WPARAM wParam, LPARAM lParam);hWnd is the window that sends the message.

wParam is a Boolean value. If you want to display or show the hWnd window, set the wParam value to TRUE. If you want to hide the hWnd window, set this value to FALSE.

lParam specifies the status of the window.
T


he syntax of this message is:

OnCreate(HWND hWnd, [color="#ff0000"]WM_SHOWWINDOW, WPARAM wParam, LPARAM lParam);[/quote]

Im confused...it states this is the syntax of the message...also to me it looks like a function..When would i ever call this function? i thought in order to handle the WM_SHOWWINDOW message you just add a case inside your windowprocedure() function to handle this message and tell it what to do inside the case statement. Thanks!


Example:
//---------------------------------------------------------------------------
LRESULT CALLBACK WndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
switch(Msg)
{
case WM_CREATE:
MessageBox(NULL, "The window is being created", WindowCaption, MB_OK);
break;
case WM_SHOWWINDOW:
break;
case WM_DESTROY:
PostQuitMessage(WM_QUIT);
break;
default:
return DefWindowProc(hWnd, Msg, wParam, lParam);
}
return 0;
}
//---------------------------------------------------------------------------
Where is this oncreate() function coming from?

Share this post


Link to post
Share on other sites
Advertisement
It looks like this tutorial has incorrect content.

I believe the author wanted to say that the OS is going to call your WndProc function with Msg being set to the WM_SHOWWINDOW and explains what wParam and lParam mean for each message...

Share this post


Link to post
Share on other sites
I haven't read the article in question, so there might be an explanation as to why they're putting it that way. The OnCreate, OnActivate, On***** are commonly used to separate implementation code from the WndProc. It would look a little like this...
//---------------------------------------------------------------------------
LRESULT CALLBACK WndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
switch(Msg)
{
case WM_CREATE:
OnCreate(hWnd, Msg, wParam, lParam);
break;
case WM_SHOWWINDOW:
OnShowWindow(hWnd, Msg, wParam, lParam);
break;
case WM_DESTROY:
OnDestroy(hWnd, Msg, wParam, lParam);
PostQuitMessage(WM_QUIT);
break;
default:
return DefWindowProc(hWnd, Msg, wParam, lParam);
}
return 0;
}
//---------------------------------------------------------------------------

OnCreate(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
// Handle message here
}

OnShowWindow(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
// Handle message here
}

OnDestroy(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
// Handle message here
}


Maybe they explained that in a different tutorial?

Share this post


Link to post
Share on other sites
It appears to be a typo. In the context they mention it, their On* functions all look more like SendMessage. As AverageMidget pointed out, it's common practice to call an On* function as your message handler in the WndProc, but in that case you would NEVER send the message ID as well - after all, what's the point? Note though that stuff like WM_SHOWWINDOW is actually sent by calling ShowWindow(), not SendMessage...

An alternate example might be something like this:

[source lang="cpp"]
CreateWindow(...);
ShowWindow(hWnd, SW_SHOW);
...
//elsewhere...
...

LRESULT CALLBACK WndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
switch(Msg)
{
...
case WM_CREATE:
OnCreate(hWnd, (CREATESTRUCT*)lParam);
break;
case WM_SHOWWINDOW:
if (wParam == TRUE)
OnShow(hWnd);
else
OnHide(hWnd);
break;

[/source]

Personally, I think some of the examples in the MSDN help would be better formed, more accurate and therefore less likely to lead you astray than a broken article.

Share this post


Link to post
Share on other sites
As AverageMidget pointed out, it's common practice to call an On* function as your message handler in the WndProc, but in that case you would NEVER send the message ID as well - after all, what's the point?


I got a little crazy with the copy/paste, without giving it much thought. :P

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!