Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

761 lines
21 KiB

  1. #include "precomp.h"
  2. #pragma hdrstop
  3. /*****************************************************************************
  4. * *
  5. * SBUTTON.C *
  6. * *
  7. * Program Description: Implements "3-D" buttons *
  8. * *
  9. ******************************************************************************
  10. * *
  11. * Revision History: Created by Todd Laney, Munged 3/27/89 by Robert Bunney *
  12. * 7/25/89 - revised by Chris Guzak for transparent *
  13. * color bitmaps. *
  14. * 7/26/89 - revised by Todd Laney to handle multi-res *
  15. * bitmaps. *
  16. * windows 3 support *
  17. * *
  18. *****************************************************************************/
  19. #define NOCOMM
  20. //
  21. // if WIN2 is defined the code will work in windows 2.x and windows 3.0
  22. // otherwise windows 3.0 is required
  23. //
  24. /*****************************************************************************
  25. * *
  26. * Defines *
  27. * *
  28. *****************************************************************************/
  29. #if DBG
  30. #define PRIV
  31. #else
  32. #define PRIV static
  33. #endif
  34. #define rgbWhite RGB(255,255,255)
  35. #define rgbBlack RGB(0,0,0)
  36. #define ISDIGIT(c) ((c) >= '0' && (c) <= '9')
  37. #define BEVEL 2
  38. #define FRAME 1
  39. #define GWW_HBM 0
  40. #define GWW_STATE GWW_HBM + sizeof(PVOID)
  41. #define GWW_FLAGS GWW_STATE + sizeof(DWORD)
  42. #define GWW_CHECK GWW_FLAGS + sizeof(DWORD)
  43. #define GWW_SIZE GWW_CHECK + sizeof(DWORD)
  44. #define GETSTYLE(hwnd) (LOWORD(GetWindowLong(hwnd,GWL_STYLE)))
  45. #define GETSTATE(hwnd) GetWindowLong(hwnd,GWW_STATE)
  46. #define GETFLAGS(hwnd) GetWindowLong(hwnd,GWW_FLAGS)
  47. #define GETCHECK(hwnd) GetWindowLong(hwnd,GWW_CHECK)
  48. #define GETHBM(hwnd) GetWindowLongPtr(hwnd,GWW_HBM)
  49. #define lpCreate ((LPCREATESTRUCT)lParam)
  50. #define DPSoa 0x00A803A9L
  51. #define DSPDxax 0x00E20746L
  52. #define EraseButton(hwnd,hdc,prc) ExtTextOut(hdc,0,0,ETO_OPAQUE,prc,NULL,0,NULL)
  53. #define NearestColor(hdc,rgb) (GetNearestColor(hdc,rgb) & 0x00FFFFFFL)
  54. /*****************************************************************************
  55. * *
  56. * Prototypes *
  57. * *
  58. *****************************************************************************/
  59. PRIV VOID DrawGrayButton (HWND, HDC, LPRECT, WORD, WORD);
  60. PRIV VOID DrawButtonFace (HWND, HDC, PRECT, WORD);
  61. PRIV BOOL PaintButton (HWND, HDC);
  62. PRIV VOID NotifyParent (HWND);
  63. PRIV VOID PatB (HDC, int, int, int, int, DWORD);
  64. PRIV HBITMAP LoadBitmapResource(HANDLE hInst, LPSTR lpName);
  65. PRIV VOID BitmapColorTranslate(HDC hdcBits, BITMAP* pbm, DWORD rgb);
  66. /*****************************************************************************
  67. * *
  68. * Variabls *
  69. * *
  70. *****************************************************************************/
  71. HBRUSH hbrGray = NULL; // Gray for text
  72. HBRUSH hbrFocus = NULL; // focus for text
  73. DWORD rgbButtonFocus;
  74. DWORD rgbButtonFace;
  75. DWORD rgbButtonText;
  76. DWORD rgbButtonShadow;
  77. PRIV char szColor[] = "Colors"; // Name of color section
  78. PRIV char szButton[] = "sbutton";
  79. /*---------------------------------------------------------------------------*\
  80. | ButtonControlInit( hInst ) |
  81. | |
  82. | Description: |
  83. | This is called when the application is first loaded into |
  84. | memory. It performs all button initialization. |
  85. | |
  86. | Arguments: |
  87. | hInst instance handle of current instance |
  88. | |
  89. | Returns: |
  90. | TRUE if successful, FALSE if not |
  91. | |
  92. \*----------------------------------------------------------------------------*/
  93. BOOL
  94. ButtonControlInit(
  95. IN HANDLE hInst
  96. )
  97. {
  98. WNDCLASS cls;
  99. UINT patGray[8];
  100. HBITMAP hbmGray;
  101. int i;
  102. HDC hdc;
  103. /* initialize the brushes */
  104. for (i=0; i<8; i+=2) {
  105. patGray[i] = 0x0000AAAA;
  106. patGray[i+1] = 0x00005555;
  107. }
  108. hbmGray = CreateBitmap(8, 8, 1, 1, (LPSTR)patGray);
  109. hbrGray = CreatePatternBrush(hbmGray);
  110. if (hbmGray) {
  111. DeleteObject(hbmGray);
  112. }
  113. hdc = GetDC(NULL);
  114. if (hdc) {
  115. rgbButtonFace = GetSysColor(COLOR_BTNFACE);
  116. rgbButtonShadow = GetSysColor(COLOR_BTNSHADOW);
  117. rgbButtonText = GetSysColor(COLOR_BTNTEXT);
  118. rgbButtonFocus = rgbWhite; // ??
  119. rgbButtonFace = NearestColor(hdc,rgbButtonFace);
  120. rgbButtonShadow = NearestColor(hdc,rgbButtonShadow);
  121. rgbButtonText = NearestColor(hdc,rgbButtonText);
  122. rgbButtonFocus = NearestColor(hdc,rgbButtonFocus);
  123. if (rgbButtonFocus == rgbButtonFace)
  124. rgbButtonFocus = rgbButtonText;
  125. ReleaseDC(NULL,hdc);
  126. }
  127. hbrFocus = CreateSolidBrush(rgbButtonFocus);
  128. cls.hCursor = LoadCursor(NULL,IDC_ARROW);
  129. cls.hIcon = NULL;
  130. cls.lpszMenuName = NULL;
  131. cls.lpszClassName = (LPSTR)szButton;
  132. cls.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  133. cls.hInstance = hInst;
  134. cls.style = CS_HREDRAW | CS_VREDRAW;
  135. cls.lpfnWndProc = fnButton;
  136. cls.cbClsExtra = 0;
  137. cls.cbWndExtra = GWW_SIZE;
  138. return(RegisterClass(&cls));
  139. }
  140. VOID
  141. ButtonControlTerm(
  142. VOID
  143. )
  144. {
  145. if (hbrGray)
  146. DeleteObject(hbrGray);
  147. if (hbrFocus)
  148. DeleteObject(hbrFocus);
  149. UnregisterClass(szButton,hInst);
  150. }
  151. /*----------------------------------------------------------------------------*\
  152. | |
  153. | Custom push-button |
  154. | |
  155. \*----------------------------------------------------------------------------*/
  156. PRIV BOOL PaintButton(HWND hwnd, HDC hdc)
  157. {
  158. WORD style;
  159. RECT rc;
  160. WORD f;
  161. HDC hdcMem;
  162. HBITMAP hbmMem,hbmT;
  163. GetClientRect(hwnd,&rc);
  164. if (!RectVisible(hdc,&rc))
  165. return TRUE;
  166. style = (WORD)((DWORD)GETSTYLE(hwnd) | ((DWORD)GETFLAGS(hwnd) & 0xFF00));
  167. f = (WORD)GETSTATE(hwnd);
  168. hdcMem = CreateCompatibleDC(hdc);
  169. hbmMem = CreateCompatibleBitmap(hdc,rc.right,rc.bottom);
  170. switch (LOBYTE(style))
  171. {
  172. case BS_PUSHBUTTON:
  173. case BS_DEFPUSHBUTTON:
  174. if (hdcMem && hbmMem)
  175. {
  176. hbmT = SelectObject(hdcMem,hbmMem);
  177. DrawGrayButton(hwnd, hdcMem, &rc, style, f);
  178. BitBlt(hdc,0,0,rc.right,rc.bottom,hdcMem,0,0,SRCCOPY);
  179. SelectObject(hdcMem,hbmT);
  180. }
  181. else
  182. {
  183. DrawGrayButton(hwnd, hdc, &rc, style, f);
  184. }
  185. break;
  186. }
  187. if (hbmMem)
  188. DeleteObject(hbmMem);
  189. if (hdcMem)
  190. DeleteDC(hdcMem);
  191. return TRUE;
  192. }
  193. /*******************
  194. **
  195. ** Name: ButtonState
  196. **
  197. ** Purpose: Compares the passed state (f) with the current state. If
  198. ** they differ, the button is invalidated and TRUE is
  199. ** is returned.
  200. **
  201. ** Arguments: hwnd - window handle of the button
  202. ** f - state to set
  203. **
  204. ** Returns: TRUE iff the current state is different than f
  205. **
  206. *******************/
  207. BOOL ButtonState(HWND hwnd, WORD f)
  208. {
  209. WORD state;
  210. state = (WORD)GETSTATE(hwnd);
  211. if (state != f)
  212. {
  213. SetWindowLong(hwnd,GWW_STATE,f);
  214. InvalidateRect(hwnd,NULL,TRUE);
  215. UpdateWindow(hwnd);
  216. return TRUE;
  217. }
  218. return FALSE;
  219. }
  220. /*******************
  221. **
  222. ** Name: fnButton
  223. **
  224. ** Purpose: Window proc for buttons
  225. **
  226. ** Arguments: Standard window proc
  227. **
  228. *******************/
  229. LRESULT APIENTRY fnButton(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
  230. {
  231. HANDLE hbm;
  232. PAINTSTRUCT ps;
  233. RECT rc;
  234. LONG l;
  235. switch (message)
  236. {
  237. case WM_CREATE:
  238. SetWindowLongPtr(hwnd,GWW_HBM,0);
  239. SetWindowLong(hwnd,GWW_STATE,0);
  240. SetWindowLong(hwnd,GWW_FLAGS,lpCreate->style & 0x0000FF00);
  241. SetWindowText(hwnd,lpCreate->lpszName);
  242. SetWindowLong(hwnd,GWL_STYLE,lpCreate->style & 0xFFFF00FF);
  243. break;
  244. case WM_LBUTTONDOWN:
  245. if (!IsWindowEnabled(hwnd))
  246. return 0L;
  247. if (GetCapture() != hwnd) /* ignore multiple DOWN's */
  248. {
  249. ButtonState(hwnd,TRUE);
  250. SetCapture(hwnd);
  251. if (!(GETFLAGS(hwnd) & BS_NOFOCUS))
  252. SetFocus(hwnd);
  253. }
  254. return 0L;
  255. case WM_MOUSEMOVE:
  256. if (GetCapture() == hwnd)
  257. {
  258. POINT point;
  259. point.x = (LONG)(LOWORD(lParam));
  260. point.y = (LONG)(HIWORD(lParam));
  261. GetClientRect(hwnd,&rc);
  262. ButtonState(hwnd,(WORD)PtInRect(&rc,point));
  263. }
  264. return 0L;
  265. case WM_LBUTTONUP:
  266. if (GetCapture() == hwnd)
  267. {
  268. ReleaseCapture();
  269. if (ButtonState(hwnd,FALSE))
  270. NotifyParent(hwnd);
  271. }
  272. return 0L;
  273. case WM_DESTROY:
  274. if (hbm = (HBITMAP)GETHBM(hwnd))
  275. DeleteObject(hbm);
  276. break;
  277. case WM_SETTEXT:
  278. if (hbm = (HBITMAP)GETHBM(hwnd))
  279. DeleteObject(hbm);
  280. if (*(LPSTR)lParam == '#')
  281. {
  282. hbm = LoadBitmapResource(
  283. (HINSTANCE)GetWindowLongPtr(hwnd,GWLP_HINSTANCE),
  284. (LPSTR)lParam+1
  285. );
  286. }
  287. else
  288. {
  289. hbm = NULL;
  290. }
  291. SetWindowLongPtr(hwnd,GWW_HBM,(LONG_PTR)hbm);
  292. InvalidateRect(hwnd,NULL,TRUE);
  293. break;
  294. case WM_ENABLE:
  295. case WM_KILLFOCUS:
  296. case WM_SETFOCUS:
  297. InvalidateRect(hwnd,NULL,TRUE);
  298. break;
  299. case WM_KEYDOWN:
  300. if (wParam == VK_SPACE && IsWindowEnabled(hwnd))
  301. ButtonState(hwnd,TRUE);
  302. break;
  303. case WM_KEYUP:
  304. case WM_SYSKEYUP:
  305. if (wParam == VK_SPACE && IsWindowEnabled(hwnd))
  306. {
  307. if (ButtonState(hwnd,FALSE))
  308. NotifyParent(hwnd);
  309. }
  310. break;
  311. case BM_GETSTATE:
  312. return((LONG)GETSTATE(hwnd));
  313. case BM_SETSTATE:
  314. if (ButtonState(hwnd,(WORD)wParam) && !wParam)
  315. // NotifyParent(hwnd);
  316. break;
  317. case BM_GETCHECK:
  318. return((LONG)GETCHECK(hwnd));
  319. case BM_SETCHECK:
  320. SetWindowLong(hwnd,GWW_CHECK,(DWORD)wParam);
  321. break;
  322. case BM_SETSTYLE:
  323. l = GetWindowLong(hwnd,GWL_STYLE);
  324. SetWindowLong(hwnd,GWL_STYLE,MAKELONG((WORD)wParam,HIWORD(l)));
  325. if (lParam)
  326. InvalidateRect(hwnd, NULL, TRUE);
  327. break;
  328. case WM_SETCURSOR:
  329. SetCursor(CurrentCursor);
  330. return(TRUE); // don't mess with cursor
  331. case WM_GETDLGCODE:
  332. switch (LOBYTE(GETSTYLE(hwnd)))
  333. {
  334. case BS_DEFPUSHBUTTON:
  335. wParam = DLGC_DEFPUSHBUTTON;
  336. break;
  337. case BS_PUSHBUTTON:
  338. wParam = DLGC_UNDEFPUSHBUTTON;
  339. break;
  340. default:
  341. wParam = 0;
  342. }
  343. return((LONG)(wParam | DLGC_BUTTON));
  344. case WM_ERASEBKGND:
  345. return 0L;
  346. case WM_PAINT:
  347. BeginPaint(hwnd, &ps);
  348. PaintButton(hwnd,ps.hdc);
  349. EndPaint(hwnd, &ps);
  350. return 0L;
  351. }
  352. return DefWindowProc(hwnd, message, wParam, lParam);
  353. }
  354. /*---------------------------------------------------------------------------*/
  355. /* */
  356. /* DrawGrayButton() - */
  357. /* */
  358. /*---------------------------------------------------------------------------*/
  359. PRIV VOID DrawGrayButton(HWND hwnd,HDC hdc,RECT *lprc,WORD style,WORD fInvert)
  360. {
  361. RECT rc;
  362. int dx,dy;
  363. HBRUSH hbr;
  364. int i;
  365. int iFrame;
  366. SetBkColor(hdc,GetSysColor(COLOR_WINDOW));
  367. hbr = (HBRUSH)SendMessage(GetParent(hwnd), WM_CTLCOLORBTN, (WPARAM)hdc, (LONG_PTR)hwnd);
  368. FillRect(hdc, lprc, hbr);
  369. rc = *lprc;
  370. dx = rc.right - rc.left;
  371. dy = rc.bottom - rc.top;
  372. iFrame = FRAME;
  373. if (LOBYTE(style) == BS_DEFPUSHBUTTON)
  374. iFrame *= 2;
  375. PatB(hdc, rc.left , rc.top , dx , iFrame, rgbBlack);
  376. PatB(hdc, rc.left , rc.bottom-iFrame, dx , iFrame, rgbBlack);
  377. PatB(hdc, rc.left , rc.top+1 , iFrame, dy-2, rgbBlack);
  378. PatB(hdc, rc.right-iFrame, rc.top+1 , iFrame, dy-2, rgbBlack);
  379. InflateRect(&rc,-iFrame,-iFrame);
  380. dx = rc.right - rc.left;
  381. dy = rc.bottom - rc.top;
  382. SetBkColor(hdc,rgbButtonFace);
  383. EraseButton(hwnd,hdc,&rc);
  384. if (fInvert)
  385. {
  386. PatB(hdc, rc.left, rc.top, 1,dy, rgbButtonShadow);
  387. PatB(hdc, rc.left, rc.top, dx,1, rgbButtonShadow);
  388. rc.left += BEVEL*2;
  389. rc.top += BEVEL*2;
  390. }
  391. else
  392. {
  393. for (i=0; i<BEVEL; i++)
  394. {
  395. PatB(hdc, rc.left, rc.top, 1,dy, rgbWhite);
  396. PatB(hdc, rc.left, rc.top, dx,1, rgbWhite);
  397. PatB(hdc, rc.right-1,rc.top+1, 1,dy-1, rgbButtonShadow);
  398. PatB(hdc, rc.left+1, rc.bottom-1, dx-1,1,rgbButtonShadow);
  399. InflateRect(&rc,-1,-1);
  400. dx -= 2;
  401. dy -= 2;
  402. }
  403. }
  404. SetBkColor(hdc,rgbButtonFace);
  405. if (GetFocus() == hwnd)
  406. SetTextColor(hdc,rgbButtonFocus);
  407. else
  408. SetTextColor(hdc,rgbButtonText);
  409. DrawButtonFace(hwnd,hdc,&rc,style);
  410. }
  411. /*******************
  412. **
  413. ** Name: DrawButtonFace
  414. **
  415. ** Purpose: Responsible for the rendering of the text or bitmap on
  416. ** on a button.
  417. **
  418. ** Arguments: hwnd - window handle of button
  419. ** hdc - hdc for window
  420. ** prc - clipping rect
  421. ** sytle - button style (push button or default pushbutton)
  422. **
  423. *******************/
  424. PRIV VOID DrawButtonFace(HWND hwnd, HDC hdc, PRECT prc, WORD style)
  425. {
  426. RECT rc;
  427. HBITMAP hbm;
  428. HDC hdcBits;
  429. BITMAP bm;
  430. BOOL fMono;
  431. rc = *prc;
  432. SaveDC(hdc);
  433. IntersectClipRect(hdc, prc->left, prc->top, prc->right, prc->bottom);
  434. if ((hbm = (HBITMAP)GETHBM(hwnd)))
  435. {
  436. hdcBits = CreateCompatibleDC(hdc);
  437. if (hdcBits) {
  438. SelectObject(hdcBits,hbm);
  439. GetObject(hbm,sizeof(bm),(LPSTR)&bm);
  440. fMono = (bm.bmPlanes == 1) && (bm.bmBitsPixel == 1);
  441. BitmapColorTranslate(hdcBits, &bm, rgbButtonFace);
  442. if (!(style & BS_STRETCH))
  443. {
  444. // now center this thing on the button face
  445. rc.left += (rc.right - rc.left - (signed)bm.bmWidth) / 2;
  446. rc.top += (rc.bottom - rc.top - (signed)bm.bmHeight) / 2;
  447. rc.right = rc.left + bm.bmWidth;
  448. rc.bottom = rc.top + bm.bmHeight;
  449. }
  450. SetStretchBltMode (hdc,fMono ? BLACKONWHITE : COLORONCOLOR);
  451. if (IsWindowEnabled(hwnd))
  452. {
  453. StretchBlt(hdc,rc.left,rc.top,
  454. rc.right - rc.left,
  455. rc.bottom - rc.top,
  456. hdcBits,0,0,
  457. bm.bmWidth,bm.bmHeight, SRCCOPY);
  458. }
  459. else
  460. {
  461. SetBkColor(hdc,rgbWhite);
  462. SetTextColor(hdc,rgbBlack);
  463. SelectObject(hdc,hbrGray);
  464. StretchBlt(hdc,rc.left,rc.top,
  465. rc.right - rc.left,
  466. rc.bottom - rc.top,
  467. hdcBits,0,0,
  468. bm.bmWidth,bm.bmHeight, DPSoa);
  469. }
  470. DeleteDC(hdcBits);
  471. }
  472. }
  473. RestoreDC(hdc, -1);
  474. }
  475. /*
  476. * using the first pixel as the "transparent" color, make all pixels
  477. * in the hdc that are equal to the "transparent" color the passed
  478. * color.
  479. */
  480. PRIV VOID BitmapColorTranslate(HDC hdcBits, BITMAP* pbm, DWORD rgb)
  481. {
  482. HDC hdcMask;
  483. HBITMAP hbmMask, hbmT;
  484. HBRUSH hbrT;
  485. BOOL fMono;
  486. /*
  487. * is the bitmap mono, or the first pixel is already equal to the
  488. * passed color? if so we have nothing to do.
  489. */
  490. fMono = pbm->bmPlanes == 1 && pbm->bmBitsPixel == 1;
  491. if (fMono || GetPixel(hdcBits, 0, 0) == rgb)
  492. return;
  493. // create a mask bitmap and associated DC
  494. if ((hbmMask = CreateBitmap(pbm->bmWidth, pbm->bmHeight, 1, 1, NULL)))
  495. {
  496. hdcMask = CreateCompatibleDC(hdcBits);
  497. // select the mask bitmap into the mono DC
  498. hbmT = SelectObject(hdcMask, hbmMask);
  499. // create the brush and select it into the bits DC
  500. hbrT = SelectObject(hdcBits, CreateSolidBrush(rgb));
  501. // do a color to mono bitblt to build the mask
  502. // generate 1's where the source is equal to the background is
  503. if (hdcMask) {
  504. SetBkColor(hdcBits, GetPixel(hdcBits, 0, 0));
  505. BitBlt(hdcMask, 0, 0, pbm->bmWidth, pbm->bmHeight, hdcBits, 0, 0, SRCCOPY);
  506. // where the mask is 1 lay down the brush, where it is 0 leave the desitnation
  507. SetBkColor(hdcBits, rgbWhite);
  508. SetTextColor(hdcBits, rgbBlack);
  509. BitBlt(hdcBits, 0, 0, pbm->bmWidth, pbm->bmHeight, hdcMask, 0, 0, DSPDxax);
  510. DeleteObject(SelectObject(hdcBits, hbrT));
  511. DeleteObject(SelectObject(hdcMask, hbmT));
  512. DeleteDC(hdcMask);
  513. }
  514. }
  515. }
  516. /*******************
  517. **
  518. ** Name: NotifyParent
  519. **
  520. *******************/
  521. PRIV VOID NotifyParent(HWND hwnd)
  522. {
  523. PostMessage(GetParent(hwnd),WM_COMMAND,MAKELONG(GetWindowLong(hwnd,GWL_ID),BN_CLICKED),(LONG_PTR)hwnd);
  524. }
  525. /*******************
  526. **
  527. ** Name: PatB
  528. **
  529. ** Fast Solid color PatBlt() using ExtTextOut()
  530. **
  531. *******************/
  532. PRIV VOID PatB(HDC hdc,int x,int y,int dx,int dy, DWORD rgb)
  533. {
  534. RECT rc;
  535. SetBkColor(hdc,rgb);
  536. rc.left = x;
  537. rc.top = y;
  538. rc.right = x + dx;
  539. rc.bottom = y + dy;
  540. ExtTextOut(hdc,0,0,ETO_OPAQUE,&rc,NULL,0,NULL);
  541. }
  542. /*
  543. * LoadBitmapResource()
  544. *
  545. * load a bitmap from a resource file that is specific to a device.
  546. *
  547. */
  548. PRIV HBITMAP LoadBitmapResource(HANDLE hInst, LPSTR lpName)
  549. {
  550. char szName[80];
  551. HBITMAP hbm;
  552. DWORD nColors = 0;
  553. DWORD dxScreen = 0;
  554. DWORD dyScreen = 0;
  555. HDC hdc;
  556. hdc = GetDC(NULL);
  557. if (hdc) {
  558. nColors = GetDeviceCaps(hdc,NUMCOLORS);
  559. dxScreen = GetSystemMetrics(SM_CXSCREEN);
  560. dyScreen = GetSystemMetrics(SM_CYSCREEN);
  561. ReleaseDC(NULL,hdc);
  562. }
  563. /* look for a resource of the form WxHxC */
  564. wsprintf(szName, "%s%dx%dx%d", lpName, dxScreen, dyScreen, nColors);
  565. hbm = LoadBitmap(hInst,szName);
  566. /* look for a resource of the form WxH */
  567. if (!hbm)
  568. {
  569. wsprintf(szName,"%s%dx%d", lpName, dxScreen, dyScreen);
  570. hbm = LoadBitmap(hInst,szName);
  571. }
  572. /* look for the default resource name */
  573. if (!hbm)
  574. {
  575. hbm = LoadBitmap(hInst,lpName);
  576. }
  577. return hbm;
  578. }
  579. #if 0
  580. /*******************
  581. **
  582. ** Name: FindGray
  583. **
  584. ** Purpose: Responsible for finding (if possible) a dark gray
  585. ** on the curent device.
  586. **
  587. ** Arguments: rgb - value for gray
  588. **
  589. ** Returns: RGB value for dark gray
  590. **
  591. *******************/
  592. DWORD FindGray(DWORD rgb)
  593. {
  594. int r,g,b;
  595. HDC hdc;
  596. hdc = GetDC(NULL);
  597. rgb == NearestColor(hdc,rgb);
  598. r = GetRValue(rgb);
  599. g = GetGValue(rgb);
  600. b = GetBValue(rgb);
  601. while ((r>0 || g>0 || b>0) && rgb == NearestColor(hdc,RGB(r,g,b)))
  602. {
  603. if (r > 0) r -= 63;
  604. if (g > 0) g -= 63;
  605. if (b > 0) b -= 63;
  606. }
  607. rgb = NearestColor(hdc,RGB(r,g,b));
  608. ReleaseDC(NULL,hdc);
  609. return rgb;
  610. }
  611. #endif