1a7312cf8967a5ca9af2dc447cbefed045383d31
[reactos.git] / rosapps / regedt32 / framewnd.c
1 /*
2 * ReactOS regedt32
3 *
4 * framewnd.c
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 <shellapi.h>
38
39 #include "main.h"
40 #include "framewnd.h"
41
42
43 ////////////////////////////////////////////////////////////////////////////////
44 // Global Variables:
45 //
46
47 BOOL bInMenuLoop = FALSE; // Tells us if we are in the menu loop
48
49
50 ////////////////////////////////////////////////////////////////////////////////
51 // Local module support methods
52 //
53
54 ////////////////////////////////////////////////////////////////////////////////
55 static HHOOK hcbthook;
56 static ChildWnd* newchild = NULL;
57
58 LRESULT CALLBACK CBTProc(int code, WPARAM wParam, LPARAM lParam)
59 {
60 if (code == HCBT_CREATEWND && newchild) {
61 ChildWnd* pChildWnd = newchild;
62 newchild = NULL;
63 pChildWnd->hWnd = (HWND)wParam;
64 SetWindowLong(pChildWnd->hWnd, GWL_USERDATA, (LPARAM)pChildWnd);
65 }
66 return CallNextHookEx(hcbthook, code, wParam, lParam);
67 }
68
69 static HWND InitChildWindow(LPTSTR param)
70 {
71 //TCHAR drv[_MAX_DRIVE];
72 TCHAR path[MAX_PATH];
73 ChildWnd* pChildWnd = NULL;
74 pChildWnd = (ChildWnd*)malloc(sizeof(ChildWnd));
75 if (pChildWnd != NULL) {
76 MDICREATESTRUCT mcs = {
77 szChildClass, path, hInst,
78 CW_USEDEFAULT, CW_USEDEFAULT,
79 CW_USEDEFAULT, CW_USEDEFAULT,
80 0/*style*/, 0/*lParam*/
81 };
82 memset(pChildWnd, 0, sizeof(ChildWnd));
83 lstrcpy(pChildWnd->szPath, path);
84 pChildWnd->pos.length = sizeof(WINDOWPLACEMENT);
85 pChildWnd->pos.flags = 0;
86 pChildWnd->pos.showCmd = SW_SHOWNORMAL;
87 pChildWnd->pos.rcNormalPosition.left = CW_USEDEFAULT;
88 pChildWnd->pos.rcNormalPosition.top = CW_USEDEFAULT;
89 pChildWnd->pos.rcNormalPosition.right = CW_USEDEFAULT;
90 pChildWnd->pos.rcNormalPosition.bottom = CW_USEDEFAULT;
91 pChildWnd->nFocusPanel = 0;
92 pChildWnd->nSplitPos = 200;
93 hcbthook = SetWindowsHookEx(WH_CBT, CBTProc, 0, GetCurrentThreadId());
94 newchild = pChildWnd;
95 pChildWnd->hWnd = (HWND)SendMessage(hMDIClient, WM_MDICREATE, 0, (LPARAM)&mcs);
96 UnhookWindowsHookEx(hcbthook);
97 if (pChildWnd->hWnd == NULL) {
98 free(pChildWnd);
99 newchild = pChildWnd = NULL;
100 }
101 return pChildWnd->hWnd;
102 }
103 return 0;
104 }
105 BOOL CALLBACK CloseEnumProc(HWND hWnd, LPARAM lParam)
106 {
107 if (!GetWindow(hWnd, GW_OWNER)) {
108 SendMessage(GetParent(hWnd), WM_MDIRESTORE, (WPARAM)hWnd, 0);
109 if (SendMessage(hWnd, WM_QUERYENDSESSION, 0, 0)) {
110 SendMessage(GetParent(hWnd), WM_MDIDESTROY, (WPARAM)hWnd, 0);
111 }
112 }
113 return 1;
114 }
115
116 ////////////////////////////////////////////////////////////////////////////////
117 //
118 // FUNCTION: _CmdWndProc(HWND, unsigned, WORD, LONG)
119 //
120 // PURPOSE: Processes WM_COMMAND messages for the main frame window.
121 //
122 //
123
124 LRESULT _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
125 {
126 HWND hChildWnd;
127 if (1) {
128 switch (LOWORD(wParam)) {
129 case ID_WINDOW_CLOSEALL:
130 EnumChildWindows(hMDIClient, &CloseEnumProc, 0);
131 break;
132 case ID_WINDOW_CLOSE:
133 hChildWnd = (HWND) SendMessage(hMDIClient, WM_MDIGETACTIVE, 0, 0);
134 if (!SendMessage(hChildWnd, WM_QUERYENDSESSION, 0, 0))
135 SendMessage(hMDIClient, WM_MDIDESTROY, (WPARAM)hChildWnd, 0);
136 break;
137 // case ID_FILE_EXIT:
138 // SendMessage(hWnd, WM_CLOSE, 0, 0);
139 // break;
140 // case IDM_EXIT:
141 // DestroyWindow(hWnd);
142 // break;
143 // case ID_FILE_OPEN:
144 case ID_REGISTRY_PRINTERSETUP:
145 //PRINTDLG pd;
146 //PrintDlg(&pd);
147 //PAGESETUPDLG psd;
148 //PageSetupDlg(&psd);
149 break;
150 case ID_REGISTRY_OPENLOCAL:
151 case ID_WINDOW_NEW_WINDOW:
152 InitChildWindow("Child Window");
153 return 0;
154 case ID_WINDOW_CASCADE:
155 SendMessage(hMDIClient, WM_MDICASCADE, 0, 0);
156 break;
157 case ID_WINDOW_TILE_HORZ:
158 SendMessage(hMDIClient, WM_MDITILE, MDITILE_HORIZONTAL, 0);
159 break;
160 case ID_WINDOW_TILE_VERT:
161 SendMessage(hMDIClient, WM_MDITILE, MDITILE_VERTICAL, 0);
162 break;
163 case ID_WINDOW_ARRANGE_ICONS:
164 SendMessage(hMDIClient, WM_MDIICONARRANGE, 0, 0);
165 break;
166 case ID_HELP_ABOUT:
167 // ShowAboutBox(hWnd);
168 {
169 HICON hIcon = LoadIcon(hInst, (LPCTSTR)IDI_REGEDT32);
170 ShellAbout(hWnd, szTitle, "FrameWndProc", hIcon);
171 //if (hIcon) DestroyIcon(hIcon); // NOT REQUIRED
172 }
173 break;
174 default:
175 hChildWnd = (HWND)SendMessage(hMDIClient, WM_MDIGETACTIVE, 0, 0);
176 if (IsWindow(hChildWnd))
177 SendMessage(hChildWnd, WM_COMMAND, wParam, lParam);
178 else
179 return DefFrameProc(hWnd, hMDIClient, message, wParam, lParam);
180 }
181 }
182 return 0;
183 }
184
185 ////////////////////////////////////////////////////////////////////////////////
186 //
187 // FUNCTION: FrameWndProc(HWND, unsigned, WORD, LONG)
188 //
189 // PURPOSE: Processes messages for the main frame window.
190 //
191 // WM_COMMAND - process the application menu
192 // WM_DESTROY - post a quit message and return
193 //
194 //
195
196 LRESULT CALLBACK FrameWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
197 {
198 switch (message) {
199 case WM_CREATE:
200 {
201 HMENU hMenuWindow = GetSubMenu(hMenuFrame, GetMenuItemCount(hMenuFrame)-2);
202 CLIENTCREATESTRUCT ccs = { hMenuWindow, IDW_FIRST_CHILD };
203 hMDIClient = CreateWindowEx(0, _T("MDICLIENT"), NULL,
204 WS_CHILD|WS_CLIPCHILDREN|WS_VSCROLL|WS_HSCROLL|WS_VISIBLE|WS_BORDER,
205 0, 0, 0, 0,
206 hWnd, (HMENU)0, hInst, &ccs);
207 }
208 break;
209 case WM_COMMAND:
210 return _CmdWndProc(hWnd, message, wParam, lParam);
211 break;
212 case WM_DESTROY:
213 PostQuitMessage(0);
214 break;
215 case WM_QUERYENDSESSION:
216 case WM_CLOSE:
217 SendMessage(hWnd, WM_COMMAND, ID_WINDOW_CLOSEALL, 0);
218 if (GetWindow(hMDIClient, GW_CHILD) != NULL)
219 return 0;
220 // else fall thru...
221 default:
222 return DefFrameProc(hWnd, hMDIClient, message, wParam, lParam);
223 }
224 return 0;
225 }
226
227