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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
|
#define WIN32_LEAN_AND_MEAN
#define STRICT
#include <windows.h>
#include "resources.h"
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR lpCmdLine, int nShowCmd)
{
UNREFERENCED_PARAMETER(lpCmdLine);
const TCHAR szWinClass[] = TEXT("Menu Accelerators");
const TCHAR szAppTitle[] = TEXT("Using Menus with Accelerators");
BOOL bReturn;
HWND hwnd;
MSG msg;
WNDCLASSEX wc;
// a handle to an accelerator table
HACCEL hAccel;
wc.cbSize = sizeof(WNDCLASSEX);
wc.hInstance = hInstance;
wc.lpszClassName = szWinClass;
wc.lpfnWndProc = WndProc;
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.hIcon = (HICON) LoadImage(NULL, IDI_APPLICATION, IMAGE_ICON, 0, 0, LR_SHARED);
wc.hIconSm = NULL;
wc.hCursor = (HCURSOR) LoadImage(NULL, IDC_ARROW, IMAGE_CURSOR, 0, 0, LR_SHARED);
wc.lpszMenuName = TEXT("TheMenu");
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
if (0 == RegisterClassEx(&wc))
{
MessageBox(NULL, TEXT("Couldn't Register the Window Class!"), TEXT("ERROR"), MB_OK | MB_ICONERROR);
return FALSE;
}
hwnd = CreateWindow(szWinClass, szAppTitle, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, NULL);
if (NULL == hwnd)
{
MessageBox(NULL, TEXT("Couldn't Create the Main Window!"), TEXT("ERROR"), MB_OK | MB_ICONERROR);
return FALSE;
}
// load the accelerator resources in the accelerator table
hAccel = LoadAccelerators(hInstance, TEXT("TheAccels"));
ShowWindow(hwnd, nShowCmd);
UpdateWindow(hwnd);
while ((bReturn = GetMessage(&msg, NULL, 0, 0) != 0) && bReturn != -1)
{
// determine if the message is an accelerator command
// if not process the message as normal
if (TranslateAccelerator(hwnd, hAccel, &msg) == 0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return (int) msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message)
{
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDM_EXIT:
PostMessage(hwnd, WM_CLOSE, wParam, lParam);
return 0;
case IDM_HELP:
MessageBox(hwnd, TEXT("Using Menus with Accelerators"), TEXT("About...."), MB_OK);
return 0;
case IDM_ALPHA:
MessageBox(hwnd, TEXT("Alpha"), TEXT("Alpha"), MB_OK);
return 0;
case IDM_BETA:
MessageBox(hwnd, TEXT("Beta"), TEXT("Beta"), MB_OK);
return 0;
case IDM_GAMMA:
MessageBox(hwnd, TEXT("Gamma"), TEXT("Gamma"), MB_OK);
return 0;
case IDM_EPSILON:
MessageBox(hwnd, TEXT("Epsilon"), TEXT("Epsilon"), MB_OK);
return 0;
case IDM_ZETA:
MessageBox(hwnd, TEXT("Zeta"), TEXT("Zeta"), MB_OK);
return 0;
case IDM_ETA:
MessageBox(hwnd, TEXT("Eta"), TEXT("Eta"), MB_OK);
return 0;
case IDM_THETA:
MessageBox(hwnd, TEXT("Theta"), TEXT("Theta"), MB_OK);
return 0;
}
break;
case WM_CLOSE:
if (MessageBox(hwnd, TEXT("Quit the Program?"), TEXT("Exit"), MB_ICONQUESTION | MB_YESNO) == IDYES)
{
DestroyWindow(hwnd);
}
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd, message, wParam, lParam);
}
|