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.

316 lines
6.5 KiB

  1. // dfuitestdlg.cpp : implementation file
  2. //
  3. #include "stdafxdfuitest.h"
  4. #include "dfuitest.h"
  5. #include "dfuitestdlg.h"
  6. #include "ourguids.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CDFUITestDlg dialog
  14. CDFUITestDlg::CDFUITestDlg(CWnd* pParent /*=NULL*/)
  15. : CDialog(CDFUITestDlg::IDD, pParent)
  16. {
  17. //{{AFX_DATA_INIT(CDFUITestDlg)
  18. m_nNumFormats = -1;
  19. m_nVia = -1;
  20. m_nDisplay = -1;
  21. m_bLayout = FALSE;
  22. m_strNames = _T("");
  23. m_nMode = -1;
  24. m_nColorSet = -1;
  25. //}}AFX_DATA_INIT
  26. // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  27. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  28. }
  29. void CDFUITestDlg::DoDataExchange(CDataExchange* pDX)
  30. {
  31. CDialog::DoDataExchange(pDX);
  32. //{{AFX_DATA_MAP(CDFUITestDlg)
  33. DDX_Radio(pDX, IDC_1, m_nNumFormats);
  34. DDX_Radio(pDX, IDC_DI, m_nVia);
  35. DDX_Radio(pDX, IDC_GDI, m_nDisplay);
  36. DDX_Check(pDX, IDC_LAYOUT, m_bLayout);
  37. DDX_Text(pDX, IDC_NAMES, m_strNames);
  38. DDX_Radio(pDX, IDC_EDIT, m_nMode);
  39. DDX_Radio(pDX, IDC_DEFAULTCS, m_nColorSet);
  40. //}}AFX_DATA_MAP
  41. }
  42. BEGIN_MESSAGE_MAP(CDFUITestDlg, CDialog)
  43. //{{AFX_MSG_MAP(CDFUITestDlg)
  44. ON_WM_PAINT()
  45. ON_WM_QUERYDRAGICON()
  46. ON_BN_CLICKED(IDC_RUN, OnRun)
  47. ON_BN_CLICKED(IDC_USER, OnUser)
  48. ON_BN_CLICKED(IDC_TEST, OnTest)
  49. ON_BN_CLICKED(IDC_NULL, OnNull)
  50. ON_BN_CLICKED(IDC_CUSTOMIZE, OnCustomize)
  51. //}}AFX_MSG_MAP
  52. END_MESSAGE_MAP()
  53. /////////////////////////////////////////////////////////////////////////////
  54. // CDFUITestDlg message handlers
  55. BOOL CDFUITestDlg::OnInitDialog()
  56. {
  57. CDialog::OnInitDialog();
  58. // Set the icon for this dialog. The framework does this automatically
  59. // when the application's main window is not a dialog
  60. SetIcon(m_hIcon, TRUE); // Set big icon
  61. SetIcon(m_hIcon, FALSE); // Set small icon
  62. OnUser();
  63. m_nVia = 0;
  64. m_nMode = 0;
  65. m_nDisplay = 0;
  66. m_nNumFormats = 0;
  67. m_nColorSet = 0;
  68. m_bLayout = TRUE;
  69. UpdateData(FALSE);
  70. return TRUE; // return TRUE unless you set the focus to a control
  71. }
  72. // If you add a minimize button to your dialog, you will need the code below
  73. // to draw the icon. For MFC applications using the document/view model,
  74. // this is automatically done for you by the framework.
  75. void CDFUITestDlg::OnPaint()
  76. {
  77. if (IsIconic())
  78. {
  79. CPaintDC dc(this); // device context for painting
  80. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  81. // Center icon in client rectangle
  82. int cxIcon = GetSystemMetrics(SM_CXICON);
  83. int cyIcon = GetSystemMetrics(SM_CYICON);
  84. CRect rect;
  85. GetClientRect(&rect);
  86. int x = (rect.Width() - cxIcon + 1) / 2;
  87. int y = (rect.Height() - cyIcon + 1) / 2;
  88. // Draw the icon
  89. dc.DrawIcon(x, y, m_hIcon);
  90. }
  91. else
  92. {
  93. CDialog::OnPaint();
  94. }
  95. }
  96. // The system calls this to obtain the cursor to display while the user drags
  97. // the minimized window.
  98. HCURSOR CDFUITestDlg::OnQueryDragIcon()
  99. {
  100. return (HCURSOR) m_hIcon;
  101. }
  102. LPCTSTR GetHResultMsg(HRESULT);
  103. TUI_VIA CDFUITestDlg::GetVia()
  104. {
  105. switch (m_nVia)
  106. {
  107. default:
  108. case 0: return TUI_VIA_DI;
  109. case 1: return TUI_VIA_CCI;
  110. }
  111. }
  112. TUI_DISPLAY CDFUITestDlg::GetDisplay()
  113. {
  114. switch (m_nDisplay)
  115. {
  116. default:
  117. case 0: return TUI_DISPLAY_GDI;
  118. case 1: return TUI_DISPLAY_DDRAW;
  119. case 2: return TUI_DISPLAY_D3D;
  120. }
  121. }
  122. TUI_CONFIGTYPE CDFUITestDlg::GetMode()
  123. {
  124. switch (m_nMode)
  125. {
  126. default:
  127. case 0: return TUI_CONFIGTYPE_EDIT;
  128. case 1: return TUI_CONFIGTYPE_VIEW;
  129. }
  130. }
  131. LPCWSTR CDFUITestDlg::GetUserNames()
  132. {
  133. if (m_strNames.IsEmpty())
  134. return NULL;
  135. CString tstr = m_strNames + _T(",,");
  136. LPWSTR wstr = AllocLPWSTR((LPCTSTR)tstr);
  137. if (wstr == NULL)
  138. return NULL;
  139. int l = wcslen(wstr);
  140. for (int i = 0; i < l; i++)
  141. if (wstr[i] == L',')
  142. wstr[i] = 0;
  143. return wstr;
  144. }
  145. void CDFUITestDlg::OnRun()
  146. {
  147. if (!UpdateData())
  148. return;
  149. TESTCONFIGUIPARAMS p;
  150. BOOL bTCUIMsg = FALSE;
  151. HRESULT hres = S_OK;
  152. LPCTSTR title = _T("CoInitialize Result");
  153. if (SUCCEEDED(hres = CoInitialize(NULL)))
  154. {
  155. title = _T("CoCreateInstance Result");
  156. IDirectInputConfigUITest* pITest = NULL;
  157. hres = ::CoCreateInstance(CLSID_CDirectInputConfigUITest, NULL, CLSCTX_INPROC_SERVER, IID_IDirectInputConfigUITest, (LPVOID*)&pITest);
  158. if (SUCCEEDED(hres))
  159. {
  160. title = _T("TestConfigUI Result");
  161. p.dwSize = sizeof(TESTCONFIGUIPARAMS);
  162. p.eVia = GetVia();
  163. p.eDisplay = GetDisplay();
  164. p.eConfigType = GetMode();
  165. p.nNumAcFors = m_nNumFormats + 1;
  166. p.nColorScheme = m_nColorSet;
  167. p.lpwszUserNames = GetUserNames();
  168. p.bEditLayout = m_bLayout;
  169. CopyStr(p.wszErrorText, "", MAX_PATH);
  170. hres = pITest->TestConfigUI(&p);
  171. if (p.lpwszUserNames != NULL)
  172. free((LPVOID)p.lpwszUserNames);
  173. p.lpwszUserNames = NULL;
  174. bTCUIMsg = TRUE;
  175. pITest->Release();
  176. }
  177. CoUninitialize();
  178. }
  179. LPCTSTR msg = _T("Uknown Error.");
  180. switch (hres)
  181. {
  182. case S_OK: msg = _T("Success."); break;
  183. case REGDB_E_CLASSNOTREG: msg = _T("REGDB_E_CLASSNOTREG!"); break;
  184. case CLASS_E_NOAGGREGATION: msg = _T("CLASS_E_NOAGGREGATION"); break;
  185. default:
  186. msg = GetHResultMsg(hres);
  187. break;
  188. }
  189. if (FAILED(hres))
  190. {
  191. if (bTCUIMsg)
  192. {
  193. TCHAR tmsg[2048];
  194. LPTSTR tstr = AllocLPTSTR(p.wszErrorText);
  195. _stprintf(tmsg, _T("TestConfigUI() failed.\n\ntszErrorText =\n\t\"%s\"\n\n\nHRESULT...\n\n%s"), tstr, msg);
  196. free(tstr);
  197. MessageBox(tmsg, title, MB_OK);
  198. }
  199. else
  200. MessageBox(msg, title, MB_OK);
  201. }
  202. }
  203. LPCTSTR GetHResultMsg(HRESULT hr)
  204. {
  205. static TCHAR str[2048];
  206. LPCTSTR tszhr = NULL, tszMeaning = NULL;
  207. switch (hr)
  208. {
  209. case E_PENDING:
  210. tszhr = _T("E_PENDING");
  211. tszMeaning = _T("Data is not yet available.");
  212. break;
  213. case E_FAIL:
  214. tszhr = _T("E_FAIL");
  215. tszMeaning = _T("General failure.");
  216. break;
  217. case E_INVALIDARG:
  218. tszhr = _T("E_INVALIDARG");
  219. tszMeaning = _T("Invalid argument.");
  220. break;
  221. case E_NOTIMPL:
  222. tszhr = _T("E_NOTIMPL");
  223. tszMeaning = _T("Not implemented.");
  224. break;
  225. default:
  226. _stprintf(str, _T("Unknown HRESULT (%08X)."), hr);
  227. return str;
  228. }
  229. _stprintf(str, _T("(%08X)\n%s:\n\n%s"), hr, tszhr, tszMeaning);
  230. return str;
  231. }
  232. void CDFUITestDlg::OnUser()
  233. {
  234. UpdateData();
  235. TCHAR tszUser[MAX_PATH + 1];
  236. tszUser[MAX_PATH] = 0;
  237. DWORD len = MAX_PATH;
  238. if (GetUserName(tszUser, &len))
  239. m_strNames = tszUser;
  240. else
  241. m_strNames = _T("UserName1");
  242. UpdateData(FALSE);
  243. }
  244. void CDFUITestDlg::OnTest()
  245. {
  246. UpdateData();
  247. m_strNames = _T("Alpha,Beta,Epsilon,Theta");
  248. UpdateData(FALSE);
  249. }
  250. void CDFUITestDlg::OnNull()
  251. {
  252. UpdateData();
  253. m_strNames.Empty();
  254. UpdateData(FALSE);
  255. }
  256. void CDFUITestDlg::OnCustomize()
  257. {
  258. // TODO: Add your control notification handler code here
  259. }