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.

324 lines
7.8 KiB

  1. // ItemInfoDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "wiatest.h"
  5. #include "ItemInfoDlg.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // CItemInfoDlg dialog
  13. /**************************************************************************\
  14. * CItemInfoDlg::CItemInfoDlg()
  15. *
  16. * Constructor for Item information Dialog
  17. *
  18. *
  19. * Arguments:
  20. *
  21. * pParent - Parent Window
  22. *
  23. * Return Value:
  24. *
  25. * none
  26. *
  27. * History:
  28. *
  29. * 2/14/1999 Original Version
  30. *
  31. \**************************************************************************/
  32. CItemInfoDlg::CItemInfoDlg(CWnd* pParent /*=NULL*/)
  33. : CDialog(CItemInfoDlg::IDD, pParent)
  34. {
  35. //{{AFX_DATA_INIT(CItemInfoDlg)
  36. m_ItemAddress = _T("");
  37. m_strItemInfoEditBox = _T("");
  38. //}}AFX_DATA_INIT
  39. }
  40. /**************************************************************************\
  41. * CItemInfoDlg::DoDataExchange()
  42. *
  43. * Handles control message maps to the correct member variables
  44. *
  45. *
  46. * Arguments:
  47. *
  48. * pDX - DataExchange object
  49. *
  50. * Return Value:
  51. *
  52. * none
  53. *
  54. * History:
  55. *
  56. * 2/14/1999 Original Version
  57. *
  58. \**************************************************************************/
  59. void CItemInfoDlg::DoDataExchange(CDataExchange* pDX)
  60. {
  61. CDialog::DoDataExchange(pDX);
  62. //{{AFX_DATA_MAP(CItemInfoDlg)
  63. DDX_Control(pDX, IDC_ITEMINFO_EDITBOX, m_ItemInfoEditBox);
  64. DDX_Text(pDX, IDC_ITEMADDRESS_EDITBOX, m_ItemAddress);
  65. DDX_Text(pDX, IDC_ITEMINFO_EDITBOX, m_strItemInfoEditBox);
  66. //}}AFX_DATA_MAP
  67. }
  68. /**************************************************************************\
  69. * CItemInfoDlg::Initialize()
  70. *
  71. * Initializes Item information dialog to the correct mode
  72. *
  73. *
  74. * Arguments:
  75. *
  76. * pIWiaItem - Item to view information about
  77. * bFlag - TRUE - Application Item
  78. * FALSE - Driver item
  79. *
  80. * Return Value:
  81. *
  82. * none
  83. *
  84. * History:
  85. *
  86. * 2/14/1999 Original Version
  87. *
  88. \**************************************************************************/
  89. void CItemInfoDlg::Initialize(IWiaItem* pIWiaItem, BOOL bFlag)
  90. {
  91. m_pIWiaItem = pIWiaItem;
  92. m_bAppItem = bFlag;
  93. }
  94. BEGIN_MESSAGE_MAP(CItemInfoDlg, CDialog)
  95. //{{AFX_MSG_MAP(CItemInfoDlg)
  96. ON_BN_CLICKED(IDC_REFRESH_ITEMINFO_BUTTON, OnRefreshIteminfoButton)
  97. ON_BN_CLICKED(IDC_RESETBACK_BUTTON, OnResetbackButton)
  98. //}}AFX_MSG_MAP
  99. END_MESSAGE_MAP()
  100. /////////////////////////////////////////////////////////////////////////////
  101. // CItemInfoDlg message handlers
  102. /**************************************************************************\
  103. * CItemInfoDlg::OnInitDialog()
  104. *
  105. * Initializes the Item Information dialog's controls/display
  106. *
  107. *
  108. * Arguments:
  109. *
  110. * none
  111. *
  112. * Return Value:
  113. *
  114. * none
  115. *
  116. * History:
  117. *
  118. * 2/14/1999 Original Version
  119. *
  120. \**************************************************************************/
  121. BOOL CItemInfoDlg::OnInitDialog()
  122. {
  123. CDialog::OnInitDialog();
  124. HRESULT hResult = S_OK;
  125. HFONT hFixedFont = (HFONT)GetStockObject(ANSI_FIXED_FONT);
  126. if(hFixedFont != NULL)
  127. m_ItemInfoEditBox.SendMessage(WM_SETFONT,(WPARAM)hFixedFont,0);
  128. if(m_pIWiaItem == NULL)
  129. AfxMessageBox("Bad item detected...");
  130. else
  131. OnResetbackButton();
  132. return TRUE; // return TRUE unless you set the focus to a control
  133. // EXCEPTION: OCX Property Pages should return FALSE
  134. }
  135. /**************************************************************************\
  136. * CItemInfoDlg::OnrefreshIteminfoButton()
  137. *
  138. * Refreshes the current Item's information display
  139. *
  140. *
  141. * Arguments:
  142. *
  143. * none
  144. *
  145. * Return Value:
  146. *
  147. * none
  148. *
  149. * History:
  150. *
  151. * 2/14/1999 Original Version
  152. *
  153. \**************************************************************************/
  154. void CItemInfoDlg::OnRefreshIteminfoButton()
  155. {
  156. int iret = 0;
  157. HRESULT hResult = S_OK;
  158. BSTR bstrItemDump;
  159. IWiaItem* pIWiaItem = NULL;
  160. // refresh information with current item Address
  161. // write new address to member variable
  162. UpdateData(TRUE);
  163. // read string into a pointer (conversion)
  164. sscanf(m_ItemAddress.GetBuffer(20),"%p",&pIWiaItem);
  165. m_ItemAddress.Format("%p",pIWiaItem);
  166. // clean old data from edit box
  167. m_strItemInfoEditBox = "";
  168. // read Dump
  169. if(m_bAppItem)
  170. {
  171. if (IsBadCodePtr((FARPROC)pIWiaItem))
  172. m_strItemInfoEditBox = "Bad Address";
  173. else
  174. {
  175. hResult = pIWiaItem->DumpItemData(&bstrItemDump);
  176. if(hResult == S_OK)
  177. {
  178. // write data to CString
  179. m_strItemInfoEditBox = bstrItemDump;
  180. // free BSTR
  181. SysFreeString(bstrItemDump);
  182. // update window text to show new item name
  183. SetWindowTextToItemName(pIWiaItem);
  184. }
  185. else
  186. {
  187. //WIA_ERROR(("*CItemInfoDlg()* pIWiaItem->DumpItemData() failed hResult = 0x%lx\n",hResult));
  188. m_strItemInfoEditBox = "<No Dump Item Data.. Check the Debugger..>";
  189. }
  190. }
  191. }
  192. else
  193. {
  194. if (IsBadCodePtr((FARPROC)pIWiaItem))
  195. m_strItemInfoEditBox = "Bad Address";
  196. else
  197. {
  198. hResult = pIWiaItem->DumpDrvItemData(&bstrItemDump);
  199. if(hResult == S_OK)
  200. {
  201. // write data to CString
  202. m_strItemInfoEditBox = bstrItemDump;
  203. // free BSTR
  204. SysFreeString(bstrItemDump);
  205. // update window text to show new item name
  206. SetWindowTextToItemName(pIWiaItem);
  207. }
  208. else
  209. {
  210. //WIA_ERROR(("*CItemInfoDlg()* pIWiaItem->DumpDrvItemData() failed hResult = 0x%lx\n",hResult));
  211. m_strItemInfoEditBox = "<No Dump Item Data.. Check the Debugger..>";
  212. }
  213. }
  214. }
  215. // write data to members, and update UI
  216. UpdateData(FALSE);
  217. }
  218. /**************************************************************************\
  219. * CItemInfoDlg::SetWindowtextToItemName()
  220. *
  221. * Sets the Window's caption to display the current item's name.
  222. *
  223. *
  224. * Arguments:
  225. *
  226. * pIWiaItem - Item to get name from
  227. *
  228. * Return Value:
  229. *
  230. * none
  231. *
  232. * History:
  233. *
  234. * 2/14/1999 Original Version
  235. *
  236. \**************************************************************************/
  237. void CItemInfoDlg::SetWindowTextToItemName(IWiaItem *pIWiaItem)
  238. {
  239. HRESULT hResult = S_OK;
  240. CString ItemName = "Item name not found";
  241. IWiaPropertyStorage *pIWiaPropStg;
  242. CHAR szPropName[ MAX_PATH ];
  243. BSTR bstrFullItemName = NULL;
  244. hResult = pIWiaItem->QueryInterface(IID_IWiaPropertyStorage,(void **)&pIWiaPropStg);
  245. if (hResult == S_OK)
  246. {
  247. hResult = ReadPropStr(WIA_IPA_FULL_ITEM_NAME, pIWiaPropStg, &bstrFullItemName);
  248. if (hResult != S_OK)
  249. {
  250. //WIA_ERROR(("ReadPropStr(WIA_IPA_FULL_ITEM_NAME) Failed", hResult));
  251. bstrFullItemName = ::SysAllocString(L"Uninitialized");
  252. }
  253. ItemName = "";
  254. // write property name
  255. WideCharToMultiByte(CP_ACP, 0,bstrFullItemName,-1,szPropName,MAX_PATH,NULL,NULL);
  256. ItemName.Format("%s",szPropName);
  257. }
  258. if(m_bAppItem)
  259. SetWindowText("Application Item Information for ["+ItemName+"]");
  260. else
  261. SetWindowText("Driver Item Information for ["+ItemName+"]");
  262. }
  263. /**************************************************************************\
  264. * CItemInfoDlg::OnResetbackButton()
  265. *
  266. * Reset the status of the dialog's display, and data to the
  267. * startup state.
  268. *
  269. *
  270. * Arguments:
  271. *
  272. * none
  273. *
  274. * Return Value:
  275. *
  276. * none
  277. *
  278. * History:
  279. *
  280. * 2/14/1999 Original Version
  281. *
  282. \**************************************************************************/
  283. void CItemInfoDlg::OnResetbackButton()
  284. {
  285. m_ItemAddress.Format("%p",m_pIWiaItem);
  286. UpdateData(FALSE);
  287. BSTR bstrItemDump;
  288. HRESULT hResult = S_OK;
  289. if(m_bAppItem)
  290. {
  291. // check if item pointer is valid item before call?
  292. hResult = m_pIWiaItem->DumpItemData(&bstrItemDump);
  293. }
  294. else
  295. {
  296. // check if item pointer is valid item before call?
  297. hResult = m_pIWiaItem->DumpDrvItemData(&bstrItemDump);
  298. }
  299. if(hResult == S_OK)
  300. {
  301. // write data to CString
  302. m_strItemInfoEditBox = bstrItemDump;
  303. // free BSTR
  304. SysFreeString(bstrItemDump);
  305. }
  306. else
  307. {
  308. //WIA_ERROR(("*CItemInfoDlg()* pIWiaItem->DumpItemData() failed hResult = 0x%lx\n",hResult));
  309. m_strItemInfoEditBox = "<No Dump Item Data.. Check the Debugger..>";
  310. }
  311. UpdateData(FALSE);
  312. SetWindowTextToItemName(m_pIWiaItem);
  313. }