1 |
// ijc.cpp : Defines the entry point for the application. |
2 |
// |
3 |
|
4 |
#include <windows.h> |
5 |
|
6 |
#include "resource.h" |
7 |
|
8 |
#define MAX_LOADSTRING 100 |
9 |
|
10 |
// Global Variables: |
11 |
HINSTANCE hInst; // current instance |
12 |
TCHAR szTitle[MAX_LOADSTRING]; // The title bar text |
13 |
TCHAR szWindowClass[MAX_LOADSTRING]; // The title bar text |
14 |
|
15 |
// Foward declarations of functions included in this code module: |
16 |
ATOM MyRegisterClass(HINSTANCE hInstance); |
17 |
BOOL InitInstance(HINSTANCE, int); |
18 |
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); |
19 |
LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM); |
20 |
|
21 |
#if 0 |
22 |
|
23 |
int APIENTRY WinMain(HINSTANCE hInstance, |
24 |
HINSTANCE hPrevInstance, |
25 |
LPSTR lpCmdLine, |
26 |
int nCmdShow) |
27 |
{ |
28 |
// TODO: Place code here. |
29 |
MSG msg; |
30 |
HACCEL hAccelTable; |
31 |
|
32 |
// Initialize global strings |
33 |
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); |
34 |
LoadString(hInstance, IDC_IJC, szWindowClass, MAX_LOADSTRING); |
35 |
MyRegisterClass(hInstance); |
36 |
|
37 |
// Perform application initialization: |
38 |
if (!InitInstance (hInstance, nCmdShow)) |
39 |
{ |
40 |
return FALSE; |
41 |
} |
42 |
|
43 |
hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_IJC); |
44 |
|
45 |
// Main message loop: |
46 |
while (GetMessage(&msg, NULL, 0, 0)) |
47 |
{ |
48 |
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) |
49 |
{ |
50 |
TranslateMessage(&msg); |
51 |
DispatchMessage(&msg); |
52 |
} |
53 |
} |
54 |
|
55 |
return msg.wParam; |
56 |
} |
57 |
#endif |
58 |
|
59 |
|
60 |
// |
61 |
// FUNCTION: MyRegisterClass() |
62 |
// |
63 |
// PURPOSE: Registers the window class. |
64 |
// |
65 |
// COMMENTS: |
66 |
// |
67 |
// This function and its usage is only necessary if you want this code |
68 |
// to be compatible with Win32 systems prior to the 'RegisterClassEx' |
69 |
// function that was added to Windows 95. It is important to call this function |
70 |
// so that the application will get 'well formed' small icons associated |
71 |
// with it. |
72 |
// |
73 |
ATOM MyRegisterClass(HINSTANCE hInstance) |
74 |
{ |
75 |
WNDCLASSEX wcex; |
76 |
|
77 |
wcex.cbSize = sizeof(WNDCLASSEX); |
78 |
|
79 |
wcex.style = CS_HREDRAW | CS_VREDRAW; |
80 |
wcex.lpfnWndProc = (WNDPROC)WndProc; |
81 |
wcex.cbClsExtra = 0; |
82 |
wcex.cbWndExtra = 0; |
83 |
wcex.hInstance = hInstance; |
84 |
wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_EGC); |
85 |
wcex.hCursor = LoadCursor(NULL, IDC_ARROW); |
86 |
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); |
87 |
wcex.lpszMenuName = (LPCSTR)IDC_EGC; |
88 |
wcex.lpszClassName = szWindowClass; |
89 |
wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL); |
90 |
|
91 |
return RegisterClassEx(&wcex); |
92 |
} |
93 |
|
94 |
|
95 |
// |
96 |
// FUNCTION: InitInstance(HANDLE, int) |
97 |
// |
98 |
// PURPOSE: Saves instance handle and creates main window |
99 |
// |
100 |
// COMMENTS: |
101 |
// |
102 |
// In this function, we save the instance handle in a global variable and |
103 |
// create and display the main program window. |
104 |
// |
105 |
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) |
106 |
{ |
107 |
HWND hWnd; |
108 |
|
109 |
hInst = hInstance; // Store instance handle in our global variable |
110 |
|
111 |
hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW, |
112 |
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL); |
113 |
|
114 |
if (!hWnd) |
115 |
{ |
116 |
return FALSE; |
117 |
} |
118 |
|
119 |
ShowWindow(hWnd, nCmdShow); |
120 |
UpdateWindow(hWnd); |
121 |
|
122 |
return TRUE; |
123 |
} |
124 |
|
125 |
// |
126 |
// FUNCTION: WndProc(HWND, unsigned, WORD, LONG) |
127 |
// |
128 |
// PURPOSE: Processes messages for the main window. |
129 |
// |
130 |
// WM_COMMAND - process the application menu |
131 |
// WM_PAINT - Paint the main window |
132 |
// WM_DESTROY - post a quit message and return |
133 |
// |
134 |
// |
135 |
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) |
136 |
{ |
137 |
int wmId, wmEvent; |
138 |
PAINTSTRUCT ps; |
139 |
HDC hdc; |
140 |
TCHAR szHello[MAX_LOADSTRING]; |
141 |
LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING); |
142 |
|
143 |
switch (message) |
144 |
{ |
145 |
case WM_COMMAND: |
146 |
wmId = LOWORD(wParam); |
147 |
wmEvent = HIWORD(wParam); |
148 |
// Parse the menu selections: |
149 |
switch (wmId) |
150 |
{ |
151 |
case IDM_ABOUT: |
152 |
DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About); |
153 |
break; |
154 |
case IDM_EXIT: |
155 |
DestroyWindow(hWnd); |
156 |
break; |
157 |
default: |
158 |
return DefWindowProc(hWnd, message, wParam, lParam); |
159 |
} |
160 |
break; |
161 |
case WM_PAINT: |
162 |
hdc = BeginPaint(hWnd, &ps); |
163 |
// TODO: Add any drawing code here... |
164 |
RECT rt; |
165 |
GetClientRect(hWnd, &rt); |
166 |
DrawText(hdc, szHello, strlen(szHello), &rt, DT_CENTER); |
167 |
EndPaint(hWnd, &ps); |
168 |
break; |
169 |
case WM_DESTROY: |
170 |
PostQuitMessage(0); |
171 |
break; |
172 |
default: |
173 |
return DefWindowProc(hWnd, message, wParam, lParam); |
174 |
} |
175 |
return 0; |
176 |
} |
177 |
|
178 |
// Mesage handler for about box. |
179 |
LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) |
180 |
{ |
181 |
switch (message) |
182 |
{ |
183 |
case WM_INITDIALOG: |
184 |
return TRUE; |
185 |
|
186 |
case WM_COMMAND: |
187 |
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) |
188 |
{ |
189 |
EndDialog(hDlg, LOWORD(wParam)); |
190 |
return TRUE; |
191 |
} |
192 |
break; |
193 |
} |
194 |
return FALSE; |
195 |
} |