c9bfd2e848fafbcbe8ce3819fadfed18556b28da
[reactos.git] / rosapps / regedt32 / regedt32.cpp
1 /*
2 * ReactOS regedt32
3 *
4 * regedt32.cpp
5 *
6 * Copyright (C) 2002 Robert Dickenson <robd@reactos.org>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23 #include "stdafx.h"
24 #include "resource.h"
25 #include <shellapi.h>
26 //#include <winspool.h>
27
28 #define MAX_LOADSTRING 100
29
30 // Global Variables:
31 HWND hMainWnd;
32 HINSTANCE hInst; // current instance
33 TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
34 TCHAR szWindowClass[MAX_LOADSTRING]; // The title bar text
35 TCHAR szFrameClass[MAX_LOADSTRING]; // The title bar text
36
37 // Foward declarations of functions included in this code module:
38 ATOM MyRegisterClass(HINSTANCE hInstance);
39 ATOM MyRegisterClass2(HINSTANCE hInstance);
40 BOOL InitInstance(HINSTANCE, int);
41 LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
42 LRESULT CALLBACK FrameWndProc(HWND, UINT, WPARAM, LPARAM);
43 LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM);
44
45 int APIENTRY WinMain(HINSTANCE hInstance,
46 HINSTANCE hPrevInstance,
47 LPSTR lpCmdLine,
48 int nCmdShow)
49 {
50 // TODO: Place code here.
51 MSG msg;
52 HACCEL hAccelTable;
53
54 // Initialize global strings
55 LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
56 LoadString(hInstance, IDC_REGEDT32, szWindowClass, MAX_LOADSTRING);
57 LoadString(hInstance, IDC_REGEDT32_FRAME, szFrameClass, MAX_LOADSTRING);
58
59 MyRegisterClass(hInstance);
60 MyRegisterClass2(hInstance);
61
62 // Perform application initialization:
63 if (!InitInstance (hInstance, nCmdShow))
64 {
65 return FALSE;
66 }
67
68 hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_REGEDT32);
69
70 // Main message loop:
71 while (GetMessage(&msg, NULL, 0, 0))
72 {
73 if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
74 {
75 TranslateMessage(&msg);
76 DispatchMessage(&msg);
77 }
78 }
79
80 return msg.wParam;
81 }
82
83
84
85 //
86 // FUNCTION: MyRegisterClass()
87 //
88 // PURPOSE: Registers the window class.
89 //
90 // COMMENTS:
91 //
92 // This function and its usage is only necessary if you want this code
93 // to be compatible with Win32 systems prior to the 'RegisterClassEx'
94 // function that was added to Windows 95. It is important to call this function
95 // so that the application will get 'well formed' small icons associated
96 // with it.
97 //
98 ATOM MyRegisterClass(HINSTANCE hInstance)
99 {
100 WNDCLASSEX wcex;
101
102 wcex.cbSize = sizeof(WNDCLASSEX);
103
104 wcex.style = CS_HREDRAW | CS_VREDRAW;
105 wcex.lpfnWndProc = (WNDPROC)WndProc;
106 wcex.cbClsExtra = 0;
107 wcex.cbWndExtra = 0;
108 wcex.hInstance = hInstance;
109 wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_REGEDT32);
110 wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
111 wcex.hbrBackground = (HBRUSH)SS_BLACKRECT/*(COLOR_WINDOW+1)*/;
112 // wcex.lpszMenuName = (LPCSTR)IDC_REGEDT32;
113 // wcex.lpszMenuName = (LPCSTR)IDR_REGEDIT_MENU;
114 wcex.lpszMenuName = (LPCSTR)IDR_REGEDT32_MENU;
115 wcex.lpszClassName = szWindowClass;
116 wcex.hIconSm = LoadIcon((HINSTANCE)wcex.hInstance, (LPCTSTR)IDI_SMALL);
117 return RegisterClassEx(&wcex);
118 }
119
120 ATOM MyRegisterClass2(HINSTANCE hInstance)
121 {
122 WNDCLASSEX wcex;
123
124 wcex.cbSize = sizeof(WNDCLASSEX);
125
126 wcex.style = CS_HREDRAW | CS_VREDRAW;
127 wcex.lpfnWndProc = (WNDPROC)FrameWndProc;
128 wcex.cbClsExtra = 0;
129 wcex.cbWndExtra = 0;
130 wcex.hInstance = hInstance;
131 wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_REGEDT32);
132 wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
133 wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
134 wcex.lpszMenuName = (LPCSTR)IDR_REGEDIT_MENU;
135 // wcex.lpszMenuName = (LPCSTR)IDR_REGEDT32_MENU;
136 wcex.lpszClassName = szFrameClass;
137 wcex.hIconSm = LoadIcon((HINSTANCE)wcex.hInstance, (LPCTSTR)IDI_SMALL);
138
139 return RegisterClassEx(&wcex);
140 }
141
142 //
143 //
144 // FUNCTION: InitInstance(HANDLE, int)
145 //
146 // PURPOSE: Saves instance handle and creates main window
147 //
148 // COMMENTS:
149 //
150 // In this function, we save the instance handle in a global variable and
151 // create and display the main program window.
152 //
153 BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
154 {
155 HWND hWnd;
156
157 hInst = hInstance; // Store instance handle in our global variable
158
159 hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
160 CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
161
162 if (!hWnd)
163 {
164 return FALSE;
165 }
166 hMainWnd = hWnd;
167
168 ShowWindow(hWnd, nCmdShow);
169 UpdateWindow(hWnd);
170
171 return TRUE;
172 }
173
174
175 LRESULT CALLBACK FrameWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
176 {
177 int wmId, wmEvent;
178 PAINTSTRUCT ps;
179 HDC hdc;
180 TCHAR szHello[MAX_LOADSTRING];
181 LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING);
182
183 switch (message)
184 {
185 case WM_COMMAND:
186 wmId = LOWORD(wParam);
187 wmEvent = HIWORD(wParam);
188 // Parse the menu selections:
189 switch (wmId)
190 {
191 case IDM_ABOUT:
192 // DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
193 {
194 HICON hIcon = LoadIcon(hInst, (LPCTSTR)IDI_REGEDT32);
195 ShellAbout(hWnd, szTitle, "FrameWndProc", hIcon);
196 //if (hIcon) DestroyIcon(hIcon); // NOT REQUIRED
197 }
198 break;
199 case IDM_EXIT:
200 DestroyWindow(hWnd);
201 break;
202 default:
203 return DefWindowProc(hWnd, message, wParam, lParam);
204 }
205 break;
206 case WM_PAINT:
207 hdc = BeginPaint(hWnd, &ps);
208 // TODO: Add any drawing code here...
209 RECT rt;
210 GetClientRect(hWnd, &rt);
211 DrawText(hdc, szHello, strlen(szHello), &rt, DT_CENTER);
212 EndPaint(hWnd, &ps);
213 break;
214 case WM_DESTROY:
215 PostQuitMessage(0);
216 break;
217 default:
218 return DefWindowProc(hWnd, message, wParam, lParam);
219 }
220 return 0;
221 }
222
223
224 //
225 // FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
226 //
227 // PURPOSE: Processes messages for the main window.
228 //
229 // WM_COMMAND - process the application menu
230 // WM_PAINT - Paint the main window
231 // WM_DESTROY - post a quit message and return
232 //
233 //
234 LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
235 {
236 int wmId, wmEvent;
237 PAINTSTRUCT ps;
238 HDC hdc;
239 //TCHAR szHello[MAX_LOADSTRING];
240 //LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING);
241
242 switch (message)
243 {
244 case WM_COMMAND:
245 wmId = LOWORD(wParam);
246 wmEvent = HIWORD(wParam);
247 // Parse the menu selections:
248 switch (wmId)
249 {
250 case ID_REGISTRY_PRINTERSETUP:
251 //PRINTDLG pd;
252 //PrintDlg(&pd);
253 //PAGESETUPDLG psd;
254 //PageSetupDlg(&psd);
255 break;
256 case ID_REGISTRY_OPENLOCAL:
257 {
258 HWND hChildWnd;
259 // hChildWnd = CreateWindow(szFrameClass, szTitle, WS_OVERLAPPEDWINDOW | WS_CHILD,
260 // CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, hWnd, NULL, hInst, NULL);
261 hChildWnd = CreateWindow(szFrameClass, szTitle, WS_OVERLAPPEDWINDOW | WS_CHILD,
262 0, 0, 150, 170, hWnd, NULL, hInst, NULL);
263 if (hChildWnd) {
264 ShowWindow(hChildWnd, 1);
265 UpdateWindow(hChildWnd);
266 }
267 }
268 break;
269 case IDM_ABOUT:
270 // DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
271 {
272 HICON hIcon = LoadIcon(hInst, (LPCTSTR)IDI_REGEDT32);
273 ShellAbout(hWnd, szTitle, "", hIcon);
274 //if (hIcon) DestroyIcon(hIcon); // NOT REQUIRED
275 }
276 break;
277 case IDM_EXIT:
278 DestroyWindow(hWnd);
279 break;
280 default:
281 return DefWindowProc(hWnd, message, wParam, lParam);
282 }
283 break;
284 case WM_PAINT:
285 hdc = BeginPaint(hWnd, &ps);
286 // TODO: Add any drawing code here...
287 RECT rt;
288 GetClientRect(hWnd, &rt);
289 //DrawText(hdc, szHello, strlen(szHello), &rt, DT_CENTER);
290 EndPaint(hWnd, &ps);
291 break;
292 case WM_DESTROY:
293 PostQuitMessage(0);
294 break;
295 default:
296 return DefWindowProc(hWnd, message, wParam, lParam);
297 }
298 return 0;
299 }
300
301 // Mesage handler for about box.
302 LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
303 {
304 switch (message)
305 {
306 case WM_INITDIALOG:
307 return TRUE;
308
309 case WM_COMMAND:
310 if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
311 {
312 EndDialog(hDlg, LOWORD(wParam));
313 return TRUE;
314 }
315 break;
316 }
317 return FALSE;
318 }