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.

907 lines
28 KiB

  1. //Copyright (c) 1997-2000 Microsoft Corporation
  2. /* LOOKPREV.C
  3. **
  4. **
  5. **
  6. ** History:
  7. **
  8. */
  9. #include "pch.hxx" // PCH
  10. #pragma hdrstop
  11. #include "AccWiz.h"
  12. #include "desk.h"
  13. //#include "deskid.h"
  14. #include "resource.h"
  15. #include "look.h"
  16. #include "LookPrev.h"
  17. #define RCZ(element) g_elements[element].rc
  18. //////////////////////////////////
  19. // Support function
  20. void MyDrawBorderBelow(HDC hdc, LPRECT prc);
  21. void MyDrawFrame(HDC hdc, LPRECT prc, HBRUSH hbrColor, int cl);
  22. HDC g_hdcMem;
  23. TCHAR g_szABC[] = TEXT("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz");
  24. int cxSize;
  25. //////////////////////////////////////////////////////////////
  26. // Declarations of static variables declared in classes
  27. BOOL CLookPreviewGlobals::sm_bOneInstanceCreated = FALSE; // This variable insures that only one instance of CLookPreviewGlobals is created
  28. CLookPreviewGlobals CLookPrev::sm_Globals;
  29. //////////////////////////////////////////////////////////////
  30. // CLookPreviewGlobals member functions
  31. //
  32. BOOL CLookPreviewGlobals::Initialize()
  33. {
  34. if(m_bInitialized)
  35. return TRUE;
  36. m_bInitialized = TRUE;
  37. // Make sure there is only one instance of this class created
  38. _ASSERT(!sm_bOneInstanceCreated);
  39. sm_bOneInstanceCreated = TRUE;
  40. //
  41. // Load our display strings.
  42. //
  43. VERIFY(LoadString(g_hInstDll, IDS_ACTIVE, m_szActive, ARRAYSIZE(m_szActive)));
  44. VERIFY(LoadString(g_hInstDll, IDS_INACTIVE, m_szInactive, ARRAYSIZE(m_szInactive)));
  45. VERIFY(LoadString(g_hInstDll, IDS_MINIMIZED, m_szMinimized, ARRAYSIZE(m_szMinimized)));
  46. VERIFY(LoadString(g_hInstDll, IDS_ICONTITLE, m_szIconTitle, ARRAYSIZE(m_szIconTitle)));
  47. VERIFY(LoadString(g_hInstDll, IDS_NORMAL, m_szNormal, ARRAYSIZE(m_szNormal)));
  48. VERIFY(LoadString(g_hInstDll, IDS_DISABLED, m_szDisabled, ARRAYSIZE(m_szDisabled)));
  49. VERIFY(LoadString(g_hInstDll, IDS_SELECTED, m_szSelected, ARRAYSIZE(m_szSelected)));
  50. VERIFY(LoadString(g_hInstDll, IDS_MSGBOX, m_szMsgBox, ARRAYSIZE(m_szMsgBox)));
  51. VERIFY(LoadString(g_hInstDll, IDS_BUTTONTEXT, m_szButton, ARRAYSIZE(m_szButton)));
  52. // VERIFY(LoadString(g_hInstDll, IDS_SMCAPTION, m_szSmallCaption, ARRAYSIZE(m_szSmallCaption)));
  53. VERIFY(LoadString(g_hInstDll, IDS_WINDOWTEXT, m_szWindowText, ARRAYSIZE(m_szWindowText)));
  54. VERIFY(LoadString(g_hInstDll, IDS_MSGBOXTEXT, m_szMsgBoxText, ARRAYSIZE(m_szMsgBoxText)));
  55. /////////////////////////////////////////////
  56. // Register Look Preview window class
  57. WNDCLASS wc;
  58. memset(&wc, 0, sizeof(wc));
  59. wc.style = 0;
  60. wc.lpfnWndProc = CLookPrev::LookPreviewWndProc;
  61. wc.cbClsExtra = 0;
  62. wc.cbWndExtra = 0;
  63. wc.hInstance = g_hInstDll;
  64. wc.hIcon = NULL;
  65. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  66. wc.hbrBackground = (HBRUSH)(COLOR_3DFACE+1);
  67. wc.lpszMenuName = NULL;
  68. wc.lpszClassName = LOOKPREV_CLASS;
  69. VERIFY(RegisterClass(&wc));
  70. /////////////////////////////////////////////
  71. // Global initialization of g_hdcMem
  72. HBITMAP hbmDefault;
  73. HDC hdc = GetDC(NULL);
  74. VERIFY(g_hdcMem = CreateCompatibleDC(hdc));
  75. ReleaseDC(NULL, hdc);
  76. HBITMAP hbm = CreateBitmap(1, 1, 1, 1, NULL);
  77. if (!hbm)
  78. return FALSE; // Prefix #113777 (avoid null handle reference)
  79. hbmDefault = (HBITMAP)SelectObject(g_hdcMem, hbm);
  80. SelectObject(g_hdcMem, hbmDefault);
  81. DeleteObject(hbm);
  82. /////////////////////////////////////////////
  83. // Old initialization form Look_InitSysStuff()
  84. int i;
  85. NONCLIENTMETRICS ncm;
  86. HKEY hkey;
  87. hdc = GetDC(NULL);
  88. g_LogDPI = GetDeviceCaps(hdc, LOGPIXELSY);
  89. g_bPalette = GetDeviceCaps(hdc, RASTERCAPS) & RC_PALETTE;
  90. ReleaseDC(NULL, hdc);
  91. // always make a palette even on non-pal device
  92. if (g_bPalette || TRUE)
  93. {
  94. DWORD pal[21];
  95. HPALETTE hpal = (HPALETTE)GetStockObject(DEFAULT_PALETTE);
  96. pal[1] = RGB(255, 255, 255);
  97. pal[2] = RGB(0, 0, 0 );
  98. pal[3] = RGB(192, 192, 192);
  99. pal[4] = RGB(128, 128, 128);
  100. pal[5] = RGB(255, 0, 0 );
  101. pal[6] = RGB(128, 0, 0 );
  102. pal[7] = RGB(255, 255, 0 );
  103. pal[8] = RGB(128, 128, 0 );
  104. pal[9] = RGB(0 , 255, 0 );
  105. pal[10] = RGB(0 , 128, 0 );
  106. pal[11] = RGB(0 , 255, 255);
  107. pal[12] = RGB(0 , 128, 128); // Needs to be changed to get Blue color
  108. pal[13] = RGB(0 , 0, 255);
  109. pal[14] = RGB(0 , 0, 128);
  110. pal[15] = RGB(255, 0, 255);
  111. pal[16] = RGB(128, 0, 128);
  112. GetPaletteEntries(hpal, 11, 1, (LPPALETTEENTRY)&pal[17]);
  113. pal[0] = MAKELONG(0x300, 17);
  114. g_hpalVGA = CreatePalette((LPLOGPALETTE)pal);
  115. // get magic colors
  116. GetPaletteEntries(hpal, 8, 4, (LPPALETTEENTRY)&pal[17]);
  117. pal[0] = MAKELONG(0x300, 20);
  118. g_hpal3D = CreatePalette((LPLOGPALETTE)pal);
  119. }
  120. // system colors
  121. for (i = 0; i < NT40_COLOR_MAX; i++)
  122. {
  123. g_Options.m_schemePreview.m_rgb[i] = GetSysColor(i);
  124. g_brushes[i] = NULL;
  125. }
  126. // sizes and fonts
  127. ncm.cbSize = sizeof(ncm);
  128. SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(ncm),
  129. (void far *)(LPNONCLIENTMETRICS)&ncm, FALSE);
  130. SetMyNonClientMetrics(&ncm);
  131. SystemParametersInfo(SPI_GETICONTITLELOGFONT, sizeof(LOGFONT),
  132. (void far *)(LPLOGFONT)&(g_fonts[FONT_ICONTITLE].lf), FALSE);
  133. SystemParametersInfo(SPI_SETGRADIENTCAPTIONS, 0, (PVOID)TRUE, 0);
  134. // default shell icon sizes
  135. g_sizes[ SIZE_ICON ].CurSize = GetSystemMetrics( SM_CXICON );
  136. g_sizes[ SIZE_SMICON ].CurSize = g_sizes[ SIZE_ICON ].CurSize / 2;
  137. if( RegOpenKeyEx( HKEY_CURRENT_USER, c_szRegPathUserMetrics, 0, KEY_QUERY_VALUE, &hkey )
  138. == ERROR_SUCCESS )
  139. {
  140. TCHAR val[ 8 ];
  141. LONG len = sizeof( val );
  142. if( RegQueryValueEx( hkey, c_szRegValIconSize, 0, NULL, (LPBYTE)val,
  143. (LPDWORD)&len ) == ERROR_SUCCESS )
  144. {
  145. val[ARRAYSIZE(val)-1] = TEXT('\0'); // ensure NUL termination
  146. g_sizes[ SIZE_ICON ].CurSize = (int)MyStrToLong( val );
  147. }
  148. len = SIZEOF( val );
  149. if( RegQueryValueEx( hkey, c_szRegValSmallIconSize, 0, NULL, (LPBYTE)val,
  150. (LPDWORD)&len ) == ERROR_SUCCESS )
  151. {
  152. val[ARRAYSIZE(val)-1] = TEXT('\0'); // ensure NUL termination
  153. g_sizes[ SIZE_SMICON ].CurSize = (int)MyStrToLong( val );
  154. }
  155. RegCloseKey( hkey );
  156. }
  157. g_sizes[ SIZE_DXICON ].CurSize =
  158. GetSystemMetrics( SM_CXICONSPACING ) - g_sizes[ SIZE_ICON ].CurSize;
  159. if( g_sizes[ SIZE_DXICON ].CurSize < 0 )
  160. g_sizes[ SIZE_DXICON ].CurSize = DEF_SPACING;
  161. g_sizes[ SIZE_DYICON ].CurSize =
  162. GetSystemMetrics( SM_CYICONSPACING ) - g_sizes[ SIZE_ICON ].CurSize;
  163. if( g_sizes[ SIZE_DYICON ].CurSize < 0 )
  164. g_sizes[ SIZE_DYICON ].CurSize = DEF_SPACING;
  165. // clean out the memory
  166. for (i = 0; i < NUM_FONTS; i++)
  167. {
  168. g_fonts[i].hfont = NULL;
  169. }
  170. // build all the brushes/fonts we need
  171. Look_RebuildSysStuff(TRUE);
  172. // From Look_InitDialog
  173. // initialize some globals
  174. cyBorder = GetSystemMetrics(SM_CYBORDER);
  175. cxBorder = GetSystemMetrics(SM_CXBORDER);
  176. cxEdge = GetSystemMetrics(SM_CXEDGE);
  177. cyEdge = GetSystemMetrics(SM_CYEDGE);
  178. return TRUE;
  179. }
  180. //////////////////////////////////////////////////////////////
  181. // CLookPreviewGlobals member functions
  182. //
  183. // This is the static window proc function of CLookPrev
  184. LRESULT CALLBACK CLookPrev::LookPreviewWndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  185. {
  186. PAINTSTRUCT ps;
  187. CLookPrev *pThis = (CLookPrev *)GetWindowLongPtr(hWnd, GWLP_USERDATA);
  188. if(!pThis)
  189. {
  190. // Create the class to handle this object
  191. // Store the 'this' pointer in
  192. pThis = new CLookPrev;
  193. if (!pThis)
  194. return ERROR_NOT_ENOUGH_MEMORY; // Prefix #113776 (catch null pointer)
  195. pThis->m_hwnd = hWnd;
  196. SetWindowLongPtr (hWnd, GWLP_USERDATA, (INT_PTR)pThis);
  197. }
  198. switch(message)
  199. {
  200. case WM_NCCREATE:
  201. {
  202. DWORD dw;
  203. dw = GetWindowLong (hWnd,GWL_STYLE);
  204. SetWindowLong (hWnd, GWL_STYLE, dw | WS_BORDER);
  205. dw = GetWindowLong (hWnd,GWL_EXSTYLE);
  206. SetWindowLong (hWnd, GWL_EXSTYLE, dw | WS_EX_CLIENTEDGE);
  207. }
  208. return TRUE;
  209. case WM_CREATE:
  210. pThis->OnCreate();
  211. break;
  212. case WM_PALETTECHANGED:
  213. if ((HWND)wParam == hWnd)
  214. break;
  215. //fallthru
  216. case WM_QUERYNEWPALETTE:
  217. if (g_hpal3D)
  218. InvalidateRect(hWnd, NULL, FALSE);
  219. break;
  220. case WM_PAINT:
  221. BeginPaint(hWnd, &ps);
  222. pThis->OnPaint(ps.hdc);
  223. EndPaint(hWnd, &ps);
  224. return 0;
  225. case LPM_REPAINT:
  226. pThis->OnRepaint();
  227. return 0;
  228. case LPM_RECALC:
  229. pThis->OnRecalc();
  230. return 0;
  231. }
  232. return DefWindowProc(hWnd,message,wParam,lParam);
  233. }
  234. void CLookPrev::OnCreate()
  235. {
  236. // Load menu for window
  237. m_hmenuSample = LoadMenu(g_hInstDll, MAKEINTRESOURCE(IDR_MENU));
  238. EnableMenuItem(m_hmenuSample, IDM_DISABLED, MF_GRAYED | MF_BYCOMMAND);
  239. HiliteMenuItem(m_hwnd, m_hmenuSample, IDM_SELECTED, MF_HILITE | MF_BYCOMMAND);
  240. // Create Bitmap for window
  241. RECT rc;
  242. HDC hdc;
  243. GetClientRect(m_hwnd, &rc);
  244. hdc = GetDC(NULL);
  245. m_hbmLook = CreateCompatibleBitmap(hdc, rc.right - rc.left, rc.bottom - rc.top);
  246. ReleaseDC(NULL, hdc);
  247. // Mirror the memory DC if the window is mirrored to keep the text readable.
  248. if (GetWindowLong(m_hwnd, GWL_EXSTYLE) & WS_EX_LAYOUTRTL) {
  249. SetLayout(g_hdcMem, LAYOUT_RTL);
  250. }
  251. }
  252. void CLookPrev::OnDestroy()
  253. {
  254. if (m_hbmLook)
  255. DeleteObject(m_hbmLook);
  256. if (m_hmenuSample)
  257. DestroyMenu(m_hmenuSample);
  258. // Un-allocate memory for this instance of the class
  259. delete this;
  260. }
  261. void CLookPrev::OnPaint(HDC hdc)
  262. {
  263. if (m_hbmLook)
  264. ShowBitmap(hdc);
  265. else
  266. Draw(hdc);
  267. }
  268. void CLookPrev::ShowBitmap(HDC hdc)
  269. {
  270. RECT rc;
  271. HBITMAP hbmOld;
  272. HPALETTE hpalOld = NULL;
  273. if (g_hpal3D)
  274. {
  275. hpalOld = SelectPalette(hdc, g_hpal3D, FALSE);
  276. RealizePalette(hdc);
  277. }
  278. GetClientRect(m_hwnd, &rc);
  279. hbmOld = (HBITMAP)SelectObject(g_hdcMem, m_hbmLook);
  280. BitBlt(hdc, 0, 0, rc.right - rc.left, rc.bottom - rc.top, g_hdcMem, 0, 0, SRCCOPY);
  281. SelectObject(g_hdcMem, hbmOld);
  282. if (hpalOld)
  283. {
  284. SelectPalette(hdc, hpalOld, FALSE);
  285. RealizePalette(hdc);
  286. }
  287. }
  288. void CLookPrev::Draw(HDC hdc)
  289. {
  290. RECT rcT;
  291. int nMode;
  292. DWORD rgbBk;
  293. int cySize;
  294. HANDLE hOldColors;
  295. HPALETTE hpalOld = NULL;
  296. HICON hiconLogo;
  297. // HFONT hfontOld;
  298. SaveDC(hdc);
  299. if (g_hpal3D)
  300. {
  301. hpalOld = SelectPalette(hdc, g_hpal3D, TRUE);
  302. RealizePalette(hdc);
  303. }
  304. hOldColors = SetSysColorsTemp(g_Options.m_schemePreview.m_rgb, g_brushes, COLOR_MAX_97_NT5/*COLOR_MAX_95_NT4*/);
  305. hiconLogo = (HICON)LoadImage(NULL, IDI_APPLICATION, IMAGE_ICON,
  306. g_sizes[SIZE_CAPTION].CurSize - 2*cxBorder,
  307. g_sizes[SIZE_CAPTION].CurSize - 2*cyBorder, 0);
  308. //
  309. // Setup drawing stuff
  310. //
  311. nMode = SetBkMode(hdc, TRANSPARENT);
  312. rgbBk = GetTextColor(hdc);
  313. // cxSize = GetSystemMetrics(SM_CXSIZE);
  314. cySize = GetSystemMetrics(SM_CYSIZE);
  315. //
  316. // Desktop
  317. //
  318. FillRect(hdc, &RCZ(ELEMENT_DESKTOP), g_brushes[COLOR_BACKGROUND]);
  319. //
  320. // Inactive window
  321. //
  322. // Border
  323. rcT = RCZ(ELEMENT_INACTIVEBORDER);
  324. DrawEdge(hdc, &rcT, EDGE_RAISED, BF_RECT | BF_ADJUST);
  325. MyDrawFrame(hdc, &rcT, g_brushes[COLOR_INACTIVEBORDER], g_sizes[SIZE_FRAME].CurSize);
  326. MyDrawFrame(hdc, &rcT, g_brushes[COLOR_3DFACE], 1);
  327. // Caption
  328. rcT = RCZ(ELEMENT_INACTIVECAPTION);
  329. MyDrawBorderBelow(hdc, &rcT);
  330. // NOTE: because USER draws icon stuff using its own DC and subsequently
  331. // its own palette, we need to make sure to use the inactivecaption
  332. // brush before USER does so that it will be realized against our palette.
  333. // this might get fixed in USER by better be safe.
  334. // "clip" the caption title under the buttons
  335. rcT.left = RCZ(ELEMENT_INACTIVESYSBUT2).left - cyEdge;
  336. FillRect(hdc, &rcT, g_brushes[COLOR_GRADIENTINACTIVECAPTION]);
  337. rcT.right = rcT.left;
  338. rcT.left = RCZ(ELEMENT_INACTIVECAPTION).left;
  339. DrawCaptionTemp(NULL, hdc, &rcT, g_fonts[FONT_CAPTION].hfont, hiconLogo, sm_Globals.m_szInactive, DC_ICON | DC_TEXT | DC_GRADIENT);
  340. DrawFrameControl(hdc, &RCZ(ELEMENT_INACTIVESYSBUT1), DFC_CAPTION, DFCS_CAPTIONCLOSE);
  341. rcT = RCZ(ELEMENT_INACTIVESYSBUT2);
  342. rcT.right -= (rcT.right - rcT.left)/2;
  343. DrawFrameControl(hdc, &rcT, DFC_CAPTION, DFCS_CAPTIONMIN);
  344. rcT.left = rcT.right;
  345. rcT.right = RCZ(ELEMENT_INACTIVESYSBUT2).right;
  346. DrawFrameControl(hdc, &rcT, DFC_CAPTION, DFCS_CAPTIONMAX);
  347. #if 0
  348. //
  349. // small caption window
  350. //
  351. {
  352. HICON hicon;
  353. int temp;
  354. rcT = RCZ(ELEMENT_SMCAPTION);
  355. hicon = (HICON)LoadImage(NULL, IDI_APPLICATION,
  356. IMAGE_ICON,
  357. g_sizes[SIZE_SMCAPTION].CurSize - 2*cxBorder,
  358. g_sizes[SIZE_SMCAPTION].CurSize - 2*cyBorder,
  359. 0);
  360. DrawEdge(hdc, &rcT, EDGE_RAISED, BF_TOP | BF_LEFT | BF_RIGHT | BF_ADJUST);
  361. MyDrawFrame(hdc, &rcT, g_brushes[COLOR_3DFACE], 1);
  362. // "clip" the caption title under the buttons
  363. temp = rcT.left; // remember start of actual caption
  364. rcT.left = RCZ(ELEMENT_SMCAPSYSBUT).left - cxEdge;
  365. FillRect(hdc, &rcT, g_brushes[COLOR_ACTIVECAPTION]);
  366. rcT.right = rcT.left;
  367. rcT.left = temp; // start of actual caption
  368. DrawCaptionTemp(NULL, hdc, &rcT, g_fonts[FONT_SMCAPTION].hfont, hicon, sm_Globals.m_szSmallCaption, DC_SMALLCAP | DC_ICON | DC_TEXT);
  369. DestroyIcon(hicon);
  370. DrawFrameControl(hdc, &RCZ(ELEMENT_SMCAPSYSBUT), DFC_CAPTION, DFCS_CAPTIONCLOSE);
  371. }
  372. #endif
  373. //
  374. // Active window
  375. //
  376. // Border
  377. rcT = RCZ(ELEMENT_ACTIVEBORDER);
  378. DrawEdge(hdc, &rcT, EDGE_RAISED, BF_RECT | BF_ADJUST);
  379. MyDrawFrame(hdc, &rcT, g_brushes[COLOR_ACTIVEBORDER], g_sizes[SIZE_FRAME].CurSize);
  380. MyDrawFrame(hdc, &rcT, g_brushes[COLOR_3DFACE], 1);
  381. // Caption
  382. rcT = RCZ(ELEMENT_ACTIVECAPTION);
  383. MyDrawBorderBelow(hdc, &rcT);
  384. // "clip" the caption title under the buttons
  385. rcT.left = RCZ(ELEMENT_ACTIVESYSBUT2).left - cxEdge;
  386. FillRect(hdc, &rcT, g_brushes[COLOR_GRADIENTACTIVECAPTION]);
  387. rcT.right = rcT.left;
  388. rcT.left = RCZ(ELEMENT_ACTIVECAPTION).left;
  389. DrawCaptionTemp(NULL, hdc, &rcT, g_fonts[FONT_CAPTION].hfont, hiconLogo, sm_Globals.m_szActive, DC_ACTIVE | DC_ICON | DC_TEXT | DC_GRADIENT);
  390. DrawFrameControl(hdc, &RCZ(ELEMENT_ACTIVESYSBUT1), DFC_CAPTION, DFCS_CAPTIONCLOSE);
  391. rcT = RCZ(ELEMENT_ACTIVESYSBUT2);
  392. rcT.right -= (rcT.right - rcT.left)/2;
  393. DrawFrameControl(hdc, &rcT, DFC_CAPTION, DFCS_CAPTIONMIN);
  394. rcT.left = rcT.right;
  395. rcT.right = RCZ(ELEMENT_ACTIVESYSBUT2).right;
  396. DrawFrameControl(hdc, &rcT, DFC_CAPTION, DFCS_CAPTIONMAX);
  397. // Menu
  398. rcT = RCZ(ELEMENT_MENUNORMAL);
  399. #if 0 // HACK TO SLIP USING DrawMenuBarTemp() which is not available on Memphis
  400. DrawMenuBarTemp(m_hwnd, hdc, &rcT, g_Options.m_hmenuSample, g_fonts[FONT_MENU].hfont);
  401. #else
  402. {
  403. // JMC: HACK - HARD CODED TEXT
  404. HFONT hOldFont = (HFONT)SelectObject(hdc, g_fonts[FONT_MENU].hfont);
  405. COLORREF clrrefOldText = SetTextColor(hdc, g_Options.m_schemePreview.m_rgb[COLOR_MENUTEXT]);
  406. COLORREF clrrefOldBk = SetBkColor(hdc, g_Options.m_schemePreview.m_rgb[COLOR_MENU]);
  407. int nOldMode = SetBkMode(hdc, OPAQUE);
  408. // LPCTSTR lpszText = __TEXT(" File Edit Help");
  409. TCHAR szText[200];
  410. LoadString(g_hInstDll, IDS_PREVIEWMENUTEXT, szText, ARRAYSIZE(szText));
  411. ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rcT, NULL, 0, NULL);
  412. DrawText(hdc, szText, lstrlen(szText), &rcT, DT_VCENTER | DT_SINGLELINE | DT_EXPANDTABS);
  413. SetTextColor(hdc, clrrefOldText);
  414. SetBkColor(hdc, clrrefOldBk);
  415. SetBkMode(hdc, nOldMode);
  416. SelectObject(hdc, hOldFont);
  417. }
  418. #endif
  419. MyDrawBorderBelow(hdc, &rcT);
  420. //
  421. // Client area
  422. //
  423. rcT = RCZ(ELEMENT_WINDOW);
  424. DrawEdge(hdc, &rcT, EDGE_SUNKEN, BF_RECT | BF_ADJUST);
  425. FillRect(hdc, &rcT, g_brushes[COLOR_WINDOW]);
  426. // window text
  427. SetBkMode(hdc, TRANSPARENT);
  428. SetTextColor(hdc, g_Options.m_schemePreview.m_rgb[COLOR_WINDOWTEXT]);
  429. TextOut(hdc, RCZ(ELEMENT_WINDOW).left + 2*cxEdge, RCZ(ELEMENT_WINDOW).top + 2*cyEdge, sm_Globals.m_szWindowText, lstrlen(sm_Globals.m_szWindowText));
  430. //
  431. // scroll bar
  432. //
  433. rcT = RCZ(ELEMENT_SCROLLBAR);
  434. //MyDrawFrame(hdc, &rcT, g_brushes[COLOR_3DSHADOW], 1);
  435. //g_brushes[COLOR_SCROLLBAR]);
  436. //FillRect(hdc, &rcT, (HBRUSH)DefWindowProc(m_hwnd, WM_CTLCOLORSCROLLBAR, (WPARAM)hdc, (LPARAM)m_hwnd));
  437. FillRect(hdc, &rcT, g_brushes[COLOR_SCROLLBAR]);
  438. DrawFrameControl(hdc, &RCZ(ELEMENT_SCROLLUP), DFC_SCROLL, DFCS_SCROLLUP);
  439. DrawFrameControl(hdc, &RCZ(ELEMENT_SCROLLDOWN), DFC_SCROLL, DFCS_SCROLLDOWN);
  440. #if 0 // Don't draw message box
  441. //
  442. // MessageBox
  443. //
  444. rcT = RCZ(ELEMENT_MSGBOX);
  445. DrawEdge(hdc, &rcT, EDGE_RAISED, BF_RECT | BF_ADJUST);
  446. FillRect(hdc, &rcT, g_brushes[COLOR_3DFACE]);
  447. rcT = RCZ(ELEMENT_MSGBOXCAPTION);
  448. MyDrawBorderBelow(hdc, &rcT);
  449. // "clip" the caption title under the buttons
  450. rcT.left = RCZ(ELEMENT_MSGBOXSYSBUT).left - cxEdge;
  451. FillRect(hdc, &rcT, g_brushes[COLOR_GRADIENTACTIVECAPTION]);
  452. rcT.right = rcT.left;
  453. rcT.left = RCZ(ELEMENT_MSGBOXCAPTION).left;
  454. DrawCaptionTemp(NULL, hdc, &rcT, g_fonts[FONT_CAPTION].hfont, hiconLogo, sm_Globals.m_szMsgBox, DC_ACTIVE | DC_ICON | DC_TEXT | DC_GRADIENT);
  455. DrawFrameControl(hdc, &RCZ(ELEMENT_MSGBOXSYSBUT), DFC_CAPTION, DFCS_CAPTIONCLOSE);
  456. // message box text
  457. SetBkMode(hdc, TRANSPARENT);
  458. SetTextColor(hdc, g_Options.m_schemePreview.m_rgb[COLOR_WINDOWTEXT]);
  459. hfontOld = (HFONT)SelectObject(hdc, g_fonts[FONT_MSGBOX].hfont);
  460. TextOut(hdc, RCZ(ELEMENT_MSGBOX).left + 3*cxEdge, RCZ(ELEMENT_MSGBOXCAPTION).bottom + cyEdge,
  461. sm_Globals.m_szMsgBoxText, lstrlen(sm_Globals.m_szMsgBoxText));
  462. if (hfontOld)
  463. SelectObject(hdc, hfontOld);
  464. //
  465. // Button
  466. //
  467. rcT = RCZ(ELEMENT_BUTTON);
  468. DrawFrameControl(hdc, &rcT, DFC_BUTTON, DFCS_BUTTONPUSH);
  469. // ?????? what font should this use ??????
  470. SetBkMode(hdc, TRANSPARENT);
  471. SetTextColor(hdc, g_Options.m_schemePreview.m_rgb[COLOR_BTNTEXT]);
  472. DrawText(hdc, sm_Globals.m_szButton, -1, &rcT, DT_CENTER | DT_NOPREFIX |
  473. DT_SINGLELINE | DT_VCENTER);
  474. #endif
  475. SetBkColor(hdc, rgbBk);
  476. SetBkMode(hdc, nMode);
  477. if (hiconLogo)
  478. DestroyIcon(hiconLogo);
  479. SetSysColorsTemp(NULL, NULL, (UINT_PTR)hOldColors);
  480. if (hpalOld)
  481. {
  482. hpalOld = SelectPalette(hdc, hpalOld, FALSE);
  483. RealizePalette(hdc);
  484. }
  485. RestoreDC(hdc, -1);
  486. }
  487. void CLookPrev::OnRepaint()
  488. {
  489. HBITMAP hbmOld;
  490. if (m_hbmLook)
  491. {
  492. hbmOld = (HBITMAP)SelectObject(g_hdcMem, m_hbmLook);
  493. Draw(g_hdcMem);
  494. SelectObject(g_hdcMem, hbmOld);
  495. }
  496. InvalidateRect(m_hwnd, NULL, FALSE);
  497. }
  498. void CLookPrev::OnRecalc()
  499. {
  500. DWORD cxNormal;
  501. int cxDisabled, cxSelected;
  502. int cxAvgCharx2;
  503. RECT rc;
  504. HFONT hfontT;
  505. int cxFrame, cyFrame;
  506. int cyCaption;
  507. int i;
  508. SIZE sizButton;
  509. GetClientRect(m_hwnd, &rc);
  510. //
  511. // Get our drawing data
  512. //
  513. cxSize = GetSystemMetrics(SM_CXSIZE);
  514. cxFrame = (g_sizes[SIZE_FRAME].CurSize + 1) * cxBorder + cxEdge;
  515. cyFrame = (g_sizes[SIZE_FRAME].CurSize + 1) * cyBorder + cyEdge;
  516. cyCaption = g_sizes[SIZE_CAPTION].CurSize;
  517. //
  518. // Get text dimensions, with proper font.
  519. //
  520. hfontT = (HFONT)SelectObject(g_hdcMem, g_fonts[FONT_MENU].hfont);
  521. GetTextExtentPoint32(g_hdcMem, sm_Globals.m_szNormal, lstrlen(sm_Globals.m_szNormal), &sizButton);
  522. cxNormal = sizButton.cx;
  523. GetTextExtentPoint32(g_hdcMem, sm_Globals.m_szDisabled, lstrlen(sm_Globals.m_szDisabled), &sizButton);
  524. cxDisabled = sizButton.cx;
  525. GetTextExtentPoint32(g_hdcMem, sm_Globals.m_szSelected, lstrlen(sm_Globals.m_szSelected), &sizButton);
  526. cxSelected = sizButton.cx;
  527. // get the average width (USER style) of menu font
  528. GetTextExtentPoint32(g_hdcMem, g_szABC, 52, &sizButton);
  529. cxAvgCharx2 = 2 * (sizButton.cx / 52);
  530. // actual menu-handling widths of strings is bigger
  531. cxDisabled += cxAvgCharx2;
  532. cxSelected += cxAvgCharx2;
  533. cxNormal += cxAvgCharx2;
  534. SelectObject(g_hdcMem, hfontT);
  535. GetTextExtentPoint32(g_hdcMem, sm_Globals.m_szButton, lstrlen(sm_Globals.m_szButton), &sizButton);
  536. //
  537. // Desktop
  538. //
  539. RCZ(ELEMENT_DESKTOP) = rc;
  540. InflateRect(&rc, -8*cxBorder, -8*cyBorder);
  541. //
  542. // Windows
  543. //
  544. rc.bottom -= cyFrame + cyCaption;
  545. RCZ(ELEMENT_ACTIVEBORDER) = rc;
  546. OffsetRect(&RCZ(ELEMENT_ACTIVEBORDER), cxFrame,
  547. cyFrame + cyCaption + cyBorder);
  548. RCZ(ELEMENT_ACTIVEBORDER).bottom -= cyCaption;
  549. //
  550. // Inactive window
  551. //
  552. rc.right -= cyCaption;
  553. RCZ(ELEMENT_INACTIVEBORDER) = rc;
  554. // Caption
  555. InflateRect(&rc, -cxFrame, -cyFrame);
  556. rc.bottom = rc.top + cyCaption + cyBorder;
  557. RCZ(ELEMENT_INACTIVECAPTION) = rc;
  558. // close button
  559. InflateRect(&rc, -cxEdge, -cyEdge);
  560. rc.bottom -= cyBorder; // compensate for magic line under caption
  561. RCZ(ELEMENT_INACTIVESYSBUT1) = rc;
  562. RCZ(ELEMENT_INACTIVESYSBUT1).left = rc.right - (cyCaption - cxEdge);
  563. // min/max buttons
  564. RCZ(ELEMENT_INACTIVESYSBUT2) = rc;
  565. RCZ(ELEMENT_INACTIVESYSBUT2).right = RCZ(ELEMENT_INACTIVESYSBUT1).left - cxEdge;
  566. RCZ(ELEMENT_INACTIVESYSBUT2).left = RCZ(ELEMENT_INACTIVESYSBUT2).right -
  567. 2 * (cyCaption - cxEdge);
  568. #if 0
  569. //
  570. // small caption window
  571. //
  572. RCZ(ELEMENT_SMCAPTION) = RCZ(ELEMENT_ACTIVEBORDER);
  573. RCZ(ELEMENT_SMCAPTION).bottom = RCZ(ELEMENT_SMCAPTION).top;
  574. RCZ(ELEMENT_SMCAPTION).top -= g_sizes[SIZE_SMCAPTION].CurSize + cyEdge + 2 * cyBorder;
  575. RCZ(ELEMENT_SMCAPTION).right -= cxFrame;
  576. RCZ(ELEMENT_SMCAPTION).left = RCZ(ELEMENT_INACTIVECAPTION).right + 2 * cxFrame;
  577. RCZ(ELEMENT_SMCAPSYSBUT) = RCZ(ELEMENT_SMCAPTION);
  578. // deflate inside frame/border to caption and then another edge's worth
  579. RCZ(ELEMENT_SMCAPSYSBUT).right -= 2 * cxEdge + cxBorder;
  580. RCZ(ELEMENT_SMCAPSYSBUT).top += 2 * cxEdge + cxBorder;
  581. RCZ(ELEMENT_SMCAPSYSBUT).bottom -= cxEdge + cxBorder;
  582. RCZ(ELEMENT_SMCAPSYSBUT).left = RCZ(ELEMENT_SMCAPSYSBUT).right -
  583. (g_sizes[SIZE_SMCAPTION].CurSize - cxEdge);
  584. #endif
  585. //
  586. // Active window
  587. //
  588. // Caption
  589. rc = RCZ(ELEMENT_ACTIVEBORDER);
  590. InflateRect(&rc, -cxFrame, -cyFrame);
  591. RCZ(ELEMENT_ACTIVECAPTION) = rc;
  592. RCZ(ELEMENT_ACTIVECAPTION).bottom =
  593. RCZ(ELEMENT_ACTIVECAPTION).top + cyCaption + cyBorder;
  594. // close button
  595. RCZ(ELEMENT_ACTIVESYSBUT1) = RCZ(ELEMENT_ACTIVECAPTION);
  596. InflateRect(&RCZ(ELEMENT_ACTIVESYSBUT1), -cxEdge, -cyEdge);
  597. RCZ(ELEMENT_ACTIVESYSBUT1).bottom -= cyBorder; // compensate for magic line under caption
  598. RCZ(ELEMENT_ACTIVESYSBUT1).left = RCZ(ELEMENT_ACTIVESYSBUT1).right -
  599. (cyCaption - cxEdge);
  600. // min/max buttons
  601. RCZ(ELEMENT_ACTIVESYSBUT2) = RCZ(ELEMENT_ACTIVESYSBUT1);
  602. RCZ(ELEMENT_ACTIVESYSBUT2).right = RCZ(ELEMENT_ACTIVESYSBUT1).left - cxEdge;
  603. RCZ(ELEMENT_ACTIVESYSBUT2).left = RCZ(ELEMENT_ACTIVESYSBUT2).right -
  604. 2 * (cyCaption - cxEdge);
  605. // Menu
  606. rc.top = RCZ(ELEMENT_ACTIVECAPTION).bottom;
  607. RCZ(ELEMENT_MENUNORMAL) = rc;
  608. rc.top = RCZ(ELEMENT_MENUNORMAL).bottom = RCZ(ELEMENT_MENUNORMAL).top + g_sizes[SIZE_MENU].CurSize;
  609. RCZ(ELEMENT_MENUDISABLED) = RCZ(ELEMENT_MENUSELECTED) = RCZ(ELEMENT_MENUNORMAL);
  610. RCZ(ELEMENT_MENUDISABLED).left = RCZ(ELEMENT_MENUNORMAL).left + cxNormal;
  611. RCZ(ELEMENT_MENUDISABLED).right = RCZ(ELEMENT_MENUSELECTED).left =
  612. RCZ(ELEMENT_MENUDISABLED).left + cxDisabled;
  613. RCZ(ELEMENT_MENUSELECTED).right = RCZ(ELEMENT_MENUSELECTED).left + cxSelected;
  614. //
  615. // Client
  616. //
  617. RCZ(ELEMENT_WINDOW) = rc;
  618. //
  619. // Scrollbar
  620. //
  621. InflateRect(&rc, -cxEdge, -cyEdge); // take off client edge
  622. RCZ(ELEMENT_SCROLLBAR) = rc;
  623. rc.right = RCZ(ELEMENT_SCROLLBAR).left = rc.right - g_sizes[SIZE_SCROLL].CurSize;
  624. RCZ(ELEMENT_SCROLLUP) = RCZ(ELEMENT_SCROLLBAR);
  625. RCZ(ELEMENT_SCROLLUP).bottom = RCZ(ELEMENT_SCROLLBAR).top + g_sizes[SIZE_SCROLL].CurSize;
  626. RCZ(ELEMENT_SCROLLDOWN) = RCZ(ELEMENT_SCROLLBAR);
  627. RCZ(ELEMENT_SCROLLDOWN).top = RCZ(ELEMENT_SCROLLBAR).bottom - g_sizes[SIZE_SCROLL].CurSize;
  628. //
  629. // Message Box
  630. //
  631. rc.top = RCZ(ELEMENT_WINDOW).top + (RCZ(ELEMENT_WINDOW).bottom - RCZ(ELEMENT_WINDOW).top) / 2;
  632. rc.bottom = RCZ(ELEMENT_DESKTOP).bottom - 2*cyEdge;
  633. rc.left = RCZ(ELEMENT_WINDOW).left + 2*cyEdge;
  634. rc.right = RCZ(ELEMENT_WINDOW).left + (RCZ(ELEMENT_WINDOW).right - RCZ(ELEMENT_WINDOW).left) / 2 + 3*cyCaption;
  635. RCZ(ELEMENT_MSGBOX) = rc;
  636. // Caption
  637. RCZ(ELEMENT_MSGBOXCAPTION) = rc;
  638. RCZ(ELEMENT_MSGBOXCAPTION).top += cyEdge + cyBorder;
  639. RCZ(ELEMENT_MSGBOXCAPTION).bottom = RCZ(ELEMENT_MSGBOXCAPTION).top + cyCaption + cyBorder;
  640. RCZ(ELEMENT_MSGBOXCAPTION).left += cxEdge + cxBorder;
  641. RCZ(ELEMENT_MSGBOXCAPTION).right -= cxEdge + cxBorder;
  642. RCZ(ELEMENT_MSGBOXSYSBUT) = RCZ(ELEMENT_MSGBOXCAPTION);
  643. InflateRect(&RCZ(ELEMENT_MSGBOXSYSBUT), -cxEdge, -cyEdge);
  644. RCZ(ELEMENT_MSGBOXSYSBUT).left = RCZ(ELEMENT_MSGBOXSYSBUT).right -
  645. (cyCaption - cxEdge);
  646. RCZ(ELEMENT_MSGBOXSYSBUT).bottom -= cyBorder; // line under caption
  647. // Button
  648. RCZ(ELEMENT_BUTTON).bottom = RCZ(ELEMENT_MSGBOX).bottom - (4*cyBorder + cyEdge);
  649. RCZ(ELEMENT_BUTTON).top = RCZ(ELEMENT_BUTTON).bottom - (sizButton.cy + 8 * cyBorder);
  650. i = (RCZ(ELEMENT_BUTTON).bottom - RCZ(ELEMENT_BUTTON).top) * 3;
  651. RCZ(ELEMENT_BUTTON).left = (rc.left + (rc.right - rc.left)/2) - i/2;
  652. RCZ(ELEMENT_BUTTON).right = RCZ(ELEMENT_BUTTON).left + i;
  653. }
  654. /////////////////////////////////////////////////////////
  655. // Support functions
  656. // ----------------------------------------------------------------------------
  657. //
  658. // MyDrawFrame() -
  659. //
  660. // Draws bordered frame, border size cl, and adjusts passed in rect.
  661. //
  662. // ----------------------------------------------------------------------------
  663. void MyDrawFrame(HDC hdc, LPRECT prc, HBRUSH hbrColor, int cl)
  664. {
  665. HBRUSH hbr;
  666. int cx, cy;
  667. RECT rcT;
  668. rcT = *prc;
  669. cx = cl * cxBorder;
  670. cy = cl * cyBorder;
  671. hbr = (HBRUSH)SelectObject(hdc, hbrColor);
  672. PatBlt(hdc, rcT.left, rcT.top, cx, rcT.bottom - rcT.top, PATCOPY);
  673. rcT.left += cx;
  674. PatBlt(hdc, rcT.left, rcT.top, rcT.right - rcT.left, cy, PATCOPY);
  675. rcT.top += cy;
  676. rcT.right -= cx;
  677. PatBlt(hdc, rcT.right, rcT.top, cx, rcT.bottom - rcT.top, PATCOPY);
  678. rcT.bottom -= cy;
  679. PatBlt(hdc, rcT.left, rcT.bottom, rcT.right - rcT.left, cy, PATCOPY);
  680. hbr = (HBRUSH)SelectObject(hdc, hbr);
  681. *prc = rcT;
  682. }
  683. /*
  684. ** draw a cyBorder band of 3DFACE at the bottom of the given rectangle.
  685. ** also, adjust the rectangle accordingly.
  686. */
  687. void MyDrawBorderBelow(HDC hdc, LPRECT prc)
  688. {
  689. int i;
  690. i = prc->top;
  691. prc->top = prc->bottom - cyBorder;
  692. FillRect(hdc, prc, g_brushes[COLOR_3DFACE]);
  693. prc->top = i;
  694. prc->bottom -= cyBorder;
  695. }
  696. /*-------------------------------------------------------------------
  697. ** draw a full window caption with system menu, minimize button,
  698. ** maximize button, and text.
  699. **-------------------------------------------------------------------*/
  700. void DrawFullCaption(HDC hdc, LPRECT prc, LPTSTR lpszTitle, UINT flags)
  701. {
  702. int iRight;
  703. int iFont;
  704. SaveDC(hdc);
  705. // special case gross for small caption that already drew on bottom
  706. if (!(flags & DC_SMALLCAP))
  707. MyDrawBorderBelow(hdc, prc);
  708. iRight = prc->right;
  709. prc->right = prc->left + cxSize;
  710. DrawFrameControl(hdc, prc, DFC_CAPTION, DFCS_CAPTIONCLOSE);
  711. prc->left = prc->right;
  712. prc->right = iRight - 2*cxSize;
  713. iFont = flags & DC_SMALLCAP ? FONT_SMCAPTION : FONT_CAPTION;
  714. DrawCaptionTemp(NULL, hdc, prc, g_fonts[iFont].hfont, NULL, lpszTitle, flags | DC_ICON | DC_TEXT);
  715. prc->left = prc->right;
  716. prc->right = prc->left + cxSize;
  717. DrawFrameControl(hdc, prc, DFC_CAPTION, DFCS_CAPTIONMIN);
  718. prc->left = prc->right;
  719. prc->right = prc->left + cxSize;
  720. DrawFrameControl(hdc, prc, DFC_CAPTION, DFCS_CAPTIONMAX);
  721. RestoreDC(hdc, -1);
  722. }