2 * PROJECT: ReactOS Device Managment
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: base/system/devmgmt/mainwnd.c
5 * PURPOSE: Main window message handler
6 * COPYRIGHT: Copyright 2006 Ged Murphy <gedmurphy@gmail.com>
12 static BOOL
pCreateToolbar(PMAIN_WND_INFO Info
);
14 static const TCHAR szMainWndClass
[] = TEXT("DevMgmtWndClass");
19 { /* iBitmap, idCommand, fsState, fsStyle, bReserved[2], dwData, iString */
20 {TBICON_PROP
, IDC_PROP
, TBSTATE_INDETERMINATE
, BTNS_BUTTON
, {0}, 0, 0}, /* properties */
21 {TBICON_REFRESH
, IDC_REFRESH
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 0, 0}, /* refresh */
23 /* Note: First item for a seperator is its width in pixels */
24 {15, 0, TBSTATE_ENABLED
, BTNS_SEP
, {0}, 0, 0}, /* separator */
26 {TBICON_HELP
, IDC_PROGHELP
,TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 0, 0 }, /* help */
27 {TBICON_EXIT
, IDC_EXIT
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 0, 0 }, /* exit */
33 static const MENU_HINT MainMenuHintTable
[] = {
35 {IDC_EXIT
, IDS_HINT_EXIT
},
38 {IDC_REFRESH
, IDS_HINT_REFRESH
},
39 {IDC_PROP
, IDS_HINT_PROP
},
42 {IDC_PROGHELP
, IDS_HINT_HELP
},
43 {IDC_ABOUT
, IDS_HINT_ABOUT
}
46 /* system menu hints */
47 static const MENU_HINT SystemMenuHintTable
[] = {
48 {SC_RESTORE
, IDS_HINT_SYS_RESTORE
},
49 {SC_MOVE
, IDS_HINT_SYS_MOVE
},
50 {SC_SIZE
, IDS_HINT_SYS_SIZE
},
51 {SC_MINIMIZE
, IDS_HINT_SYS_MINIMIZE
},
52 {SC_MAXIMIZE
, IDS_HINT_SYS_MAXIMIZE
},
53 {SC_CLOSE
, IDS_HINT_SYS_CLOSE
},
58 MainWndMenuHint(PMAIN_WND_INFO Info
,
60 const MENU_HINT
*HintArray
,
65 const MENU_HINT
*LastHint
;
66 UINT HintId
= DefHintId
;
68 LastHint
= HintArray
+ HintsCount
;
69 while (HintArray
!= LastHint
)
71 if (HintArray
->CmdId
== CmdId
)
73 HintId
= HintArray
->HintId
;
80 StatusBarLoadString(Info
->hStatus
,
90 UpdateMainStatusBar(PMAIN_WND_INFO Info
)
92 if (Info
->hStatus
!= NULL
)
94 SendMessage(Info
->hStatus
,
96 (WPARAM
)Info
->InMenuLoop
,
103 pCreateToolbar(PMAIN_WND_INFO Info
)
105 INT NumButtons
= sizeof(Buttons
) / sizeof(Buttons
[0]);
107 Info
->hTool
= CreateWindowEx(0,
110 WS_CHILD
| WS_VISIBLE
| TBSTYLE_FLAT
| TBSTYLE_TOOLTIPS
,
116 if(Info
->hTool
!= NULL
)
118 HIMAGELIST hImageList
;
120 SendMessage(Info
->hTool
,
123 TBSTYLE_EX_HIDECLIPPEDBUTTONS
);
125 SendMessage(Info
->hTool
,
130 hImageList
= InitImageList(IDB_PROP
,
134 if (hImageList
== NULL
)
137 ImageList_Destroy((HIMAGELIST
)SendMessage(Info
->hTool
,
140 (LPARAM
)hImageList
));
142 SendMessage(Info
->hTool
,
155 CreateTreeView(PMAIN_WND_INFO Info
)
157 Info
->hTreeView
= CreateWindowEx(WS_EX_CLIENTEDGE
,
160 WS_CHILD
| WS_VISIBLE
| WS_BORDER
| TVS_HASLINES
|
161 TVS_HASBUTTONS
| TVS_SHOWSELALWAYS
| TVS_LINESATROOT
,
167 if (Info
->hTreeView
== NULL
)
169 DisplayString(_T("Could not create TreeView."));
177 CreateStatusBar(PMAIN_WND_INFO Info
)
179 INT StatWidths
[] = {110, -1}; /* widths of status bar */
181 Info
->hStatus
= CreateWindowEx(0,
184 WS_CHILD
| WS_VISIBLE
| SBARS_SIZEGRIP
,
187 (HMENU
)IDC_STATUSBAR
,
190 if(Info
->hStatus
== NULL
)
194 SendMessage(Info
->hStatus
,
196 sizeof(StatWidths
) / sizeof(INT
),
204 DeviceEnumThread(LPVOID lpParameter
)
209 hTreeView
= (HWND
*)lpParameter
;
212 FreeDeviceStrings(*hTreeView
);
214 hRoot
= InitTreeView(*hTreeView
);
217 ListDevicesByType(*hTreeView
, hRoot
);
226 InitMainWnd(PMAIN_WND_INFO Info
)
228 HANDLE DevEnumThread
;
231 if (!pCreateToolbar(Info
))
232 DisplayString(_T("error creating toolbar"));
234 if (!CreateTreeView(Info
))
236 DisplayString(_T("error creating list view"));
240 if (!CreateStatusBar(Info
))
241 DisplayString(_T("error creating status bar"));
243 /* make 'properties' bold */
244 hMenu
= GetMenu(Info
->hMainWnd
);
245 hMenu
= GetSubMenu(hMenu
, 1);
246 SetMenuDefaultItem(hMenu
, IDC_PROP
, FALSE
);
248 /* Create Popup Menu */
249 Info
->hShortcutMenu
= LoadMenu(hInstance
,
250 MAKEINTRESOURCE(IDR_POPUP
));
251 Info
->hShortcutMenu
= GetSubMenu(Info
->hShortcutMenu
,
253 SetMenuDefaultItem(Info
->hShortcutMenu
, IDC_PROP
, FALSE
);
255 /* create seperate thread to emum devices */
256 DevEnumThread
= CreateThread(NULL
,
264 DisplayString(_T("Failed to enumerate devices"));
268 CloseHandle(DevEnumThread
);
274 OnContext(PMAIN_WND_INFO Info
,
281 INT xPos
= GET_X_LPARAM(lParam
);
282 INT yPos
= GET_Y_LPARAM(lParam
);
284 hSelected
= TreeView_GetSelection(Info
->hTreeView
);
286 if (TreeView_GetItemRect(Info
->hTreeView
,
291 if (GetCursorPos(&pt
) &&
292 ScreenToClient(Info
->hTreeView
, &pt
) &&
295 TrackPopupMenuEx(Info
->hShortcutMenu
,
307 OnNotify(PMAIN_WND_INFO Info
,
310 LPNMHDR pnmhdr
= (LPNMHDR
)lParam
;
312 switch (pnmhdr
->code
)
316 LPNM_TREEVIEW pnmtv
= (LPNM_TREEVIEW
)lParam
;
318 if (!TreeView_GetChild(Info
->hTreeView
,
319 pnmtv
->itemNew
.hItem
))
321 SendMessage(Info
->hTool
,
324 (LPARAM
)MAKELONG(TBSTATE_ENABLED
, 0));
326 EnableMenuItem(GetMenu(Info
->hMainWnd
), IDC_PROP
, MF_ENABLED
);
327 EnableMenuItem(Info
->hShortcutMenu
, IDC_PROP
, MF_ENABLED
);
331 SendMessage(Info
->hTool
,
334 (LPARAM
)MAKELONG(TBSTATE_INDETERMINATE
, 0));
336 EnableMenuItem(GetMenu(Info
->hMainWnd
), IDC_PROP
, MF_GRAYED
);
337 EnableMenuItem(Info
->hShortcutMenu
, IDC_PROP
, MF_GRAYED
);
344 HTREEITEM hSelected
= TreeView_GetSelection(Info
->hTreeView
);
346 if (!TreeView_GetChild(Info
->hTreeView
,
349 OpenPropSheet(Info
->hTreeView
,
357 TV_HITTESTINFO HitTest
;
359 if (GetCursorPos(&HitTest
.pt
) &&
360 ScreenToClient(Info
->hTreeView
, &HitTest
.pt
))
362 if (TreeView_HitTest(Info
->hTreeView
, &HitTest
))
363 (void)TreeView_SelectItem(Info
->hTreeView
, HitTest
.hItem
);
368 case TTN_GETDISPINFO
:
373 lpttt
= (LPTOOLTIPTEXT
)lParam
;
375 idButton
= (UINT
)lpttt
->hdr
.idFrom
;
379 lpttt
->lpszText
= MAKEINTRESOURCE(IDS_TOOLTIP_PROP
);
383 lpttt
->lpszText
= MAKEINTRESOURCE(IDS_TOOLTIP_REFRESH
);
387 lpttt
->lpszText
= MAKEINTRESOURCE(IDS_TOOLTIP_HELP
);
391 lpttt
->lpszText
= MAKEINTRESOURCE(IDS_TOOLTIP_EXIT
);
401 MainWndCommand(PMAIN_WND_INFO Info
,
405 UNREFERENCED_PARAMETER(hControl
);
411 HTREEITEM hSelected
= TreeView_GetSelection(Info
->hTreeView
);
412 OpenPropSheet(Info
->hTreeView
,
419 HANDLE DevEnumThread
;
421 SendMessage(Info
->hTool
,
424 (LPARAM
)MAKELONG(TBSTATE_INDETERMINATE
, 0));
426 EnableMenuItem(GetMenu(Info
->hMainWnd
), IDC_PROP
, MF_GRAYED
);
427 EnableMenuItem(Info
->hShortcutMenu
, IDC_PROP
, MF_GRAYED
);
429 /* create seperate thread to emum devices */
430 DevEnumThread
= CreateThread(NULL
,
438 DisplayString(_T("Failed to enumerate devices"));
442 CloseHandle(DevEnumThread
);
448 DisplayString(_T("Help is not yet implemented\n"));
449 SetFocus(Info
->hTreeView
);
455 PostMessage(Info
->hMainWnd
,
465 MAKEINTRESOURCE(IDD_ABOUTBOX
),
467 (DLGPROC
)AboutDialogProc
);
469 SetFocus(Info
->hTreeView
);
478 MainWndResize(PMAIN_WND_INFO Info
,
482 RECT rcClient
, rcTool
, rcStatus
;
483 int lvHeight
, iToolHeight
, iStatusHeight
;
485 /* Size toolbar and get height */
486 SendMessage(Info
->hTool
, TB_AUTOSIZE
, 0, 0);
487 GetWindowRect(Info
->hTool
, &rcTool
);
488 iToolHeight
= rcTool
.bottom
- rcTool
.top
;
490 /* Size status bar and get height */
491 SendMessage(Info
->hStatus
, WM_SIZE
, 0, 0);
492 GetWindowRect(Info
->hStatus
, &rcStatus
);
493 iStatusHeight
= rcStatus
.bottom
- rcStatus
.top
;
495 /* Calculate remaining height and size list view */
496 GetClientRect(Info
->hMainWnd
, &rcClient
);
497 lvHeight
= rcClient
.bottom
- iToolHeight
- iStatusHeight
;
498 SetWindowPos(Info
->hTreeView
,
508 static LRESULT CALLBACK
509 MainWndProc(HWND hwnd
,
517 /* Get the window context */
518 Info
= (PMAIN_WND_INFO
)GetWindowLongPtr(hwnd
,
520 if (Info
== NULL
&& msg
!= WM_CREATE
)
522 goto HandleDefaultMessage
;
529 Info
= (PMAIN_WND_INFO
)(((LPCREATESTRUCT
)lParam
)->lpCreateParams
);
531 /* Initialize the main window context */
532 Info
->hMainWnd
= hwnd
;
534 SetWindowLongPtr(hwnd
,
538 if (!InitMainWnd(Info
))
539 SendMessage(hwnd
, WM_CLOSE
, 0, 0);
541 /* Show the window */
558 OnNotify(Info
, lParam
);
564 OnContext(Info
, lParam
);
573 goto HandleDefaultMessage
;
578 if (Info
->hStatus
!= NULL
)
580 if (!MainWndMenuHint(Info
,
583 sizeof(MainMenuHintTable
) / sizeof(MainMenuHintTable
[0]),
586 MainWndMenuHint(Info
,
589 sizeof(SystemMenuHintTable
) / sizeof(SystemMenuHintTable
[0]),
596 case WM_ENTERMENULOOP
:
598 Info
->InMenuLoop
= TRUE
;
599 UpdateMainStatusBar(Info
);
603 case WM_EXITMENULOOP
:
605 Info
->InMenuLoop
= FALSE
;
606 UpdateMainStatusBar(Info
);
612 FreeDeviceStrings(Info
->hTreeView
);
613 DestroyMenu(Info
->hShortcutMenu
);
620 HeapFree(ProcessHeap
,
623 SetWindowLongPtr(hwnd
,
627 /* Break the message queue loop */
634 HandleDefaultMessage
:
636 Ret
= DefWindowProc(hwnd
,
649 CreateMainWindow(LPCTSTR lpCaption
,
653 HWND hMainWnd
= NULL
;
655 Info
= (PMAIN_WND_INFO
)HeapAlloc(ProcessHeap
,
657 sizeof(MAIN_WND_INFO
));
661 Info
->nCmdShow
= nCmdShow
;
663 hMainWnd
= CreateWindowEx(WS_EX_WINDOWEDGE
,
666 WS_OVERLAPPEDWINDOW
| WS_CLIPCHILDREN
| WS_CLIPSIBLINGS
,
675 if (hMainWnd
== NULL
)
678 HeapFree(ProcessHeap
,
688 InitMainWindowImpl(VOID
)
692 wc
.cbSize
= sizeof(WNDCLASSEX
);
693 wc
.lpfnWndProc
= MainWndProc
;
694 wc
.hInstance
= hInstance
;
695 wc
.hIcon
= LoadIcon(hInstance
,
696 MAKEINTRESOURCE(IDI_MAIN_ICON
));
697 wc
.hCursor
= LoadCursor(NULL
,
699 wc
.hbrBackground
= (HBRUSH
)(COLOR_BTNFACE
+ 1);
700 wc
.lpszMenuName
= MAKEINTRESOURCE(IDR_MAINMENU
);
701 wc
.lpszClassName
= szMainWndClass
;
702 wc
.hIconSm
= (HICON
)LoadImage(hInstance
,
703 MAKEINTRESOURCE(IDI_MAIN_ICON
),
709 return RegisterClassEx(&wc
) != (ATOM
)0;
714 UninitMainWindowImpl(VOID
)
716 UnregisterClass(szMainWndClass
,