1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
//Main.cpp
#include <windows.h>
#include <tchar.h>
#define IDR_MAIN_MENU 2000
#define IDM_FILE_OPEN 2100
#define IDM_FILE_EXIT 2105
LRESULT CALLBACK fnWndProc(HWND hwnd, unsigned int msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_CREATE:
{
HMENU hMenu = CreateMenu();
HMENU hSubMenu = CreatePopupMenu();
AppendMenu(hSubMenu, MF_STRING, IDM_FILE_OPEN, _T("&Open"));
AppendMenu(hSubMenu, MF_STRING, IDM_FILE_EXIT, _T("E&xit"));
AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, _T("&File"));
SetMenu(hwnd, hMenu);
return 0;
}
case WM_COMMAND:
{
switch(LOWORD(wParam))
{
case IDM_FILE_OPEN:
MessageBox(hwnd,_T("You Chose File >>> Open ..."),_T("Picked Up WM_COMMAND"),MB_OK);
break;
case IDM_FILE_EXIT:
MessageBox(hwnd,_T("You Chose File >>> Exit ..."),_T("Picked Up WM_COMMAND"),MB_OK);
SendMessage(hwnd,WM_CLOSE,0,0);
break;
}
return 0;
}
case WM_DESTROY:
{
PostQuitMessage(0);
return 0;
}
}
return (DefWindowProc(hwnd, msg, wParam, lParam));
}
int WINAPI WinMain(HINSTANCE hIns, HINSTANCE hPrevIns, LPSTR lpszArgument, int iShow)
{
TCHAR szClassName[]=_T("Mnu05");
WNDCLASS wc;
MSG messages;
HWND hWnd;
wc.style = 0, wc.lpfnWndProc = fnWndProc;
wc.lpszClassName = szClassName, wc.cbClsExtra = 0;
wc.cbWndExtra = 0, wc.hInstance = hIns,
wc.hIcon = NULL, wc.hCursor = LoadCursor(NULL,IDC_ARROW);
wc.hbrBackground = (HBRUSH)COLOR_BTNSHADOW, wc.lpszMenuName = NULL;
RegisterClass(&wc);
hWnd=CreateWindow(szClassName,szClassName,WS_OVERLAPPEDWINDOW,75,75,320,200,HWND_DESKTOP,0,hIns,0);
ShowWindow(hWnd,iShow);
while(GetMessage(&messages,NULL,0,0))
{
TranslateMessage(&messages);
DispatchMessage(&messages);
}
return messages.wParam;
}
|