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.

2114 lines
65 KiB

  1. //--------------------------------------------------------------------------
  2. // Clipper.cpp : test out theme drawing and fast clipping
  3. //--------------------------------------------------------------------------
  4. #include "stdafx.h"
  5. #include "resource.h"
  6. #define ASSERT(x)
  7. #include "uxthemep.h"
  8. #include "tmschema.h"
  9. #include "borderfill.h"
  10. #include "imagefile.h"
  11. #include "textdraw.h"
  12. #include "stdlib.h"
  13. #include "stdio.h"
  14. #include "autos.h"
  15. //--------------------------------------------------------------------------
  16. #define CLIPPER_FONTHEIGHT 55
  17. //--------------------------------------------------------------------------
  18. HINSTANCE hInst;
  19. HWND hwndMain;
  20. HWND hwndTab;
  21. HWND hwndDisplay;
  22. TCHAR *pszMainWindowClass = L"Clipper";
  23. TCHAR *pszDisplayWindowClass = L"ClipperDisplay";
  24. //-----------------------------------------------------------------------------------
  25. enum IMAGEFILEDRAW
  26. {
  27. IF_REG,
  28. IF_TRANS,
  29. IF_ALPHA
  30. };
  31. //-----------------------------------------------------------------------------------
  32. LPCWSTR szPageNames[] =
  33. {
  34. L"BorderFill",
  35. L"BorderFill-R",
  36. L"ImageFile",
  37. L"ImageFile-R",
  38. L"Glyph",
  39. L"Glyph-R",
  40. L"MultiImage",
  41. L"MultiImage-R",
  42. L"Text",
  43. L"Text-R",
  44. L"Borders",
  45. L"Borders-R",
  46. L"SourceSizing",
  47. L"SourceSizing-R",
  48. };
  49. //-----------------------------------------------------------------------------------
  50. enum GROUPID
  51. {
  52. GID_BORDERFILL,
  53. GID_IMAGEFILE,
  54. GID_GLYPH,
  55. GID_MULTIIMAGE,
  56. GID_TEXT,
  57. GID_BORDERS,
  58. GID_SRCSIZING,
  59. };
  60. //-----------------------------------------------------------------------------------
  61. #define MAXGROUPS ((ARRAYSIZE(szPageNames))/2)
  62. #define MAXTESTITEMS 50
  63. //-----------------------------------------------------------------------------------
  64. // Foward declarations of functions included in this code module:
  65. BOOL InitInstance(HINSTANCE, int);
  66. LRESULT CALLBACK MainWndProc(HWND, UINT, WPARAM, LPARAM);
  67. LRESULT CALLBACK DisplayWndProc(HWND, UINT, WPARAM, LPARAM);
  68. INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);
  69. void CreateDrawObjects();
  70. BOOL CreateAllWindows();
  71. void RegisterWindowClasses();
  72. //-----------------------------------------------------------------------------------
  73. HRESULT MakeErrorLast() {return E_FAIL;}
  74. //-----------------------------------------------------------------------------------
  75. BOOL CaptureBitmaps();
  76. BOOL WriteBitmapToFile(BITMAPINFOHEADER *pHdr, BYTE *pBits, LPCWSTR pszBaseName);
  77. BOOL WriteBitmapHeader(HANDLE hOutFile, BYTE *pMemoryHdr, DWORD dwTotalPixelBytes);
  78. void OnDisplayResize();
  79. void PaintObjects(HDC hdc, RECT *prc, int iGroupId);
  80. //-----------------------------------------------------------------------------------
  81. SIZE szCell = {100, 60};
  82. RECT rcDraw = {10, 10, 50, 45}; // where to draw within cell
  83. //-----------------------------------------------------------------------------------
  84. struct TESTITEM
  85. {
  86. HTHEME hTheme;
  87. DWORD dwDtbFlags;
  88. WCHAR szName[MAX_PATH];
  89. };
  90. //-----------------------------------------------------------------------------------
  91. //---- scrolling support ----
  92. int iVertOffset = 0;
  93. int iMaxVertOffset = 0; // set by WM_SIZE
  94. int iVertLineSize = 10; // # of pixels
  95. int iVertPageSize = 0; // set by WM_SIZE
  96. //-----------------------------------------------------------------------------------
  97. int iItemCount[MAXGROUPS] = {0};
  98. TESTITEM TestItems[MAXGROUPS][MAXTESTITEMS];
  99. BOOL fCapturing = FALSE;
  100. //-----------------------------------------------------------------------------------
  101. int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE, LPWSTR lpCmdLine, int nCmdShow)
  102. {
  103. MSG msg;
  104. HACCEL hAccelTable;
  105. hInst = hInstance;
  106. RegisterWindowClasses();
  107. InitCommonControlsEx(NULL);
  108. if (!InitInstance (hInstance, nCmdShow))
  109. {
  110. return FALSE;
  111. }
  112. //---- parse cmdline params ----
  113. USES_CONVERSION;
  114. LPCSTR p = W2A(lpCmdLine);
  115. while (*p)
  116. {
  117. while (isspace(*p))
  118. p++;
  119. //---- parse switches ----
  120. if ((*p == '/') || (*p == '-'))
  121. {
  122. p++;
  123. if ((*p == 'c') || (*p == 'C'))
  124. {
  125. p++;
  126. fCapturing = TRUE;
  127. }
  128. }
  129. }
  130. hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_CLIPPER);
  131. if (fCapturing)
  132. {
  133. CaptureBitmaps();
  134. return 0;
  135. }
  136. // Main message loop:
  137. while (GetMessage(&msg, NULL, 0, 0))
  138. {
  139. if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
  140. {
  141. TranslateMessage(&msg);
  142. DispatchMessage(&msg);
  143. }
  144. }
  145. return static_cast<int>(msg.wParam);
  146. }
  147. //--------------------------------------------------------------------------
  148. BOOL CaptureBitmaps()
  149. {
  150. //---- paint each tab page to a memory dc & convert to a bitmap file ----
  151. HDC hdcClient = GetDC(NULL);
  152. RECT rt = {0, 0, 800, 600}; // currently captures all good info
  153. BITMAPINFOHEADER BitMapHdr = {sizeof(BITMAPINFOHEADER), WIDTH(rt), HEIGHT(rt), 1, 24, BI_RGB};
  154. //---- create a DIB to paint into ----
  155. BYTE *pBits;
  156. HBITMAP hBitmap = CreateDIBSection(hdcClient, (BITMAPINFO *)&BitMapHdr, DIB_RGB_COLORS,
  157. (void **)&pBits, NULL, 0);
  158. HDC hdcMemory = CreateCompatibleDC(hdcClient);
  159. HBITMAP hOldBitmap = (HBITMAP)SelectObject(hdcMemory, hBitmap);
  160. //---- for each tab that we can draw ----
  161. for (int iTabNum=0; iTabNum < ARRAYSIZE(szPageNames); iTabNum++)
  162. {
  163. iVertOffset = 0;
  164. iVertPageSize = RECTHEIGHT(&rt);
  165. int iGroupId = iTabNum/2;
  166. //---- keep tester interested by sync. visuals ----
  167. TabCtrl_SetCurSel(hwndTab, iTabNum);
  168. OnDisplayResize();
  169. iVertPageSize = RECTHEIGHT(&rt);
  170. InvalidateRect(hwndDisplay, NULL, TRUE);
  171. if (iTabNum % 2) // if its a mirrored page
  172. SetLayout(hdcMemory, LAYOUT_RTL);
  173. else
  174. SetLayout(hdcMemory, 0);
  175. //---- clear the background first ----
  176. HBRUSH hbr = CreateSolidBrush(RGB(255, 255, 255));
  177. FillRect(hdcMemory, &rt, hbr);
  178. //---- draw the objects/labels for this tab ----
  179. PaintObjects(hdcMemory, &rt, iGroupId);
  180. //---- now copy DIB bits to a bitmap file ----
  181. WriteBitmapToFile(&BitMapHdr, pBits, szPageNames[iTabNum]);
  182. }
  183. //---- clean up ----
  184. SelectObject(hdcMemory, hOldBitmap);
  185. DeleteDC(hdcMemory);
  186. DeleteObject(hBitmap);
  187. ReleaseDC(NULL, hdcClient);
  188. return TRUE;
  189. }
  190. //--------------------------------------------------------------------------
  191. BOOL WriteBitmapToFile(BITMAPINFOHEADER *pHdr, BYTE *pBits, LPCWSTR pszBaseName)
  192. {
  193. BOOL fWroteFile = FALSE;
  194. //---- get size of bitmap ----
  195. int iDibWidth = pHdr->biWidth;
  196. int iDibHeight = pHdr->biHeight;
  197. int iRawBytes = iDibWidth * 3;
  198. int iBytesPerRow = 4*((iRawBytes+3)/4);
  199. int iPixelBytesTotal = iBytesPerRow * iDibHeight;
  200. //---- create the bitmap file ----
  201. WCHAR szName[MAX_PATH];
  202. StringCchPrintfW(szName, ARRAYSIZE(szName), L"%s.bmp", pszBaseName);
  203. HANDLE hFileOutput = CreateFile(szName, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
  204. if (hFileOutput == INVALID_HANDLE_VALUE)
  205. {
  206. printf("\nError - could not open bitmap file for output: %s\n", szName);
  207. goto exit;
  208. }
  209. //---- write the bitmap FILE header ----
  210. if (! WriteBitmapHeader(hFileOutput, (BYTE *)pHdr, iPixelBytesTotal))
  211. goto exit;
  212. //---- write the bitmap MEMORY header ----
  213. DWORD dw;
  214. if (! WriteFile(hFileOutput, pHdr, sizeof(*pHdr), &dw, NULL))
  215. goto exit;
  216. //---- write the bitmap bits ----
  217. if (! WriteFile(hFileOutput, pBits, iPixelBytesTotal, &dw, NULL))
  218. goto exit;
  219. fWroteFile = TRUE;
  220. exit:
  221. if (hFileOutput != INVALID_HANDLE_VALUE)
  222. {
  223. //---- close the file ----
  224. CloseHandle(hFileOutput);
  225. }
  226. return fWroteFile;
  227. }
  228. //---------------------------------------------------------------------------
  229. BOOL WriteBitmapHeader(HANDLE hOutFile, BYTE *pMemoryHdr, DWORD dwTotalPixelBytes)
  230. {
  231. BOOL fOK = FALSE;
  232. BYTE pbHdr1[] = {0x42, 0x4d};
  233. BYTE pbHdr2[] = {0x0, 0x0, 0x0, 0x0};
  234. int iFileLen;
  235. DWORD dw;
  236. //---- add bitmap hdr at front ----
  237. HRESULT hr = WriteFile(hOutFile, pbHdr1, sizeof(pbHdr1), &dw, NULL);
  238. if (FAILED(hr))
  239. goto exit;
  240. //---- add length of data ----
  241. iFileLen = dwTotalPixelBytes + sizeof(BITMAPFILEHEADER);
  242. hr = WriteFile(hOutFile, &iFileLen, sizeof(int), &dw, NULL);
  243. if (FAILED(hr))
  244. goto exit;
  245. hr = WriteFile(hOutFile, pbHdr2, sizeof(pbHdr2), &dw, NULL);
  246. if (FAILED(hr))
  247. goto exit;
  248. //---- offset to bits (who's idea was *this* field?) ----
  249. int iOffset, iColorTableSize;
  250. DWORD dwSize;
  251. iOffset = sizeof(BITMAPFILEHEADER);
  252. dwSize = *(DWORD *)pMemoryHdr;
  253. iOffset += dwSize;
  254. iColorTableSize = 0;
  255. switch (dwSize)
  256. {
  257. case sizeof(BITMAPCOREHEADER):
  258. BITMAPCOREHEADER *hdr1;
  259. hdr1 = (BITMAPCOREHEADER *)pMemoryHdr;
  260. if (hdr1->bcBitCount == 1)
  261. iColorTableSize = 2*sizeof(RGBTRIPLE);
  262. else if (hdr1->bcBitCount == 4)
  263. iColorTableSize = 16*sizeof(RGBTRIPLE);
  264. else if (hdr1->bcBitCount == 8)
  265. iColorTableSize = 256*sizeof(RGBTRIPLE);
  266. break;
  267. case sizeof(BITMAPINFOHEADER):
  268. case sizeof(BITMAPV4HEADER):
  269. case sizeof(BITMAPV5HEADER):
  270. BITMAPINFOHEADER *hdr2;
  271. hdr2 = (BITMAPINFOHEADER *)pMemoryHdr;
  272. if (hdr2->biClrUsed)
  273. iColorTableSize = hdr2->biClrUsed*sizeof(RGBQUAD);
  274. else
  275. {
  276. if (hdr2->biBitCount == 1)
  277. iColorTableSize = 2*sizeof(RGBQUAD);
  278. else if (hdr2->biBitCount == 4)
  279. iColorTableSize = 16*sizeof(RGBQUAD);
  280. else if (hdr2->biBitCount == 8)
  281. iColorTableSize = 256*sizeof(RGBQUAD);
  282. }
  283. break;
  284. }
  285. iOffset += iColorTableSize;
  286. hr = WriteFile(hOutFile, &iOffset, sizeof(int), &dw, NULL);
  287. if (FAILED(hr))
  288. goto exit;
  289. fOK = TRUE;
  290. exit:
  291. return fOK;
  292. }
  293. //--------------------------------------------------------------------------
  294. void DrawTargetRect(HDC hdc, RECT *prc, COLORREF cr)
  295. {
  296. //---- draw purple target dashed rect ----
  297. //---- prepare drawing objects ----
  298. HPEN hPen = CreatePen(PS_DOT, 1, cr);
  299. HPEN hOldPen = (HPEN)SelectObject(hdc, hPen);
  300. HBRUSH hOldBrush = (HBRUSH)SelectObject(hdc, GetStockObject(NULL_BRUSH));
  301. //---- draw that thing ----
  302. Rectangle(hdc, prc->left-1, prc->top-1, prc->right+1, prc->bottom+1);
  303. //---- restore DC ----
  304. SelectObject(hdc, hOldPen);
  305. SelectObject(hdc, hOldBrush);
  306. DeleteObject(hPen);
  307. }
  308. //--------------------------------------------------------------------------
  309. void DrawClip(HTHEME hTheme, HDC hdc, RECT *prc, int iRowIndex, int iColIndex,
  310. DWORD dwDtbFlags)
  311. {
  312. RECT rect, rcClip;
  313. int left = prc->left + (iColIndex+1)*szCell.cx;
  314. int top = prc->top + (iRowIndex+1)*szCell.cy;
  315. HRESULT hr = S_OK;
  316. SetRect(&rect, left + rcDraw.left, top + rcDraw.top,
  317. left + rcDraw.right, top + rcDraw.bottom);
  318. //---- draw purple target dashed rect ----
  319. DrawTargetRect(hdc, &rect, RGB(128, 128, 255));
  320. switch (iColIndex) // clipping type
  321. {
  322. case 0: // no clipping
  323. break;
  324. case 1: // over clipping
  325. rcClip = rect;
  326. rcClip.left -= 4;
  327. rcClip.right += 4;
  328. rcClip.top -= 4;
  329. rcClip.bottom += 4;
  330. break;
  331. case 2: // exact clipping
  332. rcClip = rect;
  333. break;
  334. case 3: // partial overlap
  335. rcClip = rect;
  336. rcClip.left += 8;
  337. rcClip.right -= 8;
  338. rcClip.top += 8;
  339. rcClip.bottom -= 8;
  340. break;
  341. case 4: // InOut1
  342. rcClip = rect;
  343. rcClip.left -= 3;
  344. rcClip.right = rcClip.left + 20;
  345. rcClip.top -= 3;
  346. rcClip.bottom = rcClip.top + 20;
  347. break;
  348. case 5: // InOut2
  349. rcClip = rect;
  350. rcClip.left += 20;
  351. rcClip.right += 5;
  352. rcClip.top += 15;;
  353. rcClip.bottom += 5;
  354. break;
  355. case 6: // out clip
  356. rcClip.left = rect.right + 6;
  357. rcClip.right = rcClip.left + 9;
  358. rcClip.top = rect.top - 2;
  359. rcClip.bottom = rect.bottom + 2;
  360. break;
  361. }
  362. //---- draw red clipping rect ----
  363. if (iColIndex)
  364. {
  365. HPEN hPen = CreatePen(PS_DOT, 1, RGB(255, 0, 0));
  366. HPEN hOldPen = (HPEN)SelectObject(hdc, hPen);
  367. HBRUSH hOldBrush = (HBRUSH)SelectObject(hdc, GetStockObject(NULL_BRUSH));
  368. Rectangle(hdc, rcClip.left-1, rcClip.top-1, rcClip.right+1, rcClip.bottom+1);
  369. SelectObject(hdc, hOldPen);
  370. SelectObject(hdc, hOldBrush);
  371. DeleteObject(hPen);
  372. }
  373. DTBGOPTS DtbOpts = {sizeof(DtbOpts)};
  374. DtbOpts.dwFlags = dwDtbFlags;
  375. if (iColIndex) // pass clipping rect
  376. {
  377. DtbOpts.dwFlags |= DTBG_CLIPRECT;
  378. DtbOpts.rcClip = rcClip;
  379. }
  380. hr = DrawThemeBackgroundEx(hTheme, hdc, 1, 2, &rect, &DtbOpts);
  381. if (FAILED(hr))
  382. {
  383. WCHAR buff[100];
  384. StringCchPrintfW(buff, ARRAYSIZE(buff), L"DrawThemeBackgroundEx err: hr=0x%x, irow=%d, icol=%d",
  385. hr, iRowIndex, iColIndex);
  386. //MessageBox(NULL, buff, L"Error", MB_OK);
  387. }
  388. }
  389. //--------------------------------------------------------------------------
  390. void DrawTextObjects(HTHEME hTheme, HDC hdc, RECT *prc, int iRowIndex, LPCWSTR pszName)
  391. {
  392. int left = prc->left + 4; // some padding away from edge
  393. int top = prc->top + iRowIndex*szCell.cy + 18; // try to center
  394. //---- draw label in left cell ----
  395. TextOut(hdc, left, top, pszName, wcslen(pszName));
  396. left += szCell.cx;
  397. RECT rc = {left, top, left+szCell.cx*5, top+szCell.cy};
  398. //---- draw actual test text ----
  399. HRESULT hr = DrawThemeText(hTheme, hdc, 1, 2, L"Testing Text Drawing", -1, 0, 0, &rc);
  400. if (FAILED(hr))
  401. {
  402. WCHAR buff[100];
  403. StringCchPrintfW(buff, ARRAYSIZE(buff), L"DrawThemeText err: hr=0x%x, irow=%d",
  404. hr, iRowIndex);
  405. MessageBox(NULL, buff, L"Error", MB_OK);
  406. }
  407. }
  408. //--------------------------------------------------------------------------
  409. void DrawClips(HTHEME hTheme, HDC hdc, RECT *prc, int iRowIndex, LPCWSTR pszName,
  410. DWORD dwDtbFlags)
  411. {
  412. //---- label object on left ----
  413. int left = prc->left + 4; // some padding away from edge
  414. int top = prc->top + (iRowIndex+1)*szCell.cy + 18; // try to center
  415. //---- manual page clipping ----
  416. if ((top + szCell.cy) < 0)
  417. return;
  418. if (top > iVertPageSize)
  419. return;
  420. TextOut(hdc, left, top, pszName, wcslen(pszName));
  421. //---- draw clipping variations ----
  422. for (int i=0; i <= 6; i++)
  423. {
  424. DrawClip(hTheme, hdc, prc, iRowIndex, i, dwDtbFlags);
  425. }
  426. }
  427. //--------------------------------------------------------------------------
  428. void AddItem(CDrawBase *pObject, CTextDraw *pTextObj, LPCWSTR pszName, int iGroupId,
  429. DWORD dwOtdFlags=0, DWORD dwDtbFlags=0)
  430. {
  431. HTHEME hTheme = NULL;
  432. if (iItemCount[iGroupId] >= MAXTESTITEMS)
  433. return;
  434. if (pObject)
  435. {
  436. if (pObject->_eBgType == BT_BORDERFILL)
  437. {
  438. CBorderFill *pTo = new CBorderFill;
  439. if (pTo)
  440. {
  441. CopyMemory(pTo, pObject, sizeof(CBorderFill));
  442. hTheme = CreateThemeDataFromObjects(pTo, NULL, dwOtdFlags);
  443. }
  444. }
  445. else // imagefile
  446. {
  447. CMaxImageFile *pFrom = (CMaxImageFile *)pObject;
  448. CMaxImageFile *pTo = new CMaxImageFile;
  449. if (pTo)
  450. {
  451. //---- transfer CImageFile object & variable number of DIBINFO's ----
  452. DWORD dwLen = sizeof(CImageFile) + sizeof(DIBINFO)*pFrom->_iMultiImageCount;
  453. CopyMemory(pTo, pFrom, dwLen);
  454. hTheme = CreateThemeDataFromObjects(pTo, NULL, dwOtdFlags);
  455. }
  456. }
  457. }
  458. else // text object
  459. {
  460. CTextDraw *pTo = new CTextDraw;
  461. if (pTo)
  462. {
  463. CopyMemory(pTo, pTextObj, sizeof(CTextDraw));
  464. hTheme = CreateThemeDataFromObjects(NULL, pTo, dwOtdFlags);
  465. }
  466. }
  467. if (hTheme)
  468. {
  469. int iIndex = iItemCount[iGroupId];
  470. TestItems[iGroupId][iIndex].hTheme = hTheme;
  471. TestItems[iGroupId][iIndex].dwDtbFlags = dwDtbFlags;
  472. StringCchCopyW(TestItems[iGroupId][iIndex].szName, ARRAYSIZE(TestItems[iGroupId][iIndex].szName), pszName);
  473. iItemCount[iGroupId]++;
  474. }
  475. else
  476. {
  477. MessageBox(NULL, L"Error creating hTheme from obj", L"Error", MB_OK);
  478. }
  479. }
  480. //--------------------------------------------------------------------------
  481. void CreateBorderFillNoDraw()
  482. {
  483. CBorderFill bfill;
  484. memset(&bfill, 0, sizeof(bfill));
  485. //---- make a BorderFill obj with a border ----
  486. bfill._eBgType = BT_BORDERFILL;
  487. bfill._fNoDraw = TRUE;
  488. AddItem(&bfill, NULL, L"NoDraw", GID_BORDERFILL);
  489. }
  490. //--------------------------------------------------------------------------
  491. void CreateBorderFillSquare()
  492. {
  493. CBorderFill bfill;
  494. memset(&bfill, 0, sizeof(bfill));
  495. //---- make a BorderFill obj with a border ----
  496. bfill._eBgType = BT_BORDERFILL;
  497. bfill._eBorderType = BT_RECT;
  498. bfill._iBorderSize = 0;
  499. bfill._eFillType = FT_SOLID;
  500. bfill._crFill = RGB(128, 255, 255);
  501. AddItem(&bfill, NULL, L"Square", GID_BORDERFILL);
  502. }
  503. //--------------------------------------------------------------------------
  504. void CreateBorderFillBorder()
  505. {
  506. CBorderFill bfill;
  507. memset(&bfill, 0, sizeof(bfill));
  508. //---- make a BorderFill obj with a border ----
  509. bfill._eBgType = BT_BORDERFILL;
  510. bfill._eBorderType = BT_RECT;
  511. bfill._crBorder = RGB(255, 128, 128);
  512. bfill._iBorderSize = 3;
  513. bfill._eFillType = FT_SOLID;
  514. bfill._crFill = RGB(128, 255, 255);
  515. AddItem(&bfill, NULL, L"Border", GID_BORDERFILL);
  516. }
  517. //--------------------------------------------------------------------------
  518. void CreateBorderFillCircle()
  519. {
  520. CBorderFill bfill;
  521. memset(&bfill, 0, sizeof(bfill));
  522. //---- make a BorderFill obj with a border ----
  523. bfill._eBgType = BT_BORDERFILL;
  524. bfill._eBorderType = BT_ROUNDRECT;
  525. bfill._crBorder = RGB(255, 128, 128);
  526. bfill._iBorderSize = 3;
  527. bfill._iRoundCornerWidth = 80;
  528. bfill._iRoundCornerHeight = 80;
  529. bfill._eFillType = FT_SOLID;
  530. bfill._crFill = RGB(128, 255, 255);
  531. AddItem(&bfill, NULL, L"Circle", GID_BORDERFILL);
  532. }
  533. //--------------------------------------------------------------------------
  534. void CreateBorderFillGradient()
  535. {
  536. CBorderFill bfill;
  537. memset(&bfill, 0, sizeof(bfill));
  538. //---- make a BorderFill obj with a border ----
  539. bfill._eBgType = BT_BORDERFILL;
  540. bfill._eBorderType = BT_RECT;
  541. bfill._crBorder = RGB(255, 128, 128);
  542. bfill._iBorderSize = 3;
  543. bfill._eFillType = FT_HORZGRADIENT;
  544. //---- gradients ----
  545. bfill._iGradientPartCount = 2;
  546. bfill._crGradientColors[0] = RGB(0, 0, 0);
  547. bfill._crGradientColors[1] = RGB(255, 255, 255);
  548. bfill._iGradientRatios[0] = 0;
  549. bfill._iGradientRatios[1] = 255;
  550. AddItem(&bfill, NULL, L"Gradient", GID_BORDERFILL);
  551. }
  552. //--------------------------------------------------------------------------
  553. void CreateBorderFillCircleGradient()
  554. {
  555. CBorderFill bfill;
  556. memset(&bfill, 0, sizeof(bfill));
  557. //---- make a BorderFill obj with a border ----
  558. bfill._eBgType = BT_BORDERFILL;
  559. bfill._eBorderType = BT_ROUNDRECT;
  560. bfill._crBorder = RGB(255, 128, 128);
  561. bfill._iBorderSize = 3;
  562. bfill._iRoundCornerWidth = 80;
  563. bfill._iRoundCornerHeight = 80;
  564. bfill._eFillType = FT_HORZGRADIENT;
  565. //---- gradients ----
  566. bfill._iGradientPartCount = 2;
  567. bfill._crGradientColors[0] = RGB(0, 0, 0);
  568. bfill._crGradientColors[1] = RGB(255, 255, 255);
  569. bfill._iGradientRatios[0] = 0;
  570. bfill._iGradientRatios[1] = 255;
  571. AddItem(&bfill, NULL, L"CircleGradient", GID_BORDERFILL);
  572. }
  573. //--------------------------------------------------------------------------
  574. void CreateImageFileBorder(SIZINGTYPE eSizeType, BOOL fSizeBorders, BOOL fForceSizeRect)
  575. {
  576. CImageFile cif;
  577. memset(&cif, 0, sizeof(cif));
  578. cif._ImageInfo.hProcessBitmap = (HBITMAP)LoadImage(hInst, static_cast<LPCWSTR>(IntToPtr(IDB_BORDERTEST)),
  579. IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION);
  580. //---- create a ImageFile object that sizes with STRETCH ----
  581. cif._eBgType = BT_IMAGEFILE;
  582. if (fSizeBorders)
  583. {
  584. cif._fSourceGrow = TRUE;
  585. cif._fIntegralSizing = TRUE;
  586. }
  587. cif._fMirrorImage = TRUE;
  588. cif._iImageCount = 1;
  589. cif._eImageLayout = IL_VERTICAL;
  590. cif._ImageInfo.iSingleWidth = 18;
  591. cif._ImageInfo.iSingleHeight = 17;
  592. cif._ImageInfo.eSizingType = eSizeType;
  593. cif._ImageInfo.iMinDpi = 96;
  594. cif._szNormalSize.cx = 50;
  595. cif._szNormalSize.cy = 50;
  596. SetRect((RECT *)&cif._SizingMargins, 3, 3, 3, 3);
  597. DWORD dwOtdFlags = 0;
  598. if (fForceSizeRect)
  599. {
  600. dwOtdFlags |= OTD_FORCE_RECT_SIZING;
  601. }
  602. AddItem(&cif, NULL, L"BorderTest", GID_BORDERS, dwOtdFlags);
  603. }
  604. //--------------------------------------------------------------------------
  605. void CreateImage(int iBgImageId, int iStateCount, SIZINGTYPE eSizeType, BOOL fSrcSizing, int iGroupId,
  606. LPCWSTR pszName, int lw, int rw, int th, int bh)
  607. {
  608. CMaxImageFile mif;
  609. memset(&mif, 0, sizeof(mif));
  610. if (iBgImageId)
  611. {
  612. mif._ImageInfo.hProcessBitmap = (HBITMAP)LoadImage(hInst, static_cast<LPCWSTR>(IntToPtr(iBgImageId)),
  613. IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION);
  614. }
  615. //---- create a ImageFile object ----
  616. mif._eBgType = BT_IMAGEFILE;
  617. mif._fMirrorImage = TRUE;
  618. mif._iImageCount = iStateCount;
  619. mif._eImageLayout = IL_VERTICAL;
  620. mif._ImageInfo.eSizingType = eSizeType;
  621. mif._ImageInfo.iMinDpi = 96;
  622. mif._szNormalSize.cx = 60;
  623. mif._szNormalSize.cy = 40;
  624. mif._eGlyphType = GT_IMAGEGLYPH;
  625. //---- set Width/Height ----
  626. BITMAP bm;
  627. GetObject(mif._ImageInfo.hProcessBitmap, sizeof bm, &bm);
  628. mif._ImageInfo.iSingleWidth = bm.bmWidth;
  629. mif._ImageInfo.iSingleHeight = bm.bmHeight/iStateCount;
  630. mif._ImageInfo.szMinSize.cx = bm.bmWidth;
  631. mif._ImageInfo.szMinSize.cy = bm.bmHeight/iStateCount;
  632. SetRect((RECT *)&mif._SizingMargins, lw, rw, th, bh);
  633. SetRect((RECT *)&mif._ContentMargins, lw, rw, th, bh);
  634. DWORD dwOtdFlags = 0;
  635. if (fSrcSizing)
  636. {
  637. dwOtdFlags |= OTD_FORCE_RECT_SIZING;
  638. }
  639. AddItem(&mif, NULL, pszName, iGroupId, dwOtdFlags);
  640. }
  641. //--------------------------------------------------------------------------
  642. void CreateProgressTrack()
  643. {
  644. CMaxImageFile mif;
  645. memset(&mif, 0, sizeof(mif));
  646. mif._ImageInfo.hProcessBitmap = (HBITMAP)LoadImage(hInst, static_cast<LPCWSTR>(IntToPtr(IDB_PROGRESS_TRACK)),
  647. IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION);
  648. //---- create a ImageFile object ----
  649. mif._eBgType = BT_IMAGEFILE;
  650. mif._fMirrorImage = TRUE;
  651. mif._iImageCount = 1;
  652. mif._eImageLayout = IL_VERTICAL;
  653. mif._ImageInfo.eSizingType = ST_TILE;
  654. mif._ImageInfo.iMinDpi = 96;
  655. mif._szNormalSize.cx = 60;
  656. mif._szNormalSize.cy = 40;
  657. //---- set Width/Height ----
  658. BITMAP bm;
  659. GetObject(mif._ImageInfo.hProcessBitmap, sizeof bm, &bm);
  660. mif._ImageInfo.iSingleWidth = bm.bmWidth;
  661. mif._ImageInfo.iSingleHeight = bm.bmHeight/1;
  662. mif._ImageInfo.szMinSize.cx = 10;
  663. mif._ImageInfo.szMinSize.cy = 10;
  664. mif._szNormalSize.cx = 100;
  665. mif._szNormalSize.cy = 18;
  666. mif._fSourceShrink = TRUE;
  667. SetRect((RECT *)&mif._SizingMargins, 4, 4, 3, 3);
  668. SetRect((RECT *)&mif._ContentMargins, 4, 4, 3, 3);
  669. AddItem(&mif, NULL, L"Progress", GID_SRCSIZING, 0);
  670. }
  671. //--------------------------------------------------------------------------
  672. void CreateProgressChunk()
  673. {
  674. CMaxImageFile mif;
  675. memset(&mif, 0, sizeof(mif));
  676. //---- create a ImageFile object ----
  677. mif._eBgType = BT_IMAGEFILE;
  678. mif._ImageInfo.hProcessBitmap = (HBITMAP)LoadImage(hInst, static_cast<LPCWSTR>(IntToPtr(IDB_PROGRESS_CHUNK)),
  679. IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION);
  680. mif._fMirrorImage = TRUE;
  681. mif._iImageCount = 1;
  682. mif._eImageLayout = IL_VERTICAL;
  683. mif._ImageInfo.eSizingType = ST_TILE;
  684. mif._ImageInfo.iMinDpi = 96;
  685. mif._szNormalSize.cx = 60;
  686. mif._szNormalSize.cy = 40;
  687. mif._eGlyphType = GT_IMAGEGLYPH;
  688. //---- set Width/Height ----
  689. BITMAP bm;
  690. GetObject(mif._ImageInfo.hProcessBitmap, sizeof bm, &bm);
  691. mif._ImageInfo.iSingleWidth = bm.bmWidth;
  692. mif._ImageInfo.iSingleHeight = bm.bmHeight/1;
  693. mif._ImageInfo.szMinSize.cx = 10;
  694. mif._ImageInfo.szMinSize.cy = 10;
  695. mif._szNormalSize.cx = 100;
  696. mif._szNormalSize.cy = 18;
  697. SetRect((RECT *)&mif._SizingMargins, 0, 0, 6, 5);
  698. SetRect((RECT *)&mif._ContentMargins, 0, 0, 6, 5);
  699. AddItem(&mif, NULL, L"Progress", GID_SRCSIZING, 0);
  700. }
  701. //--------------------------------------------------------------------------
  702. void CreateRadioImage()
  703. {
  704. CMaxImageFile mif;
  705. memset(&mif, 0, sizeof(mif));
  706. //---- create a ImageFile object ----
  707. mif._eBgType = BT_IMAGEFILE;
  708. mif._fMirrorImage = TRUE;
  709. mif._iImageCount = 8;
  710. mif._eImageLayout = IL_VERTICAL;
  711. mif._szNormalSize.cx = 60;
  712. mif._szNormalSize.cy = 40;
  713. mif._eImageSelectType = IST_DPI;
  714. mif._iMultiImageCount = 3;
  715. mif._eTrueSizeScalingType = TSST_DPI;
  716. mif._fUniformSizing = TRUE;
  717. mif._eHAlign = HA_CENTER;
  718. mif._eVAlign = VA_CENTER;
  719. int iMinDpis[] = {96, 118, 185};
  720. //---- process multiple images ----
  721. for (int i=0; i < 3; i++)
  722. {
  723. DIBINFO *pdi = &mif.MultiDibs[i];
  724. int idnum = IDB_RADIO13 + i;
  725. pdi->hProcessBitmap = (HBITMAP)LoadImage(hInst, static_cast<LPCWSTR>(IntToPtr(idnum)),
  726. IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION);
  727. pdi->iMinDpi = iMinDpis[i];
  728. //---- get bitmap width/height ----
  729. BITMAP bm;
  730. GetObject(pdi->hProcessBitmap, sizeof bm, &bm);
  731. pdi->iSingleWidth = bm.bmWidth;
  732. pdi->iSingleHeight = bm.bmHeight/8;
  733. pdi->szMinSize.cx = pdi->iSingleWidth;
  734. pdi->szMinSize.cy = pdi->iSingleHeight;
  735. pdi->eSizingType = ST_TRUESIZE;
  736. pdi->crTransparent = RGB(255, 0, 255);
  737. pdi->fTransparent = TRUE;
  738. }
  739. //---- set primary image ----
  740. mif._ImageInfo = mif.MultiDibs[0];
  741. AddItem(&mif, NULL, L"RadioButton", GID_SRCSIZING, OTD_FORCE_RECT_SIZING);
  742. }
  743. //--------------------------------------------------------------------------
  744. void CreateCheckImage()
  745. {
  746. CMaxImageFile mif;
  747. memset(&mif, 0, sizeof(mif));
  748. //---- create a ImageFile object ----
  749. mif._eBgType = BT_IMAGEFILE;
  750. mif._fMirrorImage = TRUE;
  751. mif._iImageCount = 12;
  752. mif._eImageLayout = IL_VERTICAL;
  753. mif._szNormalSize.cx = 60;
  754. mif._szNormalSize.cy = 40;
  755. mif._eImageSelectType = IST_DPI;
  756. mif._iMultiImageCount = 3;
  757. mif._eTrueSizeScalingType = TSST_DPI;
  758. mif._fUniformSizing = TRUE;
  759. mif._eHAlign = HA_CENTER;
  760. mif._eVAlign = VA_CENTER;
  761. int iMinDpis[] = {96, 118, 185};
  762. //---- process multiple images ----
  763. for (int i=0; i < 3; i++)
  764. {
  765. DIBINFO *pdi = &mif.MultiDibs[i];
  766. int idnum = IDB_CHECK13 + i;
  767. pdi->hProcessBitmap = (HBITMAP)LoadImage(hInst, static_cast<LPCWSTR>(IntToPtr(idnum)),
  768. IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION);
  769. pdi->iMinDpi = iMinDpis[i];
  770. //---- get bitmap width/height ----
  771. BITMAP bm;
  772. GetObject(pdi->hProcessBitmap, sizeof bm, &bm);
  773. pdi->iSingleWidth = bm.bmWidth;
  774. pdi->iSingleHeight = bm.bmHeight/12;
  775. pdi->szMinSize.cx = pdi->iSingleWidth;
  776. pdi->szMinSize.cy = pdi->iSingleHeight;
  777. pdi->eSizingType = ST_TRUESIZE;
  778. pdi->fAlphaChannel = TRUE;
  779. }
  780. //---- set primary image ----
  781. mif._ImageInfo = mif.MultiDibs[0];
  782. AddItem(&mif, NULL, L"CheckBox", GID_SRCSIZING, OTD_FORCE_RECT_SIZING);
  783. }
  784. //--------------------------------------------------------------------------
  785. void CreateScrollGlyph()
  786. {
  787. CMaxImageFile mif;
  788. memset(&mif, 0, sizeof(mif));
  789. //---- create a ImageFile object ----
  790. mif._eBgType = BT_IMAGEFILE;
  791. mif._eGlyphType = GT_IMAGEGLYPH;
  792. mif._fMirrorImage = TRUE;
  793. mif._iImageCount = 16;
  794. mif._eImageLayout = IL_VERTICAL;
  795. mif._szNormalSize.cx = 30;
  796. mif._szNormalSize.cy = 10;
  797. mif._eImageSelectType = IST_NONE;
  798. mif._fUniformSizing = TRUE;
  799. mif._eHAlign = HA_CENTER;
  800. mif._eVAlign = VA_CENTER;
  801. SetRect((RECT *)&mif._SizingMargins, 5, 5, 5, 5);
  802. SetRect((RECT *)&mif._ContentMargins, 0, 0, 3, 3);
  803. //---- background image ----
  804. DIBINFO *pdi = &mif._ImageInfo;
  805. pdi->hProcessBitmap = (HBITMAP)LoadImage(hInst, static_cast<LPCWSTR>(IntToPtr(IDB_SCROLL_ARROWS)),
  806. IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION);
  807. //---- get bitmap width/height ----
  808. BITMAP bm;
  809. GetObject(pdi->hProcessBitmap, sizeof bm, &bm);
  810. pdi->iSingleWidth = bm.bmWidth;
  811. pdi->iSingleHeight = bm.bmHeight/16;
  812. pdi->szMinSize.cx = pdi->iSingleWidth;
  813. pdi->szMinSize.cy = pdi->iSingleHeight;
  814. pdi->iMinDpi = 96;
  815. pdi->eSizingType = ST_STRETCH;
  816. //---- glyph image ----
  817. pdi = &mif._GlyphInfo;
  818. mif._GlyphInfo.hProcessBitmap = (HBITMAP)LoadImage(hInst, static_cast<LPCWSTR>(IntToPtr(IDB_SCROLL_GLPYHS)),
  819. IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION);
  820. pdi->fTransparent = TRUE;
  821. pdi->crTransparent = RGB(255, 0, 255);
  822. GetObject(pdi->hProcessBitmap, sizeof bm, &bm);
  823. pdi->iSingleWidth = bm.bmWidth;
  824. pdi->iSingleHeight = bm.bmHeight/16;
  825. pdi->szMinSize.cx = pdi->iSingleWidth;
  826. pdi->szMinSize.cy = pdi->iSingleHeight;
  827. pdi->iMinDpi = 96;
  828. pdi->eSizingType = ST_TRUESIZE;
  829. mif._fSourceShrink = TRUE;
  830. mif._fSourceGrow = TRUE;
  831. mif._eTrueSizeScalingType = TSST_SIZE;
  832. mif._iTrueSizeStretchMark = 100;
  833. //---- add it (without OTD_FORCE_RECT_SIZING) ----
  834. AddItem(&mif, NULL, L"ScrollBox", GID_SRCSIZING, 0);
  835. }
  836. //--------------------------------------------------------------------------
  837. void CreateImageFileStretch(IMAGEFILEDRAW eDraw, int iGroupId)
  838. {
  839. CImageFile cif;
  840. memset(&cif, 0, sizeof(cif));
  841. int idnum = IDB_STRETCH;
  842. if (eDraw == IF_TRANS)
  843. idnum = IDB_STRETCH_TRANS;
  844. cif._ImageInfo.hProcessBitmap = (HBITMAP)LoadImage(hInst, static_cast<LPCWSTR>(IntToPtr(idnum)),
  845. IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION);
  846. //---- create a ImageFile object that sizes with STRETCH ----
  847. cif._eBgType = BT_IMAGEFILE;
  848. cif._fMirrorImage = TRUE;
  849. cif._iImageCount = 5;
  850. cif._eImageLayout = IL_VERTICAL;
  851. cif._ImageInfo.iSingleWidth = 20;
  852. cif._ImageInfo.iSingleHeight = 19;
  853. cif._ImageInfo.eSizingType = ST_STRETCH;
  854. if (eDraw == IF_TRANS)
  855. {
  856. cif._ImageInfo.fTransparent = TRUE;
  857. cif._ImageInfo.crTransparent = RGB(255, 0, 255);
  858. }
  859. SetRect((RECT *)&cif._SizingMargins, 4, 4, 4, 4);
  860. LPCWSTR p = L"Stretch";
  861. if (eDraw == IF_TRANS)
  862. p = L"Stretch+Trans";
  863. AddItem(&cif, NULL, p, iGroupId);
  864. }
  865. //--------------------------------------------------------------------------
  866. void CreateImageFileTile(IMAGEFILEDRAW eDraw, int iGroupId)
  867. {
  868. CImageFile cif;
  869. memset(&cif, 0, sizeof(cif));
  870. int idnum = IDB_TILE;
  871. if (eDraw == IF_TRANS)
  872. idnum = IDB_TILE_TRANS;
  873. DIBINFO *pdi = &cif._ImageInfo;
  874. pdi->hProcessBitmap = (HBITMAP)LoadImage(hInst, static_cast<LPCWSTR>(IntToPtr(idnum)),
  875. IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION);
  876. //---- create a ImageFile object that sizes with TILE ----
  877. pdi->eSizingType = ST_TILE;
  878. cif._eBgType = BT_IMAGEFILE;
  879. cif._fMirrorImage = TRUE;
  880. cif._iImageCount = 5;
  881. cif._eImageLayout = IL_VERTICAL;
  882. cif._ImageInfo.iSingleWidth = 20;
  883. cif._ImageInfo.iSingleHeight = 19;
  884. if (eDraw == IF_TRANS)
  885. {
  886. cif._ImageInfo.fTransparent = TRUE;
  887. cif._ImageInfo.crTransparent = RGB(255, 0, 255);
  888. }
  889. SetRect((RECT *)&cif._SizingMargins, 4, 4, 9, 9);
  890. LPCWSTR p = L"Tile";
  891. if (eDraw == IF_TRANS)
  892. p = L"Tile+Trans";
  893. AddItem(&cif, NULL, p, iGroupId);
  894. }
  895. //--------------------------------------------------------------------------
  896. void CreateImageFileTrueSize(IMAGEFILEDRAW eDraw, int iGroupId)
  897. {
  898. CImageFile cif;
  899. memset(&cif, 0, sizeof(cif));
  900. int idnum = IDB_TRUE;
  901. if (eDraw == IF_TRANS)
  902. idnum = IDB_TRUE_TRANS;
  903. else if (eDraw == IF_ALPHA)
  904. idnum = IDB_TRUE_ALPHA;
  905. cif._ImageInfo.hProcessBitmap = (HBITMAP)LoadImage(hInst, static_cast<LPCWSTR>(IntToPtr(idnum)),
  906. IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION);
  907. //---- create a ImageFile object that sizes with STRETCH ----
  908. cif._eBgType = BT_IMAGEFILE;
  909. cif._iImageCount = 8;
  910. cif._fMirrorImage = TRUE;
  911. cif._eImageLayout = IL_HORIZONTAL;
  912. cif._ImageInfo.iSingleWidth = 16;
  913. cif._ImageInfo.iSingleHeight = 16;
  914. cif._ImageInfo.eSizingType = ST_TRUESIZE;
  915. if (eDraw == IF_TRANS)
  916. {
  917. cif._ImageInfo.fTransparent = TRUE;
  918. cif._ImageInfo.crTransparent = RGB(255, 0, 255);
  919. }
  920. else if (eDraw == IF_ALPHA)
  921. {
  922. cif._ImageInfo.fAlphaChannel = TRUE;
  923. }
  924. LPCWSTR p = L"TrueSize";
  925. if (eDraw == IF_TRANS)
  926. p = L"True+Trans";
  927. else if (eDraw == IF_ALPHA)
  928. p = L"True+Alpha";
  929. AddItem(&cif, NULL, p, iGroupId);
  930. }
  931. //--------------------------------------------------------------------------
  932. void CreateImageFileCharGlyph()
  933. {
  934. CImageFile cif;
  935. memset(&cif, 0, sizeof(cif));
  936. int idnum = IDB_GLYPHBG;
  937. cif._ImageInfo.hProcessBitmap = (HBITMAP)LoadImage(hInst, static_cast<LPCWSTR>(IntToPtr(idnum)),
  938. IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION);
  939. //---- specify bg info ----
  940. cif._eBgType = BT_IMAGEFILE;
  941. cif._fMirrorImage = TRUE;
  942. cif._iImageCount = 3;
  943. cif._eImageLayout = IL_HORIZONTAL;
  944. cif._ImageInfo.iSingleWidth = 16;
  945. cif._ImageInfo.iSingleHeight = 22;
  946. cif._ImageInfo.eSizingType = ST_STRETCH;
  947. SetRect((RECT *)&cif._SizingMargins, 1, 1, 1, 1);
  948. //---- specify the char/font info ----
  949. cif._eGlyphType = GT_FONTGLYPH;
  950. cif._crGlyphTextColor = RGB(0, 0, 255);
  951. cif._iGlyphIndex = 62;
  952. cif._lfGlyphFont.lfWeight = FW_NORMAL;
  953. cif._lfGlyphFont.lfHeight = CLIPPER_FONTHEIGHT;
  954. StringCchCopyW(cif._lfGlyphFont.lfFaceName, ARRAYSIZE(cif._lfGlyphFont.lfFaceName), L"marlett");
  955. //---- specify alignment ----
  956. cif._eHAlign = HA_CENTER;
  957. cif._eVAlign = VA_CENTER;
  958. LPCWSTR p = L"FontGlyph";
  959. AddItem(&cif, NULL, p, GID_GLYPH);
  960. }
  961. //--------------------------------------------------------------------------
  962. void CreateImageFileImageGlyph(IMAGEFILEDRAW eDraw, BOOL fForceMirror)
  963. {
  964. CImageFile cif;
  965. memset(&cif, 0, sizeof(cif));
  966. int idnum = IDB_GLYPHBG;
  967. cif._ImageInfo.hProcessBitmap = (HBITMAP)LoadImage(hInst, static_cast<LPCWSTR>(IntToPtr(idnum)),
  968. IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION);
  969. //---- specify bg info ----
  970. cif._eBgType = BT_IMAGEFILE;
  971. cif._fMirrorImage = TRUE;
  972. cif._eGlyphType = GT_IMAGEGLYPH;
  973. cif._iImageCount = 3;
  974. cif._eImageLayout = IL_HORIZONTAL;
  975. cif._ImageInfo.iSingleWidth = 16;
  976. cif._ImageInfo.iSingleHeight = 22;
  977. cif._ImageInfo.eSizingType = ST_STRETCH;
  978. SetRect((RECT *)&cif._SizingMargins, 1, 1, 1, 1);
  979. //---- specify glyph info ----
  980. WCHAR szName[MAX_PATH];
  981. if (eDraw == IF_REG)
  982. {
  983. idnum = IDB_GLYPH;
  984. StringCchCopyW(szName, ARRAYSIZE(szName), L"ImageGlyph");
  985. cif._GlyphInfo.iSingleWidth = 10;
  986. cif._GlyphInfo.iSingleHeight = 7;
  987. }
  988. else if (eDraw == IF_TRANS)
  989. {
  990. idnum = IDB_GLYPH_TRANS;
  991. StringCchCopyW(szName, ARRAYSIZE(szName), L"ImageTrans");
  992. cif._GlyphInfo.fTransparent = TRUE;
  993. cif._GlyphInfo.crTransparent = RGB(255, 0, 255);
  994. cif._GlyphInfo.iSingleWidth = 10;
  995. cif._GlyphInfo.iSingleHeight = 7;
  996. }
  997. else
  998. {
  999. idnum = IDB_GLYPH_ALPHA;
  1000. StringCchCopyW(szName, ARRAYSIZE(szName), L"ImageAlpha");
  1001. cif._GlyphInfo.fAlphaChannel = TRUE;
  1002. cif._GlyphInfo.iSingleWidth = 16;
  1003. cif._GlyphInfo.iSingleHeight = 16;
  1004. }
  1005. cif._GlyphInfo.hProcessBitmap = (HBITMAP)LoadImage(hInst, static_cast<LPCWSTR>(IntToPtr(idnum)),
  1006. IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION);
  1007. //---- specify alignment ----
  1008. cif._eHAlign = HA_CENTER;
  1009. cif._eVAlign = VA_CENTER;
  1010. DWORD dwDtbFlags = 0;
  1011. if (fForceMirror)
  1012. {
  1013. dwDtbFlags |= DTBG_MIRRORDC;
  1014. StringCchCatW(szName, ARRAYSIZE(szName), L"+M");
  1015. }
  1016. AddItem(&cif, NULL, szName, GID_GLYPH, 0, dwDtbFlags);
  1017. }
  1018. //--------------------------------------------------------------------------
  1019. void CreateMultiImage()
  1020. {
  1021. CMaxImageFile MaxIf;
  1022. memset(&MaxIf, 0, sizeof(MaxIf));
  1023. //---- specify general info ----
  1024. MaxIf._eBgType = BT_IMAGEFILE;
  1025. MaxIf._fMirrorImage = TRUE;
  1026. MaxIf._iImageCount = 8;
  1027. MaxIf._eImageLayout = IL_VERTICAL;
  1028. MaxIf._eImageSelectType = IST_SIZE;
  1029. MaxIf._iMultiImageCount = 3;
  1030. MaxIf._iTrueSizeStretchMark = 50;
  1031. MaxIf._eTrueSizeScalingType = TSST_SIZE;
  1032. MaxIf._fUniformSizing = TRUE;
  1033. MaxIf._eHAlign = HA_CENTER;
  1034. MaxIf._eVAlign = VA_CENTER;
  1035. int iUsageSizes[] = {20, 24, 32};
  1036. //---- specify alignment ----
  1037. MaxIf._eHAlign = HA_CENTER;
  1038. MaxIf._eVAlign = VA_CENTER;
  1039. for (int i=0; i < MaxIf._iMultiImageCount; i++)
  1040. {
  1041. int idnum = IDB_MULTI1 + i;
  1042. DIBINFO *pdi = &MaxIf.MultiDibs[i];
  1043. pdi->hProcessBitmap = (HBITMAP)LoadImage(hInst, static_cast<LPCWSTR>(IntToPtr(idnum)),
  1044. IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION);
  1045. pdi->szMinSize.cx = iUsageSizes[i];
  1046. pdi->szMinSize.cy = iUsageSizes[i];
  1047. //---- get bitmap width/height ----
  1048. BITMAP bm;
  1049. GetObject(pdi->hProcessBitmap, sizeof bm, &bm);
  1050. pdi->iSingleWidth = bm.bmWidth;
  1051. pdi->iSingleHeight = bm.bmHeight/8;
  1052. pdi->eSizingType = ST_TRUESIZE;
  1053. pdi->fAlphaChannel = TRUE;
  1054. }
  1055. //---- set primary image ----
  1056. MaxIf._ImageInfo = MaxIf.MultiDibs[0];
  1057. AddItem(&MaxIf, NULL, L"MultiImage", GID_MULTIIMAGE);
  1058. }
  1059. //--------------------------------------------------------------------------
  1060. void CreateTextObj()
  1061. {
  1062. CTextDraw td;
  1063. memset(&td, 0, sizeof(td));
  1064. //---- text ----
  1065. td._crText = RGB(255, 128, 128); // red
  1066. //---- font ----
  1067. td._fHaveFont = TRUE;
  1068. td._lfFont.lfWeight = FW_NORMAL;
  1069. td._lfFont.lfHeight = CLIPPER_FONTHEIGHT;
  1070. td._lfFont.lfQuality = ANTIALIASED_QUALITY;
  1071. StringCchCopyW(td._lfFont.lfFaceName, ARRAYSIZE(td._lfFont.lfFaceName), L"arial");
  1072. AddItem(NULL, &td, L"TextObj", GID_TEXT);
  1073. }
  1074. //--------------------------------------------------------------------------
  1075. void CreateShadowTextObj()
  1076. {
  1077. CTextDraw td;
  1078. memset(&td, 0, sizeof(td));
  1079. //---- text ----
  1080. td._crText = RGB(255, 139, 139); // light red
  1081. //---- font ----
  1082. td._fHaveFont = TRUE;
  1083. td._lfFont.lfWeight = FW_NORMAL;
  1084. td._lfFont.lfHeight = CLIPPER_FONTHEIGHT;
  1085. td._lfFont.lfQuality = ANTIALIASED_QUALITY;
  1086. StringCchCopyW(td._lfFont.lfFaceName, ARRAYSIZE(td._lfFont.lfFaceName), L"arial");
  1087. //---- shadow ----
  1088. td._ptShadowOffset.x = 2;
  1089. td._ptShadowOffset.y = 2;
  1090. td._crShadow = RGB(149, 0, 0); // dark red
  1091. td._eShadowType = TST_SINGLE;
  1092. AddItem(NULL, &td, L"ShadowText", GID_TEXT);
  1093. }
  1094. //--------------------------------------------------------------------------
  1095. void CreateBorderTextObj()
  1096. {
  1097. CTextDraw td;
  1098. memset(&td, 0, sizeof(td));
  1099. //---- text ----
  1100. td._crText = RGB(255, 139, 139); // light red
  1101. //---- font ----
  1102. td._fHaveFont = TRUE;
  1103. td._lfFont.lfWeight = FW_NORMAL;
  1104. td._lfFont.lfHeight = CLIPPER_FONTHEIGHT;
  1105. td._lfFont.lfQuality = ANTIALIASED_QUALITY;
  1106. StringCchCopyW(td._lfFont.lfFaceName, ARRAYSIZE(td._lfFont.lfFaceName), L"arial");
  1107. //---- border ----
  1108. td._iBorderSize = 1;
  1109. td._crBorder = RGB(128, 128, 255); // light blue
  1110. AddItem(NULL, &td, L"BorderText", GID_TEXT);
  1111. }
  1112. //--------------------------------------------------------------------------
  1113. void CreateBorderShadowTextObj()
  1114. {
  1115. CTextDraw td;
  1116. memset(&td, 0, sizeof(td));
  1117. //---- text ----
  1118. td._crText = RGB(255, 139, 139); // light red
  1119. //---- font ----
  1120. td._fHaveFont = TRUE;
  1121. td._lfFont.lfWeight = FW_NORMAL;
  1122. td._lfFont.lfHeight = CLIPPER_FONTHEIGHT;
  1123. td._lfFont.lfQuality = ANTIALIASED_QUALITY;
  1124. StringCchCopyW(td._lfFont.lfFaceName, ARRAYSIZE(td._lfFont.lfFaceName), L"arial");
  1125. //---- shadow ----
  1126. td._ptShadowOffset.x = 2;
  1127. td._ptShadowOffset.y = 2;
  1128. td._crShadow = RGB(149, 0, 0); // dark red
  1129. td._eShadowType = TST_SINGLE;
  1130. //---- border ----
  1131. td._iBorderSize = 1;
  1132. td._crBorder = RGB(0, 0, 0); // black
  1133. AddItem(NULL, &td, L"BorderShadow", GID_TEXT);
  1134. }
  1135. //--------------------------------------------------------------------------
  1136. void CreateBlurShadowTextObj()
  1137. {
  1138. CTextDraw td;
  1139. memset(&td, 0, sizeof(td));
  1140. //---- text ----
  1141. td._crText = RGB(255, 139, 139); // light red
  1142. //---- font ----
  1143. td._fHaveFont = TRUE;
  1144. td._lfFont.lfWeight = FW_NORMAL;
  1145. td._lfFont.lfHeight = CLIPPER_FONTHEIGHT;
  1146. td._lfFont.lfQuality = ANTIALIASED_QUALITY;
  1147. StringCchCopyW(td._lfFont.lfFaceName, ARRAYSIZE(td._lfFont.lfFaceName), L"arial");
  1148. //---- shadow ----
  1149. td._ptShadowOffset.x = 2;
  1150. td._ptShadowOffset.y = 2;
  1151. td._crShadow = RGB(149, 0, 0); // dark red
  1152. td._eShadowType = TST_CONTINUOUS;
  1153. AddItem(NULL, &td, L"BlurShadow", GID_TEXT);
  1154. }
  1155. //--------------------------------------------------------------------------
  1156. void LabelClip(HDC hdc, RECT *prc, int iColIndex, LPCWSTR pszName)
  1157. {
  1158. int left = prc->left + (iColIndex+1)*szCell.cx;
  1159. int top = prc->top + 6; // some padding from very top of window
  1160. //---- manual page clipping ----
  1161. if ((top + szCell.cy) < 0)
  1162. return;
  1163. if (top > iVertPageSize)
  1164. return;
  1165. TextOut(hdc, left, top, pszName, wcslen(pszName));
  1166. }
  1167. //--------------------------------------------------------------------------
  1168. void CreateDrawObjects()
  1169. {
  1170. //---- borderfill group ----
  1171. CreateBorderFillNoDraw();
  1172. CreateBorderFillSquare();
  1173. CreateBorderFillBorder();
  1174. CreateBorderFillCircle();
  1175. CreateBorderFillGradient();
  1176. CreateBorderFillCircleGradient();
  1177. //---- imagefile group ----
  1178. CreateImageFileStretch(IF_REG, GID_IMAGEFILE);
  1179. CreateImageFileStretch(IF_TRANS, GID_IMAGEFILE);
  1180. CreateImageFileTile(IF_REG, GID_IMAGEFILE);
  1181. CreateImageFileTile(IF_TRANS, GID_IMAGEFILE);
  1182. CreateImageFileTrueSize(IF_REG, GID_IMAGEFILE);
  1183. CreateImageFileTrueSize(IF_TRANS, GID_IMAGEFILE);
  1184. CreateImageFileTrueSize(IF_ALPHA, GID_IMAGEFILE);
  1185. //---- glyph group ----
  1186. //CreateImageFileCharGlyph();
  1187. CreateImageFileImageGlyph(IF_REG, FALSE);
  1188. CreateImageFileImageGlyph(IF_TRANS, FALSE);
  1189. CreateImageFileImageGlyph(IF_TRANS, TRUE);
  1190. CreateImageFileImageGlyph(IF_ALPHA, FALSE);
  1191. //---- MultiImage group ----
  1192. CreateMultiImage();
  1193. //---- text group ----
  1194. CreateTextObj();
  1195. CreateShadowTextObj();
  1196. CreateBorderTextObj();
  1197. CreateBorderShadowTextObj();
  1198. CreateBlurShadowTextObj();
  1199. //---- borders group ----
  1200. CreateImageFileBorder(ST_TRUESIZE, FALSE, FALSE);
  1201. CreateImageFileBorder(ST_STRETCH, FALSE, FALSE);
  1202. CreateImageFileBorder(ST_STRETCH, TRUE, TRUE);
  1203. CreateImageFileBorder(ST_TILE, TRUE, TRUE);
  1204. //---- SrcSizing group ----
  1205. CreateImage(IDB_PUSHBUTTON, 5, ST_STRETCH, TRUE, GID_SRCSIZING, L"PushButton",
  1206. 8, 8, 9, 9);
  1207. CreateRadioImage();
  1208. CreateCheckImage();
  1209. CreateScrollGlyph();
  1210. CreateProgressTrack();
  1211. CreateProgressChunk();
  1212. }
  1213. //--------------------------------------------------------------------------
  1214. void CenterRect(POINT &ptCenter, int iSize, RECT *prc)
  1215. {
  1216. int iSizeA = iSize/2;
  1217. int iSizeB = iSize - iSizeA;
  1218. prc->left = ptCenter.x - iSizeA;
  1219. prc->right = ptCenter.x + iSizeB;
  1220. prc->top = ptCenter.y - iSizeA;
  1221. prc->bottom = ptCenter.y + iSizeB;
  1222. }
  1223. //--------------------------------------------------------------------------
  1224. void DrawMultiImages(HDC hdc, RECT *prc, HTHEME hTheme)
  1225. {
  1226. SIZE szMyCell = {80, 80};
  1227. int iRowIndex = 0;
  1228. int iSizes[] = {12, 16, 20, 24, 32, 48, 64};
  1229. //---- draw various sizes of image ----
  1230. for (int iIndex=0; iIndex < ARRAYSIZE(iSizes); iIndex++)
  1231. {
  1232. int iSize = iSizes[iIndex];
  1233. //---- label object on left ----
  1234. int left = prc->left + 4; // some padding away from edge
  1235. int top = prc->top + (iRowIndex)*szMyCell.cy + 18; // try to center
  1236. //---- manual page clipping ----
  1237. if ((top + szMyCell.cy) < 0)
  1238. return;
  1239. if (top > iVertPageSize)
  1240. return;
  1241. WCHAR szName[MAX_PATH];
  1242. StringCchPrintfW(szName, ARRAYSIZE(szName), L"Size: %d", iSize);
  1243. TextOut(hdc, left, top+15, szName, wcslen(szName));
  1244. //---- draw image in all of its states ----
  1245. int iPartId = BP_RADIOBUTTON;
  1246. for (int iStateId=RBS_UNCHECKEDNORMAL; iStateId <= RBS_CHECKEDDISABLED; iStateId++)
  1247. {
  1248. left += szMyCell.cx;
  1249. RECT rc = {left, top, left+szMyCell.cx, top+szMyCell.cy};
  1250. //---- draw purple target dashed rect ----
  1251. DrawTargetRect(hdc, &rc, RGB(128, 128, 255));
  1252. //---- calc center pt ----
  1253. POINT ptCenter = {left + szMyCell.cx/2, top + szMyCell.cy/2};
  1254. //---- rect to draw into ----
  1255. CenterRect(ptCenter, iSize, &rc);
  1256. //---- draw red rect for "draw into" rect ----
  1257. DrawTargetRect(hdc, &rc, RGB(255, 0, 0));
  1258. HRESULT hr = DrawThemeBackground(hTheme, hdc, iPartId, iStateId, &rc, NULL);
  1259. if (FAILED(hr))
  1260. {
  1261. WCHAR buff[100];
  1262. StringCchPrintfW(buff, ARRAYSIZE(buff), L"DrawThemeBackground err: hr=0x%x, irow=%d, iPartId=%d",
  1263. hr, iRowIndex, iPartId);
  1264. //MessageBox(NULL, buff, L"Error", MB_OK);
  1265. }
  1266. }
  1267. iRowIndex++;
  1268. }
  1269. }
  1270. //--------------------------------------------------------------------------
  1271. void DrawBorders(HDC hdc, RECT *prc, TESTITEM *pTestItem)
  1272. {
  1273. int top = prc->top + 4;
  1274. int left = prc->left + 6;
  1275. //---- message on top line ----
  1276. WCHAR szBuff[100];
  1277. StringCchCopyW(szBuff, ARRAYSIZE(szBuff), L"Image: BorderTest.bmp, 18x17, 24 bit, Sizing Margins: 3, 3, 3, 3");
  1278. TextOut(hdc, left, top+15, szBuff, wcslen(szBuff));
  1279. top += 44;
  1280. //---- FIRST row: draw border test obj in 6 different sizes ----
  1281. SIZE szMyCell = {120, 120};
  1282. //---- manual page clipping ----
  1283. if (((top + szMyCell.cy) >= 0) && (top <= iVertPageSize))
  1284. {
  1285. LPCWSTR pszLabels [] = { L"TrueSize", L"Stretch", L"Stretch", L"Stretch",
  1286. L"Stretch", L"Stretch", L"Stretch"};
  1287. SIZE szSizes[] = { {60, 40}, {60, 40}, {6, 40}, {3, 40}, {60, 6}, {60, 2}, {2, 3} };
  1288. //---- draw various sizes of image ----
  1289. for (int iIndex=0; iIndex < ARRAYSIZE(szSizes); iIndex++)
  1290. {
  1291. SIZE sz = szSizes[iIndex];
  1292. //---- label object on top ----
  1293. left = prc->left + iIndex*szMyCell.cx + 6; // some padding away from edge
  1294. StringCchPrintfW(szBuff, ARRAYSIZE(szBuff), L"%s (%dx%d)", pszLabels[iIndex], sz.cx, sz.cy);
  1295. TextOut(hdc, left, top+15, szBuff, wcslen(szBuff));
  1296. //---- draw image ----
  1297. RECT rc = {left, top+50, left+sz.cx, top+50+sz.cy};
  1298. int i = (iIndex==0) ? 0 : 1;
  1299. HRESULT hr = DrawThemeBackground(pTestItem[i].hTheme, hdc, 0, 0, &rc, NULL);
  1300. if (FAILED(hr))
  1301. {
  1302. WCHAR buff[100];
  1303. StringCchPrintfW(buff, ARRAYSIZE(buff), L"DrawThemeBackground err in DrawBorders: hr=0x%x, iIndex=%d",
  1304. hr, iIndex);
  1305. //MessageBox(NULL, buff, L"Error", MB_OK);
  1306. }
  1307. }
  1308. }
  1309. //---- SECOND row: draw 2 other border objects real big (test border scaling) ----
  1310. top += szMyCell.cy;
  1311. szMyCell.cx = 380;
  1312. szMyCell.cy = 300;
  1313. SIZE sz = {szMyCell.cx - 30, szMyCell.cy - (50 + 10)};
  1314. //---- manual page clipping: first row ----
  1315. if (((top + szMyCell.cy) >= 0) && (top <= iVertPageSize))
  1316. {
  1317. LPCWSTR pszLabels [] = { L"Border Scaling (stretch)", L"Border Scaling (tile)"};
  1318. //---- draw various sizes of image ----
  1319. for (int iIndex=0; iIndex < ARRAYSIZE(pszLabels); iIndex++)
  1320. {
  1321. //---- label object on top ----
  1322. int left = prc->left + iIndex*szMyCell.cx + 6; // some padding away from edge
  1323. TextOut(hdc, left, top+15, pszLabels[iIndex], wcslen(pszLabels[iIndex]));
  1324. //---- draw image ----
  1325. RECT rc = {left, top+50, left+sz.cx, top+50+sz.cy};
  1326. HRESULT hr = DrawThemeBackground(pTestItem[2+iIndex].hTheme, hdc, 0, 0, &rc, NULL);
  1327. if (FAILED(hr))
  1328. {
  1329. WCHAR buff[100];
  1330. StringCchPrintfW(buff, ARRAYSIZE(buff), L"DrawThemeBackground err in DrawBorders: hr=0x%x, iIndex=%d",
  1331. hr, iIndex);
  1332. //MessageBox(NULL, buff, L"Error", MB_OK);
  1333. }
  1334. }
  1335. }
  1336. }
  1337. //--------------------------------------------------------------------------
  1338. void DrawSrcSizing(HDC hdc, RECT *prc, TESTITEM *pTestItem)
  1339. {
  1340. SIZE szMyCell = {120, 110};
  1341. int top = prc->top + 4;
  1342. int left = prc->left + szMyCell.cx + 6;
  1343. //---- labels on top line ----
  1344. LPCWSTR TopLabels[] = {L"Small", L"Regular", L"Large", L"High DPI"};
  1345. SIZE szStretchSizes[] = { {50, 6}, {75, 23}, {90, 65}, {340, 100} };
  1346. SIZE szTrueSizes[] = { {10, 6}, {13, 13}, {30, 30}, {340, 100} };
  1347. int iStates[] = {5, 6, 6, 0, 0};
  1348. for (int i=0; i < ARRAYSIZE(TopLabels); i++)
  1349. {
  1350. TextOut(hdc, left, top, TopLabels[i], wcslen(TopLabels[i]));
  1351. left += szMyCell.cx;
  1352. }
  1353. top += 30;
  1354. //---- draw rows ----
  1355. for (int iRow=0; iRow < 5; iRow++)
  1356. {
  1357. //---- draw name on left ----
  1358. left = prc->left + 6;
  1359. WCHAR *pszName = pTestItem[iRow].szName;
  1360. TextOut(hdc, left, top-5, pszName, wcslen(pszName));
  1361. for (int iSize=0; iSize < ARRAYSIZE(szStretchSizes); iSize++)
  1362. {
  1363. left += szMyCell.cx;
  1364. SIZE *psz;
  1365. if ((iRow > 0) && (iRow < 4))
  1366. {
  1367. psz = &szTrueSizes[iSize];
  1368. }
  1369. else
  1370. {
  1371. psz = &szStretchSizes[iSize];
  1372. }
  1373. RECT rc = {left, top, left + psz->cx, top + psz->cy};
  1374. HTHEME hTheme = pTestItem[iRow].hTheme;
  1375. if (hTheme)
  1376. {
  1377. DrawThemeBackground(hTheme, hdc, 0, iStates[iRow], &rc, NULL);
  1378. if (iRow == 4) // progress control
  1379. {
  1380. RECT rcContent;
  1381. GetThemeBackgroundContentRect(hTheme, hdc,
  1382. 0, 0, &rc, &rcContent);
  1383. DrawThemeBackground(pTestItem[5].hTheme, hdc, 0, iStates[iRow], &rcContent, NULL);
  1384. }
  1385. }
  1386. }
  1387. top += szMyCell.cy;
  1388. }
  1389. }
  1390. //--------------------------------------------------------------------------
  1391. void PaintObjects(HDC hdc, RECT *prc, int iGroupId)
  1392. {
  1393. //---- select in a fixed size font for resolution-independent bits ----
  1394. HFONT hfFixedSize = CreateFont(18, 6, 0, 0, FW_NORMAL, 0, 0, 0, ANSI_CHARSET,
  1395. 0, 0, 0, 0, L"MS Sans Serif");
  1396. HFONT hOldFont = (HFONT)SelectObject(hdc, hfFixedSize);
  1397. RECT rc = *prc;
  1398. rc.top -= iVertOffset;
  1399. rc.bottom -= iVertOffset;
  1400. if (iGroupId == GID_TEXT) // text object
  1401. {
  1402. for (int i=0; i < iItemCount[iGroupId]; i++)
  1403. {
  1404. DrawTextObjects(TestItems[iGroupId][i].hTheme, hdc, &rc, i,
  1405. TestItems[iGroupId][i].szName);
  1406. }
  1407. }
  1408. else if (iGroupId == GID_MULTIIMAGE)
  1409. {
  1410. DrawMultiImages(hdc, prc, TestItems[iGroupId][0].hTheme);
  1411. }
  1412. else if (iGroupId == GID_BORDERS)
  1413. {
  1414. DrawBorders(hdc, prc, TestItems[iGroupId]);
  1415. }
  1416. else if (iGroupId == GID_SRCSIZING)
  1417. {
  1418. DrawSrcSizing(hdc, prc, TestItems[iGroupId]);
  1419. }
  1420. else
  1421. {
  1422. LabelClip(hdc, &rc, 0, L"NoClip");
  1423. LabelClip(hdc, &rc, 1, L"OverClip");
  1424. LabelClip(hdc, &rc, 2, L"ExactClip");
  1425. LabelClip(hdc, &rc, 3, L"PartialClip");
  1426. LabelClip(hdc, &rc, 4, L"InOut1");
  1427. LabelClip(hdc, &rc, 5, L"InOut2");
  1428. LabelClip(hdc, &rc, 6, L"OutClip");
  1429. for (int i=0; i < iItemCount[iGroupId]; i++)
  1430. {
  1431. DrawClips(TestItems[iGroupId][i].hTheme, hdc, &rc, i,
  1432. TestItems[iGroupId][i].szName, TestItems[iGroupId][i].dwDtbFlags);
  1433. }
  1434. }
  1435. //---- restore the font ----
  1436. SelectObject(hdc, hOldFont);
  1437. DeleteObject(hfFixedSize);
  1438. }
  1439. //--------------------------------------------------------------------------
  1440. void RegisterWindowClasses()
  1441. {
  1442. WNDCLASSEX wcex;
  1443. wcex.cbSize = sizeof(WNDCLASSEX);
  1444. //---- register MAIN window class ----
  1445. wcex.style = 0;
  1446. wcex.lpfnWndProc = MainWndProc;
  1447. wcex.cbClsExtra = 0;
  1448. wcex.cbWndExtra = 0;
  1449. wcex.hInstance = hInst;
  1450. wcex.hIcon = LoadIcon(hInst, (LPCTSTR)IDI_CLIPPER);
  1451. wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
  1452. wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  1453. wcex.lpszMenuName = (LPCWSTR)IDC_CLIPPER;
  1454. wcex.lpszClassName = pszMainWindowClass;
  1455. wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);
  1456. RegisterClassEx(&wcex);
  1457. //---- register DISPLAY window class ----
  1458. wcex.style = CS_HREDRAW | CS_VREDRAW;
  1459. wcex.lpfnWndProc = DisplayWndProc;
  1460. wcex.cbClsExtra = 0;
  1461. wcex.cbWndExtra = 0;
  1462. wcex.hInstance = hInst;
  1463. wcex.hIcon = LoadIcon(hInst, (LPCTSTR)IDI_CLIPPER);
  1464. wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
  1465. wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  1466. wcex.lpszMenuName = (LPCWSTR)IDC_CLIPPER;
  1467. wcex.lpszClassName = pszDisplayWindowClass;
  1468. wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);
  1469. RegisterClassEx(&wcex);
  1470. }
  1471. //--------------------------------------------------------------------------
  1472. BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
  1473. {
  1474. hInst = hInstance; // Store instance handle in our global variable
  1475. CreateDrawObjects();
  1476. if (! CreateAllWindows())
  1477. return FALSE;
  1478. ShowWindow(hwndMain, nCmdShow);
  1479. UpdateWindow(hwndMain);
  1480. return TRUE;
  1481. }
  1482. //--------------------------------------------------------------------------
  1483. void HandleVScroll(int message, WPARAM wParam, LPARAM lParam)
  1484. {
  1485. int iOldVertOffset = iVertOffset;
  1486. if (message == WM_VSCROLL)
  1487. {
  1488. switch (LOWORD(wParam))
  1489. {
  1490. case SB_LINEUP:
  1491. iVertOffset -= iVertLineSize;
  1492. break;
  1493. case SB_LINEDOWN:
  1494. iVertOffset += iVertLineSize;
  1495. break;
  1496. case SB_PAGEUP:
  1497. iVertOffset -= iVertPageSize;
  1498. break;
  1499. case SB_PAGEDOWN:
  1500. iVertOffset += iVertPageSize;
  1501. break;
  1502. case SB_THUMBPOSITION:
  1503. iVertOffset = HIWORD(wParam);
  1504. break;
  1505. }
  1506. }
  1507. else // mouse wheel
  1508. {
  1509. iVertOffset -= (GET_WHEEL_DELTA_WPARAM(wParam)/10);
  1510. }
  1511. //---- keep in valid range ----
  1512. if (iVertOffset < 0)
  1513. {
  1514. iVertOffset = 0;
  1515. }
  1516. else if (iVertOffset > iMaxVertOffset)
  1517. {
  1518. iVertOffset = iMaxVertOffset;
  1519. }
  1520. //---- scroll or repaint, as needed ----
  1521. if (iVertOffset != iOldVertOffset)
  1522. {
  1523. SetScrollPos(hwndDisplay, SB_VERT, iVertOffset, TRUE);
  1524. int iDiff = (iVertOffset - iOldVertOffset);
  1525. if (abs(iDiff) >= iVertPageSize)
  1526. {
  1527. InvalidateRect(hwndDisplay, NULL, TRUE);
  1528. }
  1529. else
  1530. {
  1531. ScrollWindowEx(hwndDisplay, 0, -iDiff, NULL, NULL, NULL,
  1532. NULL, SW_INVALIDATE | SW_ERASE);
  1533. }
  1534. }
  1535. }
  1536. //--------------------------------------------------------------------------
  1537. void OnDisplayResize()
  1538. {
  1539. int iTabNum = TabCtrl_GetCurSel(hwndTab);
  1540. if (iTabNum < 0)
  1541. iTabNum = 0;
  1542. int iGroupId = iTabNum/2;
  1543. RECT rc;
  1544. GetClientRect(hwndDisplay, &rc);
  1545. iVertPageSize = RECTHEIGHT(&rc);
  1546. iMaxVertOffset = ((iItemCount[iGroupId]+1)*szCell.cy) - iVertPageSize;
  1547. if (iMaxVertOffset < 0)
  1548. iMaxVertOffset = 0;
  1549. if (iVertOffset > iMaxVertOffset)
  1550. iVertOffset = iMaxVertOffset;
  1551. //---- set scrolling info ----
  1552. SetScrollRange(hwndDisplay, SB_VERT, 0, iMaxVertOffset, FALSE);
  1553. SetScrollPos(hwndDisplay, SB_VERT, iVertOffset, TRUE);
  1554. }
  1555. //--------------------------------------------------------------------------
  1556. LRESULT CALLBACK MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  1557. {
  1558. int wmId, wmEvent;
  1559. int iWidth, iHeight;
  1560. switch (message)
  1561. {
  1562. case WM_COMMAND:
  1563. wmId = LOWORD(wParam);
  1564. wmEvent = HIWORD(wParam);
  1565. // Parse the menu selections:
  1566. switch (wmId)
  1567. {
  1568. case IDM_ABOUT:
  1569. DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, About);
  1570. break;
  1571. case IDM_EXIT:
  1572. DestroyWindow(hWnd);
  1573. break;
  1574. default:
  1575. return DefWindowProc(hWnd, message, wParam, lParam);
  1576. }
  1577. break;
  1578. case WM_NOTIFY:
  1579. NMHDR *phdr;
  1580. phdr = (NMHDR *)lParam;
  1581. if (phdr->code == TCN_SELCHANGE) // tab selection
  1582. {
  1583. iVertOffset = 0;
  1584. OnDisplayResize();
  1585. InvalidateRect(hwndDisplay, NULL, TRUE);
  1586. }
  1587. break;
  1588. case WM_SIZE:
  1589. iWidth = LOWORD(lParam);
  1590. iHeight = HIWORD(lParam);
  1591. MoveWindow(hwndTab, 0, 0, iWidth, iHeight, TRUE);
  1592. RECT rc;
  1593. SetRect(&rc, 0, 0, iWidth, iHeight);
  1594. TabCtrl_AdjustRect(hwndTab, FALSE, &rc);
  1595. MoveWindow(hwndDisplay, rc.left, rc.top, RECTWIDTH(&rc), RECTHEIGHT(&rc), TRUE);
  1596. break;
  1597. case WM_MOUSEWHEEL:
  1598. HandleVScroll(message, wParam, lParam);
  1599. return 0;
  1600. case WM_DESTROY:
  1601. PostQuitMessage(0);
  1602. break;
  1603. default:
  1604. return DefWindowProc(hWnd, message, wParam, lParam);
  1605. }
  1606. return 0;
  1607. }
  1608. //--------------------------------------------------------------------------
  1609. LRESULT CALLBACK DisplayWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  1610. {
  1611. int wmId, wmEvent;
  1612. PAINTSTRUCT ps;
  1613. HDC hdc;
  1614. int iTabNum = TabCtrl_GetCurSel(hwndTab);
  1615. if (iTabNum < 0)
  1616. iTabNum = 0;
  1617. int iGroupId = iTabNum/2;
  1618. switch (message)
  1619. {
  1620. case WM_COMMAND:
  1621. wmId = LOWORD(wParam);
  1622. wmEvent = HIWORD(wParam);
  1623. // Parse the menu selections:
  1624. switch (wmId)
  1625. {
  1626. case IDM_ABOUT:
  1627. DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, About);
  1628. break;
  1629. case IDM_EXIT:
  1630. DestroyWindow(hWnd);
  1631. break;
  1632. default:
  1633. return DefWindowProc(hWnd, message, wParam, lParam);
  1634. }
  1635. break;
  1636. case WM_PAINT:
  1637. RECT rt;
  1638. hdc = BeginPaint(hWnd, &ps);
  1639. if (iTabNum % 2) // if its a mirrored page
  1640. SetLayout(hdc, LAYOUT_RTL);
  1641. else
  1642. SetLayout(hdc, 0);
  1643. GetClientRect(hWnd, &rt);
  1644. PaintObjects(hdc, &rt, iGroupId);
  1645. EndPaint(hWnd, &ps);
  1646. break;
  1647. case WM_VSCROLL:
  1648. HandleVScroll(message, wParam, lParam);
  1649. return 0;
  1650. case WM_SIZE:
  1651. OnDisplayResize();
  1652. break;
  1653. case WM_DESTROY:
  1654. PostQuitMessage(0);
  1655. break;
  1656. default:
  1657. return DefWindowProc(hWnd, message, wParam, lParam);
  1658. }
  1659. return 0;
  1660. }
  1661. //--------------------------------------------------------------------------
  1662. BOOL CreateAllWindows()
  1663. {
  1664. TCITEM tci = {0};
  1665. BOOL fOk = FALSE;
  1666. int i;
  1667. //---- create main window ----
  1668. hwndMain = CreateWindow(pszMainWindowClass, L"Clipper", WS_OVERLAPPEDWINDOW,
  1669. CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInst, NULL);
  1670. if (! hwndMain)
  1671. goto exit;
  1672. //---- create tab control covering main client area ----
  1673. RECT rc;
  1674. GetClientRect(hwndMain, &rc);
  1675. hwndTab = CreateWindowEx(0, WC_TABCONTROL, L"",
  1676. WS_CHILD|WS_CLIPSIBLINGS|WS_CLIPCHILDREN|TCS_MULTILINE|TCS_HOTTRACK|WS_VISIBLE,
  1677. rc.left, rc.top, (int)RECTWIDTH(&rc), (int)RECTHEIGHT(&rc), hwndMain, NULL, hInst, NULL);
  1678. if (! hwndTab)
  1679. goto exit;
  1680. //---- create the display window in the tab control "display area" ----
  1681. hwndDisplay = CreateWindow(pszDisplayWindowClass, L"", WS_CHILD|WS_VSCROLL|WS_VISIBLE,
  1682. rc.left, rc.top, (int)RECTWIDTH(&rc), (int)RECTHEIGHT(&rc), hwndTab, NULL, hInst, NULL);
  1683. if (! hwndDisplay)
  1684. goto exit;
  1685. //---- add tab pages ----
  1686. tci.mask = TCIF_TEXT;
  1687. TabCtrl_SetPadding(hwndTab, 7, 3);
  1688. for (i=0; i < ARRAYSIZE(szPageNames); i++)
  1689. {
  1690. tci.pszText = (LPWSTR)szPageNames[i];
  1691. SendMessage(hwndTab, TCM_INSERTITEM, i, (LPARAM)&tci);
  1692. }
  1693. fOk = TRUE;
  1694. exit:
  1695. return fOk;
  1696. }
  1697. //--------------------------------------------------------------------------
  1698. INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  1699. {
  1700. switch (message)
  1701. {
  1702. case WM_INITDIALOG:
  1703. return TRUE;
  1704. case WM_COMMAND:
  1705. if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
  1706. {
  1707. EndDialog(hDlg, LOWORD(wParam));
  1708. return TRUE;
  1709. }
  1710. break;
  1711. }
  1712. return FALSE;
  1713. }
  1714. //--------------------------------------------------------------------------