lookprev.cpp
Upload User: xhy777
Upload Date: 2007-02-14
Package Size: 24088k
Code Size: 26k
Category:

Windows Kernel

Development Platform:

Visual C++

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