Jump to content
  • Advertisement
Sign in to follow this  
nuclear123

WndProc wont show messagebox

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


LRESULT CALLBACK WndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
static HWND hwndButton[NUM];
static int cxChar, cyChar;
int i;

switch (iMsg)
{
case WM_CREATE: // init window
// lets create buttons on window
cxChar = LOWORD(GetDialogBaseUnits()); // width of default font
cyChar = HIWORD(GetDialogBaseUnits()); // height of default font

for (i = 0; i < NUM; i++)
{
hwndButton = CreateWindow(TEXT("button"), // because were using a predefined class we dont need to worry about "repainting" for these buttons( windows also handles destruction of these buttons when the parent window is destroyed )
button.szText,
WS_CHILD | WS_VISIBLE | button.iStyle,
cxChar, // x position
cyChar * (1 + 2 * i), // y position
22 * cxChar, // width of each button
7 * cyChar / 4, // height of each button
hwnd, // handle of parent to these buttons
(HMENU) i, // child window ID to identify where a message came from
((LPCREATESTRUCT) lParam)->hInstance, // get hinstance
NULL);
}
return 0;
case WM_PAINT: // when a part of the client area becomes invalid and needs to be redrawn to the screen NOTE: when window is first created its invalid and must be drawn to screen( invoked first by UpdateWindow )
return 0; // WM_PAINT process almost alost begins with a call to BeginPaint() and ends with a call to EndPaint()
case WM_COMMAND:
switch (LOWORD(wParam))
{
case 0:
if (HIWORD(wParam) == BN_CLICKED)
{
MessageBox( hwnd, TEXT("ERROR"), TEXT("tada"), MB_OK);
}
}
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd, iMsg, wParam, lParam); // pass messages we don't handle back to windows for default handling/processing
}



Upon application execution the main window is created in which 9 buttons are created and placed onto the parent window. Im wanting my WM_COMMAND to process a button click and produce a messagebox. For some reason it's not showing the message box even when the messagebox line is being executed. Anyone have any ideas on what im doing wrong?

Share this post


Link to post
Share on other sites
Advertisement
Just wondering, why are you returning 0 on WM_PAINT? If you don't process it you should send it to DefWindowProc.

Share this post


Link to post
Share on other sites
Actually that should show as far as I can see. However bbr125 has got it right, if you return 0 on WM_PAINT make sure to have validated the client area (by either calling BeginPaint/EndPaint or ValidateRect), or pass the message on to DefWindowProc.

It might be that you get swamped by WM_PAINT messages.

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!