#include <windows.h>
#include "resource.h"
const char g_szClassName[] = "myWindowClass";
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
// *******
static HMENU hMenu = {0};
static HMENU hSubMenu1 = {0};
static HMENU hSubMenu2 = {0};
// *******
switch(msg) {
case WM_LBUTTONDOWN: {
char szFileName[MAX_PATH];
HINSTANCE hInstance = GetModuleHandle(NULL);
GetModuleFileName(hInstance, szFileName, MAX_PATH);
MessageBox(hwnd, szFileName, "This program is:", MB_OK | MB_ICONINFORMATION);
}
break;
// **************
case WM_CREATE:
hMenu = CreateMenu();
hSubMenu1 = CreatePopupMenu();
hSubMenu2 = CreatePopupMenu();
AppendMenu(hSubMenu1,MF_STRING,ID_FILE_EXIT,"Exit");
AppendMenu(hMenu,MF_STRING|MF_POPUP,(UINT_PTR)hSubMenu1,"File");
AppendMenu(hSubMenu2,MF_STRING,ID_STUFF_GO,"Go");
AppendMenu(hSubMenu2,MF_STRING,ID_STUFF_SOMEWHERE_ELSE,"Somewhere else");
AppendMenu(hMenu,MF_STRING|MF_POPUP,(UINT_PTR)hSubMenu2,"Stuff");
SetMenu(hwnd,hMenu);
break;
case WM_COMMAND:
{
switch(LOWORD(wParam))
{
case ID_FILE_EXIT:
PostMessage(hwnd,WM_CLOSE,0,0);
break;
case ID_STUFF_GO:
// geh irgendwo hin
break;
case ID_STUFF_SOMEWHERE_ELSE:
// geh woanders hin
break;
}
}
break;
// *************
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
WNDCLASSEX wc;
HWND hwnd;
MSG Msg;
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = 0;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_MYICON));
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wc.lpszMenuName = NULL;
wc.lpszClassName = g_szClassName;
wc.hIconSm = (HICON)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_MYICON), IMAGE_ICON, 16, 16, 0);
if(!RegisterClassEx(&wc)) {
MessageBox(NULL, "ERROR!", "Error", MB_ICONEXCLAMATION | MB_OK);
return 0;
}
hwnd = CreateWindowEx(WS_EX_CLIENTEDGE, g_szClassName, "TITEL", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 240, 120, NULL, NULL, hInstance, NULL);
if(hwnd == NULL) {
MessageBox(NULL, "ERROR!", "Error", MB_ICONEXCLAMATION | MB_OK);
return 0;
}
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
while(GetMessage(&Msg, NULL, 0, 0) > 0) {
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}