|
CMPT 212
Fall 1997
|
#include "menu.h"
MYMENU MENU
{
POPUP "&File"
{
MENUITEM "&Open", IDM_OPEN
MENUITEM "&Close", IDM_CLOSE
MENUITEM "&Quit", IDM_QUIT
}
POPUP "&Edit"
{
MENUITEM "Cop&y", IDM_COPY
MENUITEM "&Paste", IDM_PASTE
}
MENUITEM "&Help", IDM_HELP
}
#define IDM_OPEN 101 #define IDM_CLOSE 102 #define IDM_QUIT 103 #define IDM_COPY 104 #define IDM_PASTE 105 #define IDM_HELP 106
int WINAPI WinMain(HINSTANCE hThisInst,
HINSTANCE hPrevInst,
LPSTR lpszArgs,
int WinMode) {
...
WNDCLASS wcl;
...
wcl.lpszMenuName = "MYMENU";
...
}
#include "menu.h"
LRESULT CALLBACK WindowFunc(HWND hwnd,
UINT message,
WPARAM wParam,
LPARAM lParam) {
switch (message) {
...
case WM_COMMAND:
switch (LOWORD(wParam)) {
case IDM_OPEN:
...
break;
case IDM_CLOSE:
...
break;
case IDM_QUIT:
...
break;
case IDM_COPY:
...
break;
case IDM_PASTE:
...
break;
case IDM_HELP:
...
break;
}
...
}
return 0;
}
#include "mydialog.h"
ENTER_NAME_DIALOG DIALOG 10, 10, 150, 60
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Enter your name"
{
LTEXT "Name:", -1, 15, 15, 25, 8
EDITTEXT IDC_NAME, 50, 15, 60, 12
PUSHBUTTON "OK", IDC_OK_BUTTON, 15, 40, 50, 14
PUSHBUTTON "Cancel", IDC_CANCEL_BUTTON, 80, 40, 50, 14
}
#define IDC_NAME 101 #define IDC_OK_BUTTON 102 #define IDC_CANCEL_BUTTON 103
... DialogBox(hInst, "ENTER_NAME_DIALOG", hwnd, (DLGPROC) AddNameFunc); ...
BOOL CALLBACK AddNameFunc(HWND hwnd,
UINT message,
WPARAM wParam,
LPARAM lParam) {
const int nameLen = 80;
char name[NameLen];
switch (message) {
case WM_COMMAND:
switch (LOWORD(wParam)) {
case IDC_CANCEL_BUTTON:
EndDialog(hwnd, 0);
return 1;
case IDC_OK_BUTTON:
GetDlgItemText(hwnd, IDC_NAME, name, nameLen);
... // use "name".
EndDialog(hwnd, 0);
return 1;
}
case WM_INITDIALOG:
return 1;
}
return 0;
}
Return to lecture notes index |
|
| This page is maintained by simpson@cs.sfu.ca. | Last updated on 17 Nov 1997. |