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.

278 lines
7.4 KiB

  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <windows.h>
  4. #include "skeltest.h"
  5. #include "resource.h"
  6. #include "macros.h"
  7. extern HINSTANCE hInstance;
  8. static TESTDATA test_td;
  9. static BUFFERDATA test_bd;
  10. typedef BOOL CALLBACK DlgProc(HWND, UINT, WPARAM, LPARAM);
  11. DlgProc testDlgProc;
  12. DlgProc testAboutDlgProc;
  13. int CALLBACK PropSheetProc(HWND, UINT, LPARAM);
  14. SkeletonTest::SkeletonTest()
  15. {
  16. bzero(szTypeName, sizeof(szTypeName));
  17. bzero(szVersion, sizeof(szVersion));
  18. bzero(&td,sizeof(TESTDATA));
  19. BEGINstring((&td), "testdata");
  20. ENDstring((&td), "testdata");
  21. SetThisType("Skeleton");
  22. SetThisVersion("1.0");
  23. td.swapbuffers = FALSE; // default: single buffer
  24. td.iDuration = 1000; // default: run for 1 second
  25. td.iX = 0;
  26. td.iY = 0;
  27. td.iW = 640;
  28. td.iH = 480;
  29. td.acName[0] = 0;
  30. sprintf(td.acName, "Skeleton");
  31. sprintf(td.acAbout,"An OpenGL profiler test (sorry, no specific description for this test has been entered)");
  32. sprintf(td.acTestStatName,"Frames");
  33. td.dResult = 0;
  34. InitBD(&bd);
  35. iNumConfigPages = 1;
  36. aPSpages = (PROPSHEETPAGE*) malloc(sizeof(PROPSHEETPAGE));
  37. bzero(aPSpages, sizeof(PROPSHEETPAGE));
  38. aPSpages[0].dwSize = sizeof(PROPSHEETPAGE);
  39. aPSpages[0].dwFlags = PSP_USECALLBACK;
  40. aPSpages[0].hInstance = hInstance;
  41. aPSpages[0].pszTemplate = MAKEINTRESOURCE (IDD_GENERAL);
  42. aPSpages[0].pfnDlgProc = (DLGPROC) testDlgProc;
  43. aPSpages[0].lParam = (LPARAM) &td;
  44. }
  45. void SkeletonTest::SetThisType(const char *szType)
  46. {
  47. strncpy(szTypeName, szType, MAXTYPELENGTH);
  48. }
  49. void SkeletonTest::SetThisVersion(const char *szVer)
  50. {
  51. int iLen;
  52. iLen = strlen(szVersion);
  53. if (iLen == sizeof(szVersion))
  54. return;
  55. szVersion[iLen] = '|';
  56. iLen++;
  57. strncat(szVersion, szVer, sizeof(szVersion) - iLen);
  58. }
  59. void SkeletonTest::AddPropertyPages(int iNew, PROPSHEETPAGE *pNewPSpages)
  60. {
  61. int i;
  62. aPSpages = (PROPSHEETPAGE*)
  63. realloc(aPSpages,(iNumConfigPages+iNew) * sizeof(PROPSHEETPAGE));
  64. for (i = 0 ; i < iNew ; i++) {
  65. aPSpages[i + iNumConfigPages] = pNewPSpages[i];
  66. }
  67. iNumConfigPages += iNew;
  68. }
  69. void SkeletonTest::SaveData() { test_td = td; test_bd = bd; }
  70. void SkeletonTest::RestoreSaved() { td = test_td; bd = test_bd; }
  71. void SkeletonTest::ForgetSaved() {}
  72. int SkeletonTest::Save(HANDLE hFile)
  73. {
  74. ulong ul;
  75. if (!WriteFile(hFile, (void*) szTypeName, sizeof(szTypeName), &ul, NULL))
  76. return -1;
  77. if (ul != sizeof(szTypeName)) return -1;
  78. if (!WriteFile(hFile, (void*) szVersion, sizeof(szVersion), &ul, NULL))
  79. return -1;
  80. if (ul != sizeof(szVersion)) return -1;
  81. if (!WriteFile(hFile, (void*) &td, sizeof(td), &ul, NULL))
  82. return -1;
  83. if (ul != sizeof(td)) return -1;
  84. if (!WriteFile(hFile, (void*) &bd, sizeof(bd), &ul, NULL))
  85. return -1;
  86. if (ul != sizeof(bd)) return -1;
  87. FlushFileBuffers(hFile);
  88. return sizeof(szTypeName) + sizeof(szVersion) + sizeof(td) + sizeof(bd);
  89. }
  90. int SkeletonTest::Load(HANDLE hFile)
  91. {
  92. ulong ul;
  93. if (!ReadFile(hFile, (void*) szTypeName, sizeof(szTypeName), &ul, NULL))
  94. return -1;
  95. if (ul != sizeof(szTypeName)) return -1;
  96. if (!ReadFile(hFile, (void*) szVersion, sizeof(szVersion), &ul, NULL))
  97. return -1;
  98. if (ul != sizeof(szVersion)) return -1;
  99. if (!ReadFile(hFile, (void*) &td, sizeof(td), &ul, NULL))
  100. return -1;
  101. if (ul != sizeof(td)) return -1;
  102. if (!ReadFile(hFile, (void*) &bd, sizeof(bd), &ul, NULL))
  103. return -1;
  104. if (ul != sizeof(bd)) return -1;
  105. return sizeof(szTypeName) + sizeof(szVersion) + sizeof(td) + sizeof(bd);
  106. }
  107. int SkeletonTest::CNFGFUNCTION()
  108. {
  109. PROPSHEETHEADER pshead;
  110. char acBuffer[128];
  111. int i, j;
  112. this->SaveData();
  113. sprintf(acBuffer, "Configure Test: %s", szTypeName);
  114. // Initialize property sheet HEADER data
  115. bzero(&pshead, sizeof(pshead));
  116. pshead.dwSize = sizeof(pshead);
  117. pshead.dwFlags = PSH_PROPSHEETPAGE;
  118. pshead.hwndParent = hwndParent;
  119. pshead.pszCaption = acBuffer;
  120. pshead.nPages = iNumConfigPages;
  121. pshead.nStartPage = 0;
  122. pshead.ppsp = aPSpages;
  123. pshead.pfnCallback = PropSheetProc;
  124. SetLastError(0);
  125. i = PropertySheet (&pshead);
  126. j = GetLastError();
  127. switch (i)
  128. {
  129. case -1: // error
  130. fprintf(stderr,
  131. "CreatePropertySheet() returned: %d\n"
  132. "GetLastError() returned: %d\n",
  133. i,GetLastError());
  134. break;
  135. case 0: // cancel
  136. this->RestoreSaved();
  137. break;
  138. default: // OK
  139. this->ForgetSaved();
  140. break;
  141. }
  142. return i;
  143. }
  144. void test_SetDisplayFromData(HWND hDlg, const TESTDATA *ptd)
  145. {
  146. SetDlgItemInt(hDlg,G_IDC_WIDTH, ptd->iW, TRUE);
  147. SetDlgItemInt(hDlg,G_IDC_HEIGHT, ptd->iH, TRUE);
  148. SetDlgItemInt(hDlg,G_IDC_DURATION, ptd->iDuration, TRUE);
  149. CheckDlgButton(hDlg,G_IDC_BUFFERING,ptd->swapbuffers?1:0);
  150. }
  151. void test_GetDataFromDisplay(HWND hDlg, TESTDATA *ptd)
  152. {
  153. ptd->iW = GetDlgItemInt(hDlg, G_IDC_WIDTH, NULL, TRUE);
  154. ptd->iH = GetDlgItemInt(hDlg, G_IDC_HEIGHT, NULL, TRUE);
  155. ptd->iDuration = GetDlgItemInt(hDlg, G_IDC_DURATION, NULL, TRUE);
  156. ptd->swapbuffers = IsDlgButtonChecked(hDlg,G_IDC_BUFFERING);
  157. }
  158. BOOL CALLBACK testDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
  159. {
  160. static TESTDATA *ptd = NULL;
  161. switch (msg)
  162. {
  163. case WM_INITDIALOG:
  164. ptd = (TESTDATA*)(((PROPSHEETPAGE*)lParam)->lParam);
  165. test_SetDisplayFromData(hDlg,ptd);
  166. return TRUE;
  167. case WM_COMMAND:
  168. {
  169. int i, j;
  170. i = LOWORD(wParam);
  171. j = HIWORD(wParam); // notification code for edit boxes
  172. switch (i)
  173. {
  174. case G_IDC_WIDTH: // don't mess with display
  175. case G_IDC_HEIGHT: // while editing text
  176. case G_IDC_DURATION:
  177. if (EN_UPDATE == j)
  178. PropSheet_Changed(GetParent(hDlg),hDlg);
  179. break;
  180. default:
  181. PropSheet_Changed(GetParent(hDlg),hDlg);
  182. break;
  183. }
  184. }
  185. break;
  186. case WM_NOTIFY:
  187. {
  188. LPNMHDR pnmh = (LPNMHDR) lParam;
  189. switch (pnmh->code)
  190. {
  191. case PSN_APPLY: // user clicked on OK or Apply
  192. test_GetDataFromDisplay(hDlg, ptd);
  193. break;
  194. case PSN_RESET: // user clicked on Cancel
  195. break;
  196. case PSN_HELP: // user clicked help
  197. break;
  198. }
  199. }
  200. break;
  201. default:
  202. return FALSE;
  203. }
  204. return TRUE;
  205. }
  206. BOOL CALLBACK testAboutDlgProc(HWND hDlg,UINT msg,WPARAM wParam,LPARAM lParam)
  207. {
  208. char *szAbout;
  209. switch (msg)
  210. {
  211. case WM_INITDIALOG:
  212. szAbout = (char*)(((PROPSHEETPAGE*)lParam)->lParam);
  213. SetDlgItemText(hDlg,IDC_ABOUT_TEXT,szAbout);
  214. return TRUE;
  215. default:
  216. return FALSE;
  217. }
  218. return TRUE;
  219. }
  220. int CALLBACK PropSheetProc (HWND hwndDlg, UINT uMsg, LPARAM lParam)
  221. {
  222. switch (uMsg)
  223. {
  224. case PSCB_INITIALIZED :
  225. // Process PSCB_INITIALIZED
  226. break ;
  227. case PSCB_PRECREATE :
  228. // Process PSCB_PRECREATE
  229. break ;
  230. default :
  231. // Unknown message
  232. break ;
  233. }
  234. return 0 ;
  235. }