-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainWnd.c
102 lines (88 loc) · 2.26 KB
/
MainWnd.c
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
#include <windows.h>
#include "AboutDlg.h"
#include "Globals.h"
#include "MainWnd.h"
#include "Resource.h"
/* Main window class and title */
static char MainWndClass[] = "Windows 1 Example Application";
/* Window procedure for our main window */
LONG FAR PASCAL MainWndProc(hWnd, msg, wParam, lParam)
HWND hWnd;
unsigned msg;
WORD wParam;
LONG lParam;
{
switch (msg)
{
case WM_COMMAND:
{
WORD id = wParam;
switch (id)
{
case ID_HELP_ABOUT:
{
ShowAboutDialog(hWnd);
return 0;
}
case ID_FILE_EXIT:
{
DestroyWindow(hWnd);
return 0;
}
}
break;
}
/* Item from system menu has been invoked */
case WM_SYSCOMMAND:
{
WORD id = wParam;
switch (id)
{
/* Show "about" dialog on about system menu item */
case ID_HELP_ABOUT:
{
ShowAboutDialog(hWnd);
return 0;
}
}
break;
}
case WM_DESTROY:
{
PostQuitMessage(0);
return 0;
}
}
return DefWindowProc(hWnd, msg, wParam, lParam);
}
/* Register a class for our main window */
BOOL RegisterMainWindowClass()
{
WNDCLASS wc;
/* Class for our main window */
wc.style = 0;
wc.lpfnWndProc = MainWndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = g_hInstance;
wc.hIcon = LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_APPICON));
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wc.lpszMenuName = MAKEINTRESOURCE(IDR_MAINMENU);
wc.lpszClassName = MainWndClass;
return (RegisterClass(&wc)) ? TRUE : FALSE;
}
/* Create an instance of our main window */
HWND CreateMainWindow()
{
/* Create instance of main window */
HWND hWnd = CreateWindow(MainWndClass, MainWndClass, WS_TILEDWINDOW, 0, 0, 320, 200, NULL, NULL, g_hInstance, NULL);
if (hWnd)
{
/* Add "about" to the system menu */
HMENU hSysMenu = GetSystemMenu(hWnd, FALSE);
ChangeMenu(hSysMenu, 0, NULL, 999, MF_APPEND | MF_SEPARATOR);
ChangeMenu(hSysMenu, 0, "About", ID_HELP_ABOUT, MF_APPEND | MF_STRING);
}
return hWnd;
}