3 #include "MainWindow.h"
6 static const MENU_HINT MainMenuHintTable
[] =
9 {IDC_EXIT
, IDS_HINT_EXIT
},
12 {IDC_REFRESH
, IDS_HINT_REFRESH
},
13 {IDC_PROP
, IDS_HINT_PROP
},
15 {IDC_ABOUT
, IDS_HINT_ABOUT
}
18 /* system menu hints */
19 static const MENU_HINT SystemMenuHintTable
[] =
21 {SC_RESTORE
, IDS_HINT_SYS_RESTORE
},
22 {SC_MOVE
, IDS_HINT_SYS_MOVE
},
23 {SC_SIZE
, IDS_HINT_SYS_SIZE
},
24 {SC_MINIMIZE
, IDS_HINT_SYS_MINIMIZE
},
25 {SC_MAXIMIZE
, IDS_HINT_SYS_MAXIMIZE
},
26 {SC_CLOSE
, IDS_HINT_SYS_CLOSE
},
31 CMainWindow::CMainWindow(void) :
37 m_szMainWndClass
= L
"DevMgmtWndClass";
40 CMainWindow::~CMainWindow(void)
45 CMainWindow::CreateToolBar()
47 HIMAGELIST hImageList
;
49 UINT StartResource
, EndResource
;
53 static TBBUTTON ToolbarButtons
[] =
55 {TBICON_PROP
, IDC_PROP
, TBSTATE_INDETERMINATE
, BTNS_BUTTON
, {0}, 0, 0},
56 {TBICON_REFRESH
, IDC_REFRESH
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 0, 0},
58 /* Add a seperator: First item for a seperator is its width in pixels */
59 {15, 0, TBSTATE_ENABLED
, BTNS_SEP
, {0}, 0, 0},
62 /* Get the number of buttons */
63 NumButtons
= sizeof(ToolbarButtons
) / sizeof(ToolbarButtons
[0]);
65 /* Create the toolbar window */
66 m_hToolBar
= CreateWindowExW(0,
69 WS_CHILD
| WS_VISIBLE
| TBSTYLE_FLAT
| TBSTYLE_TOOLTIPS
,
77 /* Don't show clipped buttons */
78 SendMessageW(m_hToolBar
,
81 TBSTYLE_EX_HIDECLIPPEDBUTTONS
);
83 /* Set the struct size, the toobar needs this... */
84 SendMessageW(m_hToolBar
,
86 sizeof(ToolbarButtons
[0]),
89 /* Create the toolbar icon image list */
90 hImageList
= ImageList_Create(16,
92 ILC_MASK
| ILC_COLOR24
,
97 /* Set the index endpoints */
98 StartResource
= IDB_PROP
;
99 EndResource
= IDB_REFRESH
;
101 /* Add all icons to the image list */
102 for (UINT i
= StartResource
; i
<= EndResource
; i
++)
104 /* Load the image resource */
105 hBitmap
= (HBITMAP
)LoadImage(g_hInstance
,
113 /* Add it to the image list */
114 ImageList_AddMasked(hImageList
,
118 /* Delete the bitmap */
119 DeleteObject(hBitmap
);
123 /* Set the new image list */
124 hImageList
= (HIMAGELIST
)SendMessageW(m_hToolBar
,
129 /* Destroy any previous list */
130 if (hImageList
) ImageList_Destroy(hImageList
);
132 /* Add the buttons */
133 bRet
= (BOOL
)SendMessageW(m_hToolBar
,
136 (LPARAM
)ToolbarButtons
);
144 CMainWindow::CreateStatusBar()
146 INT StatWidths
[] = {110, -1}; /* widths of status bar */
149 /* Create the status bar */
150 m_hStatusBar
= CreateWindowExW(0,
153 WS_CHILD
| WS_VISIBLE
| SBARS_SIZEGRIP
,
156 (HMENU
)IDC_STATUSBAR
,
162 bRet
= (BOOL
)SendMessage(m_hStatusBar
,
164 sizeof(StatWidths
) / sizeof(INT
),
172 CMainWindow::StatusBarLoadString(IN HWND hStatusBar
,
174 IN HINSTANCE hInstance
,
177 CAtlString szMessage
;
180 /* Load the string */
181 if (szMessage
.LoadStringW(hInstance
, uID
))
183 /* Send the message to the status bar */
184 bRet
= (BOOL
)SendMessageW(hStatusBar
,
187 (LPARAM
)szMessage
.GetBuffer());
194 CMainWindow::OnCreate(HWND hwnd
)
201 /* Store the window handle */
204 /* Create the toolbar */
207 /* Create the statusbar */
208 if (CreateStatusBar())
210 /* Create the device view object */
211 m_DeviceView
= new CDeviceView(m_hMainWnd
);
214 if (m_DeviceView
->Initialize())
216 /* Display the window according to the user request */
217 ShowWindow(hwnd
, m_CmdShow
);
229 CMainWindow::OnSize()
231 RECT rcClient
, rcTool
, rcStatus
;
232 INT lvHeight
, iToolHeight
, iStatusHeight
;
234 /* Autosize the toolbar */
235 SendMessage(m_hToolBar
, TB_AUTOSIZE
, 0, 0);
237 /* Get the toolbar rect and save the height */
238 GetWindowRect(m_hToolBar
, &rcTool
);
239 iToolHeight
= rcTool
.bottom
- rcTool
.top
;
241 /* Resize the status bar */
242 SendMessage(m_hStatusBar
, WM_SIZE
, 0, 0);
244 /* Get the statusbar rect and save the height */
245 GetWindowRect(m_hStatusBar
, &rcStatus
);
246 iStatusHeight
= rcStatus
.bottom
- rcStatus
.top
;
248 /* Get the full client rect */
249 GetClientRect(m_hMainWnd
, &rcClient
);
251 /* Calculate the remaining height for the treeview */
252 lvHeight
= rcClient
.bottom
- iToolHeight
- iStatusHeight
;
254 /* Resize the device view */
255 m_DeviceView
->Size(0,
264 CMainWindow::OnNotify(LPARAM lParam
)
271 CMainWindow::OnContext(LPARAM lParam
)
277 CMainWindow::OnCommand(WPARAM wParam
,
283 /* Get the message */
284 Msg
= LOWORD(wParam
);
290 /* Display the device property sheet */
291 m_DeviceView
->DisplayPropertySheet();
297 /* Refresh the device list */
298 m_DeviceView
->Refresh();
304 /* Blow my own trumpet */
305 MessageBoxW(m_hMainWnd
,
306 L
"ReactOS Device Manager\r\nCopyright Ged Murphy 2011",
310 /* Set focus back to the treeview */
311 m_DeviceView
->SetFocus();
317 /* Post a close message to the window */
318 PostMessageW(m_hMainWnd
,
333 CMainWindow::OnDestroy()
335 /* Uninitialize the device view */
336 m_DeviceView
->Uninitialize();
338 /* Kill the object */
342 /* Clear the user data pointer */
343 SetWindowLongPtr(m_hMainWnd
, GWLP_USERDATA
, 0);
345 /* Break the message loop */
352 CMainWindow::MainWndProc(HWND hwnd
,
360 /* Get the object pointer from window context */
361 pThis
= (CMainWindow
*)GetWindowLongPtr(hwnd
, GWLP_USERDATA
);
363 /* Check for an invalid pointer */
366 /* Check that this isn't a create message */
367 if (msg
!= WM_CREATE
)
369 /* Don't handle null info pointer */
370 goto HandleDefaultMessage
;
378 /* Get the object pointer from the create param */
379 pThis
= (CMainWindow
*)((LPCREATESTRUCT
)lParam
)->lpCreateParams
;
381 /* Store the info pointer in the window's global user data */
382 SetWindowLongPtr(hwnd
, GWLP_USERDATA
, (LONG_PTR
)pThis
);
384 /* Call the create handler */
385 RetCode
= pThis
->OnCreate(hwnd
);
391 RetCode
= pThis
->OnSize();
397 /* Handle the notify message */
398 RetCode
= pThis
->OnNotify(lParam
);
404 /* Handle creating the context menu */
405 RetCode
= pThis
->OnContext(lParam
);
411 /* Handle the command message */
412 RetCode
= pThis
->OnCommand(wParam
, lParam
);
414 /* Hand it off to the default message handler */
415 goto HandleDefaultMessage
;
420 /* Destroy the main window */
427 /* Call the destroy handler */
428 RetCode
= pThis
->OnDestroy();
434 HandleDefaultMessage
:
435 RetCode
= DefWindowProc(hwnd
, msg
, wParam
, lParam
);
444 CMainWindow::Initialize(LPCTSTR lpCaption
,
447 CAtlString szCaption
;
448 WNDCLASSEXW wc
= {0};
450 /* Store the show window value */
451 m_CmdShow
= nCmdShow
;
453 /* Setup the window class struct */
454 wc
.cbSize
= sizeof(WNDCLASSEXW
);
455 wc
.lpfnWndProc
= MainWndProc
;
456 wc
.hInstance
= g_hInstance
;
457 wc
.hIcon
= LoadIcon(g_hInstance
, MAKEINTRESOURCEW(IDI_MAIN_ICON
));
458 wc
.hCursor
= LoadCursor(NULL
, IDC_ARROW
);
459 wc
.hbrBackground
= (HBRUSH
)(COLOR_BTNFACE
+ 1);
460 wc
.lpszMenuName
= MAKEINTRESOURCEW(IDR_MAINMENU
);
461 wc
.lpszClassName
= m_szMainWndClass
;
462 wc
.hIconSm
= (HICON
)LoadImage(g_hInstance
,
463 MAKEINTRESOURCE(IDI_MAIN_ICON
),
469 /* Register the window */
470 if (RegisterClassExW(&wc
))
472 /* Create the main window and store the info pointer */
473 m_hMainWnd
= CreateWindowExW(WS_EX_WINDOWEDGE
,
476 WS_OVERLAPPEDWINDOW
| WS_CLIPCHILDREN
| WS_CLIPSIBLINGS
,
487 /* Return creation result */
488 return !!(m_hMainWnd
);
492 CMainWindow::Uninitialize()
494 /* Unregister the window class */
495 UnregisterClassW(m_szMainWndClass
, g_hInstance
);
503 /* Pump the message queue */
504 while (GetMessageW(&Msg
, NULL
, 0, 0 ) != 0)
506 TranslateMessage(&Msg
);
507 DispatchMessageW(&Msg
);