Original Post
Hey everyone, I'm using Code::Blocks c++ compiler, and I'm making a simple windows app with 2 buttons - OK and Cancel. The buttons show up and display their text, but when I go to the message handler (fnWndProc), the code I use to handle the message doesn't work for some reason. I don't know how to get my source code to show up in the window thingy, so I'll do the best I can... #include #include #define IDC_BTNOK 200 // The ok button #define IDC_BTNCANCEL 201 // The cancel button LRESULT CALLBACK fnWindowProcedure(HWND, UINT, LPARAM, WPARAM); char szAppName[] = "Experiment"; HINSTANCE g_hInstance; HWND g_hOk, g_hCancel = NULL; int WINAPI WinMain(HINSTANCE g_hInstance, HINSTANCE hPrevInstance, LPSTR szCmdLine, int iCmdShow){ WNDCLASSEX wcx; HWND g_hWnd; HMENU g_hMenu; MSG iMsg; wcx.cbSize = sizeof(wcx); wcx.style = CS_DBLCLKS | CS_VREDRAW | CS_HREDRAW; wcx.lpfnWndProc = (WNDPROC)fnWindowProcedure; wcx.cbClsExtra = 0; wcx.cbWndExtra = 0; wcx.hInstance = g_hInstance; wcx.hIcon = LoadIcon(NULL, IDI_APPLICATION); wcx.hIconSm = LoadIcon(NULL, IDI_APPLICATION); wcx.hCursor = LoadCursor(NULL, IDI_APPLICATION); wcx.hbrBackground = (HBRUSH)GetStockObject(LTGRAY_BRUSH); wcx.lpszMenuName = NULL; wcx.lpszClassName = szAppName; if(!RegisterClassEx(&wcx)){ MessageBox(g_hWnd, "Fatal Error! Could not register window!", "ERROR!", MB_OK); } g_hWnd = CreateWindow( szAppName, "Experimental Application", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 640, 480, NULL, NULL, g_hInstance, NULL); g_hOk = CreateWindow( // Create the ok button "BUTTON", "OK", WS_VISIBLE | BS_PUSHBUTTON | WS_CHILD, 445, 395, 80, 25, g_hWnd, (HMENU)IDC_BTNOK, g_hInstance, NULL); g_hCancel = CreateWindow( // Create the cancel button "BUTTON", "Cancel", WS_VISIBLE | BS_PUSHBUTTON | WS_CHILD, 535, 395, 80, 25, g_hWnd, (HMENU)IDC_BTNCANCEL, g_hInstance, NULL); ShowWindow(g_hWnd, iCmdShow); UpdateWindow(g_hWnd); while(TRUE){ if(PeekMessage(&iMsg, NULL, 0, 0, PM_NOREMOVE)){ if(!GetMessage(&iMsg, NULL, 0, 0)) break; TranslateMessage(&iMsg); DispatchMessage(&iMsg); } } return(iMsg.wParam); } LRESULT CALLBACK fnWindowProcedure(HWND g_hWnd, UINT iMsg, LPARAM lParam, WPARAM wParam){ switch(iMsg){ case WM_COMMAND: switch(LOWORD(wParam)){ case IDC_BTNCANCEL: // where the cancel button messages go MessageBox(g_hWnd, "Cancel Button Clicked", "Cancel", MB_OK); break; } break; case WM_DESTROY: PostQuitMessage(0); return 0; case WM_CLOSE: DestroyWindow(g_hWnd); return 0; default: return DefWindowProc(g_hWnd, iMsg, lParam, wParam); } return 0; } A message box should show up when the cancel button is clicked, but nothing happens. I've tried everything I can think of to fix the problem, with no success. Any help would be appreciated. Thanks!