Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2019 lines
52 KiB

  1. //#--------------------------------------------------------------
  2. //
  3. // File: mainwindow.cpp
  4. //
  5. // Synopsis: This file holds the implementation of the
  6. // CMainWindow class
  7. //
  8. // History: 11/10/2000 serdarun Created
  9. //
  10. // Copyright (C) 1999-2000 Microsoft Corporation
  11. // All rights reserved.
  12. //
  13. //#--------------------------------------------------------------
  14. #include "stdafx.h"
  15. #include "mainwindow.h"
  16. //
  17. // PROGID of the Localization Manager
  18. //
  19. const WCHAR LOCALIZATION_MANAGER [] = L"ServerAppliance.LocalizationManager";
  20. const WCHAR szMainPage[] = L"\\localui_main.htm";
  21. const WCHAR szLocalUIDir[] = L"\\ServerAppliance\\localui";
  22. //
  23. // startup registrypages
  24. //
  25. const WCHAR szLocalUI_StartPage[] = L"\\localui_startup_start.htm";
  26. const WCHAR szLocalUI_ShutdownPage[] = L"\\localui_startup_shutdown.htm";
  27. const WCHAR szLocalUI_UpdatePage[] = L"\\localui_startup_update.htm";
  28. const WCHAR szLocalUI_ReadyPage[] = L"\\localui_startup_ready.htm";
  29. //
  30. // WBEM namespace to connection to
  31. //
  32. const WCHAR DEFAULT_NAMESPACE[] = L"\\\\.\\ROOT\\CIMV2";
  33. //
  34. // Query Language to use for WBEM
  35. //
  36. const WCHAR QUERY_LANGUAGE [] = L"WQL";
  37. //
  38. // WBEM query which specifies the type of events we are interested
  39. // in
  40. //
  41. const WCHAR QUERY_STRING [] = L"select * from Microsoft_SA_AlertEvent";
  42. //++--------------------------------------------------------------
  43. //
  44. // Function: startworkerroutine
  45. //
  46. // Synopsis: This is thread method for starting keypad reading
  47. //
  48. // Arguments: PVOID - pointer to main window class object
  49. //
  50. // Returns: DWORD - success/failure
  51. //
  52. // History: serdarun Created 11/10/2000
  53. //
  54. // Called By: Init method of CMainWindow
  55. //
  56. //----------------------------------------------------------------
  57. DWORD WINAPI startworkerroutine (
  58. /*[in]*/ PVOID pArg
  59. )
  60. {
  61. ((CMainWindow*)pArg)->KeypadReader();
  62. return 0;
  63. } // end of startworkerroutine method
  64. //++--------------------------------------------------------------
  65. //
  66. // Function: Invoke
  67. //
  68. // Synopsis: This is the Invoke method of famous IDispatch interface
  69. //
  70. // Arguments: See MSDN for detailed description
  71. //
  72. // Returns: HRESULT - success/failure
  73. //
  74. // History: serdarun Created 11/10/2000
  75. //
  76. // Called By: WebBrowser control created by main window to notify events
  77. //
  78. //----------------------------------------------------------------
  79. STDMETHODIMP CWebBrowserEventSink::Invoke(DISPID dispid, REFIID riid, LCID lcid,
  80. WORD wFlags, DISPPARAMS* pdispparams, VARIANT* pvarResult,
  81. EXCEPINFO* pexcepinfo, UINT* puArgErr)
  82. {
  83. //
  84. //return immediately if we don't have a valid window pointer
  85. //
  86. if (NULL == m_pMainWindow)
  87. return S_OK;
  88. switch (dispid)
  89. {
  90. //
  91. //Occurs when a document has reached the READYSTATE_COMPLETE state
  92. //
  93. case DISPID_DOCUMENTCOMPLETE:
  94. if ( (pdispparams->cArgs == 2)
  95. && (pdispparams->rgvarg[0].vt == (VT_VARIANT | VT_BYREF))
  96. && (pdispparams->rgvarg[1].vt == VT_DISPATCH) && m_bMainControl )
  97. m_pMainWindow->PageLoaded(pdispparams->rgvarg[1].pdispVal, pdispparams->rgvarg[0].pvarVal);
  98. else
  99. m_pMainWindow->RegistryPageLoaded(pdispparams->rgvarg[1].pdispVal, pdispparams->rgvarg[0].pvarVal);
  100. break;
  101. //
  102. //Occurs before a navigation in the given WebBrowser
  103. //
  104. case DISPID_BEFORENAVIGATE2:
  105. if (m_bMainControl)
  106. m_pMainWindow->LoadingNewPage();
  107. break;
  108. //
  109. //Not interested in rest of the events
  110. //
  111. default:
  112. break;
  113. }
  114. return S_OK;
  115. } // end of CWebBrowserEventSink::Invoke method
  116. //
  117. // constructor
  118. //
  119. CMainWindow::CMainWindow() :
  120. m_hWorkerThread(INVALID_HANDLE_VALUE),
  121. m_lDispWidth(0),
  122. m_lDispHeight(0),
  123. m_dwMainCookie(0),
  124. m_dwSecondCookie(0),
  125. m_bPageReady(FALSE),
  126. m_pSAKeypadController(NULL),
  127. m_pMainWebBrowser(NULL),
  128. m_pMainWebBrowserUnk(NULL),
  129. m_pMainInPlaceAO(NULL),
  130. m_pMainOleObject(NULL),
  131. m_pMainViewObject(NULL),
  132. m_pMainWebBrowserEventSink(NULL),
  133. m_pSecondWebBrowser(NULL),
  134. m_pSecondWebBrowserUnk(NULL),
  135. m_pSecondWebBrowserEventSink(NULL),
  136. m_pLocInfo(NULL),
  137. m_pLangChange(NULL),
  138. m_RegBitmapState(BITMAP_STARTING),
  139. m_pSAWbemSink(NULL),
  140. m_pWbemServices(NULL),
  141. m_pSAConsumer(NULL),
  142. m_dwLEDMessageCode(1),
  143. m_bInTaskorMainPage(FALSE),
  144. m_pSaDisplay(NULL),
  145. m_unintptrMainTimer(0),
  146. m_unintptrSecondTimer(0),
  147. m_bSecondIECreated(FALSE)
  148. {
  149. } // end of constructor
  150. //++--------------------------------------------------------------
  151. //
  152. // Function: OnSaKeyMessage
  153. //
  154. // Synopsis: Message handler for wm_SaKeyMessage generated by
  155. // keypad reader. It converts these messages to real
  156. // WM_KEYDOWN messages and sends to IE control
  157. //
  158. // Arguments: windows message arguments
  159. // WPARAM contains the key id
  160. //
  161. // Returns: LRESULT - success/failure
  162. //
  163. // History: serdarun Created 11/10/2000
  164. //
  165. //----------------------------------------------------------------
  166. LRESULT CMainWindow::OnSaKeyMessage(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  167. {
  168. LONG lMessage;
  169. BOOL fShiftKey;
  170. HRESULT hr;
  171. BYTE aKeyboardState[300];
  172. int iKey = wParam;
  173. if (m_pSAKeypadController)
  174. {
  175. hr = m_pSAKeypadController->GetKey(iKey,&lMessage,&fShiftKey);
  176. }
  177. else
  178. {
  179. SATraceString ("CMainWindow::OnSaKeyMessage, don't have a valid keypad pointer...");
  180. return 0;
  181. }
  182. if (FAILED(hr))
  183. {
  184. SATraceString ("CMainWindow::OnSaKeyMessage failed on m_pSAKeypadController->GetKey");
  185. return 0;
  186. }
  187. //if key is disabled
  188. if (lMessage == 0)
  189. return 0;
  190. if (lMessage == -1)
  191. {
  192. m_pMainWebBrowser->GoBack();
  193. return 0;
  194. }
  195. //
  196. // get the current keyboard state
  197. //
  198. if (GetKeyboardState(aKeyboardState) == 0)
  199. {
  200. SATraceFailure("CMainWindow::OnSaKeyMessage failed on GetKeyboardState",GetLastError());
  201. return 0;
  202. }
  203. if (fShiftKey)
  204. aKeyboardState[VK_SHIFT] = 0xFF;
  205. else
  206. aKeyboardState[VK_SHIFT] = 0x00;
  207. //
  208. // set the new state with the shift key
  209. //
  210. if (SetKeyboardState(aKeyboardState) == 0)
  211. {
  212. SATraceFailure("CMainWindow::OnSaKeyMessage failed on SetKeyboardState",GetLastError());
  213. return 0;
  214. }
  215. HWND hwnd = ::GetFocus();
  216. HWND hwndTmp = m_hwndWebBrowser;
  217. while (hwnd && hwndTmp)
  218. {
  219. if (hwnd == hwndTmp)
  220. break;
  221. hwndTmp = ::GetWindow(hwndTmp,GW_CHILD);
  222. }
  223. ::PostMessage(hwndTmp,WM_KEYDOWN,lMessage,1);
  224. return 0;
  225. } // end of CMainWindow::OnSaKeyMessage
  226. //++--------------------------------------------------------------
  227. //
  228. // Function: OnSaLocMessage
  229. //
  230. // Synopsis: Message handler for wm_SaLocMessage generated by
  231. // keypad reader. It means Loc Id for the box has been
  232. // changed
  233. //
  234. // Arguments: windows message arguments
  235. //
  236. // Returns: LRESULT - success/failure
  237. //
  238. // History: serdarun Created 11/28/2000
  239. //
  240. //----------------------------------------------------------------
  241. LRESULT CMainWindow::OnSaLocMessage(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  242. {
  243. //
  244. // Initialize the state to the first page
  245. //
  246. m_RegBitmapState = BITMAP_STARTING;
  247. CComBSTR bstrBootingPage = m_szLocalUIDir.c_str();
  248. bstrBootingPage.Append(szLocalUI_StartPage);
  249. //
  250. // Second browser start the sequence
  251. //
  252. if (m_pSecondWebBrowser)
  253. {
  254. m_pSecondWebBrowser->Navigate(bstrBootingPage.Detach(),0,0,0,0);
  255. }
  256. //
  257. // Main browser might refresh, talk to mkarki and kevinz
  258. //
  259. return 0;
  260. } // end of CMainWindow::OnSaLocMessage
  261. //++--------------------------------------------------------------
  262. //
  263. // Function: OnSaLEDMessage
  264. //
  265. // Synopsis: Message handler for wm_SaLEDMessage generated by
  266. // sa cinsumer component.
  267. //
  268. // Arguments: windows message arguments
  269. // WPARAM contains the LED code
  270. //
  271. // Returns: LRESULT - success/failure
  272. //
  273. // History: serdarun Created 11/10/2000
  274. //
  275. //----------------------------------------------------------------
  276. LRESULT CMainWindow::OnSaLEDMessage(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  277. {
  278. m_dwLEDMessageCode = wParam;
  279. return 0;
  280. } // end of CMainWindow::OnSaLEDMessage
  281. //++--------------------------------------------------------------
  282. //
  283. // Function: OnSaAlertMessage
  284. //
  285. // Synopsis: Message handler for OnSaAlertMessage generated by
  286. // sa consumer component.
  287. //
  288. // Arguments: windows message arguments
  289. //
  290. // Returns: LRESULT - success/failure
  291. //
  292. // History: serdarun Created 11/10/2000
  293. //
  294. //----------------------------------------------------------------
  295. LRESULT CMainWindow::OnSaAlertMessage(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  296. {
  297. //
  298. // if we are not in tasks or main page, ignore alerts
  299. //
  300. if (!m_bInTaskorMainPage)
  301. {
  302. return 0;
  303. }
  304. SATraceString ("CMainWindow::OnSaAlertMessage, notifying the html page");
  305. //
  306. // send the special key press to the client
  307. //
  308. HWND hwnd = ::GetFocus();
  309. HWND hwndTmp = m_hwndWebBrowser;
  310. while (hwnd && hwndTmp)
  311. {
  312. if (hwnd == hwndTmp)
  313. break;
  314. hwndTmp = ::GetWindow(hwndTmp,GW_CHILD);
  315. }
  316. //
  317. // Send a F24 key press to the html page, used for alerts
  318. //
  319. ::PostMessage(hwndTmp,WM_KEYDOWN,VK_F24,1);
  320. return 0;
  321. } // end of CMainWindow::OnSaAlertMessage
  322. LRESULT CMainWindow::OnTimer(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  323. {
  324. //
  325. // if it is a timer for registry page, print the page and go to the next page
  326. //
  327. if (wParam == m_unintptrSecondTimer)
  328. {
  329. KillTimer(m_unintptrSecondTimer);
  330. PrintRegistryPage();
  331. return 0;
  332. }
  333. if (m_bPageReady)
  334. GetBitmap();
  335. return 0;
  336. }
  337. LRESULT CMainWindow::OnFocus(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  338. {
  339. if (m_pMainOleObject)
  340. m_pMainOleObject->DoVerb(OLEIVERB_UIACTIVATE,0,0,0,0,0);
  341. return 0;
  342. }
  343. //++--------------------------------------------------------------
  344. //
  345. // Function: CreateMainIEControl
  346. //
  347. // Synopsis: Creates the main IE control and registers
  348. // in the event sink
  349. //
  350. // Arguments: none
  351. //
  352. // Returns: HRESULT - success/failure
  353. //
  354. // History: serdarun Created 11/10/2000
  355. //
  356. // Called By: CMainWindow::OnCreate method
  357. //
  358. //----------------------------------------------------------------
  359. HRESULT CMainWindow::CreateMainIEControl()
  360. {
  361. SATraceString ("Entering CMainWindow::CreateMainIEControl ...");
  362. HRESULT hr = E_FAIL;
  363. //
  364. // Create the main IE control
  365. //
  366. m_hwndWebBrowser = ::CreateWindow(_T("AtlAxWin"), m_szMainPage.c_str(),
  367. WS_CHILD|WS_VISIBLE, 0, 0, m_lDispWidth, m_lDispHeight, m_hWnd, NULL,
  368. ::GetModuleHandle(NULL), NULL);
  369. if (NULL == m_hwndWebBrowser)
  370. {
  371. SATraceString ("CreateWindow for main IE control failed");
  372. return hr;
  373. }
  374. //
  375. // Get a pointer to the control
  376. //
  377. AtlAxGetControl(m_hwndWebBrowser, &m_pMainWebBrowserUnk);
  378. if (m_pMainWebBrowserUnk == NULL)
  379. {
  380. SATraceString ("Getting a pointer to the main control failed");
  381. return hr;
  382. }
  383. //
  384. // QI for the IWebBrowser2 interface
  385. //
  386. hr = m_pMainWebBrowserUnk->QueryInterface(IID_IWebBrowser2, (void**)&m_pMainWebBrowser);
  387. if (FAILED(hr))
  388. {
  389. SATraceString ("QI for IWebBrowser2 interface failed");
  390. return hr;
  391. }
  392. //
  393. // QI for the IOleInPlaceActiveObject interface
  394. //
  395. hr = m_pMainWebBrowserUnk->QueryInterface(IID_IOleInPlaceActiveObject, (void**)&m_pMainInPlaceAO);
  396. if (FAILED(hr))
  397. {
  398. SATraceString ("QI for IOleInPlaceActiveObject interface failed");
  399. return hr;
  400. }
  401. //
  402. // QI for the IOleObject interface
  403. //
  404. hr = m_pMainWebBrowserUnk->QueryInterface(IID_IOleObject, (void**)&m_pMainOleObject);
  405. if (FAILED(hr))
  406. {
  407. SATraceString ("QI for IOleObject interface failed");
  408. return hr;
  409. }
  410. //
  411. // QI for the IViewObject2 interface
  412. //
  413. hr = m_pMainWebBrowser->QueryInterface(IID_IViewObject2, (void**)&m_pMainViewObject);
  414. if (FAILED(hr))
  415. {
  416. SATraceString ("QI for IViewObject2 interface failed");
  417. return hr;
  418. }
  419. //
  420. // Create the sink object for the events
  421. //
  422. hr = CComObject<CWebBrowserEventSink>::CreateInstance(&m_pMainWebBrowserEventSink);
  423. if (FAILED(hr))
  424. {
  425. SATraceString ("CreateInstance for sink object failed");
  426. return hr;
  427. }
  428. //
  429. // Store the main window pointer for callbacks
  430. //
  431. m_pMainWebBrowserEventSink->m_pMainWindow = this;
  432. //
  433. // Register in the event sink of the main IE control
  434. //
  435. hr = AtlAdvise(m_pMainWebBrowserUnk, m_pMainWebBrowserEventSink->GetUnknown(), DIID_DWebBrowserEvents2, &m_dwMainCookie);
  436. if (FAILED(hr))
  437. {
  438. SATraceString ("AtlAdvise for main IE control failed");
  439. return hr;
  440. }
  441. return S_OK;
  442. } // end of CMainWindow::CreateMainIEControl
  443. //++--------------------------------------------------------------
  444. //
  445. // Function: CreateSecondIEControl
  446. //
  447. // Synopsis: Creates the second IE control and registers
  448. // in the event sink
  449. //
  450. // Arguments: none
  451. //
  452. // Returns: HRESULT - success/failure
  453. //
  454. // History: serdarun Created 11/10/2000
  455. //
  456. // Called By: CMainWindow::OnCreate method
  457. //
  458. //----------------------------------------------------------------
  459. HRESULT CMainWindow::CreateSecondIEControl()
  460. {
  461. SATraceString ("Entering CMainWindow::CreateSecondIEControl ...");
  462. HRESULT hr = E_FAIL;
  463. wstring szStartUpPage;
  464. szStartUpPage.assign(m_szLocalUIDir);
  465. szStartUpPage.append(szLocalUI_StartPage);
  466. //
  467. // Create the main IE control
  468. //
  469. HWND m_hwndSecondWebBrowser = ::CreateWindow(_T("AtlAxWin"), szStartUpPage.c_str(),
  470. WS_CHILD|WS_VISIBLE, 0, m_lDispHeight, m_lDispWidth, m_lDispHeight, m_hWnd, NULL,
  471. ::GetModuleHandle(NULL), NULL);
  472. if (NULL == m_hwndSecondWebBrowser)
  473. {
  474. SATraceString ("CreateWindow for second IE control failed");
  475. return hr;
  476. }
  477. //
  478. // Get a pointer to the control
  479. //
  480. AtlAxGetControl(m_hwndSecondWebBrowser, &m_pSecondWebBrowserUnk);
  481. if (m_pSecondWebBrowserUnk == NULL)
  482. {
  483. SATraceString ("Getting a pointer to the main control failed");
  484. return hr;
  485. }
  486. //
  487. // QI for the IWebBrowser2 interface
  488. //
  489. hr = m_pSecondWebBrowserUnk->QueryInterface(IID_IWebBrowser2, (void**)&m_pSecondWebBrowser);
  490. if (FAILED(hr))
  491. {
  492. SATraceString ("QI for IWebBrowser2 interface failed");
  493. return hr;
  494. }
  495. //
  496. // Create the sink object for the events
  497. //
  498. hr = CComObject<CWebBrowserEventSink>::CreateInstance(&m_pSecondWebBrowserEventSink);
  499. if (FAILED(hr))
  500. {
  501. SATraceString ("CreateInstance for sink object failed");
  502. return hr;
  503. }
  504. //
  505. // Store the main window pointer for callbacks
  506. //
  507. m_pSecondWebBrowserEventSink->m_pMainWindow = this;
  508. m_pSecondWebBrowserEventSink->m_bMainControl = FALSE;
  509. //
  510. // Register in the event sink of the main IE control
  511. //
  512. hr = AtlAdvise(m_pSecondWebBrowserUnk, m_pSecondWebBrowserEventSink->GetUnknown(), DIID_DWebBrowserEvents2, &m_dwSecondCookie);
  513. if (FAILED(hr))
  514. {
  515. SATraceString ("AtlAdvise for second IE control failed");
  516. return hr;
  517. }
  518. return S_OK;
  519. } // end of CMainWindow::CreateSecondIEControl
  520. //++--------------------------------------------------------------
  521. //
  522. // Function: OnCreate
  523. //
  524. // Synopsis: Creates the IE controls
  525. //
  526. // Arguments: windows message arguments
  527. //
  528. // Returns: LRESULT - success(0)/failure(-1)
  529. //
  530. // History: serdarun Created 11/10/2000
  531. //
  532. //----------------------------------------------------------------
  533. LRESULT CMainWindow::OnCreate(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  534. {
  535. HRESULT hr;
  536. SATraceString ("Entering CMainWindow::OnCreate...");
  537. //
  538. // Create main IE control
  539. //
  540. hr = CreateMainIEControl();
  541. if (FAILED(hr))
  542. {
  543. SATraceString ("CreateMainIEControl failed");
  544. return -1;
  545. }
  546. //
  547. // Create the memory DC used for rendering
  548. //
  549. m_HdcMem = ::CreateCompatibleDC(NULL);
  550. if (NULL == m_HdcMem)
  551. {
  552. SATraceFailure (
  553. "CMainWindow::OnCreate failed on CreateCompatibleDC(NULL):",
  554. GetLastError ());
  555. return -1;
  556. }
  557. //
  558. // Create the monochrome bitmap
  559. //
  560. m_hBitmap = CreateBitmap(m_lDispWidth, m_lDispHeight,1,1,0);
  561. if (NULL == m_HdcMem)
  562. {
  563. SATraceFailure (
  564. "CMainWindow::OnCreate failed on CreateBitmap:",
  565. GetLastError ());
  566. return -1;
  567. }
  568. //
  569. // Select bitmap into DC
  570. //
  571. SelectObject(m_HdcMem, m_hBitmap);
  572. //
  573. // Set the timer
  574. //
  575. m_unintptrMainTimer = ::SetTimer(m_hWnd,1,250,0);
  576. return 0;
  577. }
  578. //++--------------------------------------------------------------
  579. //
  580. // Function: ShutDown
  581. //
  582. // Synopsis: Clean up all the resources
  583. //
  584. // Arguments: none
  585. //
  586. // Returns: none(just logs the problem)
  587. //
  588. // History: serdarun Created 11/20/2000
  589. //
  590. // Called By: CMainWindow::OnDestroy method
  591. //
  592. //----------------------------------------------------------------
  593. void CMainWindow::ShutDown()
  594. {
  595. BOOL bStatus = FALSE;
  596. HRESULT hr;
  597. SATraceString ("Entering CMainWindow::ShutDown method ...");
  598. if (INVALID_HANDLE_VALUE != m_hWorkerThread)
  599. {
  600. //
  601. // cleanup thread handle
  602. //
  603. ::CloseHandle (m_hWorkerThread);
  604. m_hWorkerThread = INVALID_HANDLE_VALUE;
  605. }
  606. //
  607. // delete Memory DC
  608. //
  609. if (m_HdcMem)
  610. {
  611. ::DeleteDC (m_HdcMem);
  612. m_HdcMem = NULL;
  613. }
  614. //
  615. // release the localization manager
  616. //
  617. if (m_pLocInfo)
  618. {
  619. m_pLocInfo->Release ();
  620. m_pLocInfo = NULL;
  621. }
  622. //
  623. // do the reverse sequence of initialization
  624. //
  625. if (m_pLangChange)
  626. {
  627. m_pLangChange->ClearCallback ();
  628. m_pLangChange->Release();
  629. m_pLangChange= NULL;
  630. }
  631. //
  632. // Unadvise event sinks for IE controls
  633. //
  634. if (m_dwMainCookie != 0)
  635. AtlUnadvise(m_pMainWebBrowserUnk, DIID_DWebBrowserEvents2, m_dwMainCookie);
  636. if (m_dwSecondCookie != 0)
  637. AtlUnadvise(m_pSecondWebBrowserUnk, DIID_DWebBrowserEvents2, m_dwSecondCookie);
  638. if ((m_pWbemServices) && (m_pSAWbemSink))
  639. {
  640. //
  641. // cancel reception of events
  642. //
  643. hr = m_pWbemServices->CancelAsyncCall (m_pSAWbemSink);
  644. if (FAILED (hr))
  645. {
  646. SATracePrintf ("CMainWindow::Shutdown failed on-CancelAsyncCall failed with error:%x:",hr);
  647. }
  648. }
  649. //
  650. // release all of the smart pointers
  651. //
  652. m_pMainWebBrowser = NULL;
  653. m_pMainWebBrowserUnk = NULL;
  654. m_pMainWebBrowserEventSink = NULL;
  655. m_pMainInPlaceAO = NULL;
  656. m_pMainOleObject = NULL;
  657. m_pMainViewObject = NULL;
  658. m_pSAKeypadController = NULL;
  659. m_pSecondWebBrowser = NULL;
  660. m_pSecondWebBrowserUnk = NULL;
  661. m_pSecondWebBrowserEventSink = NULL;
  662. m_pWbemServices = NULL;
  663. m_pSAWbemSink = NULL;
  664. m_pSaDisplay = NULL;
  665. if (m_pSAConsumer)
  666. {
  667. m_pSAConsumer->Release();
  668. m_pSAConsumer= NULL;
  669. }
  670. return;
  671. } // end of CMainWindow::ShutDown method
  672. LRESULT CMainWindow::OnDestroy(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  673. {
  674. HRESULT hr;
  675. KillTimer(m_unintptrMainTimer);
  676. ShutDown();
  677. PostThreadMessage(id, WM_QUIT, 0, 0);
  678. return 0;
  679. }
  680. //++--------------------------------------------------------------
  681. //
  682. // Function: LoadingNewPage
  683. //
  684. // Synopsis: It is called before a new page is loaded by web control
  685. //
  686. // Arguments: none
  687. //
  688. // Returns: none(just logs the problem)
  689. //
  690. // History: serdarun Created 11/20/2000
  691. //
  692. // Called By: CWebBrowserEventSink::Invoke method
  693. //
  694. //----------------------------------------------------------------
  695. void CMainWindow::LoadingNewPage()
  696. {
  697. SATraceString ("Entering CMainWindow::LoadingNewPage method");
  698. //
  699. // Set ready flad to FALSE, we won't print any bitmaps until page is ready
  700. //
  701. m_bPageReady = FALSE;
  702. m_bInTaskorMainPage = FALSE;
  703. //
  704. // Load the default key messages for the new page
  705. //
  706. HRESULT hr;
  707. if (m_pSAKeypadController)
  708. {
  709. hr = m_pSAKeypadController->LoadDefaults();
  710. if (FAILED(hr))
  711. {
  712. SATraceString ("Setting default key messages failed");
  713. }
  714. }
  715. return;
  716. } // end of CMainWindow::LoadingNewPage method
  717. //++--------------------------------------------------------------
  718. //
  719. // Function: PageLoaded
  720. //
  721. // Synopsis: It is called after a new page is loaded by web control
  722. //
  723. // Arguments: none
  724. //
  725. // Returns: none(just logs the problem)
  726. //
  727. // History: serdarun Created 11/20/2000
  728. //
  729. // Called By: CWebBrowserEventSink::Invoke method
  730. //
  731. //----------------------------------------------------------------
  732. void CMainWindow::PageLoaded(IDispatch* pdisp, VARIANT* purl)
  733. {
  734. SATraceString ("Entering CMainWindow::PageLoaded method");
  735. BSTR bstrLocation;
  736. HRESULT hr;
  737. if (m_bSecondIECreated == FALSE)
  738. {
  739. hr = CreateSecondIEControl();
  740. if (FAILED(hr))
  741. {
  742. SATraceString ("CreateSecondIEControl failed");
  743. }
  744. m_bSecondIECreated = TRUE;
  745. }
  746. if (m_pMainWebBrowser)
  747. {
  748. if (SUCCEEDED(m_pMainWebBrowser->get_LocationName(&bstrLocation)))
  749. {
  750. if ( ( 0 == _wcsicmp (L"localui_main", bstrLocation ) ) ||
  751. ( 0 == _wcsicmp (L"localui_tasks", bstrLocation ) ) )
  752. {
  753. m_bInTaskorMainPage = TRUE;
  754. }
  755. else
  756. {
  757. m_bInTaskorMainPage = FALSE;
  758. }
  759. SysFreeString(bstrLocation);
  760. }
  761. }
  762. //
  763. // Inplace activate the web control
  764. //
  765. if (m_pMainOleObject)
  766. {
  767. m_pMainOleObject->DoVerb(OLEIVERB_UIACTIVATE,0,0,0,0,0);
  768. }
  769. //
  770. // begin printing new bitmaps
  771. //
  772. m_bPageReady = TRUE;
  773. return;
  774. } // end of CMainWindow::PageLoaded method
  775. //++--------------------------------------------------------------
  776. //
  777. // Function: RegistryPageLoaded
  778. //
  779. // Synopsis: It is called after a new page is loaded by secondary
  780. // web control
  781. //
  782. // Arguments: none
  783. //
  784. // Returns: none(just logs the problem)
  785. //
  786. // History: serdarun Created 11/25/2000
  787. //
  788. // Called By: CWebBrowserEventSink::Invoke method
  789. //
  790. //----------------------------------------------------------------
  791. void CMainWindow::RegistryPageLoaded(IDispatch* pdisp, VARIANT* purl)
  792. {
  793. m_unintptrSecondTimer = ::SetTimer(m_hWnd,2,3000,0);
  794. }// end of CMainWindow::RegistryPageLoaded method
  795. //++--------------------------------------------------------------
  796. //
  797. // Function: PrintRegistryPage
  798. //
  799. // Synopsis: It is called after a new page is loaded by secondary
  800. // web control
  801. //
  802. // Arguments: none
  803. //
  804. // Returns: none(just logs the problem)
  805. //
  806. // History: serdarun Created 11/25/2000
  807. //
  808. // Called By: OnTimer method
  809. //
  810. //----------------------------------------------------------------
  811. void CMainWindow::PrintRegistryPage()
  812. {
  813. CComPtr<IViewObject2> pViewObject;
  814. HRESULT hr;
  815. BYTE DispBitmap [SA_DISPLAY_MAX_BITMAP_IN_BYTES];
  816. RECTL rcBounds = { 0, 0, m_lDispWidth, m_lDispHeight };
  817. BYTE BitMapInfoBuffer[sizeof(BITMAPINFO)+sizeof(RGBQUAD)];
  818. BITMAPINFO * pBitMapInfo = (BITMAPINFO*)BitMapInfoBuffer;
  819. BOOL bStatus;
  820. HKEY hOpenKey = NULL;
  821. LONG lMessageId;
  822. SATraceString ("Entering CMainWindow::PrintRegistryPage method");
  823. //
  824. // Make sure we have a valid pointer to draw
  825. //
  826. if (!m_pSecondWebBrowser)
  827. {
  828. SATraceString ("m_pSecondWebBrowser is NULL in CMainWindow::PrintRegistryPage method");
  829. return;
  830. }
  831. //
  832. // Get the drawing interface pointer
  833. //
  834. hr = m_pSecondWebBrowser->QueryInterface(IID_IViewObject2,(void**)&pViewObject);
  835. if (FAILED(hr))
  836. {
  837. SATraceString ("CMainWindow::PrintRegistryPage method failed on QI for IViewObject");
  838. return;
  839. }
  840. //
  841. // Draw on the memory DC
  842. //
  843. hr = pViewObject->Draw(DVASPECT_CONTENT, -1, NULL, NULL, NULL, m_HdcMem, &rcBounds, NULL, NULL, 0);
  844. if (FAILED(hr))
  845. {
  846. SATraceString ("CMainWindow::PrintRegistryPage failed on Draw method");
  847. return;
  848. }
  849. //
  850. // Initialize the bitmap info structure
  851. //
  852. pBitMapInfo->bmiHeader.biSize = sizeof (BitMapInfoBuffer);
  853. pBitMapInfo->bmiHeader.biBitCount = 0;
  854. //
  855. // call to fill up the BITMAPINFO structure
  856. //
  857. bStatus = ::GetDIBits (
  858. m_HdcMem,
  859. (HBITMAP)m_hBitmap,
  860. 0,
  861. 0,
  862. NULL,
  863. pBitMapInfo,
  864. DIB_RGB_COLORS
  865. );
  866. if (FALSE == bStatus)
  867. {
  868. SATraceFailure (
  869. "CMainWindow::PrintRegistryPage failed on GetDIBits:",
  870. GetLastError()
  871. );
  872. return;
  873. }
  874. ::memset (DispBitmap, 0, SA_DISPLAY_MAX_BITMAP_IN_BYTES);
  875. //
  876. // get the bitmap into a buffer now
  877. //
  878. bStatus = ::GetDIBits (
  879. m_HdcMem,
  880. (HBITMAP)m_hBitmap,
  881. 0,
  882. m_lDispHeight,
  883. (PVOID)DispBitmap,
  884. pBitMapInfo,
  885. DIB_RGB_COLORS
  886. );
  887. if (FALSE == bStatus)
  888. {
  889. SATraceFailure (
  890. "CMainWindow::PrintRegistryPage failed on GetDIBits:",
  891. GetLastError()
  892. );
  893. return;
  894. }
  895. for (int i = 0; i < SA_DISPLAY_MAX_BITMAP_IN_BYTES; i++)
  896. {
  897. DispBitmap[i] = ~DispBitmap[i];
  898. }
  899. if (m_RegBitmapState == BITMAP_STARTING)
  900. {
  901. lMessageId = SA_DISPLAY_STARTING;
  902. m_RegBitmapState = BITMAP_CHECKDISK;
  903. }
  904. else if (m_RegBitmapState == BITMAP_CHECKDISK)
  905. {
  906. lMessageId = SA_DISPLAY_CHECK_DISK;
  907. m_RegBitmapState = BITMAP_READY;
  908. }
  909. else if (m_RegBitmapState == BITMAP_READY)
  910. {
  911. lMessageId = SA_DISPLAY_READY;
  912. m_RegBitmapState = BITMAP_SHUTDOWN;
  913. }
  914. else if (m_RegBitmapState == BITMAP_SHUTDOWN)
  915. {
  916. lMessageId = SA_DISPLAY_SHUTTING_DOWN;
  917. m_RegBitmapState = BITMAP_UPDATE;
  918. }
  919. else if (m_RegBitmapState == BITMAP_UPDATE)
  920. {
  921. lMessageId = SA_DISPLAY_ADD_START_TASKS;
  922. m_RegBitmapState = BITMAP_STARTING;
  923. }
  924. //
  925. // call display helper to store the bitmap in the registry
  926. //
  927. hr = m_pSaDisplay->StoreBitmap(
  928. lMessageId,
  929. m_lDispWidth,
  930. m_lDispHeight,
  931. DispBitmap
  932. );
  933. if (FAILED(hr))
  934. {
  935. SATracePrintf (
  936. "CMainWindow::PrintRegistryPage failed on StoreBitmap %x",
  937. hr
  938. );
  939. }
  940. CComBSTR bstrStatePage;
  941. bstrStatePage = m_szLocalUIDir.c_str();
  942. //
  943. // append "ShutDown" to URL
  944. //
  945. if (m_RegBitmapState == BITMAP_SHUTDOWN)
  946. {
  947. bstrStatePage.Append(szLocalUI_ShutdownPage);
  948. }
  949. else if (m_RegBitmapState == BITMAP_CHECKDISK)
  950. {
  951. bstrStatePage.Append(szLocalUI_UpdatePage);
  952. }
  953. else if (m_RegBitmapState == BITMAP_UPDATE)
  954. {
  955. bstrStatePage.Append(szLocalUI_UpdatePage);
  956. }
  957. else if (m_RegBitmapState == BITMAP_READY)
  958. {
  959. bstrStatePage.Append(szLocalUI_ReadyPage);
  960. }
  961. //
  962. // go to the next page if sequence is not completed
  963. //
  964. if (m_RegBitmapState != BITMAP_STARTING)
  965. {
  966. m_pSecondWebBrowser->Navigate(bstrStatePage.Detach(),0,0,0,0);
  967. }
  968. else
  969. {
  970. //
  971. // tell the driver to pick up the new bitmaps
  972. //
  973. hr = m_pSaDisplay->ReloadRegistryBitmaps();
  974. if (FAILED(hr))
  975. {
  976. SATracePrintf (
  977. "CMainWindow::PrintRegistryPage failed on ReloadRegistryBitmaps %x",
  978. hr
  979. );
  980. }
  981. }
  982. return;
  983. } // end of CMainWindow::PrintRegistryPage method
  984. //++--------------------------------------------------------------
  985. //
  986. // Function: ConstructUrlStrings
  987. //
  988. // Synopsis: creates full path for main page
  989. //
  990. // Arguments: none
  991. //
  992. // Returns: none(just logs the problem)
  993. //
  994. // History: serdarun Created 02/06/2001
  995. //
  996. // Called By: CMainWindow::Initialize method
  997. //
  998. //----------------------------------------------------------------
  999. HRESULT CMainWindow::ConstructUrlStrings()
  1000. {
  1001. HRESULT hr = S_OK;
  1002. WCHAR szSystemDir[MAX_PATH];
  1003. //
  1004. // Get system32 directory
  1005. //
  1006. if (GetSystemDirectory(szSystemDir,MAX_PATH) == 0)
  1007. {
  1008. SATraceFailure (
  1009. "CMainWindow::ConstructUrlStrings, failed on GetSystemDirectory",
  1010. GetLastError()
  1011. );
  1012. return hr;
  1013. }
  1014. //
  1015. // localui dir = system directory + "ServerAppliance\localui"
  1016. //
  1017. m_szLocalUIDir.assign(szSystemDir);
  1018. m_szLocalUIDir.append(szLocalUIDir);
  1019. //
  1020. // construct local ui main page
  1021. //
  1022. m_szMainPage.assign(m_szLocalUIDir);
  1023. m_szMainPage.append(szMainPage);
  1024. SATracePrintf ("ConstructUrlStrings Main Page:%ws",m_szMainPage.c_str());
  1025. SATracePrintf ("ConstructUrlStrings LocalUI directory:%ws",m_szLocalUIDir.c_str());
  1026. return hr;
  1027. }
  1028. // end of CMainWindow::ConstructUrlStrings method
  1029. //++--------------------------------------------------------------
  1030. //
  1031. // Function: CorrectTheFocus
  1032. //
  1033. // Synopsis: Sets focus to the first active element in the page
  1034. //
  1035. // Arguments: none
  1036. //
  1037. // Returns: none(just logs the problem)
  1038. //
  1039. // History: serdarun Created 11/20/2000
  1040. //
  1041. // Called By: CMainWindow::CorrectTheFocus method
  1042. //
  1043. //----------------------------------------------------------------
  1044. void CMainWindow::CorrectTheFocus()
  1045. {
  1046. CComPtr<IDispatch> pDisp;
  1047. CComPtr<IHTMLDocument2> pHTMLDocument;
  1048. CComPtr<IHTMLElement> pHTMLElement;
  1049. CComBSTR bstrTagName;
  1050. HRESULT hr;
  1051. USES_CONVERSION;
  1052. //
  1053. // If browser pointer is not valid, return
  1054. //
  1055. if (m_pMainWebBrowser == NULL)
  1056. return;
  1057. //
  1058. // Get the current document from browser
  1059. //
  1060. hr = m_pMainWebBrowser->get_Document(&pDisp);
  1061. if (FAILED(hr))
  1062. {
  1063. SATraceString ("CMainWindow::CorrectTheFocus failed on get_Document");
  1064. return;
  1065. }
  1066. //
  1067. // Get the document interface
  1068. //
  1069. hr = pDisp->QueryInterface(IID_IHTMLDocument2,(void**)&pHTMLDocument);
  1070. if (FAILED(hr))
  1071. {
  1072. SATraceString ("CMainWindow::CorrectTheFocus failed on QueryInterface for IHTMLDocument");
  1073. return;
  1074. }
  1075. //
  1076. // Get the active element
  1077. //
  1078. if ( FAILED( pHTMLDocument->get_activeElement(&pHTMLElement) ) )
  1079. {
  1080. SATraceString ("CMainWindow::CorrectTheFocus failed on get_activeElement");
  1081. return;
  1082. }
  1083. //
  1084. // There is no active element, send a tab message
  1085. //
  1086. else if (pHTMLElement == NULL)
  1087. {
  1088. PostThreadMessage(GetCurrentThreadId(),WM_KEYDOWN,(WPARAM)VK_TAB,(LPARAM)1);
  1089. }
  1090. //
  1091. // If body is the active element, also send a tab message
  1092. // We want something else to have the focus
  1093. //
  1094. else
  1095. {
  1096. hr = pHTMLElement->get_tagName(&bstrTagName);
  1097. m_bActiveXFocus = FALSE;
  1098. if (FAILED(hr))
  1099. {
  1100. SATraceString ("CMainWindow::CorrectTheFocus failed on get_tagName");
  1101. return;
  1102. }
  1103. //
  1104. // Check if the tag is body
  1105. //
  1106. //else if (_wcsicmp(W2T(bstrTagName),_T("body")) == 0)
  1107. // PostThreadMessage(GetCurrentThreadId(),WM_KEYDOWN,(WPARAM)VK_TAB,(LPARAM)1);
  1108. else if (_wcsicmp(W2T(bstrTagName),_T("object")) == 0)
  1109. m_bActiveXFocus = TRUE;
  1110. }
  1111. } // end of CMainWindow::CorrectTheFocus
  1112. //++--------------------------------------------------------------
  1113. //
  1114. // Function: GetBitmap
  1115. //
  1116. // Synopsis: Gets the bitmap from IE control and writes to LCD
  1117. //
  1118. // Arguments: none
  1119. //
  1120. // Returns: none(just logs the problem)
  1121. //
  1122. // History: serdarun Created 11/20/2000
  1123. //
  1124. // Called By: CMainWindow::OnTimer method
  1125. //
  1126. //----------------------------------------------------------------
  1127. void CMainWindow::GetBitmap()
  1128. {
  1129. HRESULT hr;
  1130. RECTL rcBounds = { 0, 0, m_lDispWidth, m_lDispHeight };
  1131. BOOL bStatus;
  1132. BYTE DisplayBitmap[SA_DISPLAY_MAX_BITMAP_IN_BYTES];
  1133. BYTE BitMapInfoBuffer[sizeof(BITMAPINFO)+sizeof(RGBQUAD)];
  1134. ::memset ((PVOID)BitMapInfoBuffer, 0, sizeof(BitMapInfoBuffer));
  1135. BITMAPINFO * pBitMapInfo = (BITMAPINFO*)BitMapInfoBuffer;
  1136. //SATraceString ("Entering CMainWindow::GetBitmap method");
  1137. //
  1138. // Make sure there is an active element
  1139. //
  1140. CorrectTheFocus();
  1141. //
  1142. // If IViewObject2 interface is NULL, we cannot get the bitmap
  1143. //
  1144. if (m_pMainViewObject == NULL)
  1145. return;
  1146. //
  1147. // Draw on the memory DC
  1148. //
  1149. hr = m_pMainViewObject->Draw(DVASPECT_CONTENT, -1, NULL, NULL, NULL, m_HdcMem, &rcBounds, NULL, NULL, 0);
  1150. if (FAILED(hr))
  1151. {
  1152. SATraceString ("CMainWindow::GetBitmap failed on Draw method");
  1153. return;
  1154. }
  1155. //
  1156. // Initialize the bitmap info structure
  1157. //
  1158. pBitMapInfo->bmiHeader.biSize = sizeof(BitMapInfoBuffer);
  1159. pBitMapInfo->bmiHeader.biBitCount = 0;
  1160. //
  1161. // Initialize the display buffer
  1162. //
  1163. ::memset ((PVOID)DisplayBitmap, 0, SA_DISPLAY_MAX_BITMAP_IN_BYTES);
  1164. //
  1165. // call to fill up the BITMAPINFO structure
  1166. //
  1167. bStatus = ::GetDIBits (
  1168. m_HdcMem,
  1169. (HBITMAP)m_hBitmap,
  1170. 0,
  1171. 0,
  1172. NULL,
  1173. pBitMapInfo,
  1174. DIB_RGB_COLORS
  1175. );
  1176. if (FALSE == bStatus)
  1177. {
  1178. SATraceFailure (
  1179. "CMainWindow::GetBitmap failed on GetDIBits:",
  1180. GetLastError()
  1181. );
  1182. return;
  1183. }
  1184. //
  1185. // get the bitmap into a buffer now
  1186. //
  1187. bStatus = ::GetDIBits (
  1188. m_HdcMem,
  1189. (HBITMAP)m_hBitmap,
  1190. 0,
  1191. m_lDispHeight,
  1192. (PVOID)(DisplayBitmap),
  1193. pBitMapInfo,
  1194. DIB_RGB_COLORS
  1195. );
  1196. if (FALSE == bStatus)
  1197. {
  1198. SATraceFailure (
  1199. "CMainWindow::GetBitmap failed on GetDIBits:",
  1200. GetLastError()
  1201. );
  1202. return;
  1203. }
  1204. for (int i = 0; i < SA_DISPLAY_MAX_BITMAP_IN_BYTES; i++)
  1205. {
  1206. DisplayBitmap[i] = ~DisplayBitmap[i];
  1207. }
  1208. hr = m_pSaDisplay->ShowMessage(
  1209. m_dwLEDMessageCode,
  1210. m_lDispWidth,
  1211. m_lDispHeight,
  1212. (DisplayBitmap)
  1213. );
  1214. if (FAILED(hr))
  1215. {
  1216. SATracePrintf (
  1217. "CMainWindow::GetBitmap failed on ShowMessage: %x",
  1218. hr
  1219. );
  1220. }
  1221. return;
  1222. } // end of CMainWindow::GetBitmap
  1223. //++--------------------------------------------------------------
  1224. //
  1225. // Function: Initialize
  1226. //
  1227. // Synopsis: This is method for initializing the drivers and
  1228. // creating the main window for the service
  1229. //
  1230. // Arguments: none
  1231. //
  1232. // Returns: HRESULT - success/failure
  1233. //
  1234. // History: serdarun Created 11/20/2000
  1235. //
  1236. // Called By; Run method of the service
  1237. //
  1238. //----------------------------------------------------------------
  1239. HRESULT CMainWindow::Initialize()
  1240. {
  1241. SATraceString ("Entering CMainWindow::Initialize method");
  1242. HRESULT hr = S_OK;
  1243. if (!AtlAxWinInit())
  1244. {
  1245. SATraceString ("CMainWindow::Initialize, AtlAxWinInit failed...");
  1246. return E_FAIL;
  1247. }
  1248. //
  1249. // Construct the URL strings
  1250. //
  1251. ConstructUrlStrings();
  1252. //
  1253. //Create the keypad component
  1254. //
  1255. CComPtr<IClassFactory> pCF;
  1256. hr = CoGetClassObject(CLSID_SAKeypadController,CLSCTX_INPROC_SERVER,0,IID_IClassFactory,(void**)&pCF);
  1257. if (FAILED(hr))
  1258. {
  1259. SATracePrintf ("Initialize couldn't get class object for keypad controller:%x",hr);
  1260. return hr;
  1261. }
  1262. hr = pCF->CreateInstance(NULL,IID_ISAKeypadController,(void**)&m_pSAKeypadController);
  1263. if (FAILED(hr))
  1264. {
  1265. SATracePrintf ("Initialize couldn't create keypad controller:%x",hr);
  1266. return hr;
  1267. }
  1268. else
  1269. {
  1270. m_pSAKeypadController->LoadDefaults();
  1271. }
  1272. //
  1273. // initialize connection to display helper component
  1274. //
  1275. hr = InitDisplayComponent();
  1276. if (FAILED(hr))
  1277. return hr;
  1278. //
  1279. // initialize consumer component
  1280. //
  1281. hr = InitWMIConsumer();
  1282. if (FAILED(hr))
  1283. {
  1284. SATraceString ("CMainWindow::Initialize method failed on initializing WMI consumer");
  1285. //we can continue without consumer
  1286. //return hr;
  1287. }
  1288. RECT rcMain = { 0, 0, m_lDispWidth+8, 2*m_lDispHeight+27 };
  1289. HWND hwnd = Create(
  1290. NULL, //parent window
  1291. rcMain, //coordinates
  1292. L"Main Window",
  1293. WS_OVERLAPPEDWINDOW);
  1294. if (NULL == hwnd)
  1295. {
  1296. SATraceString ("CMainWindow::Initialize method failed creating the main window");
  1297. ShutDown();
  1298. return E_FAIL;
  1299. }
  1300. //
  1301. // set the service window
  1302. //
  1303. m_pSAConsumer->SetServiceWindow(hwnd);
  1304. //
  1305. // following operations all depend on keypad driver
  1306. //
  1307. if (TRUE)
  1308. {
  1309. //
  1310. // initialize connection to localization manager
  1311. //
  1312. hr = InitLanguageCallback();
  1313. if (FAILED(hr))
  1314. {
  1315. //
  1316. // we can continue without loc manager
  1317. //
  1318. SATraceString ("CMainWindow::Initialize failed on InitLanguageCallback method..");
  1319. //return hr;
  1320. }
  1321. //
  1322. // spawn the worker thread now
  1323. //
  1324. DWORD dwThreadID = 0;
  1325. m_hWorkerThread = ::CreateThread (
  1326. NULL, //security
  1327. 0, //stack size
  1328. startworkerroutine,
  1329. (PVOID)this,
  1330. 0, //init flag
  1331. &dwThreadID
  1332. );
  1333. if (INVALID_HANDLE_VALUE == m_hWorkerThread)
  1334. {
  1335. SATraceFailure (
  1336. "CMainWindow::Initialize failed on CreateThread:",
  1337. GetLastError ()
  1338. );
  1339. // we can continue without the reader thread
  1340. }
  1341. }
  1342. SATraceString ("CMainWindow::Initialize completed successfully...");
  1343. hr = S_OK;
  1344. return hr;
  1345. } // end of CMainWindow::Initialize method
  1346. //++--------------------------------------------------------------
  1347. //
  1348. // Function: InitLanguageCallback
  1349. //
  1350. // Synopsis: This is CMainWindow private method for
  1351. // initializing the localization manager the
  1352. // callback function from CLangChange class
  1353. //
  1354. // Arguments: none
  1355. //
  1356. // Returns: HRESULT - success/failure
  1357. //
  1358. // History: serdarun Created 11/21/2000
  1359. //
  1360. // Called By: CMainWindow::InitLanguageCallback method
  1361. //
  1362. //----------------------------------------------------------------
  1363. HRESULT
  1364. CMainWindow::InitLanguageCallback(
  1365. VOID
  1366. )
  1367. {
  1368. SATraceString("Entering CMainWindow::InitLanguageCallback....");
  1369. CLSID clsidLocMgr;
  1370. HRESULT hr;
  1371. IUnknown *pLangChangeUnk = NULL;
  1372. //
  1373. // initialize the localization manager
  1374. //
  1375. hr = ::CLSIDFromProgID (LOCALIZATION_MANAGER,&clsidLocMgr);
  1376. if (FAILED(hr))
  1377. {
  1378. SATracePrintf ("Display Adapter unable to get CLSID for Loc Mgr:%x",hr);
  1379. return hr;
  1380. }
  1381. //
  1382. // create the Localization Manager COM object
  1383. //
  1384. hr = ::CoCreateInstance (
  1385. clsidLocMgr,
  1386. NULL,
  1387. CLSCTX_INPROC_SERVER,
  1388. __uuidof (ISALocInfo),
  1389. (PVOID*) &m_pLocInfo
  1390. );
  1391. if (FAILED (hr))
  1392. {
  1393. SATracePrintf ("Display Adapter unable to create Loc Mgr:%x",hr);
  1394. m_pLocInfo = NULL;
  1395. return hr;
  1396. }
  1397. //
  1398. // create object that supports ILangChange interface
  1399. //
  1400. m_pLangChange = new CLangChange;
  1401. m_pLangChange->AddRef();
  1402. if (m_pLangChange)
  1403. {
  1404. //
  1405. // Get the IUnkown pointer from m_pLangChange
  1406. //
  1407. hr = m_pLangChange->QueryInterface(IID_IUnknown, (void **)&pLangChangeUnk);
  1408. if (FAILED(hr))
  1409. {
  1410. SATracePrintf("Query(IUnknown) failed %X",hr);
  1411. delete m_pLangChange;
  1412. m_pLangChange = NULL;
  1413. return hr;
  1414. }
  1415. }
  1416. else
  1417. {
  1418. SATraceString("new CLangChange failed");
  1419. return E_FAIL;
  1420. }
  1421. //
  1422. // Set Language change call back interface
  1423. //
  1424. hr = m_pLocInfo->SetLangChangeCallBack(pLangChangeUnk);
  1425. if (FAILED(hr))
  1426. {
  1427. //
  1428. // for now, ignore if can't set lang change
  1429. // call back
  1430. //
  1431. SATracePrintf("SetLangChangeCallBack failed %X",hr);
  1432. pLangChangeUnk->Release();
  1433. pLangChangeUnk = NULL;
  1434. return hr;
  1435. }
  1436. else
  1437. {
  1438. m_pLangChange->OnLangChangeCallback (m_hWnd);
  1439. pLangChangeUnk->Release();
  1440. pLangChangeUnk = NULL;
  1441. }
  1442. return S_OK;
  1443. } // end of CMainWindow::InitLanguageCallback method
  1444. //++--------------------------------------------------------------
  1445. //
  1446. // Function: KeypadReader
  1447. //
  1448. // Synopsis: This is CMainWindow private method in which
  1449. // the worker thread executes
  1450. //
  1451. // Arguments: none
  1452. //
  1453. // Returns: VOID
  1454. //
  1455. // History: serdarun Created 11/22/2000
  1456. //
  1457. //----------------------------------------------------------------
  1458. void CMainWindow::KeypadReader()
  1459. {
  1460. HRESULT hr = E_FAIL;
  1461. CoInitialize(NULL);
  1462. SAKEY sakey;
  1463. CComPtr<ISaKeypad> pSaKeypad;
  1464. SATraceString("CMainWindow::KeypadReader....");
  1465. //
  1466. // create the display helper component
  1467. //
  1468. hr = CoCreateInstance(
  1469. CLSID_SaKeypad,
  1470. NULL,
  1471. CLSCTX_INPROC_SERVER,
  1472. IID_ISaKeypad,
  1473. (void**)&pSaKeypad
  1474. );
  1475. if (FAILED(hr))
  1476. {
  1477. SATracePrintf("CMainWindow::KeypadReader failed on CoCreateInstance, %d",hr);
  1478. return;
  1479. }
  1480. hr = pSaKeypad->get_Key(&sakey);
  1481. while (SUCCEEDED(hr))
  1482. {
  1483. SATracePrintf("KeypadReader received a key press, %d",sakey);
  1484. if ( (sakey >= SAKEY_UP) && (sakey <= SAKEY_RETURN))
  1485. {
  1486. PostMessage(wm_SaKeyMessage,(WPARAM)(sakey-1),(LPARAM)0);
  1487. }
  1488. else
  1489. {
  1490. SATracePrintf("CMainWindow::KeypadReader received unknown key, %d",sakey);
  1491. }
  1492. hr = pSaKeypad->get_Key(&sakey);
  1493. }
  1494. if (FAILED(hr))
  1495. {
  1496. SATracePrintf("CMainWindow::KeypadReader failed on get_Key, %d",hr);
  1497. }
  1498. return;
  1499. SATraceFunction("Leaving CMainWindow::KeypadReader....");
  1500. return;
  1501. } // end of CMainWindow::KeypadReader
  1502. //++--------------------------------------------------------------
  1503. //
  1504. // Function: InitDisplayComponent
  1505. //
  1506. // Synopsis: This is CMainWindow private method for
  1507. // initializing the local display adapter
  1508. // connection to the display driver
  1509. //
  1510. // Arguments: none
  1511. //
  1512. // Returns: HRESULT - success/failure
  1513. //
  1514. // History: serdarun Created 11/21/2000
  1515. //
  1516. // Called By: CMainWindow::Initialize method
  1517. //
  1518. //----------------------------------------------------------------
  1519. HRESULT
  1520. CMainWindow::InitDisplayComponent(
  1521. VOID
  1522. )
  1523. {
  1524. HRESULT hr = E_FAIL;
  1525. SATraceString("CMainWindow::InitDisplayComponent....");
  1526. do
  1527. {
  1528. //
  1529. // create the display helper component
  1530. //
  1531. hr = CoCreateInstance(
  1532. CLSID_SaDisplay,
  1533. NULL,
  1534. CLSCTX_INPROC_SERVER,
  1535. IID_ISaDisplay,
  1536. (void**)&m_pSaDisplay
  1537. );
  1538. if (FAILED(hr))
  1539. {
  1540. SATracePrintf("CMainWindow::InitDisplayComponent failed on CoCreateInstance, %d",hr);
  1541. break;
  1542. }
  1543. //
  1544. // get the dimensions for the lcd
  1545. //
  1546. hr = m_pSaDisplay->get_DisplayWidth(&m_lDispWidth);
  1547. if (FAILED(hr))
  1548. {
  1549. SATracePrintf("CMainWindow::InitDisplayComponent failed on get_DisplayWidth, %d",hr);
  1550. break;
  1551. }
  1552. hr = m_pSaDisplay->get_DisplayHeight(&m_lDispHeight);
  1553. if (FAILED(hr))
  1554. {
  1555. SATracePrintf("CMainWindow::InitDisplayComponent failed on get_DisplayHeight, %d",hr);
  1556. break;
  1557. }
  1558. }
  1559. while (false);
  1560. return (S_OK);
  1561. } // end of CMainWindow::InitDisplayComponent method
  1562. //++--------------------------------------------------------------
  1563. //
  1564. // Function: InitWMIConsumer
  1565. //
  1566. // Synopsis: This is CMainWindow private method for
  1567. // registering the alert consumer
  1568. //
  1569. // Arguments: none
  1570. //
  1571. // Returns: HRESULT - success/failure
  1572. //
  1573. //
  1574. // History: serdarun Created 12/10/2000
  1575. //
  1576. // Called By: CMainWindow::Initialize method
  1577. //
  1578. //----------------------------------------------------------------
  1579. HRESULT CMainWindow::InitWMIConsumer()
  1580. {
  1581. SATraceString("CMainWindow::InitWMIConsumer....");
  1582. HRESULT hr = S_OK;
  1583. CComPtr <IWbemLocator> pWbemLocator;
  1584. m_pSAConsumer = new CSAConsumer();
  1585. if (!m_pSAConsumer)
  1586. {
  1587. SATraceString("CMainWindow::InitWMIConsumer failed on memory allocation");
  1588. return E_OUTOFMEMORY;
  1589. }
  1590. m_pSAConsumer->AddRef();
  1591. //
  1592. // get IWbemObjectSink interface
  1593. //
  1594. hr = m_pSAConsumer->QueryInterface(IID_IWbemObjectSink,(LPVOID*)&m_pSAWbemSink);
  1595. if (FAILED(hr))
  1596. {
  1597. SATracePrintf ("InitWMIConsumer couldn't get IWbemObjectSink interface:%x",hr);
  1598. return hr;
  1599. }
  1600. //
  1601. // create the WBEM locator object
  1602. //
  1603. hr = ::CoCreateInstance (
  1604. __uuidof (WbemLocator),
  1605. 0, //aggregation pointer
  1606. CLSCTX_INPROC_SERVER,
  1607. __uuidof (IWbemLocator),
  1608. (PVOID*) &pWbemLocator
  1609. );
  1610. if (SUCCEEDED (hr) && (pWbemLocator.p))
  1611. {
  1612. CComBSTR strNetworkRes (DEFAULT_NAMESPACE);
  1613. //
  1614. // connect to WMI
  1615. //
  1616. hr = pWbemLocator->ConnectServer (
  1617. strNetworkRes,
  1618. NULL, //user-name
  1619. NULL, //password
  1620. NULL, //current-locale
  1621. 0, //reserved
  1622. NULL, //authority
  1623. NULL, //context
  1624. &m_pWbemServices
  1625. );
  1626. if (SUCCEEDED (hr))
  1627. {
  1628. CComBSTR strQueryLang (QUERY_LANGUAGE);
  1629. CComBSTR strQueryString (QUERY_STRING);
  1630. //
  1631. // set up the consumer object as the event sync
  1632. // for the object type we are interested in
  1633. //
  1634. hr = m_pWbemServices->ExecNotificationQueryAsync (
  1635. strQueryLang,
  1636. strQueryString,
  1637. 0, //no-status
  1638. NULL, //status
  1639. (IWbemObjectSink*)(m_pSAWbemSink)
  1640. );
  1641. if (SUCCEEDED (hr))
  1642. {
  1643. SATraceString ("Consumer component successfully registered...");
  1644. return hr;
  1645. }
  1646. SATracePrintf ("Consumer component didn't register sink with WMI:%x",hr);
  1647. }
  1648. else
  1649. {
  1650. SATracePrintf ("Consumer component failed in connect to WMI:%x",hr);
  1651. }
  1652. }
  1653. else
  1654. {
  1655. SATracePrintf ("Consumer component failed on Creating the WBEM Locator:%x",hr);
  1656. }
  1657. return (hr);
  1658. } // end of CMainWindow::InitWMIConsumer method