Revert back to the old devmgr I'll install gcc and reapply the changes tonight.
[reactos.git] / reactos / dll / win32 / devmgr / devmgmt / MainWindow.cpp
1 /*
2 * PROJECT: ReactOS Device Manager
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: dll/win32/devmgr/devmgr/MainWindow.cpp
5 * PURPOSE: Implements the main container window for the device view
6 * COPYRIGHT: Copyright 2014 - 2015 Ged Murphy <gedmurphy@reactos.org>
7 */
8
9
10 #include "stdafx.h"
11 #include "devmgmt.h"
12 #include "MainWindow.h"
13
14
15 /* DATA *****************************************************/
16
17 #define BTN_PROPERTIES 0
18 #define BTN_SCAN_HARDWARE 1
19 #define BTN_ENABLE_DRV 2
20 #define BTN_DISABLE_DRV 3
21 #define BTN_UPDATE_DRV 4
22 #define BTN_UNINSTALL_DRV 5
23
24
25 // menu hints
26 static const MENU_HINT MainMenuHintTable[] =
27 {
28 // File Menu
29 { IDC_EXIT, IDS_HINT_EXIT },
30
31 // Action Menu
32 { IDC_PROPERTIES, IDS_HINT_PROPERTIES },
33 { IDC_SCAN_HARDWARE, IDS_HINT_SCAN },
34 { IDC_ENABLE_DRV, IDS_HINT_ENABLE },
35 { IDC_DISABLE_DRV, IDS_HINT_DISABLE },
36 { IDC_UPDATE_DRV, IDS_HINT_UPDATE },
37 { IDC_UNINSTALL_DRV, IDS_HINT_UNINSTALL },
38 { IDC_ADD_HARDWARE, IDS_HINT_ADD },
39
40
41 // View Menu
42 { IDC_DEVBYTYPE, IDS_HINT_DEV_BY_TYPE},
43 { IDC_DEVBYCONN, IDS_HINT_DEV_BY_CONN},
44 { IDC_RESBYTYPE, IDS_HINT_RES_BY_TYPE},
45 { IDC_RESBYCONN, IDS_HINT_RES_BY_TYPE},
46 { IDC_SHOWHIDDEN, IDS_HINT_SHOW_HIDDEN },
47
48 { IDC_ABOUT, IDS_HINT_ABOUT }
49
50 };
51
52
53 // system menu hints
54 static const MENU_HINT SystemMenuHintTable[] =
55 {
56 {SC_RESTORE, IDS_HINT_SYS_RESTORE},
57 {SC_MOVE, IDS_HINT_SYS_MOVE},
58 {SC_SIZE, IDS_HINT_SYS_SIZE},
59 {SC_MINIMIZE, IDS_HINT_SYS_MINIMIZE},
60 {SC_MAXIMIZE, IDS_HINT_SYS_MAXIMIZE},
61 {SC_CLOSE, IDS_HINT_SYS_CLOSE},
62 };
63
64 static TBBUTTON TbButtons[] =
65 {
66 { BTN_PROPERTIES, IDC_PROPERTIES, TBSTATE_ENABLED, BTNS_BUTTON, 0, 0 },
67 { BTN_SCAN_HARDWARE, IDC_SCAN_HARDWARE, TBSTATE_ENABLED, BTNS_BUTTON, 0, 0 },
68 { 2, IDC_STATIC, TBSTATE_ENABLED, BTNS_SEP, 0, 0 },
69 { BTN_ENABLE_DRV, IDC_ENABLE_DRV, TBSTATE_ENABLED, BTNS_BUTTON, 0, 0 },
70 { BTN_DISABLE_DRV, IDC_DISABLE_DRV, TBSTATE_ENABLED, BTNS_BUTTON, 0, 0 },
71 { BTN_UPDATE_DRV, IDC_UPDATE_DRV, TBSTATE_ENABLED, BTNS_BUTTON, 0, 0 },
72 { BTN_UNINSTALL_DRV, IDC_UNINSTALL_DRV, TBSTATE_ENABLED, BTNS_BUTTON, 0, 0 }
73 };
74
75
76 /* PUBLIC METHODS **********************************************/
77
78 CMainWindow::CMainWindow(void) :
79 m_ToolbarhImageList(NULL),
80 m_hMainWnd(NULL),
81 m_hStatusBar(NULL),
82 m_hToolBar(NULL),
83 m_CmdShow(0)
84 {
85 m_szMainWndClass = L"DevMgmtWndClass";
86 }
87
88 CMainWindow::~CMainWindow(void)
89 {
90 // Destroy any previous list
91 if (m_ToolbarhImageList) ImageList_Destroy(m_ToolbarhImageList);
92 }
93
94 bool
95 CMainWindow::Initialize(LPCTSTR lpCaption,
96 int nCmdShow)
97 {
98 CAtlStringW szCaption;
99 WNDCLASSEXW wc = {0};
100
101 // Store the show window value
102 m_CmdShow = nCmdShow;
103
104 // Setup the window class struct
105 wc.cbSize = sizeof(WNDCLASSEXW);
106 wc.lpfnWndProc = MainWndProc;
107 wc.hInstance = g_hInstance;
108 wc.hIcon = LoadIcon(g_hInstance, MAKEINTRESOURCEW(IDI_MAIN_ICON));
109 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
110 wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
111 wc.lpszMenuName = MAKEINTRESOURCEW(IDR_MAINMENU);
112 wc.lpszClassName = m_szMainWndClass;
113 wc.hIconSm = (HICON)LoadImage(g_hInstance,
114 MAKEINTRESOURCE(IDI_MAIN_ICON),
115 IMAGE_ICON,
116 16,
117 16,
118 LR_SHARED);
119
120 // Register the window
121 if (RegisterClassExW(&wc))
122 {
123 // Create the main window and store the object pointer
124 m_hMainWnd = CreateWindowExW(WS_EX_WINDOWEDGE,
125 m_szMainWndClass,
126 lpCaption,
127 WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS,
128 CW_USEDEFAULT,
129 CW_USEDEFAULT,
130 550,
131 500,
132 NULL,
133 NULL,
134 g_hInstance,
135 this);
136 }
137
138 // Return creation result
139 return !!(m_hMainWnd);
140 }
141
142 void
143 CMainWindow::Uninitialize()
144 {
145 // Unregister the window class
146 UnregisterClassW(m_szMainWndClass, g_hInstance);
147 }
148
149 int
150 CMainWindow::Run()
151 {
152 MSG Msg;
153
154 // Pump the message queue
155 while (GetMessageW(&Msg, NULL, 0, 0 ) != 0)
156 {
157 TranslateMessage(&Msg);
158 DispatchMessageW(&Msg);
159 }
160
161 return 0;
162 }
163
164
165 /* PRIVATE METHODS **********************************************/
166
167 bool
168 CMainWindow::MainWndMenuHint(WORD CmdId,
169 const MENU_HINT *HintArray,
170 DWORD HintsCount,
171 UINT DefHintId)
172 {
173 bool Found = false;
174 const MENU_HINT *LastHint;
175 UINT HintId = DefHintId;
176
177 LastHint = HintArray + HintsCount;
178 while (HintArray != LastHint)
179 {
180 if (HintArray->CmdId == CmdId)
181 {
182 HintId = HintArray->HintId;
183 Found = true;
184 break;
185 }
186 HintArray++;
187 }
188
189 StatusBarLoadString(m_hStatusBar,
190 SB_SIMPLEID,
191 g_hInstance,
192 HintId);
193
194 return Found;
195 }
196
197 void
198 CMainWindow::UpdateStatusBar(
199 _In_ bool InMenuLoop
200 )
201 {
202 SendMessageW(m_hStatusBar,
203 SB_SIMPLE,
204 (WPARAM)InMenuLoop,
205 0);
206 }
207
208 bool
209 CMainWindow::RefreshView(ViewType Type)
210 {
211 UINT CheckId = 0;
212 BOOL bSuccess;
213
214 // Refreshed the cached view
215 m_DeviceView->Refresh(Type, FALSE, TRUE, NULL);
216
217 // Get the menu item id
218 switch (Type)
219 {
220 case DevicesByType: CheckId = IDC_DEVBYTYPE; break;
221 case DevicesByConnection: CheckId = IDC_DEVBYCONN; break;
222 case ResourcesByType: CheckId = IDC_RESBYTYPE; break;
223 case ResourcesByConnection: CheckId = IDC_RESBYCONN; break;
224 default: ATLASSERT(FALSE); break;
225 }
226
227 // Set the new check item
228 bSuccess = CheckMenuRadioItem(m_hMenu,
229 IDC_DEVBYTYPE,
230 IDC_RESBYCONN,
231 CheckId,
232 MF_BYCOMMAND);
233
234 return TRUE;
235 }
236
237 bool
238 CMainWindow::CreateToolBar()
239 {
240 TBADDBITMAP TbAddBitmap;
241 INT Index;
242
243 DWORD dwStyles = WS_CHILDWINDOW | TBSTYLE_FLAT | TBSTYLE_WRAPABLE | TBSTYLE_TOOLTIPS | CCS_NODIVIDER;
244 DWORD dwExStyles = WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR;
245
246 // Create the toolbar window
247 m_hToolBar = CreateWindowExW(dwExStyles,
248 TOOLBARCLASSNAME,
249 NULL,
250 dwStyles,
251 0, 0, 0, 0,
252 m_hMainWnd,
253 (HMENU)IDC_TOOLBAR,
254 g_hInstance,
255 NULL);
256 if (m_hToolBar == NULL) return FALSE;
257
258 // Don't show clipped buttons
259 SendMessageW(m_hToolBar,
260 TB_SETEXTENDEDSTYLE,
261 0,
262 TBSTYLE_EX_HIDECLIPPEDBUTTONS);
263
264 SendMessageW(m_hToolBar, TB_SETBITMAPSIZE, 0, MAKELONG(16, 16));
265
266 // Set the struct size, the toobar needs this...
267 SendMessageW(m_hToolBar,
268 TB_BUTTONSTRUCTSIZE,
269 sizeof(TBBUTTON),
270 0);
271
272 TbAddBitmap.hInst = g_hInstance;
273 TbAddBitmap.nID = IDB_TOOLBAR;
274 Index = SendMessageW(m_hToolBar, TB_ADDBITMAP, _countof(TbButtons), (LPARAM)&TbAddBitmap);
275
276 SendMessageW(m_hToolBar, TB_ADDBUTTONSW, _countof(TbButtons), (LPARAM)TbButtons);
277 SendMessageW(m_hToolBar, TB_AUTOSIZE, 0, 0);
278
279 if (TRUE)
280 {
281 ShowWindow(m_hToolBar, SW_SHOW);
282 }
283
284 return TRUE;
285 }
286
287 bool
288 CMainWindow::CreateStatusBar()
289 {
290 int StatWidths[] = {110, -1}; // widths of status bar
291 bool bRet = FALSE;
292
293 // Create the status bar
294 m_hStatusBar = CreateWindowExW(0,
295 STATUSCLASSNAME,
296 NULL,
297 WS_CHILD | WS_VISIBLE | SBARS_SIZEGRIP,
298 0, 0, 0, 0,
299 m_hMainWnd,
300 (HMENU)IDC_STATUSBAR,
301 g_hInstance,
302 NULL);
303 if (m_hStatusBar)
304 {
305 // Set the width
306 bRet = (SendMessageW(m_hStatusBar,
307 SB_SETPARTS,
308 sizeof(StatWidths) / sizeof(int),
309 (LPARAM)StatWidths) != 0);
310 }
311
312 return bRet;
313 }
314
315 void CMainWindow::UpdateToolbar()
316 {
317 WORD State;
318
319 CNode *Node = m_DeviceView->GetSelectedNode();
320
321 // properties button
322 if (Node->HasProperties())
323 {
324 State = TBSTATE_ENABLED;
325 }
326 else
327 {
328 State = TBSTATE_HIDDEN;
329 }
330 SendMessageW(m_hToolBar, TB_SETSTATE, IDC_PROPERTIES, MAKELPARAM(State, 0));
331 SendMessageW(m_hToolBar, TB_SETSTATE, IDC_UPDATE_DRV, MAKELPARAM(State, 0)); //hack
332 SendMessageW(m_hToolBar, TB_SETSTATE, IDC_UNINSTALL_DRV, MAKELPARAM(State, 0)); // hack
333
334
335
336 // enable driver button
337 if (Node->GetNodeType() == DeviceNode &&
338 dynamic_cast<CDeviceNode *>(Node)->IsDisabled())
339 {
340 State = TBSTATE_ENABLED;
341 }
342 else
343 {
344 State = TBSTATE_HIDDEN;
345 }
346 SendMessageW(m_hToolBar, TB_SETSTATE, IDC_ENABLE_DRV, MAKELPARAM(State, 0));
347
348 // disable driver button
349 if (Node->GetNodeType() == DeviceNode &&
350 dynamic_cast<CDeviceNode *>(Node)->CanDisable() &&
351 !dynamic_cast<CDeviceNode *>(Node)->IsDisabled())
352 {
353 State = TBSTATE_ENABLED;
354 }
355 else
356 {
357 State = TBSTATE_HIDDEN;
358 }
359 SendMessageW(m_hToolBar, TB_SETSTATE, IDC_DISABLE_DRV, MAKELPARAM(State, 0));
360
361
362
363
364
365 }
366
367
368
369 bool
370 CMainWindow::StatusBarLoadString(IN HWND hStatusBar,
371 IN INT PartId,
372 IN HINSTANCE hInstance,
373 IN UINT uID)
374 {
375 CAtlStringW szMessage;
376 bool bRet = false;
377
378 // Load the string
379 if (szMessage.LoadStringW(hInstance, uID))
380 {
381 // Show the string on the status bar
382 bRet = (SendMessageW(hStatusBar,
383 SB_SETTEXT,
384 (WPARAM)PartId,
385 (LPARAM)szMessage.GetBuffer()) != 0);
386 }
387
388 return bRet;
389 }
390
391 LRESULT
392 CMainWindow::OnCreate(HWND hwnd)
393 {
394 LRESULT RetCode;
395
396 RetCode = -1;
397 m_hMainWnd = hwnd;
398
399 // Store a handle to the main menu
400 m_hMenu = GetMenu(m_hMainWnd);
401
402 // Create the toolbar and statusbar
403 if (CreateToolBar() && CreateStatusBar())
404 {
405 // Create the device view object
406 m_DeviceView = new CDeviceView(m_hMainWnd);
407 if (m_DeviceView->Initialize())
408 {
409 // Do the initial scan
410 m_DeviceView->Refresh(m_DeviceView->GetCurrentView(),
411 true,
412 true,
413 NULL);
414
415 // Display the window according to the user request
416 ShowWindow(hwnd, m_CmdShow);
417 RetCode = 0;
418 }
419 }
420
421 return RetCode;
422 }
423
424 LRESULT
425 CMainWindow::OnSize()
426 {
427 RECT rcClient, rcTool, rcStatus;
428 INT lvHeight, iToolHeight, iStatusHeight;
429
430 // Autosize the toolbar
431 SendMessage(m_hToolBar, TB_AUTOSIZE, 0, 0);
432
433 // Get the toolbar rect and save the height
434 GetWindowRect(m_hToolBar, &rcTool);
435 iToolHeight = rcTool.bottom - rcTool.top;
436
437 // Resize the status bar
438 SendMessage(m_hStatusBar, WM_SIZE, 0, 0);
439
440 // Get the statusbar rect and save the height
441 GetWindowRect(m_hStatusBar, &rcStatus);
442 iStatusHeight = rcStatus.bottom - rcStatus.top;
443
444 // Get the full client rect
445 GetClientRect(m_hMainWnd, &rcClient);
446
447 // Calculate the remaining height for the treeview
448 lvHeight = rcClient.bottom - iToolHeight - iStatusHeight;
449
450 // Resize the device view
451 m_DeviceView->OnSize(0,
452 iToolHeight,
453 rcClient.right,
454 lvHeight);
455
456 return 0;
457 }
458
459 LRESULT
460 CMainWindow::OnNotify(LPARAM lParam)
461 {
462 LPNMHDR NmHdr = (LPNMHDR)lParam;
463 LRESULT Ret;
464
465 switch (NmHdr->code)
466 {
467 case TVN_SELCHANGED:
468 {
469 UpdateToolbar();
470 break;
471 }
472
473 case NM_DBLCLK:
474 {
475 m_DeviceView->DisplayPropertySheet();
476 break;
477 }
478
479 case NM_RCLICK:
480 {
481 Ret = m_DeviceView->OnRightClick(NmHdr);
482 break;
483 }
484
485 case NM_RETURN:
486 {
487 m_DeviceView->DisplayPropertySheet();
488 break;
489 }
490
491 case TTN_GETDISPINFO:
492 {
493 LPTOOLTIPTEXT lpttt = (LPTOOLTIPTEXT)lParam;
494
495 UINT_PTR idButton = lpttt->hdr.idFrom;
496 switch (idButton)
497 {
498 case IDC_PROPERTIES:
499 lpttt->lpszText = MAKEINTRESOURCEW(IDS_TOOLTIP_PROPERTIES);
500 break;
501 case IDC_SCAN_HARDWARE:
502 lpttt->lpszText = MAKEINTRESOURCEW(IDS_TOOLTIP_SCAN);
503 break;
504 case IDC_ENABLE_DRV:
505 lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_ENABLE);
506 break;
507 case IDC_DISABLE_DRV:
508 lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_DISABLE);
509 break;
510 case IDC_UPDATE_DRV:
511 lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_UPDATE);
512 break;
513 case IDC_UNINSTALL_DRV:
514 lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_UNINSTALL);
515 break;
516 }
517 break;
518 }
519 }
520
521 return 0;
522 }
523
524 LRESULT
525 CMainWindow::OnContext(LPARAM lParam)
526 {
527 return m_DeviceView->OnContextMenu(lParam);
528 }
529
530 LRESULT
531 CMainWindow::OnCommand(WPARAM wParam,
532 LPARAM /*lParam*/)
533 {
534 LRESULT RetCode = 0;
535 WORD Msg;
536
537 // Get the message
538 Msg = LOWORD(wParam);
539
540 switch (Msg)
541 {
542 case IDC_PROPERTIES:
543 case IDC_SCAN_HARDWARE:
544 case IDC_ENABLE_DRV:
545 case IDC_DISABLE_DRV:
546 case IDC_UPDATE_DRV:
547 case IDC_UNINSTALL_DRV:
548 case IDC_ADD_HARDWARE:
549 {
550 m_DeviceView->OnAction(Msg);
551 break;
552 }
553
554 case IDC_ACTIONMENU:
555 {
556 // Create a popup menu with all the actions for the selected node
557 HMENU hMenu = CreatePopupMenu();
558 m_DeviceView->CreateActionMenu(hMenu, true);
559
560 // Calculate where to put the menu
561 RECT rc;
562 GetMenuItemRect(m_hMainWnd, m_hMenu, 1, &rc);
563 LONG Height = rc.bottom - rc.top;
564
565 // Display the menu
566 TrackPopupMenuEx(hMenu,
567 TPM_RIGHTBUTTON,
568 rc.left,
569 rc.top + Height,
570 m_hMainWnd,
571 NULL);
572
573 DestroyMenu(hMenu);
574 break;
575 }
576
577 case IDC_DEVBYTYPE:
578 {
579 RefreshView(DevicesByType);
580 break;
581 }
582
583 case IDC_DEVBYCONN:
584 {
585 RefreshView(DevicesByConnection);
586 break;
587 }
588
589 case IDC_SHOWHIDDEN:
590 {
591 // Get the current state
592 UINT CurCheckState = GetMenuState(m_hMenu, IDC_SHOWHIDDEN, MF_BYCOMMAND);
593 if (CurCheckState == MF_CHECKED)
594 {
595 m_DeviceView->SetHiddenDevices(false);
596 CheckMenuItem(m_hMenu, IDC_SHOWHIDDEN, MF_BYCOMMAND | MF_UNCHECKED);
597 }
598 else if (CurCheckState == MF_UNCHECKED)
599 {
600 m_DeviceView->SetHiddenDevices(true);
601 CheckMenuItem(m_hMenu, IDC_SHOWHIDDEN, MF_BYCOMMAND | MF_CHECKED);
602 }
603 // Refresh the device view
604 m_DeviceView->Refresh(m_DeviceView->GetCurrentView(),
605 false,
606 true,
607 NULL);
608 break;
609 }
610
611 case IDC_ABOUT:
612 {
613 // Apportion blame
614 MessageBoxW(m_hMainWnd,
615 L"ReactOS Device Manager\r\nCopyright Ged Murphy 2015",
616 L"About",
617 MB_OK | MB_APPLMODAL);
618
619 // Set focus back to the treeview
620 m_DeviceView->SetFocus();
621 break;
622 }
623
624 case IDC_EXIT:
625 {
626 // Post a close message to the window
627 PostMessageW(m_hMainWnd,
628 WM_CLOSE,
629 0,
630 0);
631 break;
632 }
633
634 default:
635 // We didn't handle it
636 RetCode = -1;
637 break;
638 }
639
640 return RetCode;
641 }
642
643 LRESULT
644 CMainWindow::OnDestroy()
645 {
646 // Uninitialize the device view
647 m_DeviceView->Uninitialize();
648
649 // Kill the object
650 delete m_DeviceView;
651 m_DeviceView = NULL;
652
653 // Clear the user data pointer
654 SetWindowLongPtr(m_hMainWnd, GWLP_USERDATA, 0);
655
656 // Break the message loop
657 PostQuitMessage(0);
658
659 return 0;
660 }
661
662 LRESULT CALLBACK
663 CMainWindow::MainWndProc(HWND hwnd,
664 UINT msg,
665 WPARAM wParam,
666 LPARAM lParam)
667 {
668 CMainWindow *This;
669 LRESULT RetCode = 0;
670
671 // Get the object pointer from window context
672 This = (CMainWindow *)GetWindowLongPtr(hwnd, GWLP_USERDATA);
673 if (This == NULL)
674 {
675 // Check that this isn't a create message
676 if (msg != WM_CREATE)
677 {
678 // Don't handle null info pointer
679 goto HandleDefaultMessage;
680 }
681 }
682
683 switch(msg)
684 {
685 case WM_CREATE:
686 {
687 // Get the object pointer from the create param
688 This = (CMainWindow *)((LPCREATESTRUCT)lParam)->lpCreateParams;
689
690 // Store the pointer in the window's global user data
691 SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)This);
692
693 // Call the create handler
694 RetCode = This->OnCreate(hwnd);
695 break;
696 }
697
698 case WM_SIZE:
699 {
700 RetCode = This->OnSize();
701 break;
702 }
703
704 case WM_NOTIFY:
705 {
706 RetCode = This->OnNotify(lParam);
707 break;
708 }
709
710 case WM_CONTEXTMENU:
711 {
712 RetCode = This->OnContext(lParam);
713 break;
714 }
715
716 case WM_MENUSELECT:
717 {
718 if (This->m_hStatusBar != NULL)
719 {
720 if (!This->MainWndMenuHint(LOWORD(wParam),
721 MainMenuHintTable,
722 sizeof(MainMenuHintTable) / sizeof(MainMenuHintTable[0]),
723 IDS_HINT_BLANK))
724 {
725 This->MainWndMenuHint(LOWORD(wParam),
726 SystemMenuHintTable,
727 sizeof(SystemMenuHintTable) / sizeof(SystemMenuHintTable[0]),
728 IDS_HINT_BLANK);
729 }
730 }
731
732 break;
733 }
734
735 case WM_COMMAND:
736 {
737 // Handle the command message
738 RetCode = This->OnCommand(wParam, lParam);
739 if (RetCode == -1)
740 {
741 // Hand it off to the default message handler
742 goto HandleDefaultMessage;
743 }
744 break;
745 }
746
747 case WM_ENTERMENULOOP:
748 {
749 This->UpdateStatusBar(true);
750 break;
751 }
752
753 case WM_EXITMENULOOP:
754 {
755 This->UpdateStatusBar(false);
756 break;
757 }
758
759 case WM_CLOSE:
760 {
761 // Destroy the main window
762 DestroyWindow(hwnd);
763 break;
764 }
765
766
767 case WM_DESTROY:
768 {
769 // Call the destroy handler
770 RetCode = This->OnDestroy();
771 break;
772 }
773
774 default:
775 {
776 HandleDefaultMessage:
777 RetCode = DefWindowProc(hwnd, msg, wParam, lParam);
778 break;
779 }
780 }
781
782 return RetCode;
783 }
784
785
786 //////// MOVE ME ////////////////
787
788 HINSTANCE g_hInstance = NULL;
789 HANDLE ProcessHeap = NULL;
790
791 BOOL
792 WINAPI
793 DeviceManager_ExecuteW(HWND /*hWndParent*/,
794 HINSTANCE hInst,
795 LPCWSTR /*lpMachineName*/,
796 int nCmdShow)
797 {
798 CMainWindow MainWindow;
799 INITCOMMONCONTROLSEX icex;
800 CAtlStringW szAppName;
801 int Ret = 1;
802
803 // Store the global values
804 g_hInstance = hInst;
805 ProcessHeap = GetProcessHeap();
806
807 // Initialize common controls
808 icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
809 icex.dwICC = ICC_BAR_CLASSES | ICC_COOL_CLASSES;
810 InitCommonControlsEx(&icex);
811
812 // Load the application name
813 if (szAppName.LoadStringW(g_hInstance, IDS_APPNAME))
814 {
815 // Initialize the main window
816 if (MainWindow.Initialize(szAppName, nCmdShow))
817 {
818 // Run the application
819 Ret = MainWindow.Run();
820
821 // Uninitialize the main window
822 MainWindow.Uninitialize();
823 }
824 }
825
826 return Ret;
827 }