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
|
#include "resource.h"
#include <windows.h>
const char CName[]="myClass";
BOOL CALLBACK OptimizeDlgProc (HWND hwnd, UINT msg, WPARAM wParam,LPARAM lParam){
switch (msg){
case WM_INITDIALOG :
break;
case WM_COMMAND :
switch (LOWORD(wParam)){
case IDOK:
EndDialog (hwnd, IDOK);
break;
case IDCANCEL :
EndDialog (hwnd, IDCANCEL);
break;
}
break;
default :
return false;
}
return true;
}
LRESULT CALLBACK WndProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam){
switch (msg){
case WM_CREATE:{
HMENU hMenu, hSubMenu;
hMenu = CreateMenu ();
hSubMenu = CreatePopupMenu ();
AppendMenu (hSubMenu, MF_STRING, ID_EXIT,"E&xit");
AppendMenu (hMenu,MF_STRING|MF_POPUP, (UINT)hSubMenu, "&File");
hSubMenu = CreatePopupMenu ();
AppendMenu (hSubMenu, MF_STRING,ID_VIEW,"&View");
AppendMenu(hSubMenu, MF_STRING, ID_OPTIMIZE, "O&ptimize");
AppendMenu (hMenu,MF_STRING|MF_POPUP, (UINT)hSubMenu,"&Edit");
SetMenu(hwnd,hMenu);
}
break;
case WM_COMMAND :
switch (LOWORD (wParam)){
case ID_EXIT:
SendMessage (hwnd, WM_CLOSE, NULL,NULL);
break;
case ID_VIEW :
MessageBox (hwnd, "View your head, u might find sth there","Info", MB_OK);
break;
case ID_OPTIMIZE :
DialogBox(GetModuleHandle(NULL),MAKEINTRESOURCE(ID_DLGOPTIMIZE),hwnd,OptimizeDlgProc);
break;
}
break;
case WM_CLOSE:
PostQuitMessage (0);
break;
case WM_DESTROY :
DestroyWindow (hwnd);
break;
default :
break;
}
return DefWindowProc (hwnd, msg, wParam, lParam);
}
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow){
HWND hwnd;
WNDCLASSEX wc;
MSG msg;
wc.cbSize = sizeof (WNDCLASSEX);
wc.style = 0;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hCursor = LoadCursor (NULL,IDC_ARROW);
wc.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wc.lpszClassName = CName;
wc.lpszMenuName = NULL;
wc.hbrBackground = (HBRUSH) (COLOR_WINDOW+1);
wc.hIconSm = NULL;
hwnd = CreateWindowEx (WS_EX_CLIENTEDGE,
CName,
"Program",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,CW_USEDEFAULT,
400,400, NULL,NULL,
hInstance, NULL);
if (hwnd == NULL){
MessageBox (hwnd, "Window creation failed!","Error", MB_OK|MB_ICONWARNING);
return 1;
}
ShowWindow (hwnd, nCmdShow);
UpdateWindow (hwnd);
while (GetMessage(&msg,hwnd, NULL,NULL)>0){
TranslateMessage (&msg);
DispatchMessage (&msg);
}
return msg.wParam;
}
|