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
37 //#include <shellapi.h>
53 ////////////////////////////////////////////////////////////////////////////////
54 // Global and Local Variables:
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
61 static HHOOK hcbthook
;
62 static ChildWnd
* newchild
= NULL
;
65 ////////////////////////////////////////////////////////////////////////////////
66 // Local module support methods
69 static void resize_frame_rect(HWND hWnd
, PRECT prect
)
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;
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
);
87 // prect->bottom -= rt.bottom+2;
88 prect
->bottom
-= rt
.bottom
-1;
90 if (IsWindowVisible(Globals
.hStatusBar
)) {
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
;
98 MoveWindow(Globals
.hMDIClient
, prect
->left
-1,prect
->top
-1,prect
->right
+2,prect
->bottom
+1, TRUE
);
101 static void resize_frame(HWND hWnd
, int cx
, int cy
)
103 RECT rect
= {0, 0, cx
, cy
};
105 resize_frame_rect(hWnd
, &rect
);
108 void resize_frame_client(HWND hWnd
)
112 GetClientRect(hWnd
, &rect
);
113 resize_frame_rect(hWnd
, &rect
);
116 ////////////////////////////////////////////////////////////////////////////////
118 static LRESULT CALLBACK
CBTProc(int code
, WPARAM wParam
, LPARAM lParam
)
120 if (code
== HCBT_CREATEWND
&& newchild
) {
121 ChildWnd
* pChildWnd
= newchild
;
123 pChildWnd
->hWnd
= (HWND
)wParam
;
124 SetWindowLong(pChildWnd
->hWnd
, GWL_USERDATA
, (LPARAM
)pChildWnd
);
126 return CallNextHookEx(hcbthook
, code
, wParam
, lParam
);
131 BOOL FindChildWindow(int cmd)
133 TCHAR drv[_MAX_DRIVE];
134 LPCTSTR root = Globals.drives;
136 for(i = cmd - ID_DRIVE_FIRST; i--; root++)
139 if (activate_drive_window(root))
141 _tsplitpath(root, drv, 0, 0, 0);
142 if (!SetCurrentDirectory(drv)) {
143 display_error(hWnd, GetLastError());
150 static ChildWnd
* alloc_child_window(LPCTSTR path
)
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
;
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
;
164 pChildWnd
->right
.visible_cols
= COL_SIZE
|COL_DATE
|COL_TIME
|COL_ATTRIBUTES
;
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__)
181 root
->drive_type
= GetDriveType(path
);
182 lstrcat(drv
, _T("/"));
183 lstrcpy(root
->volname
, _T("root fs"));
185 lstrcpy(root
->fs
, _T("unixfs"));
186 lstrcpy(root
->path
, _T("/"));
187 entry
= read_tree_unix(root
, path
, pChildWnd
->sortOrder
);
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
);
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
);
205 HWND
CreateChildWindow(int drv_id
)
207 //TCHAR drv[_MAX_DRIVE];
208 TCHAR path
[MAX_PATH
];
209 ChildWnd
* pChildWnd
= NULL
;
211 LPCTSTR root = Globals.drives;
213 for(i = cmd - ID_DRIVE_FIRST; i--; root++)
216 if (activate_drive_window(root))
218 _tsplitpath(root, drv, 0, 0, 0);
219 if (!SetCurrentDirectory(drv)) {
220 display_error(hWnd, GetLastError());
224 GetCurrentDirectory(MAX_PATH
, path
);
225 // pChildWnd = (ChildWnd*)malloc(sizeof(ChildWnd));
226 pChildWnd
= alloc_child_window(path
);
227 // if (!create_child_window(pChildWnd))
230 if (pChildWnd
!= NULL
) {
231 MDICREATESTRUCT mcs
= {
232 szChildClass
, path
, hInst
,
233 // CW_USEDEFAULT, CW_USEDEFAULT,
234 // CW_USEDEFAULT, CW_USEDEFAULT,
237 // 0/*style*/, 0/*lParam*/
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
;
247 newchild
= pChildWnd
= NULL
;
253 static BOOL CALLBACK
CloseEnumProc(HWND hWnd
, LPARAM lParam
)
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);
264 static void OnEnterMenuLoop(HWND hWnd
)
268 // Update the status bar pane sizes
270 SendMessage(Globals
.hStatusBar
, SB_SETPARTS
, 1, (long)&nParts
);
272 SendMessage(Globals
.hStatusBar
, SB_SETTEXT
, (WPARAM
)0, (LPARAM
)_T(""));
275 static void OnExitMenuLoop(HWND hWnd
)
282 // Update the status bar pane sizes
283 GetClientRect(hWnd, &rc);
286 nParts[2] = rc.right;
287 SendMessage(Globals.hStatusBar, SB_SETPARTS, 3, (long)nParts);
288 SendMessage(Globals.hStatusBar, SB_SETTEXT, 0, (LPARAM)_T(""));
290 SendMessage(Globals
.hStatusBar
, SB_SETTEXT
, 0, (LPARAM
)_T(""));
292 SetupStatusBar(TRUE
);
296 static void OnMenuSelect(HWND hWnd
, UINT nItemID
, UINT nFlags
, HMENU hSysMenu
)
300 if (hSysMenu
== NULL
) return;
302 _tcscpy(str
, _T(""));
303 if (nFlags
& MF_POPUP
) {
306 //EnableMenuItem(hSysMenu, uIDEnableItem, MF_BYCOMMAND|MF_ENABLED);
309 // EnableMenuItem(hSysMenu, ID_DISK_COPY_DISK, MF_BYCOMMAND|MF_GRAYED);
310 EnableMenuItem(hSysMenu
, ID_DISK_COPY_DISK
, MF_BYCOMMAND
|MF_ENABLED
);
314 case ID_OPTIONS_MENU
:
315 case ID_SECURITY_MENU
:
320 // if (hSysMenu != GetMenu(hWnd)) {
321 // if (nItemID == 2) nItemID = 5;
324 if (LoadString(Globals
.hInstance
, nItemID
, str
, 100)) {
325 // load appropriate string
327 // first newline terminates actual string
328 lpsz
= _tcschr(lpsz
, '\n');
332 SendMessage(Globals
.hStatusBar
, SB_SETTEXT
, 0, (LPARAM
)str
);
336 static BOOL
activate_drive_window(LPCTSTR path
)
338 TCHAR drv1
[_MAX_DRIVE
], drv2
[_MAX_DRIVE
];
341 _tsplitpath(path
, drv1
, 0, 0, 0);
343 // search for a already open window for the same drive
344 for (child_wnd
= GetNextWindow(Globals
.hMDIClient
,GW_CHILD
);
346 child_wnd
= GetNextWindow(child_wnd
, GW_HWNDNEXT
)) {
347 ChildWnd
* pChildWnd
= (ChildWnd
*) GetWindowLong(child_wnd
, GWL_USERDATA
);
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
);
361 static void toggle_child(HWND hWnd
, UINT cmd
, HWND hchild
)
363 BOOL vis
= IsWindowVisible(hchild
);
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
);
371 resize_frame_client(hWnd
);
374 ////////////////////////////////////////////////////////////////////////////////
376 // FUNCTION: _CmdWndProc(HWND, unsigned, WORD, LONG)
378 // PURPOSE: Processes WM_COMMAND messages for the main frame window.
382 static BOOL
_CmdWndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
384 UINT cmd
= LOWORD(wParam
);
386 // HWND hwndClient = (HWND)SendMessage(Globals.hMDIClient, WM_MDIGETACTIVE, 0, 0);
388 // if (SendMessage(hwndClient, WM_DISPATCH_COMMAND, wParam, lParam))
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
;
397 for (i
= cmd
- ID_DRIVE_FIRST
; i
--; root
++)
400 if (activate_drive_window(root
)) {
403 _tsplitpath(root
, drv
, 0, 0, 0);
404 if (!SetCurrentDirectory(drv
)) {
405 display_error(hWnd
, GetLastError());
408 //GetCurrentDirectory(MAX_PATH, path); //@@ letztes Verzeichnis pro Laufwerk speichern
409 //CreateChildWindow(path);
410 CreateChildWindow(cmd
- ID_DRIVE_FIRST
);
412 // pChildWnd = alloc_child_window(path);
413 // if (!create_child_window(pChildWnd))
417 case ID_WINDOW_CLOSEALL
:
418 EnumChildWindows(Globals
.hMDIClient
, &CloseEnumProc
, 0);
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);
426 case ID_DISK_COPY_DISK
:
429 case ID_DISK_LABEL_DISK
:
432 case ID_DISK_FORMAT_DISK
:
435 // SHFormatDrive(hWnd, 0 /* A: */, SHFMT_ID_DEFAULT, 0);
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.
445 case ID_DISK_CONNECT_NETWORK_DRIVE
:
446 MapNetworkDrives(hWnd
, TRUE
);
448 case ID_DISK_DISCONNECT_NETWORK_DRIVE
:
449 MapNetworkDrives(hWnd
, FALSE
);
451 case ID_DISK_SHARE_AS
:
452 ModifySharing(hWnd
, TRUE
);
454 case ID_DISK_STOP_SHARING
:
455 ModifySharing(hWnd
, FALSE
);
457 case ID_DISK_SELECT_DRIVE
:
460 case ID_VIEW_BY_FILE_TYPE
:
462 struct ExecuteDialog dlg
= {{0}};
463 if (DialogBoxParam(Globals
.hInstance
, MAKEINTRESOURCE(IDD_DIALOG_VIEW_TYPE
), hWnd
, ViewFileTypeWndProc
, (LPARAM
)&dlg
) == IDOK
) {
467 case ID_OPTIONS_CONFIRMATION
:
469 struct ExecuteDialog dlg
= {{0}};
470 if (DialogBoxParam(Globals
.hInstance
, MAKEINTRESOURCE(IDD_DIALOG_OPTIONS_CONFIRMATON
), hWnd
, OptionsConfirmationWndProc
, (LPARAM
)&dlg
) == IDOK
) {
474 case ID_OPTIONS_FONT
:
476 case ID_OPTIONS_CUSTOMISE_TOOLBAR
:
477 SendMessage(Globals
.hToolBar
, TB_CUSTOMIZE
, 0, 0);
479 case ID_OPTIONS_TOOLBAR
:
480 toggle_child(hWnd
, cmd
, Globals
.hToolBar
);
482 case ID_OPTIONS_DRIVEBAR
:
483 toggle_child(hWnd
, cmd
, Globals
.hDriveBar
);
485 case ID_OPTIONS_STATUSBAR
:
486 toggle_child(hWnd
, cmd
, Globals
.hStatusBar
);
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
);
493 Globals
.Options
|= OPTIONS_OPEN_NEW_WINDOW_ON_CONNECT
;
494 CheckMenuItem(Globals
.hMenuOptions
, cmd
, MF_BYCOMMAND
| MF_CHECKED
);
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
);
502 Globals
.Options
|= ID_OPTIONS_MINIMISE_ON_USE
;
503 CheckMenuItem(Globals
.hMenuOptions
, cmd
, MF_BYCOMMAND
| MF_CHECKED
);
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
);
511 Globals
.Options
|= OPTIONS_SAVE_ON_EXIT
;
512 CheckMenuItem(Globals
.hMenuOptions
, cmd
, MF_BYCOMMAND
| MF_CHECKED
);
515 case ID_WINDOW_NEW_WINDOW
:
516 CreateChildWindow(-1);
518 case ID_WINDOW_CASCADE
:
519 SendMessage(Globals
.hMDIClient
, WM_MDICASCADE
, 0, 0);
521 case ID_WINDOW_TILE_HORZ
:
522 SendMessage(Globals
.hMDIClient
, WM_MDITILE
, MDITILE_HORIZONTAL
, 0);
524 case ID_WINDOW_TILE_VERT
:
525 SendMessage(Globals
.hMDIClient
, WM_MDITILE
, MDITILE_VERTICAL
, 0);
527 case ID_WINDOW_ARRANGE_ICONS
:
528 SendMessage(Globals
.hMDIClient
, WM_MDIICONARRANGE
, 0, 0);
530 case ID_WINDOW_REFRESH
:
533 case ID_HELP_CONTENTS
:
534 WinHelp(hWnd
, _T("winfile"), HELP_CONTENTS
, 0);
536 case ID_HELP_SEARCH_HELP
:
537 WinHelp(hWnd
, _T("winfile"), HELP_FINDER
, 0);
539 case ID_HELP_HOW_TO_USE_HELP
:
540 WinHelp(hWnd
, _T("winfile"), HELP_HELPONHELP
, 0);
544 ShellAbout(hWnd
, szTitle
, "", LoadIcon(Globals
.hInstance
, (LPCTSTR
)IDI_WINFILE
));
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);
555 return DefFrameProc(hWnd, Globals.hMDIClient, message, wParam, lParam);
558 hChildWnd = (HWND)SendMessage(Globals.hMDIClient, WM_MDIGETACTIVE, 0, 0);
559 if (IsWindow(hChildWnd))
560 SendMessage(hChildWnd, WM_COMMAND, wParam, lParam);
562 return DefFrameProc(hWnd, Globals.hMDIClient, message, wParam, lParam);
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
},
579 static LRESULT
MsgNotify(HWND hwnd
, UINT uMessage
, WPARAM wparam
, LPARAM lparam
)
584 static int nResetCount
;
585 static LPTBBUTTON lpSaveButtons
;
589 lpnmhdr
= (LPNMHDR
)lparam
;
591 // The following code allows the toolbar to be customized.
592 // If you return FALSE the Customize Toolbar dialog flashes
595 if (lpnmhdr->code == TBN_QUERYINSERT || lpnmhdr->code == TBN_QUERYDELETE) {
599 if (lpnmhdr->code == TBN_GETBUTTONINFO) {
600 LPTBNOTIFY lpTbNotify = (LPTBNOTIFY)lparam;
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},
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);
627 switch (lpnmhdr
->code
) {
628 case TBN_QUERYINSERT
:
629 case TBN_QUERYDELETE
:
632 case TBN_GETBUTTONINFO
:
634 LPTBNOTIFY lpTbNotify
= (LPTBNOTIFY
)lparam
;
637 typedef struct _TBBUTTON {
644 } TBBUTTON, NEAR* PTBBUTTON, FAR* LPTBBUTTON;
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
);
661 case TBN_BEGINADJUST
: // Start customizing the toolbar.
663 LPTBNOTIFY lpTB
= (LPTBNOTIFY
)lparam
;
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
);
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
));
680 LPTBNOTIFY lpTB
= (LPTBNOTIFY
)lparam
;
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);
689 // Restore the buttons that were saved.
690 SendMessage(lpTB
->hdr
.hwndFrom
, TB_ADDBUTTONS
, (WPARAM
)nResetCount
, (LPARAM
)lpSaveButtons
);
695 // Free the memory allocated during TBN_BEGINADJUST
696 GlobalFree((HGLOBAL
)lpSaveButtons
);
702 ////////////////////////////////////////////////////////////////////////////////
704 // FUNCTION: FrameWndProc(HWND, unsigned, WORD, LONG)
706 // PURPOSE: Processes messages for the main frame window.
708 // WM_COMMAND - process the application menu
709 // WM_DESTROY - post a quit message and return
713 LRESULT CALLBACK
FrameWndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
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
,
723 hWnd
, (HMENU
)0, hInst
, &ccs
);
725 CheckShellAvailable();
726 CreateNetworkMonitorThread(hWnd
);
727 CreateMonitorThread(hWnd
);
728 CreateChildWindow(-1);
729 SetTimer(hWnd
, 1, 5000, NULL
);
734 if (MsgNotify(hWnd
, message
, wParam
, lParam
)) return TRUE
;
735 // return MsgNotify(hWnd, message, wParam, lParam);
736 switch (((LPNMHDR
)lParam
)->code
) {
738 case TTN_GETDISPINFO
:
741 lpttt
= (LPTOOLTIPTEXT
)lParam
;
742 lpttt
->hinst
= hInst
;
743 // load appropriate string
744 lpttt
->lpszText
= MAKEINTRESOURCE(lpttt
->hdr
.idFrom
);
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
))
761 return DefFrameProc(hWnd
, Globals
.hMDIClient
, message
, wParam
, lParam
);
766 SignalMonitorEvent();
767 SignalNetworkMonitorEvent();
771 resize_frame_client(hWnd
);
773 case WM_ENTERMENULOOP
:
774 OnEnterMenuLoop(hWnd
);
776 case WM_EXITMENULOOP
:
777 OnExitMenuLoop(hWnd
);
780 OnMenuSelect(hWnd
, LOWORD(wParam
), HIWORD(wParam
), (HMENU
)lParam
);
783 WinHelp(hWnd
, _T("winfile"), HELP_QUIT
, 0);
785 DestryMonitorThread();
786 DestryNetworkMonitorThread();
789 case WM_QUERYENDSESSION
:
791 SendMessage(hWnd
, WM_COMMAND
, ID_WINDOW_CLOSEALL
, 0);
792 if (GetWindow(Globals
.hMDIClient
, GW_CHILD
) != NULL
)
796 return DefFrameProc(hWnd
, Globals
.hMDIClient
, message
, wParam
, lParam
);