efecd1bccd69dd9de52052e1373dea7b88955133
6 * Copyright (C) 2002 Robert Dickenson <robd@reactos.org>
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.
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.
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.
26 #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
40 //#include "childwnd.h"
43 ////////////////////////////////////////////////////////////////////////////////
47 BOOL bInMenuLoop
= FALSE
; // Tells us if we are in the menu loop
49 ////////////////////////////////////////////////////////////////////////////////
50 // Local module support methods
53 static void resize_frame_rect(HWND hWnd
, PRECT prect
)
57 if (IsWindowVisible(hToolBar
)) {
58 SendMessage(hToolBar
, WM_SIZE
, 0, 0);
59 GetClientRect(hToolBar
, &rt
);
60 prect
->top
= rt
.bottom
+3;
61 prect
->bottom
-= rt
.bottom
+3;
63 if (IsWindowVisible(hStatusBar
)) {
64 int parts
[] = {300, 500};
66 SendMessage(hStatusBar
, WM_SIZE
, 0, 0);
67 SendMessage(hStatusBar
, SB_SETPARTS
, 2, (LPARAM
)&parts
);
68 GetClientRect(hStatusBar
, &rt
);
69 prect
->bottom
-= rt
.bottom
;
71 MoveWindow(hMDIClient
, prect
->left
-1,prect
->top
-1,prect
->right
+2,prect
->bottom
+1, TRUE
);
74 static void resize_frame(HWND hWnd
, int cx
, int cy
)
76 RECT rect
= {0, 0, cx
, cy
};
78 resize_frame_rect(hWnd
, &rect
);
81 void resize_frame_client(HWND hWnd
)
85 GetClientRect(hWnd
, &rect
);
86 resize_frame_rect(hWnd
, &rect
);
89 ////////////////////////////////////////////////////////////////////////////////
90 static HHOOK hcbthook
;
91 static ChildWnd
* newchild
= NULL
;
93 LRESULT CALLBACK
CBTProc(int code
, WPARAM wParam
, LPARAM lParam
)
95 if (code
== HCBT_CREATEWND
&& newchild
) {
96 ChildWnd
* pChildWnd
= newchild
;
98 pChildWnd
->hWnd
= (HWND
)wParam
;
99 SetWindowLong(pChildWnd
->hWnd
, GWL_USERDATA
, (LPARAM
)pChildWnd
);
101 return CallNextHookEx(hcbthook
, code
, wParam
, lParam
);
105 HWND
create_child_window(ChildWnd
* pChildWnd
)
107 MDICREATESTRUCT mcs
= {
108 szChildClass
, (LPTSTR
)pChildWnd
->path
, hInst
,
109 pChildWnd
->pos
.rcNormalPosition
.left
, pChildWnd
->pos
.rcNormalPosition
.top
,
110 pChildWnd
->pos
.rcNormalPosition
.right
-pChildWnd
->pos
.rcNormalPosition
.left
,
111 pChildWnd
->pos
.rcNormalPosition
.bottom
-pChildWnd
->pos
.rcNormalPosition
.top
,
112 0/*style*/, 0/*lParam*/
114 hcbthook
= SetWindowsHookEx(WH_CBT
, CBTProc
, 0, GetCurrentThreadId());
115 newchild
= pChildWnd
;
116 pChildWnd
->hWnd
= (HWND
)SendMessage(hMDIClient
, WM_MDICREATE
, 0, (LPARAM
)&mcs
);
117 if (!pChildWnd
->hWnd
)
119 UnhookWindowsHookEx(hcbthook
);
120 return pChildWnd
->hWnd
;
126 void toggle_child(HWND hWnd
, UINT cmd
, HWND hchild
)
128 BOOL vis
= IsWindowVisible(hchild
);
130 HMENU hMenuOptions
= GetSubMenu(hMenuFrame
, ID_OPTIONS_MENU
);
131 CheckMenuItem(hMenuOptions
, cmd
, vis
?MF_BYCOMMAND
:MF_BYCOMMAND
|MF_CHECKED
);
132 ShowWindow(hchild
, vis
?SW_HIDE
:SW_SHOW
);
133 resize_frame_client(hWnd
);
137 static HWND
InitChildWindow(LPTSTR param
)
139 //TCHAR drv[_MAX_DRIVE];
140 TCHAR path
[MAX_PATH
];
141 ChildWnd
* pChildWnd
= NULL
;
143 LPCTSTR root = Globals.drives;
145 for(i = cmd - ID_DRIVE_FIRST; i--; root++)
148 if (activate_drive_window(root))
150 _tsplitpath(root, drv, 0, 0, 0);
151 if (!SetCurrentDirectory(drv)) {
152 display_error(hWnd, GetLastError());
156 GetCurrentDirectory(MAX_PATH
, path
);
157 // pChildWnd = alloc_child_window(path);
158 // if (!create_child_window(pChildWnd))
160 pChildWnd
= (ChildWnd
*)malloc(sizeof(ChildWnd
));
161 if (pChildWnd
!= NULL
) {
162 MDICREATESTRUCT mcs
= {
163 szChildClass
, path
, hInst
,
164 CW_USEDEFAULT
, CW_USEDEFAULT
,
165 CW_USEDEFAULT
, CW_USEDEFAULT
,
166 0/*style*/, 0/*lParam*/
168 memset(pChildWnd
, 0, sizeof(ChildWnd
));
169 lstrcpy(pChildWnd
->szPath
, path
);
170 pChildWnd
->pos
.length
= sizeof(WINDOWPLACEMENT
);
171 pChildWnd
->pos
.flags
= 0;
172 pChildWnd
->pos
.showCmd
= SW_SHOWNORMAL
;
173 pChildWnd
->pos
.rcNormalPosition
.left
= CW_USEDEFAULT
;
174 pChildWnd
->pos
.rcNormalPosition
.top
= CW_USEDEFAULT
;
175 pChildWnd
->pos
.rcNormalPosition
.right
= CW_USEDEFAULT
;
176 pChildWnd
->pos
.rcNormalPosition
.bottom
= CW_USEDEFAULT
;
177 pChildWnd
->nFocusPanel
= 0;
178 pChildWnd
->nSplitPos
= 200;
179 hcbthook
= SetWindowsHookEx(WH_CBT
, CBTProc
, 0, GetCurrentThreadId());
180 newchild
= pChildWnd
;
181 pChildWnd
->hWnd
= (HWND
)SendMessage(hMDIClient
, WM_MDICREATE
, 0, (LPARAM
)&mcs
);
182 UnhookWindowsHookEx(hcbthook
);
183 if (pChildWnd
->hWnd
== NULL
) {
185 newchild
= pChildWnd
= NULL
;
187 return pChildWnd
->hWnd
;
192 BOOL CALLBACK
CloseEnumProc(HWND hWnd
, LPARAM lParam
)
194 if (!GetWindow(hWnd
, GW_OWNER
)) {
195 SendMessage(GetParent(hWnd
), WM_MDIRESTORE
, (WPARAM
)hWnd
, 0);
196 if (SendMessage(hWnd
, WM_QUERYENDSESSION
, 0, 0)) {
197 SendMessage(GetParent(hWnd
), WM_MDIDESTROY
, (WPARAM
)hWnd
, 0);
203 void OnEnterMenuLoop(HWND hWnd
)
207 // Update the status bar pane sizes
209 SendMessage(hStatusBar
, SB_SETPARTS
, 1, (long)&nParts
);
211 SendMessage(hStatusBar
, SB_SETTEXT
, (WPARAM
)0, (LPARAM
)_T(""));
214 void OnExitMenuLoop(HWND hWnd
)
220 // Update the status bar pane sizes
221 GetClientRect(hWnd
, &rc
);
224 nParts
[2] = rc
.right
;
225 SendMessage(hStatusBar
, SB_SETPARTS
, 3, (long)nParts
);
226 SendMessage(hStatusBar
, SB_SETTEXT
, 0, (LPARAM
)_T(""));
230 void OnMenuSelect(HWND hWnd
, UINT nItemID
, UINT nFlags
, HMENU hSysMenu
)
234 strcpy(str
, TEXT(""));
235 if (nFlags
& MF_POPUP
) {
236 if (hSysMenu
!= GetMenu(hWnd
)) {
237 if (nItemID
== 2) nItemID
= 5;
240 if (LoadString(hInst
, nItemID
, str
, 100)) {
241 // load appropriate string
243 // first newline terminates actual string
244 lpsz
= _tcschr(lpsz
, '\n');
248 SendMessage(hStatusBar
, SB_SETTEXT
, 0, (LPARAM
)str
);
251 ////////////////////////////////////////////////////////////////////////////////
253 // FUNCTION: _CmdWndProc(HWND, unsigned, WORD, LONG)
255 // PURPOSE: Processes WM_COMMAND messages for the main frame window.
259 LRESULT
_CmdWndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
265 switch (LOWORD(wParam
)) {
266 case ID_WINDOW_CLOSEALL
:
267 EnumChildWindows(hMDIClient
, &CloseEnumProc
, 0);
269 case ID_WINDOW_CLOSE
:
270 hChildWnd
= (HWND
) SendMessage(hMDIClient
, WM_MDIGETACTIVE
, 0, 0);
271 if (!SendMessage(hChildWnd
, WM_QUERYENDSESSION
, 0, 0))
272 SendMessage(hMDIClient
, WM_MDIDESTROY
, (WPARAM
)hChildWnd
, 0);
275 SendMessage(hWnd
, WM_CLOSE
, 0, 0);
277 case ID_OPTIONS_TOOLBAR
:
278 toggle_child(hWnd
, LOWORD(wParam
), hToolBar
);
280 case ID_OPTIONS_STATUSBAR
:
281 toggle_child(hWnd
, LOWORD(wParam
), hStatusBar
);
285 case ID_WINDOW_NEW_WINDOW
:
286 InitChildWindow("Child Window");
288 case ID_WINDOW_CASCADE
:
289 SendMessage(hMDIClient
, WM_MDICASCADE
, 0, 0);
291 case ID_WINDOW_TILE_HORZ
:
292 SendMessage(hMDIClient
, WM_MDITILE
, MDITILE_HORIZONTAL
, 0);
294 case ID_WINDOW_TILE_VERT
:
295 SendMessage(hMDIClient
, WM_MDITILE
, MDITILE_VERTICAL
, 0);
297 case ID_WINDOW_ARRANGE_ICONS
:
298 SendMessage(hMDIClient
, WM_MDIICONARRANGE
, 0, 0);
304 hChildWnd
= (HWND
)SendMessage(hMDIClient
, WM_MDIGETACTIVE
, 0, 0);
305 if (IsWindow(hChildWnd
))
306 SendMessage(hChildWnd
, WM_COMMAND
, wParam
, lParam
);
308 return DefFrameProc(hWnd
, hMDIClient
, message
, wParam
, lParam
);
314 ////////////////////////////////////////////////////////////////////////////////
316 // FUNCTION: FrameWndProc(HWND, unsigned, WORD, LONG)
318 // PURPOSE: Processes messages for the main frame window.
320 // WM_COMMAND - process the application menu
321 // WM_DESTROY - post a quit message and return
325 LRESULT CALLBACK
FrameWndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
330 HMENU hMenuWindow
= GetSubMenu(hMenuFrame
, GetMenuItemCount(hMenuFrame
)-2);
331 CLIENTCREATESTRUCT ccs
= { hMenuWindow
, IDW_FIRST_CHILD
};
333 hMDIClient
= CreateWindow(_T("MDICLIENT"), NULL
,
334 WS_CHILD
|WS_CLIPCHILDREN
|WS_VISIBLE
,
336 hWnd
, (HMENU
)1, hInst
, &ccs
);
338 hMDIClient
= CreateWindowEx(0, _T("MDICLIENT"), NULL
,
339 // hMDIClient = CreateWindowEx(0, (LPCTSTR)(int)hChildWndClass, NULL,
340 WS_CHILD
|WS_CLIPCHILDREN
|WS_VSCROLL
|WS_HSCROLL
|WS_VISIBLE
|WS_BORDER
,
342 hWnd
, (HMENU
)0, hInst
, &ccs
);
347 return _CmdWndProc(hWnd
, message
, wParam
, lParam
);
350 resize_frame_client(hWnd
);
352 case WM_ENTERMENULOOP
:
353 OnEnterMenuLoop(hWnd
);
355 case WM_EXITMENULOOP
:
356 OnExitMenuLoop(hWnd
);
359 OnMenuSelect(hWnd
, LOWORD(wParam
), HIWORD(wParam
), (HMENU
)lParam
);
364 case WM_QUERYENDSESSION
:
366 SendMessage(hWnd
, WM_COMMAND
, ID_WINDOW_CLOSEALL
, 0);
367 if (GetWindow(hMDIClient
, GW_CHILD
) != NULL
)
371 return DefFrameProc(hWnd
, hMDIClient
, message
, wParam
, lParam
);