Reputation: 15
I have an application in win32 that has a top menu in its main window, this menu has 2 options with submenus in each.
The problem is..after some clicks on its options it suddenly freezes. The rest of the application keeps responding normally, but when i click on the menu options, the buttons go down like pressed and the submenus just doesnt appear, and i need to restart the application or it wont work anymore.
I thik it is something related to memory allocation, maybe i need to free some allocation, but since im new to this kind of programming, i can say just looking at it.
Some code..i think its in the window procedure where i manipulate the WM_COMMAND that theres something wrong:
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
HMENU hMenubar = CreateMenu();
HMENU hFile = CreateMenu();
HMENU hEDIT = CreateMenu();
HMENU hHelp = CreateMenu();
switch (message)
{
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
case ID_FILE_DIALOG2:
DialogBox(hInst, MAKEINTRESOURCE(IDD_DIALOG2), hWnd, Add);
break;
case ID_FILE_TESTE:
Check();
break;
case ID_FILE_DIALOG1:
DialogBox(hInst, MAKEINTRESOURCE(IDD_DIALOG1), hWnd, Conf);
break;
case ID_OPEN:
Open();
break;
case IDM_ABOUT:
DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
break;
case IDM_EXIT:
DestroyWindow(hWnd);
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_PAINT:
break;
case WM_CLOSE:
DestroyWindow(hWnd);
PostQuitMessage(0);
break;
case WM_DESTROY:
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
Upvotes: 0
Views: 185
Reputation: 9278
You are probably running out of handles as you're creating the menus each time WndProc is called. This function gets called a lot!
Create the menus once during the app initialisation.
Upvotes: 5