Source code of Windows XP (NT5)
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.

869 lines
30 KiB

  1. #include "stdafx.h"
  2. #include "resource.h"
  3. #include "msgwrap.h"
  4. #include "clistbox.h"
  5. #ifdef _OVERRIDE_LIST_BOXES
  6. //////////////////////////////////////////////////////////////////////////
  7. //
  8. // extern global functions
  9. // Details: DeviceListBox() - Controls the WIA device list box
  10. // EventListBox() - Controls the WIA event list box
  11. //
  12. //////////////////////////////////////////////////////////////////////////
  13. extern LRESULT CALLBACK DeviceListBox(HWND, UINT, WPARAM, LPARAM);
  14. extern LRESULT CALLBACK EventListBox(HWND, UINT, WPARAM, LPARAM);
  15. extern WNDPROC DefDeviceListBox;
  16. extern WNDPROC DefEventListBox;
  17. #endif
  18. #define _REGISTER_ON
  19. //////////////////////////////////////////////////////////////////////////
  20. //
  21. // Function: CMessageWrapper()
  22. // Details: Constructor
  23. //
  24. //
  25. //////////////////////////////////////////////////////////////////////////
  26. CMessageWrapper::CMessageWrapper()
  27. {
  28. m_hInstance = NULL;
  29. m_hSmallIcon = NULL;
  30. }
  31. //////////////////////////////////////////////////////////////////////////
  32. //
  33. // Function: ~CMessageWrapper()
  34. // Details: Destructor
  35. //
  36. //
  37. //////////////////////////////////////////////////////////////////////////
  38. CMessageWrapper::~CMessageWrapper()
  39. {
  40. //
  41. // free Icon??? (m_hSmallIcon)
  42. //
  43. }
  44. //////////////////////////////////////////////////////////////////////////
  45. //
  46. // Function: Initialize()
  47. // Details: This function handles all initialization for the message wrapper
  48. //
  49. // hInstance - handle to the application's instance
  50. //
  51. //////////////////////////////////////////////////////////////////////////
  52. VOID CMessageWrapper::Initialize(HINSTANCE hInstance)
  53. {
  54. m_hInstance = hInstance;
  55. }
  56. //////////////////////////////////////////////////////////////////////////
  57. //
  58. // Function: OnInitDialog()
  59. // Details: This function handles all initialization for the dialog.
  60. // This includes control initialization.
  61. //
  62. // hDlg - handle to the dialog's window
  63. //
  64. //////////////////////////////////////////////////////////////////////////
  65. BOOL CMessageWrapper::OnInitDialog(HWND hDlg)
  66. {
  67. TCHAR szString[255];
  68. //
  69. // Set dialog's title
  70. //
  71. if(!SetWindowText(hDlg,GetResourceString(IDS_DIALOG_TITLE, szString))) {
  72. Trace(TEXT("Could not set dialog's window title."));
  73. }
  74. //
  75. // Set dialog's small icon
  76. //
  77. m_hSmallIcon = LoadIcon(m_hInstance,MAKEINTRESOURCE(IDI_SMALL));
  78. if(m_hSmallIcon) {
  79. SendMessage(hDlg,WM_SETICON,(WPARAM)ICON_SMALL,(LPARAM)m_hSmallIcon);
  80. } else {
  81. Trace(TEXT("Could not load Small icon from dialog resource."));
  82. }
  83. //
  84. // Initialize WIA Device List box
  85. //
  86. if(!OnRefreshDeviceListBox(hDlg)){
  87. EnableAllControls(hDlg,FALSE);
  88. } else {
  89. EnableAllControls(hDlg,TRUE);
  90. }
  91. #ifdef _OVERRIDE_LIST_BOXES
  92. HWND hListBox = NULL;
  93. hListBox = GetDlgItem(hDlg,IDC_WIA_DEVICE_LIST);
  94. if(NULL != hListBox) {
  95. DefDeviceListBox = (WNDPROC)GetWindowLongPtr(hListBox,GWL_WNDPROC);
  96. SetWindowLongPtr(hListBox,GWL_WNDPROC,(LONG_PTR)DeviceListBox);
  97. OnRefreshDeviceListBox(hDlg);
  98. }
  99. #endif
  100. //
  101. // Initialize WIA Device Event List box
  102. //
  103. if(!OnRefreshEventListBox(hDlg)){
  104. EnableAllControls(hDlg,FALSE);
  105. } else {
  106. EnableAllControls(hDlg,TRUE);
  107. }
  108. #ifdef _OVERRIDE_LIST_BOXES
  109. HWND hEventListBox = NULL;
  110. hEventListBox = GetDlgItem(hDlg,IDC_WIA_EVENT_LIST);
  111. if(NULL != hEventListBox) {
  112. DefEventListBox = (WNDPROC)GetWindowLongPtr(hEventListBox,GWL_WNDPROC);
  113. SetWindowLongPtr(hEventListBox,GWL_WNDPROC,(LONG_PTR)EventListBox);
  114. OnRefreshEventListBox(hDlg);
  115. }
  116. #endif
  117. return TRUE;
  118. }
  119. //////////////////////////////////////////////////////////////////////////
  120. //
  121. // Function: OnAbout()
  122. // Details: This function handles the "About" information for the dialog.
  123. //
  124. // hDlg - handle to the dialog's window
  125. //
  126. //////////////////////////////////////////////////////////////////////////
  127. BOOL CMessageWrapper::OnAbout(HWND hDlg)
  128. {
  129. TCHAR szString[255];
  130. TCHAR szStringTitle[255];
  131. MessageBox(hDlg,GetResourceString(IDS_DIALOG_ABOUT_TEXT, szString),
  132. GetResourceString(IDS_DIALOG_ABOUT_TITLE, szStringTitle),MB_OK);
  133. return TRUE;
  134. }
  135. //////////////////////////////////////////////////////////////////////////
  136. //
  137. // Function: OnExit()
  138. // Details: This function handles the exiting for the dialog.
  139. //
  140. // hDlg - handle to the dialog's window
  141. // wParam - WPARAM parameter (used for windows data/argument passing)
  142. //
  143. //////////////////////////////////////////////////////////////////////////
  144. BOOL CMessageWrapper::OnExit(HWND hDlg, WPARAM wParam)
  145. {
  146. //
  147. // clean up any things here, and exit using the Window's API EndDialog()
  148. //
  149. return EndDialog(hDlg, LOWORD(wParam));
  150. }
  151. //////////////////////////////////////////////////////////////////////////
  152. //
  153. // Function: OnBrowse()
  154. // Details: This function handles the Browse functionality for the dialog.
  155. //
  156. // hDlg - handle to the dialog's window
  157. // szApplicationFilePath - File path to selected application
  158. //
  159. //////////////////////////////////////////////////////////////////////////
  160. BOOL CMessageWrapper::OnBrowse(HWND hDlg, LPTSTR szApplicationFilePath)
  161. {
  162. OPENFILENAME ofn; // common dialog box structure
  163. TCHAR szString[255]; // string for title display
  164. // Initialize OPENFILENAME
  165. char szFile[260]; // buffer for file name
  166. char szBrowseDialogTitle[260]; // buffer for dialog title
  167. ZeroMemory(szFile,sizeof(szFile));
  168. ZeroMemory(szBrowseDialogTitle,sizeof(szBrowseDialogTitle));
  169. GetResourceString(IDS_DIALOG_BROWSE_TITLE,szBrowseDialogTitle,sizeof(szBrowseDialogTitle));
  170. HWND hListBox = NULL;
  171. hListBox = GetDlgItem(hDlg,IDC_WIA_DEVICE_LIST);
  172. if(NULL != hListBox) {
  173. CListBoxUtil DevListBox(hListBox);
  174. BSTR bstrDeviceID = NULL;
  175. DevListBox.GetCurSelTextAndData(szString,(void**)&bstrDeviceID);
  176. lstrcat(szBrowseDialogTitle,szString);
  177. } else {
  178. return FALSE;
  179. }
  180. ZeroMemory(&ofn, sizeof(OPENFILENAME));
  181. ofn.lStructSize = sizeof(OPENFILENAME);
  182. ofn.hwndOwner = hDlg;
  183. ofn.lpstrFile = szFile;
  184. ofn.nMaxFile = sizeof(szFile);
  185. ofn.lpstrFilter = "*.EXE\0*.EXE\0";
  186. ofn.nFilterIndex = 1;
  187. ofn.lpstrFileTitle = NULL;
  188. ofn.nMaxFileTitle = 0;
  189. ofn.lpstrInitialDir = NULL;
  190. ofn.lpstrTitle = szBrowseDialogTitle;
  191. ofn.Flags = 0;
  192. //
  193. // Display the Open dialog box.
  194. //
  195. if (GetOpenFileName(&ofn) == TRUE){
  196. lstrcpy(szApplicationFilePath, szFile);
  197. } else {
  198. return FALSE;
  199. }
  200. return TRUE;
  201. }
  202. //////////////////////////////////////////////////////////////////////////
  203. //
  204. // Function: Register()
  205. // Details: This function handles the Application Registration for the dialog.
  206. //
  207. // hDlg - handle to the dialog's window
  208. // lFlags - WIA_REGISTER_EVENT_CALLBACK, or WIA_UNREGISTER_EVENT_CALLBACK
  209. //
  210. //////////////////////////////////////////////////////////////////////////
  211. BOOL CMessageWrapper::Register(HWND hDlg, long lFlags)
  212. {
  213. TCHAR szCommandLine[1024];
  214. TCHAR szArgs[1024];
  215. memset(szCommandLine,0,sizeof(szCommandLine));
  216. memset(szArgs,0,sizeof(szArgs));
  217. BSTR bstrDeviceID = NULL;
  218. BSTR bstrCommandline = NULL;
  219. BSTR bstrName = NULL;
  220. BSTR bstrDescription = NULL;
  221. GUID *pEventGUID = NULL;
  222. HWND hCommandLineEditBox = NULL;
  223. hCommandLineEditBox = GetDlgItem(hDlg,IDC_APPLICATION_LAUNCH_PATH_EDITBOX);
  224. if(NULL != hCommandLineEditBox){
  225. GetWindowText(hCommandLineEditBox,szCommandLine,sizeof(szCommandLine));
  226. if(lstrlen(szCommandLine) > 0) {
  227. //
  228. // add any additional command-line arguments, if needed to
  229. // the command line.
  230. //
  231. HWND hCommandLineArgumentsEditBox = NULL;
  232. hCommandLineArgumentsEditBox = GetDlgItem(hDlg,IDC_COMMAND_LINE_ARGS_EDITBOX);
  233. if(NULL != hCommandLineArgumentsEditBox){
  234. GetWindowText(hCommandLineArgumentsEditBox,szArgs,sizeof(szArgs));
  235. if(lstrlen(szArgs) > 0){
  236. lstrcat(szCommandLine,TEXT(" "));
  237. lstrcat(szCommandLine,szArgs);
  238. }
  239. }
  240. //
  241. // we have a command-line, so lets use it to register the
  242. // application.
  243. //
  244. HRESULT hr = S_OK;
  245. IWiaDevMgr *pIWiaDevMgr = NULL;
  246. hr = CoCreateInstance(CLSID_WiaDevMgr, NULL, CLSCTX_LOCAL_SERVER,
  247. IID_IWiaDevMgr,(void**)&pIWiaDevMgr);
  248. if(SUCCEEDED(hr)){
  249. if(NULL != pIWiaDevMgr){
  250. //
  251. // Get EVENT GUID
  252. //
  253. HWND hEventListBox = NULL;
  254. hEventListBox = GetDlgItem(hDlg,IDC_WIA_EVENT_LIST);
  255. if(NULL != hEventListBox) {
  256. CListBoxUtil EvListBox(hEventListBox);
  257. TCHAR szEventName[255];
  258. EvListBox.GetCurSelTextAndData(szEventName,(void**)&pEventGUID);
  259. if(*pEventGUID != GUID_NULL){
  260. //
  261. // Get DEVICE ID
  262. //
  263. HWND hListBox = NULL;
  264. hListBox = GetDlgItem(hDlg,IDC_WIA_DEVICE_LIST);
  265. if(NULL != hListBox) {
  266. CListBoxUtil DevListBox(hListBox);
  267. TCHAR szDeviceName[255];
  268. DevListBox.GetCurSelTextAndData(szDeviceName,(void**)&bstrDeviceID);
  269. if(bstrDeviceID != NULL){
  270. #ifdef UNICODE
  271. WCHAR wszAppName[255];
  272. memset(wszAppName,0,sizeof(wszAppName));
  273. bstrCommandline = SysAllocString(szCommandLine);
  274. _wsplitpath(szCommandLine, NULL, NULL, wszAppName, NULL);
  275. bstrName = SysAllocString(wszAppName);
  276. #else
  277. //
  278. // convert char to wchar, so we can create a BSTRs properly
  279. //
  280. WCHAR wszCommandLine[1024];
  281. WCHAR wszAppName[255];
  282. memset(wszCommandLine,0,sizeof(wszCommandLine));
  283. memset(wszAppName,0,sizeof(wszAppName));
  284. MultiByteToWideChar(CP_ACP, 0,szCommandLine,-1,wszCommandLine,sizeof(wszCommandLine));
  285. _wsplitpath(wszCommandLine, NULL, NULL, wszAppName, NULL);
  286. bstrCommandline = SysAllocString(wszCommandLine);
  287. bstrName = SysAllocString(wszAppName);
  288. #endif
  289. Trace(TEXT("Register This command Line: %ws"),bstrCommandline);
  290. Trace(TEXT("Register with this Name: %ws"),bstrName);
  291. WCHAR *pszGUID = NULL;
  292. StringFromCLSID(*pEventGUID,&pszGUID);
  293. if(NULL != pszGUID) {
  294. Trace(TEXT("Register with this GUID: %ws"),pszGUID);
  295. CoTaskMemFree(pszGUID);
  296. } else {
  297. Trace(TEXT("Register with this GUID: BAD GUID!!"));
  298. }
  299. #ifdef _REGISTER_ON
  300. hr = pIWiaDevMgr->RegisterEventCallbackProgram(
  301. lFlags,
  302. bstrDeviceID,
  303. pEventGUID,
  304. bstrCommandline,
  305. bstrName,
  306. bstrName,
  307. bstrCommandline);
  308. TCHAR szText[255];
  309. TCHAR szCaption[255];
  310. memset(szText,0,sizeof(szText));
  311. memset(szCaption,0,sizeof(szCaption));
  312. if(SUCCEEDED(hr)){
  313. GetResourceString(IDS_SUCCESSFUL_REGISTER,szText,sizeof(szText));
  314. GetResourceString(IDS_DIALOG_TITLE,szCaption,sizeof(szCaption));
  315. MessageBox(hDlg,szText,szCaption,MB_OK);
  316. } else {
  317. TCHAR szErrorCode[255];
  318. memset(szErrorCode,0,sizeof(szErrorCode));
  319. GetResourceString(IDS_UNSUCCESSFUL_REGISTER,szText,sizeof(szText));
  320. sprintf(szErrorCode,TEXT(" hr = 0x%X"),hr);
  321. lstrcat(szText,szErrorCode);
  322. GetResourceString(IDS_DIALOG_ERROR_TITLE,szCaption,sizeof(szCaption));
  323. MessageBox(hDlg,szText,szCaption,MB_ICONERROR);
  324. }
  325. #endif
  326. //
  327. // free and allocated strings
  328. //
  329. if(NULL != bstrCommandline){
  330. SysFreeString(bstrCommandline);
  331. }
  332. if(NULL != bstrName){
  333. SysFreeString(bstrName);
  334. }
  335. }
  336. }
  337. }
  338. }
  339. pIWiaDevMgr->Release();
  340. pIWiaDevMgr = NULL;
  341. }
  342. } else {
  343. return FALSE;
  344. }
  345. } else {
  346. return FALSE;
  347. }
  348. } else {
  349. return FALSE;
  350. }
  351. return TRUE;
  352. }
  353. //////////////////////////////////////////////////////////////////////////
  354. //
  355. // Function: OnRefreshDeviceListBox()
  356. // Details: This function handles refreshing the WIA device ListBox for the dialog.
  357. //
  358. // hDlg - handle to the dialog's window
  359. //
  360. //////////////////////////////////////////////////////////////////////////
  361. BOOL CMessageWrapper::OnRefreshDeviceListBox(HWND hDlg)
  362. {
  363. HWND hListBox = NULL;
  364. int iDeviceCount = 0;
  365. //
  366. // grab the WIA device list box
  367. //
  368. hListBox = GetDlgItem(hDlg,IDC_WIA_DEVICE_LIST);
  369. if(NULL != hListBox) {
  370. //
  371. // setup utils, and continue
  372. //
  373. CListBoxUtil DevListBox(hListBox);
  374. //
  375. // clean device listbox
  376. //
  377. DevListBox.ResetContent();
  378. HRESULT hr = S_OK;
  379. ULONG ulFetched = 0;
  380. IWiaDevMgr *pIWiaDevMgr = NULL;
  381. hr = CoCreateInstance(CLSID_WiaDevMgr, NULL, CLSCTX_LOCAL_SERVER,
  382. IID_IWiaDevMgr,(void**)&pIWiaDevMgr);
  383. if(SUCCEEDED(hr)){
  384. if(NULL != pIWiaDevMgr){
  385. IWiaPropertyStorage *pIWiaPropStg = NULL;
  386. IEnumWIA_DEV_INFO *pWiaEnumDevInfo = NULL;
  387. //
  388. // enumerate WIA devices
  389. //
  390. hr = pIWiaDevMgr->EnumDeviceInfo(WIA_DEVINFO_ENUM_LOCAL,&pWiaEnumDevInfo);
  391. if (SUCCEEDED(hr)){
  392. //
  393. // call reset, just in case
  394. //
  395. hr = pWiaEnumDevInfo->Reset();
  396. if (SUCCEEDED(hr)) {
  397. do {
  398. //
  399. // call NEXT()
  400. //
  401. hr = pWiaEnumDevInfo->Next(1,&pIWiaPropStg,&ulFetched);
  402. if (hr == S_OK) {
  403. if(ulFetched > 0){
  404. //
  405. // we have a device, so increment the
  406. // device counter
  407. //
  408. iDeviceCount++;
  409. PROPSPEC PropSpec[2];
  410. PROPVARIANT PropVar [2];
  411. //
  412. // clean the propvar
  413. //
  414. memset(PropVar,0,sizeof(PropVar));
  415. PropSpec[0].ulKind = PRSPEC_PROPID;
  416. PropSpec[0].propid = WIA_DIP_DEV_ID;
  417. PropSpec[1].ulKind = PRSPEC_PROPID;
  418. PropSpec[1].propid = WIA_DIP_DEV_NAME;
  419. //
  420. // read the device name, and device ID
  421. //
  422. hr = pIWiaPropStg->ReadMultiple(sizeof(PropSpec)/sizeof(PROPSPEC),
  423. PropSpec,
  424. PropVar);
  425. if (hr == S_OK) {
  426. //
  427. // write device name to the listbox, and save the
  428. // device ID for later use (EVENT ENUMERATION)
  429. //
  430. Trace(TEXT("Device Name: %ws"),PropVar[1].bstrVal);
  431. Trace(TEXT("Device ID: %ws"),PropVar[0].bstrVal);
  432. //
  433. // convert the BSTR to a CHAR, and copy the BSTR
  434. // for later use (DEVICE CREATION)
  435. //
  436. TCHAR szString[255];
  437. sprintf(szString,TEXT("%ws"),PropVar[1].bstrVal);
  438. BSTR bstrDeviceID = SysAllocString(PropVar[0].bstrVal);
  439. //
  440. // add information to the listbox
  441. //
  442. DevListBox.AddStringAndData(szString,(void*)bstrDeviceID);
  443. //
  444. // free propvariant array
  445. //
  446. FreePropVariantArray(sizeof(PropSpec)/sizeof(PROPSPEC),PropVar);
  447. //
  448. // release property storage
  449. //
  450. pIWiaPropStg->Release();
  451. pIWiaPropStg = NULL;
  452. } else
  453. Trace(TEXT("ReadMultiple() Failed while reading device name,server,and deviceID"));
  454. } else {
  455. //
  456. // force enumeration to exit cleanly
  457. //
  458. hr = S_FALSE;
  459. }
  460. } else if (hr == S_FALSE) {
  461. //
  462. // end of enumeration
  463. //
  464. } else
  465. Trace(TEXT("Next() Failed requesting 1 item"));
  466. } while (hr == S_OK);
  467. } else
  468. Trace(TEXT("Reset() Failed"));
  469. } else{
  470. Trace(TEXT("EnumDeviceInfo Failed"));
  471. return FALSE;
  472. }
  473. } else {
  474. Trace(TEXT("WIA Device Manager is NULL"));
  475. return FALSE;
  476. }
  477. //
  478. // release WIA device manager
  479. //
  480. if(pIWiaDevMgr){
  481. pIWiaDevMgr->Release();
  482. pIWiaDevMgr = NULL;
  483. }
  484. }
  485. //
  486. // if no WIA devices were found during enumeration
  487. // set a nice message inthe list box for the users to
  488. // see.
  489. //
  490. if(iDeviceCount == 0){
  491. TCHAR szString[255];
  492. GetResourceString(IDS_NO_WIA_DEVICES, szString, sizeof(szString));
  493. DevListBox.AddStringAndData(szString,NULL);
  494. //
  495. // always default to the first selection in the listbox
  496. //
  497. DevListBox.SetCurSel(0);
  498. return FALSE; // no devices
  499. }
  500. //
  501. // always default to the first selection in the listbox
  502. //
  503. DevListBox.SetCurSel(0);
  504. return TRUE;
  505. }
  506. return FALSE;
  507. }
  508. //////////////////////////////////////////////////////////////////////////
  509. //
  510. // Function: OnRefreshEventListBox()
  511. // Details: This function handles the WIA event ListBox for the dialog.
  512. //
  513. // hDlg - handle to the dialog's window
  514. //
  515. //////////////////////////////////////////////////////////////////////////
  516. BOOL CMessageWrapper::OnRefreshEventListBox(HWND hDlg)
  517. {
  518. HWND hListBox = NULL;
  519. HWND hDevListBox = NULL;
  520. int iEventCount = 0;
  521. //
  522. // grab both list box windows
  523. //
  524. hListBox = GetDlgItem(hDlg,IDC_WIA_EVENT_LIST);
  525. hDevListBox = GetDlgItem(hDlg,IDC_WIA_DEVICE_LIST);
  526. if((NULL != hListBox)&&NULL != hDevListBox) {
  527. //
  528. // setup utils, and continue
  529. //
  530. CListBoxUtil EvListBox(hListBox);
  531. CListBoxUtil DevListBox(hDevListBox);
  532. //
  533. // clean event listbox
  534. //
  535. EvListBox.ResetContent();
  536. HRESULT hr = S_OK;
  537. ULONG ulFetched = 0;
  538. IWiaDevMgr *pIWiaDevMgr = NULL;
  539. IWiaItem *pIWiaDevice = NULL;
  540. BSTR bstrDeviceID = NULL;
  541. TCHAR szDeviceName[255];
  542. hr = CoCreateInstance(CLSID_WiaDevMgr, NULL, CLSCTX_LOCAL_SERVER,
  543. IID_IWiaDevMgr,(void**)&pIWiaDevMgr);
  544. if(SUCCEEDED(hr)){
  545. if(NULL != pIWiaDevMgr){
  546. DevListBox.GetCurSelTextAndData(szDeviceName,(void**)&bstrDeviceID);
  547. if(NULL != bstrDeviceID) {
  548. hr = pIWiaDevMgr->CreateDevice(bstrDeviceID,&pIWiaDevice);
  549. if(SUCCEEDED(hr)){
  550. IEnumWIA_DEV_CAPS *pIEnumDeviceCaps = NULL;
  551. hr = pIWiaDevice->EnumDeviceCapabilities(WIA_DEVICE_EVENTS, &pIEnumDeviceCaps);
  552. if(SUCCEEDED(hr)){
  553. //
  554. // enumerate EVENTS onlym looking specifically for
  555. // action events..
  556. //
  557. do {
  558. //
  559. // clean DEV info structure
  560. //
  561. WIA_DEV_CAP DevInfo;
  562. memset(&DevInfo,0,sizeof(WIA_DEV_CAP));
  563. //
  564. // call NEXT()
  565. //
  566. hr = pIEnumDeviceCaps->Next(1,&DevInfo,&ulFetched);
  567. if (hr == S_OK) {
  568. if(ulFetched > 0){
  569. //
  570. // are we an ACTION event??
  571. //
  572. if(DevInfo.ulFlags & WIA_ACTION_EVENT){
  573. TCHAR szString[255];
  574. sprintf(szString,TEXT("%ws"),DevInfo.bstrName);
  575. GUID *pEventGUID = new GUID;
  576. memcpy(pEventGUID, &DevInfo.guid, sizeof(GUID));
  577. EvListBox.AddStringAndData(szString,(void*)pEventGUID);
  578. //
  579. // since we have an ACTION event, increment
  580. // the event counter
  581. //
  582. iEventCount++;
  583. }
  584. } else {
  585. //
  586. // force enumeration to exit cleanly
  587. //
  588. hr = S_FALSE;
  589. }
  590. } else if (hr == S_FALSE) {
  591. //
  592. // end of enumeration
  593. //
  594. } else {
  595. Trace(TEXT("Next() Failed requesting 1 item"));
  596. }
  597. } while (hr == S_OK);
  598. }
  599. //
  600. // release WIA device
  601. //
  602. pIWiaDevice->Release();
  603. pIWiaDevice = NULL;
  604. }
  605. }
  606. //
  607. // release WIA device manager
  608. //
  609. pIWiaDevMgr->Release();
  610. pIWiaDevMgr = NULL;
  611. }
  612. }
  613. //
  614. // if no ACTION events were found during enumeration
  615. // set a nice message inthe list box for the users to
  616. // see.
  617. //
  618. if(iEventCount == 0){
  619. TCHAR szString[255];
  620. GetResourceString(IDS_NO_WIA_EVENTS, szString, sizeof(szString));
  621. EvListBox.AddStringAndData(szString,NULL);
  622. //
  623. // always default to the first selection in the listbox
  624. //
  625. EvListBox.SetCurSel(0);
  626. return FALSE; // no devices
  627. }
  628. //
  629. // always default to the first selection in the listbox
  630. //
  631. EvListBox.SetCurSel(0);
  632. return TRUE;
  633. }
  634. return FALSE;
  635. }
  636. //////////////////////////////////////////////////////////////////////////
  637. //
  638. // Function: EnableAllControls()
  639. // Details: This function enables/disables buttons, on the main dialog.
  640. //
  641. // bEnable - Resource ID of the Error Code string
  642. // hDlg - Handle to parent window
  643. //
  644. //////////////////////////////////////////////////////////////////////////
  645. VOID CMessageWrapper::EnableAllControls(HWND hDlg, bool bEnable)
  646. {
  647. HWND hWindow = NULL;
  648. hWindow = GetDlgItem(hDlg,IDC_BROWSE_BUTTON);
  649. if(NULL != hWindow){
  650. EnableWindow(hWindow,bEnable);
  651. }
  652. hWindow = GetDlgItem(hDlg,IDC_REGISTER_BUTTON);
  653. if(NULL != hWindow){
  654. EnableWindow(hWindow,bEnable);
  655. }
  656. hWindow = GetDlgItem(hDlg,IDC_UNREGISTER_BUTTON);
  657. if(NULL != hWindow){
  658. EnableWindow(hWindow,bEnable);
  659. }
  660. }
  661. //////////////////////////////////////////////////////////////////////////
  662. //
  663. // Function: DisplayError()
  664. // Details: This function fills a string, loaded from the application's
  665. // resource, and display's it as an error dialog to the user.
  666. //
  667. // ErrorCode - Resource ID of the Error Code string
  668. //
  669. //////////////////////////////////////////////////////////////////////////
  670. VOID CMessageWrapper::DisplayError(INT ErrorCode)
  671. {
  672. TCHAR szString[255];
  673. GetResourceString(ErrorCode, szString);
  674. #ifdef _ERROR_POPUP
  675. TCHAR szStringTitle[255];
  676. MessageBox(NULL,szString,
  677. GetResourceString(IDS_DIALOG_ERROR_TITLE, szStringTitle),
  678. MB_OK|MB_ICONERROR);
  679. #endif
  680. Trace(TEXT("Error Dialog: %s\n"),szString);
  681. }
  682. //////////////////////////////////////////////////////////////////////////
  683. //
  684. // Function: GetResourceString()
  685. // Details: This function fills a string, loaded from the application's
  686. // resource.
  687. //
  688. // ResourceID - Resource ID of the error code's text
  689. // szString - String to be filled with the resource value
  690. // isize - Size of the string buffer, in BYTES
  691. //
  692. //////////////////////////////////////////////////////////////////////////
  693. LPTSTR CMessageWrapper::GetResourceString(INT ResourceID, LPTSTR szString, INT isize)
  694. {
  695. LoadString(m_hInstance,ResourceID,szString,isize);
  696. return szString;
  697. }
  698. /*
  699. //
  700. // get Device ID
  701. //
  702. BSTR bstrDeviceID = NULL;
  703. DevListBox.GetCurSelTextAndData(szString,(void**)&bstrDeviceID);
  704. Trace(TEXT("Device ID String = %ws"),bstrDeviceID);
  705. */