Minor updates, added status bar support from TaskMgr.
[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 #ifdef _MSC_VER
24 #include "stdafx.h"
25 #else
26 #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
27 #include <windows.h>
28 #include <commctrl.h>
29 #include <stdlib.h>
30 #include <malloc.h>
31 #include <memory.h>
32 #include <tchar.h>
33 #include <process.h>
34 #include <stdio.h>
35 #endif
36
37 #include "resource.h"
38 #include <shellapi.h>
39 //#include <winspool.h>
40
41 #define STATUS_WINDOW 2001
42 #define MAX_LOADSTRING 100
43
44 // Global Variables:
45 HINSTANCE hInst; // current instance
46
47 HWND hMainWnd; // Main Window
48 HWND hStatusWnd; // Status Bar Window
49 HWND hTabWnd; // Tab Control Window
50
51 int nMinimumWidth; // Minimum width of the dialog (OnSize()'s cx)
52 int nMinimumHeight; // Minimum height of the dialog (OnSize()'s cy)
53
54 int nOldWidth; // Holds the previous client area width
55 int nOldHeight; // Holds the previous client area height
56
57 BOOL bInMenuLoop = FALSE; // Tells us if we are in the menu loop
58
59 TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
60 TCHAR szWindowClass[MAX_LOADSTRING]; // The title bar text
61 TCHAR szFrameClass[MAX_LOADSTRING]; // The title bar text
62
63 // Foward declarations of functions included in this code module:
64 ATOM MyRegisterClass(HINSTANCE hInstance);
65 ATOM MyRegisterClass2(HINSTANCE hInstance);
66 BOOL InitInstance(HINSTANCE, int);
67 LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
68 LRESULT CALLBACK FrameWndProc(HWND, UINT, WPARAM, LPARAM);
69 LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM);
70
71 int APIENTRY WinMain(HINSTANCE hInstance,
72 HINSTANCE hPrevInstance,
73 LPSTR lpCmdLine,
74 int nCmdShow)
75 {
76 MSG msg;
77 HACCEL hAccelTable;
78
79 // Initialize global strings
80 LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
81 LoadString(hInstance, IDC_REGEDT32, szWindowClass, MAX_LOADSTRING);
82 LoadString(hInstance, IDC_REGEDT32_FRAME, szFrameClass, MAX_LOADSTRING);
83
84 MyRegisterClass(hInstance);
85 MyRegisterClass2(hInstance);
86
87 // Perform application initialization:
88 if (!InitInstance(hInstance, nCmdShow)) {
89 return FALSE;
90 }
91 hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_REGEDT32);
92
93 // Main message loop:
94 while (GetMessage(&msg, NULL, 0, 0)) {
95 if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) {
96 TranslateMessage(&msg);
97 DispatchMessage(&msg);
98 }
99 }
100 return msg.wParam;
101 }
102
103
104
105 //
106 // FUNCTION: MyRegisterClass()
107 //
108 // PURPOSE: Registers the window class.
109 //
110 // COMMENTS:
111 //
112 // This function and its usage is only necessary if you want this code
113 // to be compatible with Win32 systems prior to the 'RegisterClassEx'
114 // function that was added to Windows 95. It is important to call this function
115 // so that the application will get 'well formed' small icons associated
116 // with it.
117 //
118 ATOM MyRegisterClass(HINSTANCE hInstance)
119 {
120 WNDCLASSEX wcex;
121
122 wcex.cbSize = sizeof(WNDCLASSEX);
123 wcex.style = CS_HREDRAW | CS_VREDRAW;
124 wcex.lpfnWndProc = (WNDPROC)WndProc;
125 wcex.cbClsExtra = 0;
126 wcex.cbWndExtra = 0;
127 wcex.hInstance = hInstance;
128 wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_REGEDT32);
129 wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
130 wcex.hbrBackground = (HBRUSH)SS_BLACKRECT/*(COLOR_WINDOW+1)*/;
131 // wcex.lpszMenuName = (LPCSTR)IDC_REGEDT32;
132 // wcex.lpszMenuName = (LPCSTR)IDR_REGEDIT_MENU;
133 wcex.lpszMenuName = (LPCSTR)IDR_REGEDT32_MENU;
134 wcex.lpszClassName = szWindowClass;
135 wcex.hIconSm = LoadIcon((HINSTANCE)wcex.hInstance, (LPCTSTR)IDI_SMALL);
136 return RegisterClassEx(&wcex);
137 }
138
139 ATOM MyRegisterClass2(HINSTANCE hInstance)
140 {
141 WNDCLASSEX wcex;
142
143 wcex.cbSize = sizeof(WNDCLASSEX);
144 wcex.style = CS_HREDRAW | CS_VREDRAW;
145 wcex.lpfnWndProc = (WNDPROC)FrameWndProc;
146 wcex.cbClsExtra = 0;
147 wcex.cbWndExtra = 0;
148 wcex.hInstance = hInstance;
149 wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_REGEDT32);
150 wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
151 wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
152 wcex.lpszMenuName = (LPCSTR)IDR_REGEDIT_MENU;
153 // wcex.lpszMenuName = (LPCSTR)IDR_REGEDT32_MENU;
154 wcex.lpszClassName = szFrameClass;
155 wcex.hIconSm = LoadIcon((HINSTANCE)wcex.hInstance, (LPCTSTR)IDI_SMALL);
156 return RegisterClassEx(&wcex);
157 }
158
159 //
160 //
161 // FUNCTION: InitInstance(HANDLE, int)
162 //
163 // PURPOSE: Saves instance handle and creates main window
164 //
165 // COMMENTS:
166 //
167 // In this function, we save the instance handle in a global variable and
168 // create and display the main program window.
169 //
170 BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
171 {
172 int nParts[3];
173
174 // Initialize the Windows Common Controls DLL
175 InitCommonControls();
176
177 hInst = hInstance; // Store instance handle in our global variable
178 hMainWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
179 CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
180 if (!hMainWnd) {
181 return FALSE;
182 }
183
184 // Get the minimum window sizes
185 // GetWindowRect(hMainWnd, &rc);
186 // nMinimumWidth = (rc.right - rc.left);
187 // nMinimumHeight = (rc.bottom - rc.top);
188
189 // Create the status bar
190 hStatusWnd = CreateStatusWindow(WS_VISIBLE|WS_CHILD|WS_CLIPSIBLINGS|SBT_NOBORDERS,
191 "", hMainWnd, STATUS_WINDOW);
192 if (!hStatusWnd)
193 return FALSE;
194
195 // Create the status bar panes
196 nParts[0] = 100;
197 nParts[1] = 210;
198 nParts[2] = 400;
199 SendMessage(hStatusWnd, SB_SETPARTS, 3, (long)nParts);
200
201
202 ShowWindow(hMainWnd, nCmdShow);
203 UpdateWindow(hMainWnd);
204 return TRUE;
205 }
206
207
208 // OnSize()
209 // This function handles all the sizing events for the application
210 // It re-sizes every window, and child window that needs re-sizing
211 void OnSize(UINT nType, int cx, int cy)
212 {
213 int nParts[3];
214 int nXDifference;
215 int nYDifference;
216 RECT rc;
217
218 if (nType == SIZE_MINIMIZED)
219 return;
220
221 nXDifference = cx - nOldWidth;
222 nYDifference = cy - nOldHeight;
223 nOldWidth = cx;
224 nOldHeight = cy;
225
226 // Update the status bar size
227 GetWindowRect(hStatusWnd, &rc);
228 SendMessage(hStatusWnd, WM_SIZE, nType, MAKELPARAM(cx, cy + (rc.bottom - rc.top)));
229
230 // Update the status bar pane sizes
231 nParts[0] = bInMenuLoop ? -1 : 100;
232 nParts[1] = 210;
233 nParts[2] = cx;
234 SendMessage(hStatusWnd, SB_SETPARTS, bInMenuLoop ? 1 : 3, (long)nParts);
235 }
236
237 void OnEnterMenuLoop(HWND hWnd)
238 {
239 int nParts;
240
241 // Update the status bar pane sizes
242 nParts = -1;
243 SendMessage(hStatusWnd, SB_SETPARTS, 1, (long)&nParts);
244 bInMenuLoop = TRUE;
245 SendMessage(hStatusWnd, SB_SETTEXT, (WPARAM)0, (LPARAM)_T(""));
246 }
247
248 void OnExitMenuLoop(HWND hWnd)
249 {
250 RECT rc;
251 int nParts[3];
252 TCHAR text[260];
253
254 bInMenuLoop = FALSE;
255 // Update the status bar pane sizes
256 GetClientRect(hWnd, &rc);
257 nParts[0] = 100;
258 nParts[1] = 210;
259 nParts[2] = rc.right;
260 SendMessage(hStatusWnd, SB_SETPARTS, 3, (long)nParts);
261 SendMessage(hStatusWnd, SB_SETTEXT, 0, (LPARAM)_T(""));
262 // wsprintf(text, _T("CPU Usage: %3d%%"), PerfDataGetProcessorUsage());
263 // SendMessage(hStatusWnd, SB_SETTEXT, 1, (LPARAM)text);
264 // wsprintf(text, _T("Processes: %d"), PerfDataGetProcessCount());
265 // SendMessage(hStatusWnd, SB_SETTEXT, 0, (LPARAM)text);
266 }
267
268 void OnMenuSelect(HWND hWnd, UINT nItemID, UINT nFlags, HMENU hSysMenu)
269 {
270 TCHAR str[100];
271
272 strcpy(str, TEXT(""));
273 if (LoadString(hInst, nItemID, str, 100)) {
274 // load appropriate string
275 LPTSTR lpsz = str;
276 // first newline terminates actual string
277 lpsz = _tcschr(lpsz, '\n');
278 if (lpsz != NULL)
279 *lpsz = '\0';
280 }
281 SendMessage(hStatusWnd, SB_SETTEXT, 0, (LPARAM)str);
282 }
283
284
285 LRESULT CALLBACK FrameWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
286 {
287 int wmId, wmEvent;
288 PAINTSTRUCT ps;
289 HDC hdc;
290 TCHAR szHello[MAX_LOADSTRING];
291 LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING);
292
293 switch (message) {
294 case WM_COMMAND:
295 wmId = LOWORD(wParam);
296 wmEvent = HIWORD(wParam);
297 // Parse the menu selections:
298 switch (wmId) {
299 case IDM_ABOUT:
300 // DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
301 {
302 HICON hIcon = LoadIcon(hInst, (LPCTSTR)IDI_REGEDT32);
303 ShellAbout(hWnd, szTitle, "FrameWndProc", hIcon);
304 //if (hIcon) DestroyIcon(hIcon); // NOT REQUIRED
305 }
306 break;
307 case IDM_EXIT:
308 DestroyWindow(hWnd);
309 break;
310 default:
311 return DefWindowProc(hWnd, message, wParam, lParam);
312 }
313 break;
314 case WM_PAINT:
315 hdc = BeginPaint(hWnd, &ps);
316 // TODO: Add any drawing code here...
317 RECT rt;
318 GetClientRect(hWnd, &rt);
319 DrawText(hdc, szHello, strlen(szHello), &rt, DT_CENTER);
320 EndPaint(hWnd, &ps);
321 break;
322 case WM_DESTROY:
323 PostQuitMessage(0);
324 break;
325 default:
326 return DefWindowProc(hWnd, message, wParam, lParam);
327 }
328 return 0;
329 }
330
331
332 //
333 // FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
334 //
335 // PURPOSE: Processes messages for the main window.
336 //
337 // WM_COMMAND - process the application menu
338 // WM_PAINT - Paint the main window
339 // WM_DESTROY - post a quit message and return
340 //
341 //
342 LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
343 {
344 int wmId, wmEvent;
345 PAINTSTRUCT ps;
346 HDC hdc;
347 //TCHAR szHello[MAX_LOADSTRING];
348 //LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING);
349
350 switch (message) {
351 case WM_COMMAND:
352 wmId = LOWORD(wParam);
353 wmEvent = HIWORD(wParam);
354 // Parse the menu selections:
355 switch (wmId) {
356 case ID_REGISTRY_PRINTERSETUP:
357 //PRINTDLG pd;
358 //PrintDlg(&pd);
359 //PAGESETUPDLG psd;
360 //PageSetupDlg(&psd);
361 break;
362 case ID_REGISTRY_OPENLOCAL:
363 {
364 HWND hChildWnd;
365 // hChildWnd = CreateWindow(szFrameClass, szTitle, WS_OVERLAPPEDWINDOW | WS_CHILD,
366 // CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, hWnd, NULL, hInst, NULL);
367 hChildWnd = CreateWindow(szFrameClass, szTitle, WS_OVERLAPPEDWINDOW | WS_CHILD,
368 0, 0, 150, 170, hWnd, NULL, hInst, NULL);
369 if (hChildWnd) {
370 ShowWindow(hChildWnd, 1);
371 UpdateWindow(hChildWnd);
372 }
373 }
374 break;
375 case IDM_ABOUT:
376 // DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
377 {
378 HICON hIcon = LoadIcon(hInst, (LPCTSTR)IDI_REGEDT32);
379 ShellAbout(hWnd, szTitle, "", hIcon);
380 //if (hIcon) DestroyIcon(hIcon); // NOT REQUIRED
381 }
382 break;
383 case IDM_EXIT:
384 DestroyWindow(hWnd);
385 break;
386 default:
387 return DefWindowProc(hWnd, message, wParam, lParam);
388 }
389 break;
390 case WM_SIZE:
391 // Handle the window sizing in it's own function
392 OnSize(wParam, LOWORD(lParam), HIWORD(lParam));
393 break;
394 case WM_PAINT:
395 hdc = BeginPaint(hWnd, &ps);
396 // TODO: Add any drawing code here...
397 RECT rt;
398 GetClientRect(hWnd, &rt);
399 //DrawText(hdc, szHello, strlen(szHello), &rt, DT_CENTER);
400 EndPaint(hWnd, &ps);
401 break;
402 case WM_DESTROY:
403 PostQuitMessage(0);
404 break;
405 case WM_TIMER:
406 break;
407
408 case WM_ENTERMENULOOP:
409 OnEnterMenuLoop(hWnd);
410 break;
411 case WM_EXITMENULOOP:
412 OnExitMenuLoop(hWnd);
413 break;
414 case WM_MENUSELECT:
415 OnMenuSelect(hWnd, LOWORD(wParam), HIWORD(wParam), (HMENU)lParam);
416 break;
417 default:
418 return DefWindowProc(hWnd, message, wParam, lParam);
419 }
420 return 0;
421 }
422
423 // Mesage handler for about box.
424 LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
425 {
426 switch (message) {
427 case WM_INITDIALOG:
428 return TRUE;
429 case WM_COMMAND:
430 if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) {
431 EndDialog(hDlg, LOWORD(wParam));
432 return TRUE;
433 }
434 break;
435 }
436 return FALSE;
437 }