f91ea135b9ed4e3073eb4584004bcaf6bd64720d
[reactos.git] / rosapps / winfile / framewnd.c
1 /*
2 * ReactOS winfile
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 #include <windowsx.h>
39 #include <assert.h>
40 #define ASSERT assert
41
42 #include "main.h"
43 #include "about.h"
44 #include "framewnd.h"
45 #include "childwnd.h"
46 #include "worker.h"
47 #include "utils.h"
48 #include "shell.h"
49 #include "network.h"
50 #include "dialogs.h"
51
52
53 ////////////////////////////////////////////////////////////////////////////////
54 // Global and Local Variables:
55 //
56
57 BOOL bInMenuLoop = FALSE; // Tells us if we are in the menu loop
58 int nOldWidth; // Holds the previous client area width
59 int nOldHeight; // Holds the previous client area height
60
61 static HHOOK hcbthook;
62 static ChildWnd* newchild = NULL;
63
64
65 ////////////////////////////////////////////////////////////////////////////////
66 // Local module support methods
67 //
68
69 static void resize_frame_rect(HWND hWnd, PRECT prect)
70 {
71 int new_top;
72 RECT rt;
73
74 if (IsWindowVisible(Globals.hToolBar)) {
75 SendMessage(Globals.hToolBar, WM_SIZE, 0, 0);
76 GetClientRect(Globals.hToolBar, &rt);
77 prect->top = rt.bottom+3;
78 prect->bottom -= rt.bottom+3;
79 }
80 if (IsWindowVisible(Globals.hDriveBar)) {
81 SendMessage(Globals.hDriveBar, WM_SIZE, 0, 0);
82 GetClientRect(Globals.hDriveBar, &rt);
83 // new_top = --prect->top + rt.bottom+3;
84 new_top = --prect->top + rt.bottom+0;
85 MoveWindow(Globals.hDriveBar, 0, prect->top, rt.right, new_top, TRUE);
86 prect->top = new_top;
87 // prect->bottom -= rt.bottom+2;
88 prect->bottom -= rt.bottom-1;
89 }
90 if (IsWindowVisible(Globals.hStatusBar)) {
91 SetupStatusBar(TRUE);
92 // int parts[] = {300, 500};
93 // SendMessage(Globals.hStatusBar, WM_SIZE, 0, 0);
94 // SendMessage(Globals.hStatusBar, SB_SETPARTS, 2, (LPARAM)&parts);
95 GetClientRect(Globals.hStatusBar, &rt);
96 prect->bottom -= rt.bottom;
97 }
98 MoveWindow(Globals.hMDIClient, prect->left-1,prect->top-1,prect->right+2,prect->bottom+1, TRUE);
99 }
100
101 static void resize_frame(HWND hWnd, int cx, int cy)
102 {
103 RECT rect = {0, 0, cx, cy};
104
105 resize_frame_rect(hWnd, &rect);
106 }
107
108 void resize_frame_client(HWND hWnd)
109 {
110 RECT rect;
111
112 GetClientRect(hWnd, &rect);
113 resize_frame_rect(hWnd, &rect);
114 }
115
116 ////////////////////////////////////////////////////////////////////////////////
117
118 static LRESULT CALLBACK CBTProc(int code, WPARAM wParam, LPARAM lParam)
119 {
120 if (code == HCBT_CREATEWND && newchild) {
121 ChildWnd* pChildWnd = newchild;
122 newchild = NULL;
123 pChildWnd->hWnd = (HWND)wParam;
124 SetWindowLong(pChildWnd->hWnd, GWL_USERDATA, (LPARAM)pChildWnd);
125 }
126 return CallNextHookEx(hcbthook, code, wParam, lParam);
127 }
128
129
130 /*
131 BOOL FindChildWindow(int cmd)
132 {
133 TCHAR drv[_MAX_DRIVE];
134 LPCTSTR root = Globals.drives;
135 int i;
136 for(i = cmd - ID_DRIVE_FIRST; i--; root++)
137 while(*root)
138 root++;
139 if (activate_drive_window(root))
140 return TRUE;
141 _tsplitpath(root, drv, 0, 0, 0);
142 if (!SetCurrentDirectory(drv)) {
143 display_error(hWnd, GetLastError());
144 //return TRUE;
145 }
146 return FALSE;
147 }
148 */
149
150 static ChildWnd* alloc_child_window(LPCTSTR path)
151 {
152 TCHAR drv[_MAX_DRIVE+1], dir[_MAX_DIR], name[_MAX_FNAME], ext[_MAX_EXT];
153 ChildWnd* pChildWnd = (ChildWnd*)malloc(sizeof(ChildWnd));
154 Root* root = &pChildWnd->root;
155 Entry* entry;
156
157 memset(pChildWnd, 0, sizeof(ChildWnd));
158 pChildWnd->left.treePane = TRUE;
159 pChildWnd->left.visible_cols = 0;
160 pChildWnd->right.treePane = FALSE;
161 #ifndef _NO_EXTENSIONS
162 pChildWnd->right.visible_cols = COL_SIZE|COL_DATE|COL_TIME|COL_ATTRIBUTES|COL_INDEX|COL_LINKS;
163 #else
164 pChildWnd->right.visible_cols = COL_SIZE|COL_DATE|COL_TIME|COL_ATTRIBUTES;
165 #endif
166 pChildWnd->pos.length = sizeof(WINDOWPLACEMENT);
167 pChildWnd->pos.flags = 0;
168 pChildWnd->pos.showCmd = SW_SHOWNORMAL;
169 pChildWnd->pos.rcNormalPosition.left = CW_USEDEFAULT;
170 pChildWnd->pos.rcNormalPosition.top = CW_USEDEFAULT;
171 pChildWnd->pos.rcNormalPosition.right = CW_USEDEFAULT;
172 pChildWnd->pos.rcNormalPosition.bottom = CW_USEDEFAULT;
173 pChildWnd->nFocusPanel = 0;
174 pChildWnd->nSplitPos = 300;
175 pChildWnd->sortOrder = SORT_NAME;
176 pChildWnd->header_wdths_ok = FALSE;
177 lstrcpy(pChildWnd->szPath, path);
178 _tsplitpath(path, drv, dir, name, ext);
179 #if !defined(_NO_EXTENSIONS) && defined(__linux__)
180 if (*path == '/') {
181 root->drive_type = GetDriveType(path);
182 lstrcat(drv, _T("/"));
183 lstrcpy(root->volname, _T("root fs"));
184 root->fs_flags = 0;
185 lstrcpy(root->fs, _T("unixfs"));
186 lstrcpy(root->path, _T("/"));
187 entry = read_tree_unix(root, path, pChildWnd->sortOrder);
188 } else
189 #endif
190 {
191 root->drive_type = GetDriveType(path);
192 lstrcat(drv, _T("\\"));
193 GetVolumeInformation(drv, root->volname, _MAX_FNAME, 0, 0, &root->fs_flags, root->fs, _MAX_DIR);
194 lstrcpy(root->path, drv);
195 entry = read_tree_win(root, path, pChildWnd->sortOrder);
196 }
197 //@@lstrcpy(root->entry.data.cFileName, drv);
198 wsprintf(root->entry.data.cFileName, _T("%s - %s"), drv, root->fs);
199 root->entry.data.dwFileAttributes = FILE_ATTRIBUTE_DIRECTORY;
200 pChildWnd->left.root = &root->entry;
201 set_curdir(pChildWnd, entry);
202 return pChildWnd;
203 }
204
205 HWND CreateChildWindow(int drv_id)
206 {
207 //TCHAR drv[_MAX_DRIVE];
208 TCHAR path[MAX_PATH];
209 ChildWnd* pChildWnd = NULL;
210 /*
211 LPCTSTR root = Globals.drives;
212 int i;
213 for(i = cmd - ID_DRIVE_FIRST; i--; root++)
214 while(*root)
215 root++;
216 if (activate_drive_window(root))
217 return 0;
218 _tsplitpath(root, drv, 0, 0, 0);
219 if (!SetCurrentDirectory(drv)) {
220 display_error(hWnd, GetLastError());
221 return 0;
222 }
223 */
224 GetCurrentDirectory(MAX_PATH, path);
225 // pChildWnd = (ChildWnd*)malloc(sizeof(ChildWnd));
226 pChildWnd = alloc_child_window(path);
227 // if (!create_child_window(pChildWnd))
228 // free(pChildWnd);
229
230 if (pChildWnd != NULL) {
231 MDICREATESTRUCT mcs = {
232 szChildClass, path, hInst,
233 // CW_USEDEFAULT, CW_USEDEFAULT,
234 // CW_USEDEFAULT, CW_USEDEFAULT,
235 20, 20, 200, 200,
236 WS_MAXIMIZE, 0
237 // 0/*style*/, 0/*lParam*/
238 };
239 hcbthook = SetWindowsHookEx(WH_CBT, CBTProc, 0, GetCurrentThreadId());
240 newchild = pChildWnd;
241 pChildWnd->hWnd = (HWND)SendMessage(Globals.hMDIClient, WM_MDICREATE, 0, (LPARAM)&mcs);
242 UnhookWindowsHookEx(hcbthook);
243 if (pChildWnd->hWnd != NULL) {
244 return pChildWnd->hWnd;
245 } else {
246 free(pChildWnd);
247 newchild = pChildWnd = NULL;
248 }
249 }
250 return 0;
251 }
252
253 static BOOL CALLBACK CloseEnumProc(HWND hWnd, LPARAM lParam)
254 {
255 if (!GetWindow(hWnd, GW_OWNER)) {
256 SendMessage(GetParent(hWnd), WM_MDIRESTORE, (WPARAM)hWnd, 0);
257 if (SendMessage(hWnd, WM_QUERYENDSESSION, 0, 0)) {
258 SendMessage(GetParent(hWnd), WM_MDIDESTROY, (WPARAM)hWnd, 0);
259 }
260 }
261 return 1;
262 }
263
264 static void OnEnterMenuLoop(HWND hWnd)
265 {
266 int nParts;
267
268 // Update the status bar pane sizes
269 nParts = -1;
270 SendMessage(Globals.hStatusBar, SB_SETPARTS, 1, (long)&nParts);
271 bInMenuLoop = TRUE;
272 SendMessage(Globals.hStatusBar, SB_SETTEXT, (WPARAM)0, (LPARAM)_T(""));
273 }
274
275 static void OnExitMenuLoop(HWND hWnd)
276 {
277 /*
278 RECT rc;
279 int nParts[3];
280
281 bInMenuLoop = FALSE;
282 // Update the status bar pane sizes
283 GetClientRect(hWnd, &rc);
284 nParts[0] = 100;
285 nParts[1] = 210;
286 nParts[2] = rc.right;
287 SendMessage(Globals.hStatusBar, SB_SETPARTS, 3, (long)nParts);
288 SendMessage(Globals.hStatusBar, SB_SETTEXT, 0, (LPARAM)_T(""));
289 */
290 SendMessage(Globals.hStatusBar, SB_SETTEXT, 0, (LPARAM)_T(""));
291 bInMenuLoop = FALSE;
292 SetupStatusBar(TRUE);
293 UpdateStatusBar();
294 }
295
296 static void OnMenuSelect(HWND hWnd, UINT nItemID, UINT nFlags, HMENU hSysMenu)
297 {
298 TCHAR str[100];
299
300 if (hSysMenu == NULL) return;
301
302 _tcscpy(str, _T(""));
303 if (nFlags & MF_POPUP) {
304 switch (nItemID) {
305 case ID_FILE_MENU:
306 //EnableMenuItem(hSysMenu, uIDEnableItem, MF_BYCOMMAND|MF_ENABLED);
307 break;
308 case ID_DISK_MENU:
309 // EnableMenuItem(hSysMenu, ID_DISK_COPY_DISK, MF_BYCOMMAND|MF_GRAYED);
310 EnableMenuItem(hSysMenu, ID_DISK_COPY_DISK, MF_BYCOMMAND|MF_ENABLED);
311 break;
312 case ID_TREE_MENU:
313 case ID_VIEW_MENU:
314 case ID_OPTIONS_MENU:
315 case ID_SECURITY_MENU:
316 case ID_WINDOW_MENU:
317 case ID_HELP_MENU:
318 break;
319 }
320 // if (hSysMenu != GetMenu(hWnd)) {
321 // if (nItemID == 2) nItemID = 5;
322 // }
323 }
324 if (LoadString(Globals.hInstance, nItemID, str, 100)) {
325 // load appropriate string
326 LPTSTR lpsz = str;
327 // first newline terminates actual string
328 lpsz = _tcschr(lpsz, '\n');
329 if (lpsz != NULL)
330 *lpsz = '\0';
331 }
332 SendMessage(Globals.hStatusBar, SB_SETTEXT, 0, (LPARAM)str);
333 }
334
335
336 static BOOL activate_drive_window(LPCTSTR path)
337 {
338 TCHAR drv1[_MAX_DRIVE], drv2[_MAX_DRIVE];
339 HWND child_wnd;
340
341 _tsplitpath(path, drv1, 0, 0, 0);
342
343 // search for a already open window for the same drive
344 for (child_wnd = GetNextWindow(Globals.hMDIClient,GW_CHILD);
345 child_wnd;
346 child_wnd = GetNextWindow(child_wnd, GW_HWNDNEXT)) {
347 ChildWnd* pChildWnd = (ChildWnd*) GetWindowLong(child_wnd, GWL_USERDATA);
348 if (pChildWnd) {
349 _tsplitpath(pChildWnd->root.path, drv2, 0, 0, 0);
350 if (!lstrcmpi(drv2, drv1)) {
351 SendMessage(Globals.hMDIClient, WM_MDIACTIVATE, (WPARAM)child_wnd, 0);
352 if (IsMinimized(child_wnd))
353 ShowWindow(child_wnd, SW_SHOWNORMAL);
354 return TRUE;
355 }
356 }
357 }
358 return FALSE;
359 }
360
361 static void toggle_child(HWND hWnd, UINT cmd, HWND hchild)
362 {
363 BOOL vis = IsWindowVisible(hchild);
364
365 CheckMenuItem(Globals.hMenuOptions, cmd, vis?MF_BYCOMMAND:MF_BYCOMMAND|MF_CHECKED);
366 ShowWindow(hchild, vis?SW_HIDE:SW_SHOW);
367 #ifndef _NO_EXTENSIONS
368 if (g_fullscreen.mode)
369 fullscreen_move(hWnd);
370 #endif
371 resize_frame_client(hWnd);
372 }
373
374 ////////////////////////////////////////////////////////////////////////////////
375 //
376 // FUNCTION: _CmdWndProc(HWND, unsigned, WORD, LONG)
377 //
378 // PURPOSE: Processes WM_COMMAND messages for the main frame window.
379 //
380 //
381
382 static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
383 {
384 UINT cmd = LOWORD(wParam);
385 HWND hChildWnd;
386 // HWND hwndClient = (HWND)SendMessage(Globals.hMDIClient, WM_MDIGETACTIVE, 0, 0);
387 // if (hwndClient)
388 // if (SendMessage(hwndClient, WM_DISPATCH_COMMAND, wParam, lParam))
389 // return 0;
390
391 if (cmd >= ID_DRIVE_FIRST && cmd <= (ID_DRIVE_FIRST + 0xFF)) {
392 TCHAR drv[_MAX_DRIVE];
393 //TCHAR path[MAX_PATH];
394 //ChildWnd* pChildWnd;
395 LPCTSTR root = Globals.drives;
396 int i;
397 for (i = cmd - ID_DRIVE_FIRST; i--; root++)
398 while (*root)
399 root++;
400 if (activate_drive_window(root)) {
401 return TRUE;
402 }
403 _tsplitpath(root, drv, 0, 0, 0);
404 if (!SetCurrentDirectory(drv)) {
405 display_error(hWnd, GetLastError());
406 return TRUE;
407 }
408 //GetCurrentDirectory(MAX_PATH, path); //@@ letztes Verzeichnis pro Laufwerk speichern
409 //CreateChildWindow(path);
410 CreateChildWindow(cmd - ID_DRIVE_FIRST);
411
412 // pChildWnd = alloc_child_window(path);
413 // if (!create_child_window(pChildWnd))
414 // free(pChildWnd);
415 } else {
416 switch (cmd) {
417 case ID_WINDOW_CLOSEALL:
418 EnumChildWindows(Globals.hMDIClient, &CloseEnumProc, 0);
419 break;
420 case ID_WINDOW_CLOSE:
421 hChildWnd = (HWND) SendMessage(Globals.hMDIClient, WM_MDIGETACTIVE, 0, 0);
422 if (!SendMessage(hChildWnd, WM_QUERYENDSESSION, 0, 0))
423 SendMessage(Globals.hMDIClient, WM_MDIDESTROY, (WPARAM)hChildWnd, 0);
424 break;
425
426 case ID_DISK_COPY_DISK:
427 CopyDisk(hWnd);
428 break;
429 case ID_DISK_LABEL_DISK:
430 LabelDisk(hWnd);
431 break;
432 case ID_DISK_FORMAT_DISK:
433 FormatDisk(hWnd);
434 #if 0
435 // SHFormatDrive(hWnd, 0 /* A: */, SHFMT_ID_DEFAULT, 0);
436 {
437 UINT OldMode = SetErrorMode(0); // Get the current Error Mode settings.
438 SetErrorMode(OldMode & ~SEM_FAILCRITICALERRORS); // Force O/S to handle
439 // Call SHFormatDrive here.
440 SHFormatDrive(hWnd, 0 /* A: */, SHFMT_ID_DEFAULT, 0);
441 SetErrorMode(OldMode); // Put it back the way it was.
442 }
443 #endif
444 break;
445 case ID_DISK_CONNECT_NETWORK_DRIVE:
446 MapNetworkDrives(hWnd, TRUE);
447 break;
448 case ID_DISK_DISCONNECT_NETWORK_DRIVE:
449 MapNetworkDrives(hWnd, FALSE);
450 break;
451 case ID_DISK_SHARE_AS:
452 ModifySharing(hWnd, TRUE);
453 break;
454 case ID_DISK_STOP_SHARING:
455 ModifySharing(hWnd, FALSE);
456 break;
457 case ID_DISK_SELECT_DRIVE:
458 break;
459
460 case ID_VIEW_BY_FILE_TYPE:
461 {
462 struct ExecuteDialog dlg = {{0}};
463 if (DialogBoxParam(Globals.hInstance, MAKEINTRESOURCE(IDD_DIALOG_VIEW_TYPE), hWnd, ViewFileTypeWndProc, (LPARAM)&dlg) == IDOK) {
464 }
465 }
466 break;
467 case ID_OPTIONS_CONFIRMATION:
468 {
469 struct ExecuteDialog dlg = {{0}};
470 if (DialogBoxParam(Globals.hInstance, MAKEINTRESOURCE(IDD_DIALOG_OPTIONS_CONFIRMATON), hWnd, OptionsConfirmationWndProc, (LPARAM)&dlg) == IDOK) {
471 }
472 }
473 break;
474 case ID_OPTIONS_FONT:
475 break;
476 case ID_OPTIONS_CUSTOMISE_TOOLBAR:
477 SendMessage(Globals.hToolBar, TB_CUSTOMIZE, 0, 0);
478 break;
479 case ID_OPTIONS_TOOLBAR:
480 toggle_child(hWnd, cmd, Globals.hToolBar);
481 break;
482 case ID_OPTIONS_DRIVEBAR:
483 toggle_child(hWnd, cmd, Globals.hDriveBar);
484 break;
485 case ID_OPTIONS_STATUSBAR:
486 toggle_child(hWnd, cmd, Globals.hStatusBar);
487 break;
488 case ID_OPTIONS_OPEN_NEW_WINDOW_ON_CONNECT:
489 if (Globals.Options & OPTIONS_OPEN_NEW_WINDOW_ON_CONNECT) {
490 Globals.Options &= ~OPTIONS_OPEN_NEW_WINDOW_ON_CONNECT;
491 CheckMenuItem(Globals.hMenuOptions, cmd, MF_BYCOMMAND);
492 } else {
493 Globals.Options |= OPTIONS_OPEN_NEW_WINDOW_ON_CONNECT;
494 CheckMenuItem(Globals.hMenuOptions, cmd, MF_BYCOMMAND | MF_CHECKED);
495 }
496 break;
497 case ID_OPTIONS_MINIMISE_ON_USE:
498 if (Globals.Options & ID_OPTIONS_MINIMISE_ON_USE) {
499 Globals.Options &= ~ID_OPTIONS_MINIMISE_ON_USE;
500 CheckMenuItem(Globals.hMenuOptions, cmd, MF_BYCOMMAND);
501 } else {
502 Globals.Options |= ID_OPTIONS_MINIMISE_ON_USE;
503 CheckMenuItem(Globals.hMenuOptions, cmd, MF_BYCOMMAND | MF_CHECKED);
504 }
505 break;
506 case ID_OPTIONS_SAVE_ON_EXIT:
507 if (Globals.Options & OPTIONS_SAVE_ON_EXIT) {
508 Globals.Options &= ~OPTIONS_SAVE_ON_EXIT;
509 CheckMenuItem(Globals.hMenuOptions, cmd, MF_BYCOMMAND);
510 } else {
511 Globals.Options |= OPTIONS_SAVE_ON_EXIT;
512 CheckMenuItem(Globals.hMenuOptions, cmd, MF_BYCOMMAND | MF_CHECKED);
513 }
514 break;
515 case ID_WINDOW_NEW_WINDOW:
516 CreateChildWindow(-1);
517 break;
518 case ID_WINDOW_CASCADE:
519 SendMessage(Globals.hMDIClient, WM_MDICASCADE, 0, 0);
520 break;
521 case ID_WINDOW_TILE_HORZ:
522 SendMessage(Globals.hMDIClient, WM_MDITILE, MDITILE_HORIZONTAL, 0);
523 break;
524 case ID_WINDOW_TILE_VERT:
525 SendMessage(Globals.hMDIClient, WM_MDITILE, MDITILE_VERTICAL, 0);
526 break;
527 case ID_WINDOW_ARRANGE_ICONS:
528 SendMessage(Globals.hMDIClient, WM_MDIICONARRANGE, 0, 0);
529 break;
530 case ID_WINDOW_REFRESH:
531 // TODO:
532 break;
533 case ID_HELP_CONTENTS:
534 WinHelp(hWnd, _T("winfile"), HELP_CONTENTS, 0);
535 break;
536 case ID_HELP_SEARCH_HELP:
537 WinHelp(hWnd, _T("winfile"), HELP_FINDER, 0);
538 break;
539 case ID_HELP_HOW_TO_USE_HELP:
540 WinHelp(hWnd, _T("winfile"), HELP_HELPONHELP, 0);
541 break;
542 case ID_HELP_ABOUT:
543 #ifdef WINSHELLAPI
544 ShellAbout(hWnd, szTitle, "", LoadIcon(Globals.hInstance, (LPCTSTR)IDI_WINFILE));
545 #else
546 ShowAboutBox(hWnd);
547 #endif
548 break;
549 default:
550 /*
551 if ((cmd<IDW_FIRST_CHILD || cmd>=IDW_FIRST_CHILD+0x100) &&
552 (cmd<SC_SIZE || cmd>SC_RESTORE)) {
553 MessageBox(hWnd, _T("Not yet implemented"), _T("Winefile"), MB_OK);
554 }
555 return DefFrameProc(hWnd, Globals.hMDIClient, message, wParam, lParam);
556 */
557 /*
558 hChildWnd = (HWND)SendMessage(Globals.hMDIClient, WM_MDIGETACTIVE, 0, 0);
559 if (IsWindow(hChildWnd))
560 SendMessage(hChildWnd, WM_COMMAND, wParam, lParam);
561 else
562 return DefFrameProc(hWnd, Globals.hMDIClient, message, wParam, lParam);
563 */
564 return FALSE;
565 }
566 }
567 return TRUE;
568 }
569
570
571 static TBBUTTON tbButtonNew[] = {
572 {0, ID_WINDOW_CASCADE, TBSTATE_ENABLED, TBSTYLE_BUTTON},
573 {0, ID_WINDOW_CASCADE, TBSTATE_ENABLED, TBSTYLE_BUTTON},
574 {0, ID_WINDOW_CASCADE, TBSTATE_ENABLED, TBSTYLE_BUTTON},
575 {0, ID_WINDOW_CASCADE, TBSTATE_ENABLED, TBSTYLE_BUTTON},
576 {0, ID_WINDOW_CASCADE, TBSTATE_ENABLED, TBSTYLE_BUTTON},
577 };
578
579 static LRESULT MsgNotify(HWND hwnd, UINT uMessage, WPARAM wparam, LPARAM lparam)
580 {
581 LPNMHDR lpnmhdr;
582
583 //LPNMHDR lpnmhdr;
584 static int nResetCount;
585 static LPTBBUTTON lpSaveButtons;
586 //LPARAM lParam;
587
588
589 lpnmhdr = (LPNMHDR)lparam;
590 /*
591 // The following code allows the toolbar to be customized.
592 // If you return FALSE the Customize Toolbar dialog flashes
593 // and goes away.
594
595 if (lpnmhdr->code == TBN_QUERYINSERT || lpnmhdr->code == TBN_QUERYDELETE) {
596 return TRUE;
597 }
598
599 if (lpnmhdr->code == TBN_GETBUTTONINFO) {
600 LPTBNOTIFY lpTbNotify = (LPTBNOTIFY)lparam;
601 TCHAR szBuffer[20];
602
603 // int tbButtonNew[20] = { 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20 };
604 TBBUTTON tbButtonNew[] = {
605 {0, ID_WINDOW_CASCADE, TBSTATE_ENABLED, TBSTYLE_BUTTON},
606 {0, ID_WINDOW_CASCADE, TBSTATE_ENABLED, TBSTYLE_BUTTON},
607 {0, ID_WINDOW_CASCADE, TBSTATE_ENABLED, TBSTYLE_BUTTON},
608 {0, ID_WINDOW_CASCADE, TBSTATE_ENABLED, TBSTYLE_BUTTON},
609 {0, ID_WINDOW_CASCADE, TBSTATE_ENABLED, TBSTYLE_BUTTON},
610 };
611
612 // 20 = total number of buttons.
613 // tbButton and tbButtonNew send information about
614 // the other 12 buttons in tbButtonNew.
615 if (lpTbNotify->iItem < 5) {
616 lpTbNotify->tbButton = tbButtonNew[lpTbNotify->iItem];
617 // LoadString(hInst, 4000+lpTbNotify->iItem, szBuffer, sizeof(szBuffer)/sizeof(TCHAR));
618 LoadString(hInst, lpTbNotify->iItem, szBuffer, sizeof(szBuffer)/sizeof(TCHAR));
619 lstrcpy (lpTbNotify->pszText, szBuffer);
620 lpTbNotify->cchText = sizeof(szBuffer)/sizeof(TCHAR);
621 return TRUE;
622 } else {
623 return 0;
624 }
625 }
626 */
627 switch (lpnmhdr->code) {
628 case TBN_QUERYINSERT:
629 case TBN_QUERYDELETE:
630 return TRUE;
631
632 case TBN_GETBUTTONINFO:
633 {
634 LPTBNOTIFY lpTbNotify = (LPTBNOTIFY)lparam;
635 TCHAR szBuffer[20];
636 /*
637 typedef struct _TBBUTTON {
638 int iBitmap;
639 int idCommand;
640 BYTE fsState;
641 BYTE fsStyle;
642 DWORD dwData;
643 INT_PTR iString;
644 } TBBUTTON, NEAR* PTBBUTTON, FAR* LPTBBUTTON;
645 */
646 // 20 = total number of buttons.
647 // tbButton and tbButtonNew send information about
648 // the other 12 buttons in tbButtonNew.
649 if (lpTbNotify->iItem < 12) {
650 lpTbNotify->tbButton = tbButtonNew[lpTbNotify->iItem];
651 LoadString(hInst, lpTbNotify->iItem + 32769, szBuffer, sizeof(szBuffer)/sizeof(TCHAR));
652 lstrcpy(lpTbNotify->pszText, szBuffer);
653 lpTbNotify->cchText = sizeof(szBuffer)/sizeof(TCHAR);
654 return TRUE;
655 } else {
656 return 0;
657 }
658 }
659 break;
660
661 case TBN_BEGINADJUST: // Start customizing the toolbar.
662 {
663 LPTBNOTIFY lpTB = (LPTBNOTIFY)lparam;
664 int i;
665
666 // Allocate memory to store the button information.
667 nResetCount = SendMessage(lpTB->hdr.hwndFrom, TB_BUTTONCOUNT, 0, 0);
668 lpSaveButtons = (LPTBBUTTON)GlobalAlloc(GPTR, sizeof(TBBUTTON) * nResetCount);
669
670 // Save the current configuration so if the user presses
671 // reset, the original toolbar can be restored.
672 for (i = 0; i < nResetCount; i++) {
673 SendMessage(lpTB->hdr.hwndFrom, TB_GETBUTTON, i, (LPARAM)(lpSaveButtons + i));
674 }
675 }
676 return TRUE;
677
678 case TBN_RESET:
679 {
680 LPTBNOTIFY lpTB = (LPTBNOTIFY)lparam;
681 int nCount, i;
682
683 // Remove all of the existing buttons starting with the last and working down.
684 nCount = SendMessage(lpTB->hdr.hwndFrom, TB_BUTTONCOUNT, 0, 0);
685 for (i = nCount - 1; i >= 0; i--) {
686 SendMessage(lpTB->hdr.hwndFrom, TB_DELETEBUTTON, i, 0);
687 }
688
689 // Restore the buttons that were saved.
690 SendMessage(lpTB->hdr.hwndFrom, TB_ADDBUTTONS, (WPARAM)nResetCount, (LPARAM)lpSaveButtons);
691 }
692 return TRUE;
693
694 case TBN_ENDADJUST:
695 // Free the memory allocated during TBN_BEGINADJUST
696 GlobalFree((HGLOBAL)lpSaveButtons);
697 return TRUE;
698 }
699 return 0;
700 }
701
702 ////////////////////////////////////////////////////////////////////////////////
703 //
704 // FUNCTION: FrameWndProc(HWND, unsigned, WORD, LONG)
705 //
706 // PURPOSE: Processes messages for the main frame window.
707 //
708 // WM_COMMAND - process the application menu
709 // WM_DESTROY - post a quit message and return
710 //
711 //
712
713 LRESULT CALLBACK FrameWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
714 {
715 switch (message) {
716 case WM_CREATE:
717 {
718 HMENU hMenuWindow = GetSubMenu(Globals.hMenuFrame, GetMenuItemCount(Globals.hMenuFrame)-2);
719 CLIENTCREATESTRUCT ccs = { hMenuWindow, IDW_FIRST_CHILD };
720 Globals.hMDIClient = CreateWindowEx(0, _T("MDICLIENT"), NULL,
721 WS_EX_MDICHILD|WS_CHILD|WS_CLIPCHILDREN|WS_VISIBLE,
722 0, 0, 0, 0,
723 hWnd, (HMENU)0, hInst, &ccs);
724 }
725 CheckShellAvailable();
726 CreateNetworkMonitorThread(hWnd);
727 CreateMonitorThread(hWnd);
728 CreateChildWindow(-1);
729 SetTimer(hWnd, 1, 5000, NULL);
730 break;
731
732 case WM_NOTIFY:
733
734 if (MsgNotify(hWnd, message, wParam, lParam)) return TRUE;
735 // return MsgNotify(hWnd, message, wParam, lParam);
736 switch (((LPNMHDR)lParam)->code) {
737 #ifdef _MSC_VER
738 case TTN_GETDISPINFO:
739 {
740 LPTOOLTIPTEXT lpttt;
741 lpttt = (LPTOOLTIPTEXT)lParam;
742 lpttt->hinst = hInst;
743 // load appropriate string
744 lpttt->lpszText = MAKEINTRESOURCE(lpttt->hdr.idFrom);
745 }
746 break;
747 #endif
748 default:
749 break;
750 }
751 break;
752
753 case WM_COMMAND:
754 if (!_CmdWndProc(hWnd, message, wParam, lParam)) {
755 // if (LOWORD(wParam) > ID_CMD_FIRST && LOWORD(wParam) < ID_CMD_LAST) {
756 HWND hChildWnd = (HWND)SendMessage(Globals.hMDIClient, WM_MDIGETACTIVE, 0, 0);
757 if (IsWindow(hChildWnd))
758 if (SendMessage(hChildWnd, WM_DISPATCH_COMMAND, wParam, lParam))
759 break;
760 // }
761 return DefFrameProc(hWnd, Globals.hMDIClient, message, wParam, lParam);
762 }
763 break;
764
765 case WM_TIMER:
766 SignalMonitorEvent();
767 SignalNetworkMonitorEvent();
768 break;
769
770 case WM_SIZE:
771 resize_frame_client(hWnd);
772 break;
773 case WM_ENTERMENULOOP:
774 OnEnterMenuLoop(hWnd);
775 break;
776 case WM_EXITMENULOOP:
777 OnExitMenuLoop(hWnd);
778 break;
779 case WM_MENUSELECT:
780 OnMenuSelect(hWnd, LOWORD(wParam), HIWORD(wParam), (HMENU)lParam);
781 break;
782 case WM_DESTROY:
783 WinHelp(hWnd, _T("winfile"), HELP_QUIT, 0);
784 KillTimer(hWnd, 1);
785 DestryMonitorThread();
786 DestryNetworkMonitorThread();
787 PostQuitMessage(0);
788 break;
789 case WM_QUERYENDSESSION:
790 case WM_CLOSE:
791 SendMessage(hWnd, WM_COMMAND, ID_WINDOW_CLOSEALL, 0);
792 if (GetWindow(Globals.hMDIClient, GW_CHILD) != NULL)
793 return 0;
794 // else fall thru...
795 default: //def:
796 return DefFrameProc(hWnd, Globals.hMDIClient, message, wParam, lParam);
797 }
798 return 0;
799 }
800
801