Hello, I'm trying to learn how to create Windows applications using the WIN32 API. To do this, I go through The Forgers Tutorial on this. I was stuck trying to open my first dialog when I clicked on a menu item. I checked the MSDN website and looked at the documentation for all the relevant functions in my code and everything that makes APREARS right for me. But, of course, I donβt know, because Iβm just studying, I wonder if anyone can point out my mistake or maybe point me in the direction of what I might lack in the documentation. I'm sure this is something really dumb (as is always the case with these things) anyway here is my little script. Hope any of you can help. thank
#include <windows.h>
#include "resource.h"
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
BOOL CALLBACK AboutDlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
char szClassName[ ] = "WindowsApp";
int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nFunsterStil)
{
HWND hwnd;
MSG messages;
WNDCLASSEX wincl;
wincl.hInstance = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure;
wincl.style = CS_DBLCLKS;
wincl.cbSize = sizeof (WNDCLASSEX);
wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL;
wincl.cbClsExtra = 0;
wincl.cbWndExtra = 0;
wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
if (!RegisterClassEx (&wincl))
return 0;
hwnd = CreateWindowEx (
0,
szClassName,
"Windows App",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
544,
375,
HWND_DESKTOP,
NULL,
hThisInstance,
NULL
);
ShowWindow (hwnd, nFunsterStil);
while (GetMessage (&messages, NULL, 0, 0))
{
TranslateMessage(&messages);
DispatchMessage(&messages);
}
return messages.wParam;
}
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_CREATE:
{
HMENU hMenu, hSubMenu, hOtherMenu, hOtherSubMenu;
hMenu = CreateMenu();
hSubMenu = CreatePopupMenu();
hOtherMenu = CreateMenu();
hOtherSubMenu = CreatePopupMenu();
AppendMenu(hSubMenu, MF_STRING, ID_FILE_EXIT, "E&xit");
AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, "&File");
AppendMenu(hSubMenu, MF_STRING, ID_STUFF, "S&tuff");
AppendMenu(hOtherSubMenu, MF_STRING,ID_OTHER_SUB, "O&ther");
AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hOtherSubMenu, "&Other");
SetMenu(hwnd, hMenu);
}
break;
case WM_LBUTTONDOWN:
MessageBox(hwnd, "this is my program", "program box", 0);
break;
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage (0);
break;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case ID_STUFF:
DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_ABOUT), hwnd, AboutDlgProc);
break;
case ID_FILE_EXIT:
PostQuitMessage(0);
break;
}
default:
return DefWindowProc (hwnd, message, wParam, lParam);
}
return 0;
}
BOOL CALLBACK AboutDlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam){
switch(message)
{
case WM_INITDIALOG:
return TRUE;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDOK:
EndDialog(hwnd, IDOK);
break;
case IDCANCEL:
EndDialog(hwnd, IDCANCEL);
break;
}
break;
default:
return FALSE;
}
return TRUE;
}
this is .rc
IDR_MYMENU MENU
BEGIN
POPUP "F&ile"
BEGIN
MENUITEM "E&xit", ID_FILE_EXIT
MENUITEM "stuff I like", ID_STUFF
END
END
IDD_ABOUT DIALOG DISCARDABLE 0,0,239,66
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "About Box"
FONT 8, "MS Sans Serif"
BEGIN
DEFPUSHBUTTON "&ok", IDOK, 174,18,50,14
PUSHBUTTON "&Cancel", IDCANCEL, 174,18,50,14
GROUPBOX "About this program...",IDC_STATIC,7,7,225,52
CTEXT "This is a Modular Database program", IDC_STATIC, 16,18,144,33
END
and this is the title for .rc
#define IDR_MYMENU 101
#define ID_FILE_EXIT 4001
#define ID_STUFF 4002
#define IDC_STATIC -1
#define IDD_ABOUT 102
#define ID_OTHER_SUB 4003
P.S. , , , , . !