Windows NT 4.0 source code leak
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.

215 lines
6.6 KiB

4 years ago
  1. /*
  2. * ICONBOX.CPP
  3. *
  4. * Implemenatation of an IconBox control for OLE 2.0 UI dialogs that we'll
  5. * use wherever a dialog needs an icon/label display. Through the control's
  6. * interface we can change the image or control label visibility.
  7. *
  8. * The IconBox discusses images in CF_METAFILEPICT format. When drawing
  9. * such a metafile, the entire aspect is centered in the IconBox, so long
  10. * labels are chopped at either end.
  11. *
  12. * Copyright (c)1992 Microsoft Corporation, All Right Reserved
  13. */
  14. #include "precomp.h"
  15. #include "iconbox.h"
  16. #include "utility.h"
  17. #include "uiclass.h"
  18. OLEDBGDATA
  19. //Flag indicating if we've registered the class
  20. static BOOL fRegistered;
  21. /*
  22. * FIconBoxInitialize
  23. *
  24. * Purpose:
  25. * Registers the IconBox control class.
  26. *
  27. * Parameters:
  28. * hInst HINSTANCE instance of the DLL.
  29. *
  30. * hPrevInst HINSTANCE of the previous instance. Used to
  31. * determine whether to register window classes or not.
  32. *
  33. * Return Value:
  34. * BOOL TRUE if all initialization succeeded, FALSE otherwise.
  35. */
  36. #pragma code_seg(".text$initseg")
  37. BOOL FIconBoxInitialize(HINSTANCE hInst, HINSTANCE hPrevInst)
  38. {
  39. // Only register class if we're the first instance
  40. if (hPrevInst)
  41. fRegistered = TRUE;
  42. else
  43. {
  44. // Static flag fRegistered guards against calling this function more
  45. // than once
  46. if (!fRegistered)
  47. {
  48. WNDCLASS wc;
  49. wc.lpfnWndProc =IconBoxWndProc;
  50. wc.cbClsExtra =0;
  51. wc.cbWndExtra =CBICONBOXWNDEXTRA;
  52. wc.hInstance =hInst;
  53. wc.hIcon =NULL;
  54. wc.hCursor =LoadCursor(NULL, IDC_ARROW);
  55. wc.hbrBackground =(HBRUSH)NULL;
  56. wc.lpszMenuName =NULL;
  57. wc.style =CS_GLOBALCLASS | CS_VREDRAW | CS_HREDRAW;
  58. wc.lpszClassName = TEXT(SZCLASSICONBOX1);
  59. fRegistered = RegisterClass(&wc);
  60. wc.lpszClassName = TEXT(SZCLASSICONBOX2);
  61. fRegistered = RegisterClass(&wc);
  62. wc.lpszClassName = TEXT(SZCLASSICONBOX3);
  63. fRegistered = RegisterClass(&wc);
  64. }
  65. }
  66. return fRegistered;
  67. }
  68. #pragma code_seg()
  69. /*
  70. * IconBoxUninitialize
  71. *
  72. * Purpose:
  73. * Cleans up anything done in FIconBoxInitialize. Currently there is
  74. * nothing, but we do this for symmetry.
  75. *
  76. * Parameters:
  77. * None
  78. *
  79. * Return Value:
  80. * None
  81. */
  82. void IconBoxUninitialize(void)
  83. {
  84. return;
  85. }
  86. /*
  87. * IconBoxWndProc
  88. *
  89. * Purpose:
  90. * Window Procedure for the IconBox custom control. Only handles
  91. * WM_CREATE, WM_PAINT, and private messages to manipulate the image.
  92. *
  93. * Parameters:
  94. * Standard
  95. *
  96. * Return Value:
  97. * Standard
  98. */
  99. LONG CALLBACK IconBoxWndProc(HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
  100. {
  101. //Handle standard Windows messages.
  102. switch (iMsg)
  103. {
  104. case WM_CREATE:
  105. SetWindowLong(hWnd, IBWW_HIMAGE, 0);
  106. SetWindowWord(hWnd, IBWW_FLABEL, TRUE);
  107. return 0L;
  108. case WM_ERASEBKGND:
  109. {
  110. RECT rect;
  111. GetClientRect(hWnd, &rect);
  112. HBRUSH hBrush = (HBRUSH)SendMessage(GetParent(hWnd), WM_CTLCOLORDLG,
  113. wParam, (LPARAM)GetParent(hWnd));
  114. if (!hBrush)
  115. return FALSE;
  116. UnrealizeObject(hBrush);
  117. SetBrushOrgEx((HDC)wParam, 0, 0, NULL);
  118. FillRect((HDC)wParam, &rect, hBrush);
  119. return TRUE;
  120. }
  121. case WM_PAINT:
  122. {
  123. HGLOBAL hMF = (HGLOBAL)GetWindowLong(hWnd, IBWW_HIMAGE);
  124. //BeginPaint and EndPaint clear us even if hMF is NULL.
  125. PAINTSTRUCT ps;
  126. HDC hDC = BeginPaint(hWnd, &ps);
  127. if (NULL != hMF)
  128. {
  129. //Now we get to paint the metafile, centered in our rect.
  130. RECT rc;
  131. GetClientRect(hWnd, &rc);
  132. /*
  133. * If we're doing icon only, then place the metafile
  134. * at the center of our box minus half the icon width.
  135. * Top is top.
  136. */
  137. BOOL fLabel = GetWindowWord(hWnd, IBWW_FLABEL);
  138. //Go draw where we decided to place it.
  139. OleUIMetafilePictIconDraw(hDC, &rc, hMF, !fLabel);
  140. }
  141. EndPaint(hWnd, &ps);
  142. }
  143. break;
  144. case IBXM_IMAGESET:
  145. {
  146. /*
  147. * wParam is a flag to delete the old or not.
  148. * lParam contains the new handle.
  149. */
  150. HGLOBAL hMF = (HGLOBAL)SetWindowLong(hWnd, IBWW_HIMAGE, lParam);
  151. InvalidateRect(hWnd, NULL, TRUE);
  152. UpdateWindow(hWnd);
  153. //Delete the old handle if requested
  154. if (0L!=wParam)
  155. {
  156. OleUIMetafilePictIconFree(hMF);
  157. hMF=NULL;
  158. }
  159. return (LONG)(UINT)hMF;
  160. }
  161. case IBXM_IMAGEGET:
  162. {
  163. //Return the current index.
  164. HGLOBAL hMF=(HGLOBAL)GetWindowLong(hWnd, IBWW_HIMAGE);
  165. return (LONG)(UINT)hMF;
  166. }
  167. case IBXM_IMAGEFREE:
  168. {
  169. //Free up whatever we're holding.
  170. HGLOBAL hMF=(HGLOBAL)GetWindowLong(hWnd, IBWW_HIMAGE);
  171. OleUIMetafilePictIconFree(hMF);
  172. SetWindowLong(hWnd, IBWW_HIMAGE, 0);
  173. return 1L;
  174. }
  175. case IBXM_LABELENABLE:
  176. //wParam has the new flag, returns the previous flag.
  177. return (LONG)SetWindowWord(hWnd, IBWW_FLABEL, (WORD)wParam);
  178. default:
  179. return DefWindowProc(hWnd, iMsg, wParam, lParam);
  180. }
  181. return 0L;
  182. }