0, 0, 0, 0,
m_hMainWnd,
(HMENU)IDC_TREEVIEW,
- g_hInstance,
+ g_hThisInstance,
NULL);
if (m_hTreeView)
{
if (Enable == false)
{
CAtlStringW str;
- if (str.LoadStringW(g_hInstance, IDS_CONFIRM_DISABLE))
+ if (str.LoadStringW(g_hThisInstance, IDS_CONFIRM_DISABLE))
{
if (MessageBoxW(m_hMainWnd,
str,
if (DeviceNode->CanUpdate())
{
- String.LoadStringW(g_hInstance, IDS_MENU_UPDATE);
+ String.LoadStringW(g_hThisInstance, IDS_MENU_UPDATE);
MenuItemInfo.wID = IDC_UPDATE_DRV;
MenuItemInfo.dwTypeData = String.GetBuffer();
InsertMenuItemW(OwnerMenu, i, TRUE, &MenuItemInfo);
if (DeviceNode->IsDisabled())
{
- String.LoadStringW(g_hInstance, IDS_MENU_ENABLE);
+ String.LoadStringW(g_hThisInstance, IDS_MENU_ENABLE);
MenuItemInfo.wID = IDC_ENABLE_DRV;
MenuItemInfo.dwTypeData = String.GetBuffer();
InsertMenuItemW(OwnerMenu, i, TRUE, &MenuItemInfo);
if (DeviceNode->CanDisable() && !DeviceNode->IsDisabled())
{
- String.LoadStringW(g_hInstance, IDS_MENU_DISABLE);
+ String.LoadStringW(g_hThisInstance, IDS_MENU_DISABLE);
MenuItemInfo.wID = IDC_DISABLE_DRV;
MenuItemInfo.dwTypeData = String.GetBuffer();
InsertMenuItemW(OwnerMenu, i, TRUE, &MenuItemInfo);
if (DeviceNode->CanUninstall())
{
- String.LoadStringW(g_hInstance, IDS_MENU_UNINSTALL);
+ String.LoadStringW(g_hThisInstance, IDS_MENU_UNINSTALL);
MenuItemInfo.wID = IDC_UNINSTALL_DRV;
MenuItemInfo.dwTypeData = String.GetBuffer();
InsertMenuItemW(OwnerMenu, i, TRUE, &MenuItemInfo);
}
// All nodes have the scan option
- String.LoadStringW(g_hInstance, IDS_MENU_SCAN);
+ String.LoadStringW(g_hThisInstance, IDS_MENU_SCAN);
MenuItemInfo.wID = IDC_SCAN_HARDWARE;
MenuItemInfo.dwTypeData = String.GetBuffer();
InsertMenuItemW(OwnerMenu, i, TRUE, &MenuItemInfo);
if ((Node->GetNodeType() == RootNode) || (MainMenu == true))
{
- String.LoadStringW(g_hInstance, IDS_MENU_ADD);
+ String.LoadStringW(g_hThisInstance, IDS_MENU_ADD);
MenuItemInfo.wID = IDC_ADD_HARDWARE;
MenuItemInfo.dwTypeData = String.GetBuffer();
InsertMenuItemW(OwnerMenu, i, TRUE, &MenuItemInfo);
InsertMenuItemW(OwnerMenu, i, TRUE, &MenuSeperator);
i++;
- String.LoadStringW(g_hInstance, IDS_MENU_PROPERTIES);
+ String.LoadStringW(g_hThisInstance, IDS_MENU_PROPERTIES);
MenuItemInfo.wID = IDC_PROPERTIES;
MenuItemInfo.dwTypeData = String.GetBuffer();
InsertMenuItemW(OwnerMenu, i, TRUE, &MenuItemInfo);
#define BTN_UPDATE_DRV 4
#define BTN_UNINSTALL_DRV 5
+HINSTANCE g_hThisInstance = NULL;
+HINSTANCE g_hParentInstance = NULL;
// menu hints
static const MENU_HINT MainMenuHintTable[] =
/* PUBLIC METHODS **********************************************/
-CMainWindow::CMainWindow(void) :
- m_ToolbarhImageList(NULL),
+CDeviceManager::CDeviceManager(void) :
m_hMainWnd(NULL),
m_hStatusBar(NULL),
m_hToolBar(NULL),
m_szMainWndClass = L"DevMgmtWndClass";
}
-CMainWindow::~CMainWindow(void)
+CDeviceManager::~CDeviceManager(void)
{
- // Destroy any previous list
- if (m_ToolbarhImageList) ImageList_Destroy(m_ToolbarhImageList);
}
+
+bool
+CDeviceManager::Create(_In_ HWND /*hWndParent*/,
+ _In_ HINSTANCE hInst,
+ _In_opt_z_ LPCWSTR /*lpMachineName*/,
+ _In_ int nCmdShow)
+{
+ CDeviceManager MainWindow;
+ INITCOMMONCONTROLSEX icex;
+ CAtlStringW szAppName;
+ int Ret = 1;
+
+ // Store the instances
+ g_hParentInstance = hInst;
+ g_hThisInstance = GetModuleHandleW(L"devmgr.dll");
+
+ // Initialize common controls
+ icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
+ icex.dwICC = ICC_BAR_CLASSES | ICC_COOL_CLASSES;
+ InitCommonControlsEx(&icex);
+
+ // Load the application name
+ if (szAppName.LoadStringW(g_hThisInstance, IDS_APPNAME))
+ {
+ // Initialize the main window
+ if (MainWindow.Initialize(szAppName, nCmdShow))
+ {
+ // Run the application
+ Ret = MainWindow.Run();
+
+ // Uninitialize the main window
+ MainWindow.Uninitialize();
+ }
+ }
+
+ return (Ret == 0);
+}
+
+
+
+/* PRIVATE METHODS **********************************************/
+
bool
-CMainWindow::Initialize(LPCTSTR lpCaption,
- int nCmdShow)
+CDeviceManager::Initialize(_In_z_ LPCTSTR lpCaption,
+ _In_ int nCmdShow)
{
CAtlStringW szCaption;
WNDCLASSEXW wc = {0};
// Setup the window class struct
wc.cbSize = sizeof(WNDCLASSEXW);
wc.lpfnWndProc = MainWndProc;
- wc.hInstance = g_hInstance;
- wc.hIcon = LoadIcon(g_hInstance, MAKEINTRESOURCEW(IDI_MAIN_ICON));
+ wc.hInstance = g_hThisInstance;
+ wc.hIcon = LoadIcon(g_hThisInstance, MAKEINTRESOURCEW(IDI_MAIN_ICON));
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
wc.lpszMenuName = MAKEINTRESOURCEW(IDR_MAINMENU);
wc.lpszClassName = m_szMainWndClass;
- wc.hIconSm = (HICON)LoadImage(g_hInstance,
+ wc.hIconSm = (HICON)LoadImage(g_hThisInstance,
MAKEINTRESOURCE(IDI_MAIN_ICON),
IMAGE_ICON,
16,
500,
NULL,
NULL,
- g_hInstance,
+ g_hThisInstance,
this);
}
}
void
-CMainWindow::Uninitialize()
+CDeviceManager::Uninitialize(void)
{
// Unregister the window class
- UnregisterClassW(m_szMainWndClass, g_hInstance);
+ UnregisterClassW(m_szMainWndClass, g_hThisInstance);
}
int
-CMainWindow::Run()
+CDeviceManager::Run(void)
{
MSG Msg;
return 0;
}
-
-/* PRIVATE METHODS **********************************************/
-
bool
-CMainWindow::MainWndMenuHint(WORD CmdId,
- const MENU_HINT *HintArray,
- DWORD HintsCount,
- UINT DefHintId)
+CDeviceManager::MainWndMenuHint(_In_ WORD CmdId,
+ _In_ const MENU_HINT *HintArray,
+ _In_ DWORD HintsCount,
+ _In_ UINT DefHintId)
{
bool Found = false;
const MENU_HINT *LastHint;
StatusBarLoadString(m_hStatusBar,
SB_SIMPLEID,
- g_hInstance,
+ g_hThisInstance,
HintId);
return Found;
}
void
-CMainWindow::UpdateStatusBar(
- _In_ bool InMenuLoop
- )
+CDeviceManager::UpdateStatusBar(_In_ bool InMenuLoop)
{
SendMessageW(m_hStatusBar,
SB_SIMPLE,
}
bool
-CMainWindow::RefreshView(ViewType Type)
+CDeviceManager::RefreshView(_In_ ViewType Type)
{
UINT CheckId = 0;
BOOL bSuccess;
}
bool
-CMainWindow::CreateToolBar()
+CDeviceManager::CreateToolBar(void)
{
TBADDBITMAP TbAddBitmap;
INT Index;
0, 0, 0, 0,
m_hMainWnd,
(HMENU)IDC_TOOLBAR,
- g_hInstance,
+ g_hThisInstance,
NULL);
if (m_hToolBar == NULL) return FALSE;
sizeof(TBBUTTON),
0);
- TbAddBitmap.hInst = g_hInstance;
+ TbAddBitmap.hInst = g_hThisInstance;
TbAddBitmap.nID = IDB_TOOLBAR;
Index = SendMessageW(m_hToolBar, TB_ADDBITMAP, _countof(TbButtons), (LPARAM)&TbAddBitmap);
}
bool
-CMainWindow::CreateStatusBar()
+CDeviceManager::CreateStatusBar(void)
{
int StatWidths[] = {110, -1}; // widths of status bar
bool bRet = FALSE;
0, 0, 0, 0,
m_hMainWnd,
(HMENU)IDC_STATUSBAR,
- g_hInstance,
+ g_hThisInstance,
NULL);
if (m_hStatusBar)
{
return bRet;
}
-void CMainWindow::UpdateToolbar()
+void CDeviceManager::UpdateToolbar()
{
WORD State;
bool
-CMainWindow::StatusBarLoadString(IN HWND hStatusBar,
- IN INT PartId,
- IN HINSTANCE hInstance,
- IN UINT uID)
+CDeviceManager::StatusBarLoadString(_In_ HWND hStatusBar,
+ _In_ INT PartId,
+ _In_ HINSTANCE hInstance,
+ _In_ UINT uID)
{
CAtlStringW szMessage;
bool bRet = false;
}
LRESULT
-CMainWindow::OnCreate(HWND hwnd)
+CDeviceManager::OnCreate(_In_ HWND hwnd)
{
LRESULT RetCode;
}
LRESULT
-CMainWindow::OnSize()
+CDeviceManager::OnSize(void)
{
RECT rcClient, rcTool, rcStatus;
INT lvHeight, iToolHeight, iStatusHeight;
}
LRESULT
-CMainWindow::OnNotify(LPARAM lParam)
+CDeviceManager::OnNotify(_In_ LPARAM lParam)
{
LPNMHDR NmHdr = (LPNMHDR)lParam;
LRESULT Ret;
case TTN_GETDISPINFO:
{
LPTOOLTIPTEXT lpttt = (LPTOOLTIPTEXT)lParam;
+ lpttt->hinst = g_hThisInstance;
UINT_PTR idButton = lpttt->hdr.idFrom;
switch (idButton)
lpttt->lpszText = MAKEINTRESOURCEW(IDS_TOOLTIP_SCAN);
break;
case IDC_ENABLE_DRV:
- lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_ENABLE);
+ lpttt->lpszText = MAKEINTRESOURCEW(IDS_TOOLTIP_ENABLE);
break;
case IDC_DISABLE_DRV:
- lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_DISABLE);
+ lpttt->lpszText = MAKEINTRESOURCEW(IDS_TOOLTIP_DISABLE);
break;
case IDC_UPDATE_DRV:
- lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_UPDATE);
+ lpttt->lpszText = MAKEINTRESOURCEW(IDS_TOOLTIP_UPDATE);
break;
case IDC_UNINSTALL_DRV:
- lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_UNINSTALL);
+ lpttt->lpszText = MAKEINTRESOURCEW(IDS_TOOLTIP_UNINSTALL);
break;
}
+ idButton = idButton;
break;
}
}
}
LRESULT
-CMainWindow::OnContext(LPARAM lParam)
+CDeviceManager::OnContext(_In_ LPARAM lParam)
{
return m_DeviceView->OnContextMenu(lParam);
}
LRESULT
-CMainWindow::OnCommand(WPARAM wParam,
- LPARAM /*lParam*/)
+CDeviceManager::OnCommand(_In_ WPARAM wParam,
+ _In_ LPARAM /*lParam*/)
{
LRESULT RetCode = 0;
WORD Msg;
}
LRESULT
-CMainWindow::OnDestroy()
+CDeviceManager::OnDestroy(void)
{
// Uninitialize the device view
m_DeviceView->Uninitialize();
}
LRESULT CALLBACK
-CMainWindow::MainWndProc(HWND hwnd,
- UINT msg,
- WPARAM wParam,
- LPARAM lParam)
+CDeviceManager::MainWndProc(_In_ HWND hwnd,
+ _In_ UINT msg,
+ _In_ WPARAM wParam,
+ _In_ LPARAM lParam)
{
- CMainWindow *This;
+ CDeviceManager *This;
LRESULT RetCode = 0;
// Get the object pointer from window context
- This = (CMainWindow *)GetWindowLongPtr(hwnd, GWLP_USERDATA);
+ This = (CDeviceManager *)GetWindowLongPtr(hwnd, GWLP_USERDATA);
if (This == NULL)
{
// Check that this isn't a create message
case WM_CREATE:
{
// Get the object pointer from the create param
- This = (CMainWindow *)((LPCREATESTRUCT)lParam)->lpCreateParams;
+ This = (CDeviceManager *)((LPCREATESTRUCT)lParam)->lpCreateParams;
// Store the pointer in the window's global user data
SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)This);
}
-//////// MOVE ME ////////////////
-
-HINSTANCE g_hInstance = NULL;
-HANDLE ProcessHeap = NULL;
-
-
+#if 1 // test
BOOL
WINAPI
-DeviceManager_ExecuteW(HWND /*hWndParent*/,
+DeviceManager_ExecuteW(HWND hWndParent,
HINSTANCE hInst,
- LPCWSTR /*lpMachineName*/,
+ LPCWSTR lpMachineName,
int nCmdShow)
{
- CMainWindow MainWindow;
- INITCOMMONCONTROLSEX icex;
- CAtlStringW szAppName;
- int Ret = 1;
-
- // Store the global values
- g_hInstance = hInst;
- ProcessHeap = GetProcessHeap();
-
- // Initialize common controls
- icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
- icex.dwICC = ICC_BAR_CLASSES | ICC_COOL_CLASSES;
- InitCommonControlsEx(&icex);
-
- //__debugbreak();
- g_hInstance = GetModuleHandle(L"devmgr.dll");
-
- // Load the application name
- if (szAppName.LoadStringW(g_hInstance, IDS_APPNAME))
- {
- // Initialize the main window
- if (MainWindow.Initialize(szAppName, nCmdShow))
- {
- // Run the application
- Ret = MainWindow.Run();
-
- // Uninitialize the main window
- MainWindow.Uninitialize();
- }
- }
-
- return Ret;
+ CDeviceManager DevMgr;
+ return DevMgr.Create(hWndParent, hInst, lpMachineName, nCmdShow);
}
+#endif
\ No newline at end of file