1a7312cf8967a5ca9af2dc447cbefed045383d31
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
43 ////////////////////////////////////////////////////////////////////////////////
47 BOOL bInMenuLoop
= FALSE
; // Tells us if we are in the menu loop
50 ////////////////////////////////////////////////////////////////////////////////
51 // Local module support methods
54 ////////////////////////////////////////////////////////////////////////////////
55 static HHOOK hcbthook
;
56 static ChildWnd
* newchild
= NULL
;
58 LRESULT CALLBACK
CBTProc(int code
, WPARAM wParam
, LPARAM lParam
)
60 if (code
== HCBT_CREATEWND
&& newchild
) {
61 ChildWnd
* pChildWnd
= newchild
;
63 pChildWnd
->hWnd
= (HWND
)wParam
;
64 SetWindowLong(pChildWnd
->hWnd
, GWL_USERDATA
, (LPARAM
)pChildWnd
);
66 return CallNextHookEx(hcbthook
, code
, wParam
, lParam
);
69 static HWND
InitChildWindow(LPTSTR param
)
71 //TCHAR drv[_MAX_DRIVE];
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*/
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());
95 pChildWnd
->hWnd
= (HWND
)SendMessage(hMDIClient
, WM_MDICREATE
, 0, (LPARAM
)&mcs
);
96 UnhookWindowsHookEx(hcbthook
);
97 if (pChildWnd
->hWnd
== NULL
) {
99 newchild
= pChildWnd
= NULL
;
101 return pChildWnd
->hWnd
;
105 BOOL CALLBACK
CloseEnumProc(HWND hWnd
, LPARAM lParam
)
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);
116 ////////////////////////////////////////////////////////////////////////////////
118 // FUNCTION: _CmdWndProc(HWND, unsigned, WORD, LONG)
120 // PURPOSE: Processes WM_COMMAND messages for the main frame window.
124 LRESULT
_CmdWndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
128 switch (LOWORD(wParam
)) {
129 case ID_WINDOW_CLOSEALL
:
130 EnumChildWindows(hMDIClient
, &CloseEnumProc
, 0);
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);
137 // case ID_FILE_EXIT:
138 // SendMessage(hWnd, WM_CLOSE, 0, 0);
141 // DestroyWindow(hWnd);
143 // case ID_FILE_OPEN:
144 case ID_REGISTRY_PRINTERSETUP
:
148 //PageSetupDlg(&psd);
150 case ID_REGISTRY_OPENLOCAL
:
151 case ID_WINDOW_NEW_WINDOW
:
152 InitChildWindow("Child Window");
154 case ID_WINDOW_CASCADE
:
155 SendMessage(hMDIClient
, WM_MDICASCADE
, 0, 0);
157 case ID_WINDOW_TILE_HORZ
:
158 SendMessage(hMDIClient
, WM_MDITILE
, MDITILE_HORIZONTAL
, 0);
160 case ID_WINDOW_TILE_VERT
:
161 SendMessage(hMDIClient
, WM_MDITILE
, MDITILE_VERTICAL
, 0);
163 case ID_WINDOW_ARRANGE_ICONS
:
164 SendMessage(hMDIClient
, WM_MDIICONARRANGE
, 0, 0);
167 // ShowAboutBox(hWnd);
169 HICON hIcon
= LoadIcon(hInst
, (LPCTSTR
)IDI_REGEDT32
);
170 ShellAbout(hWnd
, szTitle
, "FrameWndProc", hIcon
);
171 //if (hIcon) DestroyIcon(hIcon); // NOT REQUIRED
175 hChildWnd
= (HWND
)SendMessage(hMDIClient
, WM_MDIGETACTIVE
, 0, 0);
176 if (IsWindow(hChildWnd
))
177 SendMessage(hChildWnd
, WM_COMMAND
, wParam
, lParam
);
179 return DefFrameProc(hWnd
, hMDIClient
, message
, wParam
, lParam
);
185 ////////////////////////////////////////////////////////////////////////////////
187 // FUNCTION: FrameWndProc(HWND, unsigned, WORD, LONG)
189 // PURPOSE: Processes messages for the main frame window.
191 // WM_COMMAND - process the application menu
192 // WM_DESTROY - post a quit message and return
196 LRESULT CALLBACK
FrameWndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
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
,
206 hWnd
, (HMENU
)0, hInst
, &ccs
);
210 return _CmdWndProc(hWnd
, message
, wParam
, lParam
);
215 case WM_QUERYENDSESSION
:
217 SendMessage(hWnd
, WM_COMMAND
, ID_WINDOW_CLOSEALL
, 0);
218 if (GetWindow(hMDIClient
, GW_CHILD
) != NULL
)
222 return DefFrameProc(hWnd
, hMDIClient
, message
, wParam
, lParam
);