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