d0e419de60526e6e67acc80177699992eefe11dd
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 ////////////////////////////////////////////////////////////////////////////////
44 // Globals and Variables:
47 BOOL bInMenuLoop
= FALSE
; // Tells us if we are in the menu loop
49 static HHOOK hcbthook
;
50 static ChildWnd
* newchild
= NULL
;
52 ////////////////////////////////////////////////////////////////////////////////
53 // Local module support methods
56 static LRESULT CALLBACK
CBTProc(int code
, WPARAM wParam
, LPARAM lParam
)
58 if (code
== HCBT_CREATEWND
&& newchild
) {
59 ChildWnd
* pChildWnd
= newchild
;
61 pChildWnd
->hWnd
= (HWND
)wParam
;
62 SetWindowLong(pChildWnd
->hWnd
, GWL_USERDATA
, (LPARAM
)pChildWnd
);
64 return CallNextHookEx(hcbthook
, code
, wParam
, lParam
);
67 static HWND
InitChildWindow(LPTSTR param
)
69 //TCHAR drv[_MAX_DRIVE];
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*/
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());
93 pChildWnd
->hWnd
= (HWND
)SendMessage(hMDIClient
, WM_MDICREATE
, 0, (LPARAM
)&mcs
);
94 UnhookWindowsHookEx(hcbthook
);
95 if (pChildWnd
->hWnd
== NULL
) {
97 newchild
= pChildWnd
= NULL
;
99 return pChildWnd
->hWnd
;
104 static BOOL CALLBACK
CloseEnumProc(HWND hWnd
, LPARAM lParam
)
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);
115 static LRESULT
_CmdWndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
118 switch (LOWORD(wParam
)) {
119 case ID_WINDOW_CLOSEALL
:
120 EnumChildWindows(hMDIClient
, &CloseEnumProc
, 0);
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);
127 // case ID_FILE_EXIT:
128 // SendMessage(hWnd, WM_CLOSE, 0, 0);
131 // DestroyWindow(hWnd);
133 // case ID_FILE_OPEN:
134 case ID_REGISTRY_PRINTERSETUP
:
138 //PageSetupDlg(&psd);
140 case ID_REGISTRY_OPENLOCAL
:
141 case ID_WINDOW_NEW_WINDOW
:
142 InitChildWindow("Child Window");
144 case ID_WINDOW_CASCADE
:
145 SendMessage(hMDIClient
, WM_MDICASCADE
, 0, 0);
147 case ID_WINDOW_TILE_HORZ
:
148 SendMessage(hMDIClient
, WM_MDITILE
, MDITILE_HORIZONTAL
, 0);
150 case ID_WINDOW_TILE_VERT
:
151 SendMessage(hMDIClient
, WM_MDITILE
, MDITILE_VERTICAL
, 0);
153 case ID_WINDOW_ARRANGE_ICONS
:
154 SendMessage(hMDIClient
, WM_MDIICONARRANGE
, 0, 0);
157 // ShowAboutBox(hWnd);
159 HICON hIcon
= LoadIcon(hInst
, (LPCTSTR
)IDI_REGEDT32
);
160 ShellAbout(hWnd
, szTitle
, "FrameWndProc", hIcon
);
161 //if (hIcon) DestroyIcon(hIcon); // NOT REQUIRED
165 hChildWnd
= (HWND
)SendMessage(hMDIClient
, WM_MDIGETACTIVE
, 0, 0);
166 if (IsWindow(hChildWnd
))
167 SendMessage(hChildWnd
, WM_COMMAND
, wParam
, lParam
);
169 return DefFrameProc(hWnd
, hMDIClient
, message
, wParam
, lParam
);
174 ////////////////////////////////////////////////////////////////////////////////
176 // FUNCTION: FrameWndProc(HWND, unsigned, WORD, LONG)
178 // PURPOSE: Processes messages for the main frame window.
180 // WM_COMMAND - process the application menu
181 // WM_DESTROY - post a quit message and return
185 LRESULT CALLBACK
FrameWndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
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
,
195 hWnd
, (HMENU
)0, hInst
, &ccs
);
199 return _CmdWndProc(hWnd
, message
, wParam
, lParam
);
204 case WM_QUERYENDSESSION
:
206 SendMessage(hWnd
, WM_COMMAND
, ID_WINDOW_CLOSEALL
, 0);
207 if (GetWindow(hMDIClient
, GW_CHILD
) != NULL
)
211 return DefFrameProc(hWnd
, hMDIClient
, message
, wParam
, lParam
);