ReactOS  0.4.14-dev-323-g6fe6a88
framewnd.c
Go to the documentation of this file.
1 /*
2  * ReactOS Application
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 "main.h"
38 #include "about.h"
39 #include "framewnd.h"
40 
41 
43 // Global Variables:
44 //
45 
46 BOOL bInMenuLoop = FALSE; // Tells us if we are in the menu loop
47 
49 // Local module support methods
50 //
51 
52 static void resize_frame_rect(HWND hWnd, PRECT prect)
53 {
54  RECT rt;
55 
58  GetClientRect(hToolBar, &rt);
59  prect->top = rt.bottom+3;
60  prect->bottom -= rt.bottom+3;
61  }
63  int parts[] = {300, 500};
64 
68  prect->bottom -= rt.bottom;
69  }
70  MoveWindow(hMDIClient, prect->left-1,prect->top-1,prect->right+2,prect->bottom+1, TRUE);
71 }
72 
73 /* static void resize_frame(HWND hWnd, int cx, int cy)
74 {
75  RECT rect = {0, 0, cx, cy};
76 
77  resize_frame_rect(hWnd, &rect);
78 }*/
79 
81 {
82  RECT rect;
83 
86 }
87 
89 static HHOOK hcbthook;
91 
93 {
94  if (code == HCBT_CREATEWND && newchild) {
95  ChildWnd* pChildWnd = newchild;
96  newchild = NULL;
97  pChildWnd->hWnd = (HWND)wParam;
98  SetWindowLongPtr(pChildWnd->hWnd, GWLP_USERDATA, (LPARAM)pChildWnd);
99  }
101 }
102 
103 #if 0
105 {
106  MDICREATESTRUCT mcs = {
107  szChildClass, (LPTSTR)pChildWnd->path, hInst,
108  pChildWnd->pos.rcNormalPosition.left, pChildWnd->pos.rcNormalPosition.top,
109  pChildWnd->pos.rcNormalPosition.right-pChildWnd->pos.rcNormalPosition.left,
110  pChildWnd->pos.rcNormalPosition.bottom-pChildWnd->pos.rcNormalPosition.top,
111  0/*style*/, 0/*lParam*/
112  };
114  newchild = pChildWnd;
115  pChildWnd->hWnd = (HWND)SendMessage(hMDIClient, WM_MDICREATE, 0, (LPARAM)&mcs);
116  if (!pChildWnd->hWnd)
117  return 0;
119  return pChildWnd->hWnd;
120 }
121 
122 #endif
123 
124 
126 {
127  BOOL vis = IsWindowVisible(hchild);
128 
129  HMENU hMenuOptions = GetSubMenu(hMenuFrame, ID_OPTIONS_MENU);
131  ShowWindow(hchild, vis?SW_HIDE:SW_SHOW);
133 }
134 
135 
137 {
138  //TCHAR drv[_MAX_DRIVE];
140  ChildWnd* pChildWnd = NULL;
141 /*
142  LPCTSTR root = Globals.drives;
143  int i;
144  for(i = cmd - ID_DRIVE_FIRST; i--; root++)
145  while(*root)
146  root++;
147  if (activate_drive_window(root))
148  return 0;
149  _tsplitpath(root, drv, 0, 0, 0);
150  if (!SetCurrentDirectory(drv)) {
151  display_error(hWnd, GetLastError());
152  return 0;
153  }
154  */
156 // pChildWnd = alloc_child_window(path);
157 // if (!create_child_window(pChildWnd))
158 // free(pChildWnd);
159  pChildWnd = (ChildWnd*)malloc(sizeof(ChildWnd));
160  if (pChildWnd != NULL) {
161  MDICREATESTRUCT mcs = {
165  0/*style*/, 0/*lParam*/
166  };
167  memset(pChildWnd, 0, sizeof(ChildWnd));
168  lstrcpy(pChildWnd->szPath, path);
169  pChildWnd->pos.length = sizeof(WINDOWPLACEMENT);
170  pChildWnd->pos.flags = 0;
171  pChildWnd->pos.showCmd = SW_SHOWNORMAL;
172  pChildWnd->pos.rcNormalPosition.left = CW_USEDEFAULT;
173  pChildWnd->pos.rcNormalPosition.top = CW_USEDEFAULT;
176  pChildWnd->nFocusPanel = 0;
177  pChildWnd->nSplitPos = 200;
179  newchild = pChildWnd;
180  pChildWnd->hWnd = (HWND)SendMessage(hMDIClient, WM_MDICREATE, 0, (LPARAM)&mcs);
182  if (pChildWnd->hWnd == NULL) {
183  free(pChildWnd);
184  newchild = pChildWnd = NULL;
185  }
186  return pChildWnd->hWnd;
187  }
188  return 0;
189 }
190 
192 {
193  if (!GetWindow(hWnd, GW_OWNER)) {
195  if (SendMessage(hWnd, WM_QUERYENDSESSION, 0, 0)) {
197  }
198  }
199  return 1;
200 }
201 
203 {
204  int nParts;
205 
206  // Update the status bar pane sizes
207  nParts = -1;
208  SendMessage(hStatusBar, SB_SETPARTS, 1, (LPARAM)&nParts);
209  bInMenuLoop = TRUE;
211 }
212 
214 {
215  RECT rc;
216  int nParts[3];
217 
218  bInMenuLoop = FALSE;
219  // Update the status bar pane sizes
220  GetClientRect(hWnd, &rc);
221  nParts[0] = 100;
222  nParts[1] = 210;
223  nParts[2] = rc.right;
226  UpdateStatusBar();
227 }
228 
229 void OnMenuSelect(HWND hWnd, UINT nItemID, UINT nFlags, HMENU hSysMenu)
230 {
231  TCHAR str[100];
232 
233  strcpy(str, TEXT(""));
234  if (nFlags & MF_POPUP) {
235  if (hSysMenu != GetMenu(hWnd)) {
236  if (nItemID == 2) nItemID = 5;
237  }
238  }
239  if (LoadString(hInst, nItemID, str, 100)) {
240  // load appropriate string
241  LPTSTR lpsz = str;
242  // first newline terminates actual string
243  lpsz = _tcschr(lpsz, '\n');
244  if (lpsz != NULL)
245  *lpsz = '\0';
246  }
248 }
249 
251 //
252 // FUNCTION: _CmdWndProc(HWND, unsigned, WORD, LONG)
253 //
254 // PURPOSE: Processes WM_COMMAND messages for the main frame window.
255 //
256 //
257 
259 {
260  HWND hChildWnd;
261 
262  if (1) {
263 
264  switch (LOWORD(wParam)) {
265  case ID_WINDOW_CLOSEALL:
267  break;
268  case ID_WINDOW_CLOSE:
269  hChildWnd = (HWND) SendMessage(hMDIClient, WM_MDIGETACTIVE, 0, 0);
270  if (!SendMessage(hChildWnd, WM_QUERYENDSESSION, 0, 0))
271  SendMessage(hMDIClient, WM_MDIDESTROY, (WPARAM)hChildWnd, 0);
272  break;
273  case ID_FILE_EXIT:
274  SendMessage(hWnd, WM_CLOSE, 0, 0);
275  break;
276  case ID_OPTIONS_TOOLBAR:
278  break;
281  break;
282 
283  case ID_FILE_OPEN:
285  InitChildWindow("Child Window");
286  return 0;
287  case ID_WINDOW_CASCADE:
289  break;
290  case ID_WINDOW_TILE_HORZ:
292  break;
293  case ID_WINDOW_TILE_VERT:
295  break;
298  break;
299  case ID_HELP_ABOUT:
301  break;
302  default:
303  hChildWnd = (HWND)SendMessage(hMDIClient, WM_MDIGETACTIVE, 0, 0);
304  if (IsWindow(hChildWnd))
305  SendMessage(hChildWnd, WM_COMMAND, wParam, lParam);
306  else
308  }
309  }
310  return 0;
311 }
312 
314 //
315 // FUNCTION: FrameWndProc(HWND, unsigned, WORD, LONG)
316 //
317 // PURPOSE: Processes messages for the main frame window.
318 //
319 // WM_COMMAND - process the application menu
320 // WM_DESTROY - post a quit message and return
321 //
322 //
323 
325 {
326  switch (message) {
327  case WM_CREATE:
328  {
330  CLIENTCREATESTRUCT ccs = { hMenuWindow, IDW_FIRST_CHILD };
331 #if 0
332  hMDIClient = CreateWindow(_T("MDICLIENT"), NULL,
334  0, 0, 0, 0,
335  hWnd, (HMENU)1, hInst, &ccs);
336 #else
337  hMDIClient = CreateWindowEx(0, _T("MDICLIENT"), NULL,
338 // hMDIClient = CreateWindowEx(0, (LPCTSTR)(int)hChildWndClass, NULL,
340  0, 0, 0, 0,
341  hWnd, (HMENU)0, hInst, &ccs);
342 #endif
343  }
344  break;
345  case WM_COMMAND:
346  return _CmdWndProc(hWnd, message, wParam, lParam);
347  break;
348  case WM_SIZE:
350  break;
351  case WM_ENTERMENULOOP:
353  break;
354  case WM_EXITMENULOOP:
356  break;
357  case WM_MENUSELECT:
359  break;
360  case WM_DESTROY:
361  PostQuitMessage(0);
362  break;
363  case WM_QUERYENDSESSION:
364  case WM_CLOSE:
367  return 0;
368  // else fall thru...
369  default:
371  }
372  return 0;
373 }
374 
375 
void OnExitMenuLoop(HWND hWnd)
Definition: framewnd.c:213
BOOL WINAPI EnumChildWindows(_In_opt_ HWND, _In_ WNDENUMPROC, _In_ LPARAM)
static HWND create_child_window(ChildWnd *child)
Definition: winefile.c:1595
Definition: tftpd.h:59
#define TRUE
Definition: types.h:120
#define HCBT_CREATEWND
Definition: winuser.h:58
WCHAR path[MAX_PATH]
Definition: winefile.c:138
#define MF_BYCOMMAND
Definition: winuser.h:202
struct _WINDOWPLACEMENT WINDOWPLACEMENT
#define GW_CHILD
Definition: winuser.h:758
#define ID_OPTIONS_TOOLBAR
Definition: resource.h:40
static ChildWnd * newchild
Definition: framewnd.c:90
#define CreateWindow
Definition: winuser.h:5655
BOOL WINAPI IsWindow(_In_opt_ HWND)
void ShowAboutBox(HWND hWnd)
Definition: about.c:25
Definition: ftp_var.h:139
#define ID_WINDOW_CLOSE
Definition: resource.h:32
GLsizei const GLchar ** path
Definition: glext.h:7234
#define SW_HIDE
Definition: winuser.h:762
static const D3D_BLOB_PART parts[]
Definition: blob.c:76
#define free
Definition: debug_ros.c:5
#define WM_MDICASCADE
Definition: winuser.h:1801
#define WM_QUERYENDSESSION
Definition: winuser.h:1604
#define CALLBACK
Definition: compat.h:27
HWND hWnd
Definition: settings.c:17
LONG top
Definition: windef.h:292
HANDLE HWND
Definition: compat.h:13
static void resize_frame_rect(HWND hWnd, PRECT prect)
Definition: framewnd.c:52
#define ID_FILE_OPEN
Definition: resource.h:42
static HWND InitChildWindow(LPTSTR param)
Definition: framewnd.c:136
HWND hToolBar
Definition: mplay32.c:23
UINT_PTR WPARAM
Definition: windef.h:207
#define ID_WINDOW_TILE_VERT
Definition: resource.h:49
#define WS_CHILD
Definition: pedump.c:617
LONG left
Definition: windef.h:291
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
#define WS_CLIPCHILDREN
Definition: pedump.c:619
LONG right
Definition: windef.h:293
#define SetWindowLongPtr
Definition: treelist.c:70
& rect
Definition: startmenu.cpp:1413
WPARAM wParam
Definition: combotst.c:138
CHAR * LPTSTR
Definition: xmlstorage.h:192
#define DefFrameProc
Definition: ros2win.h:32
#define WM_MDIICONARRANGE
Definition: winuser.h:1802
#define IDW_FIRST_CHILD
Definition: explorer.h:58
int nSplitPos
Definition: main.h:65
void UpdateStatusBar(void)
Definition: framewnd.c:179
unsigned int BOOL
Definition: ntddk_ex.h:94
WINDOWPLACEMENT pos
Definition: main.h:66
#define WM_ENTERMENULOOP
Definition: winuser.h:1786
#define ID_FILE_EXIT
Definition: resource.h:47
#define MDITILE_HORIZONTAL
Definition: winuser.h:2163
#define WM_MENUSELECT
Definition: winuser.h:1729
int WINAPI GetMenuItemCount(_In_opt_ HMENU)
#define GetCurrentDirectory
Definition: winbase.h:3629
#define ID_OPTIONS_MENU
Definition: resource.h:8
#define CreateWindowEx
Definition: winuser.h:5656
#define CW_USEDEFAULT
Definition: winuser.h:225
#define GWLP_USERDATA
Definition: treelist.c:63
#define ID_HELP_ABOUT
Definition: resource.h:77
const WCHAR * str
#define WM_EXITMENULOOP
Definition: winuser.h:1787
smooth NULL
Definition: ftsmooth.c:416
LONG_PTR LPARAM
Definition: windef.h:208
void resize_frame_client(HWND hWnd)
Definition: framewnd.c:80
#define WH_CBT
Definition: winuser.h:35
#define SW_SHOW
Definition: winuser.h:769
_TCHAR * _tcschr(const _TCHAR *s, _XINT c)
Definition: tcschr.h:4
DWORD WINAPI GetCurrentThreadId(VOID)
Definition: thread.c:458
#define WM_DESTROY
Definition: winuser.h:1591
#define ID_WINDOW_CASCADE
Definition: resource.h:78
LRESULT _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
Definition: framewnd.c:258
#define MF_CHECKED
Definition: winuser.h:132
char TCHAR
Definition: xmlstorage.h:189
WCHAR szPath[MAX_PATH]
Definition: main.h:67
#define _T(x)
Definition: vfdio.h:22
BOOL CALLBACK CloseEnumProc(HWND hWnd, LPARAM lParam)
Definition: framewnd.c:191
#define WM_SIZE
Definition: winuser.h:1593
#define MDITILE_VERTICAL
Definition: winuser.h:2164
#define ID_WINDOW_CLOSEALL
Definition: resource.h:33
HWND hWnd
Definition: main.h:59
#define WM_CLOSE
Definition: winuser.h:1603
GLfloat param
Definition: glext.h:5796
#define MAX_PATH
Definition: compat.h:26
#define SetWindowsHookEx
Definition: winuser.h:5757
HWND hStatusBar
Definition: main.cpp:35
DWORD WINAPI CheckMenuItem(_In_ HMENU, _In_ UINT, _In_ UINT)
#define WS_HSCROLL
Definition: pedump.c:628
#define WM_MDIGETACTIVE
Definition: winuser.h:1803
#define ID_WINDOW_TILE_HORZ
Definition: resource.h:48
#define MF_POPUP
Definition: winuser.h:136
HWND WINAPI GetWindow(_In_ HWND, _In_ UINT)
#define SB_SETTEXT
Definition: commctrl.h:1945
LRESULT CALLBACK CBTProc(int code, WPARAM wParam, LPARAM lParam)
Definition: framewnd.c:92
WCHAR szChildClass[MAX_LOADSTRING]
Definition: main.c:40
static HHOOK hcbthook
Definition: framewnd.c:89
HMENU WINAPI GetSubMenu(_In_ HMENU, _In_ int)
#define WM_COMMAND
Definition: winuser.h:1722
BOOL WINAPI MoveWindow(_In_ HWND, _In_ int, _In_ int, _In_ int, _In_ int, _In_ BOOL)
#define WM_MDIDESTROY
Definition: winuser.h:1795
BOOL WINAPI UnhookWindowsHookEx(_In_ HHOOK)
BOOL bInMenuLoop
Definition: framewnd.c:46
BOOL WINAPI GetClientRect(_In_ HWND, _Out_ LPRECT)
HWND WINAPI GetParent(_In_ HWND)
LRESULT WINAPI CallNextHookEx(_In_opt_ HHOOK, _In_ int, _In_ WPARAM, _In_ LPARAM)
#define SW_SHOWNORMAL
Definition: winuser.h:764
HINSTANCE hInst
Definition: dxdiag.c:13
#define TEXT(s)
Definition: k32.h:26
#define WS_BORDER
Definition: pedump.c:625
HMENU hMenuFrame
Definition: main.c:32
#define WM_MDIRESTORE
Definition: winuser.h:1797
#define ID_WINDOW_ARRANGE_ICONS
Definition: resource.h:48
LRESULT CALLBACK FrameWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
Definition: framewnd.c:1304
#define lstrcpy
Definition: winbase.h:3698
void OnEnterMenuLoop(HWND hWnd)
Definition: framewnd.c:202
void toggle_child(HWND hWnd, UINT cmd, HWND hchild)
Definition: framewnd.c:125
Definition: services.c:325
#define ID_OPTIONS_STATUSBAR
Definition: resource.h:41
unsigned int UINT
Definition: ndis.h:50
#define WS_VSCROLL
Definition: pedump.c:627
#define GW_OWNER
Definition: winuser.h:761
#define SB_SETPARTS
Definition: commctrl.h:1950
#define WM_MDICREATE
Definition: winuser.h:1794
RECT rcNormalPosition
Definition: winuser.h:3269
Definition: main.h:57
#define SendMessage
Definition: winuser.h:5744
#define WM_CREATE
Definition: winuser.h:1590
static struct myctx * mcs
Definition: adnstest.c:53
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
#define HIWORD(l)
Definition: typedefs.h:246
BOOL WINAPI IsWindowVisible(_In_ HWND)
LONG bottom
Definition: windef.h:294
#define malloc
Definition: debug_ros.c:4
LONG_PTR LRESULT
Definition: windef.h:209
#define ID_WINDOW_NEW_WINDOW
Definition: resource.h:44
#define WS_VISIBLE
Definition: pedump.c:620
#define memset(x, y, z)
Definition: compat.h:39
HMENU WINAPI GetMenu(_In_ HWND)
static const CLSID *static CLSID *static const GUID VARIANT VARIANT *static IServiceProvider DWORD *static HMENU
Definition: ordinal.c:60
void OnMenuSelect(HWND hWnd, UINT nItemID, UINT nFlags, HMENU hSysMenu)
Definition: framewnd.c:229
LPARAM lParam
Definition: combotst.c:139
#define LOWORD(l)
Definition: pedump.c:82
__analysis_noreturn void WINAPI PostQuitMessage(_In_ int)
#define LoadString
Definition: winuser.h:5720
#define WM_MDITILE
Definition: winuser.h:1800
HWND hMDIClient
Definition: main.c:49
int nFocusPanel
Definition: main.h:64