-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainWnd.c
108 lines (92 loc) · 2.53 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
103
104
105
106
107
108
#include "AboutDlg.h"
#include "Globals.h"
#include "MainWnd.h"
#include "Resource.h"
/* Main window class and title */
static LPCTSTR MainWndClass = TEXT("Win32s Example Application");
/* Window procedure for our main window */
LRESULT CALLBACK MainWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg)
{
case WM_COMMAND:
{
WORD id = LOWORD(wParam);
switch (id)
{
case ID_HELP_ABOUT:
{
ShowAboutDialog(hWnd);
return 0;
}
case ID_FILE_EXIT:
{
DestroyWindow(hWnd);
return 0;
}
}
break;
}
case WM_GETMINMAXINFO:
{
/* Prevent our window from being sized too small */
MINMAXINFO *minMax = (MINMAXINFO*)lParam;
minMax->ptMinTrackSize.x = 220;
minMax->ptMinTrackSize.y = 110;
return 0;
}
/* Item from system menu has been invoked */
case WM_SYSCOMMAND:
{
WORD id = LOWORD(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_BTNFACE + 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 = CreateWindowEx(0, MainWndClass, MainWndClass, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 320, 200,
NULL, NULL, g_hInstance, NULL);
if (hWnd)
{
/* Add "about" to the system menu */
HMENU hSysMenu = GetSystemMenu(hWnd, FALSE);
InsertMenu(hSysMenu, 5, MF_BYPOSITION | MF_SEPARATOR, 0, NULL);
InsertMenu(hSysMenu, 6, MF_BYPOSITION, ID_HELP_ABOUT, TEXT("About"));
}
return hWnd;
}