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.

384 lines
12 KiB

  1. #include "windows.h"
  2. #include "frame.h"
  3. #include "dib.h"
  4. #include "resource.h"
  5. #include "mmfw.h"
  6. //constants for bitmap placement in FRAME.BMP
  7. #define PIECE_WIDTH 9
  8. #define PIECE_HEIGHT 10
  9. #define SMALL_MODE_OFFSET 90
  10. //outer edges
  11. #define TOP_LEFT_CORNER 0
  12. #define TOP_STRIP 1
  13. #define TOP_RIGHT_CORNER 2
  14. #define LEFT_STRIP 3
  15. #define SEPARATOR_BAR 4
  16. #define RIGHT_STRIP 5
  17. #define BOTTOM_LEFT_CORNER 6
  18. #define BOTTOM_STRIP 7
  19. #define BOTTOM_RIGHT_CORNER 8
  20. //inner edges
  21. #define TOP_LEFT_CORNER_VIEW 9
  22. #define TOP_STRIP_VIEW 10
  23. #define TOP_RIGHT_CORNER_VIEW 11
  24. #define LEFT_STRIP_VIEW 12
  25. #define RIGHT_STRIP_VIEW 13
  26. #define BOTTOM_LEFT_CORNER_VIEW 14
  27. #define BOTTOM_STRIP_VIEW 15
  28. #define BOTTOM_RIGHT_CORNER_VIEW 16
  29. #define LEFT_INNER_STRIP_VIEW 17
  30. #define RIGHT_INNER_STRIP_VIEW 18
  31. #define LEFT_INNER_X_OFFSET 5
  32. #define LEFT_INNER_Y_OFFSET 7
  33. #define RIGHT_INNER_X_OFFSET 9
  34. #define RIGHT_INNER_Y_OFFSET 7
  35. //system menu icon
  36. #define SYSTEM_MENU_INDEX 52
  37. #define SYSTEM_MENU_WIDTH 12
  38. #define SYSTEM_MENU_HEIGHT 14
  39. //volume control notch
  40. #define VOLUME_X_OFFSET 2
  41. #define BACKGROUND_COLOR RGB(0x7F, 0x7F, 0x7F)
  42. #define BACKGROUND_COLOR_16 RGB(0xC0, 0xC0, 0xC0)
  43. #define BACKGROUND_COLOR_HI RGB(0xFF, 0xFF, 0xFF)
  44. extern HPALETTE hpalMain; //main palette of app
  45. extern HINSTANCE hInst; //instance of app
  46. extern int g_nColorMode; //color mode
  47. HANDLE BuildFrameBitmap(HDC hDC, //dc to be compatible with
  48. LPRECT pMainRect, //overall window size
  49. LPRECT pViewRect, //rect of black viewport window,
  50. //where gradient should begin,
  51. //with 0,0 as top left of main
  52. int nViewMode, //if in normal, restore, small
  53. LPPOINT pSysMenuPt, //point where sys menu icon is placed
  54. LPRECT pSepRects, //array of rects for separator bars
  55. int nNumSeps, //number of separtors in array
  56. BITMAP* pBM) //bitmap info
  57. {
  58. HDC memDC = CreateCompatibleDC(hDC);
  59. HPALETTE hpalOld = SelectPalette(memDC, hpalMain, FALSE);
  60. HBITMAP hbmpOld;
  61. HBITMAP hbmpTemp;
  62. HBITMAP hbmpFinal;
  63. int nSmallOffset = 0;
  64. if ((nViewMode != VIEW_MODE_NORMAL) && (nViewMode != VIEW_MODE_NOBAR))
  65. {
  66. nSmallOffset = SMALL_MODE_OFFSET;
  67. }
  68. //load frame bitmap
  69. int nBitmap = IDB_FRAME_TOOLKIT;
  70. switch (g_nColorMode)
  71. {
  72. case COLOR_16 : nBitmap = IDB_FRAME_TOOLKIT_16; break;
  73. case COLOR_HICONTRAST : nBitmap = IDB_FRAME_TOOLKIT_HI; break;
  74. }
  75. hbmpTemp = (HBITMAP)LoadImage(hInst,MAKEINTRESOURCE(nBitmap),IMAGE_BITMAP,0,0,LR_CREATEDIBSECTION);
  76. HANDLE hbmpFrame = DibFromBitmap((HBITMAP)hbmpTemp,0,0,NULL,0);
  77. DeleteObject(hbmpTemp);
  78. hbmpFinal = CreateCompatibleBitmap(hDC,
  79. pMainRect->right - pMainRect->left,
  80. pMainRect->bottom - pMainRect->top);
  81. hbmpOld = (HBITMAP)SelectObject(memDC, hbmpFinal);
  82. //first paint the background
  83. COLORREF colorBackground = BACKGROUND_COLOR;
  84. switch (g_nColorMode)
  85. {
  86. case COLOR_16 : colorBackground = BACKGROUND_COLOR_16; break;
  87. case COLOR_HICONTRAST : colorBackground = BACKGROUND_COLOR_HI; break;
  88. }
  89. HBRUSH hbrBack = CreateSolidBrush(colorBackground);
  90. FillRect(memDC,pMainRect,hbrBack);
  91. DeleteObject(hbrBack);
  92. //now draw the separators
  93. for (int i = 0; i < nNumSeps; i++)
  94. {
  95. StretchDibBlt(memDC,
  96. pSepRects[i].left,
  97. pSepRects[i].top,
  98. PIECE_WIDTH,
  99. pSepRects[i].bottom - pSepRects[i].top,
  100. hbmpFrame,
  101. SEPARATOR_BAR*PIECE_WIDTH,0,
  102. PIECE_WIDTH,
  103. PIECE_HEIGHT,
  104. SRCCOPY,0);
  105. }
  106. //draw each side
  107. StretchDibBlt(memDC,
  108. pMainRect->left,
  109. pMainRect->top,
  110. pMainRect->right - pMainRect->left,
  111. PIECE_HEIGHT,
  112. hbmpFrame,
  113. TOP_STRIP*PIECE_WIDTH,0,
  114. PIECE_WIDTH,
  115. PIECE_HEIGHT,
  116. SRCCOPY,0);
  117. StretchDibBlt(memDC,
  118. pMainRect->left,
  119. pMainRect->top,
  120. PIECE_WIDTH,
  121. pMainRect->bottom - pMainRect->top,
  122. hbmpFrame,
  123. LEFT_STRIP*PIECE_WIDTH,0,
  124. PIECE_WIDTH,
  125. PIECE_HEIGHT,
  126. SRCCOPY,0);
  127. StretchDibBlt(memDC,
  128. pMainRect->right - PIECE_WIDTH,
  129. pMainRect->top,
  130. PIECE_WIDTH,
  131. pMainRect->bottom - pMainRect->top,
  132. hbmpFrame,
  133. RIGHT_STRIP*PIECE_WIDTH,0,
  134. PIECE_WIDTH,
  135. PIECE_HEIGHT,
  136. SRCCOPY,0);
  137. StretchDibBlt(memDC,
  138. pMainRect->left,
  139. pMainRect->bottom - PIECE_HEIGHT,
  140. pMainRect->right - pMainRect->left,
  141. PIECE_HEIGHT,
  142. hbmpFrame,
  143. BOTTOM_STRIP*PIECE_WIDTH,0,
  144. PIECE_WIDTH,
  145. PIECE_HEIGHT,
  146. SRCCOPY,0);
  147. //draw each corner
  148. DibBlt(memDC,
  149. pMainRect->left,
  150. pMainRect->top,
  151. PIECE_WIDTH,
  152. PIECE_HEIGHT,
  153. hbmpFrame,
  154. TOP_LEFT_CORNER*PIECE_WIDTH,0,
  155. SRCCOPY,0);
  156. DibBlt(memDC,
  157. pMainRect->right-PIECE_WIDTH,
  158. pMainRect->top,
  159. PIECE_WIDTH,
  160. PIECE_HEIGHT,
  161. hbmpFrame,
  162. TOP_RIGHT_CORNER*PIECE_WIDTH,0,
  163. SRCCOPY,0);
  164. DibBlt(memDC,
  165. pMainRect->left,
  166. pMainRect->bottom - PIECE_HEIGHT,
  167. PIECE_WIDTH,
  168. PIECE_HEIGHT,
  169. hbmpFrame,
  170. BOTTOM_LEFT_CORNER*PIECE_WIDTH,0,
  171. SRCCOPY,0);
  172. DibBlt(memDC,
  173. pMainRect->right - PIECE_WIDTH,
  174. pMainRect->bottom - PIECE_HEIGHT,
  175. PIECE_WIDTH,
  176. PIECE_HEIGHT,
  177. hbmpFrame,
  178. BOTTOM_RIGHT_CORNER*PIECE_WIDTH,0,
  179. SRCCOPY,0);
  180. //draw each side of the interior viewport
  181. StretchDibBlt(memDC,
  182. pViewRect->left,
  183. pViewRect->top,
  184. pViewRect->right - pViewRect->left,
  185. PIECE_HEIGHT,
  186. hbmpFrame,
  187. TOP_STRIP_VIEW*PIECE_WIDTH+nSmallOffset,0,
  188. PIECE_WIDTH,
  189. PIECE_HEIGHT,
  190. SRCCOPY,0);
  191. StretchDibBlt(memDC,
  192. pViewRect->left,
  193. pViewRect->top,
  194. PIECE_WIDTH,
  195. pViewRect->bottom - pViewRect->top,
  196. hbmpFrame,
  197. LEFT_STRIP_VIEW*PIECE_WIDTH+nSmallOffset,0,
  198. PIECE_WIDTH,
  199. PIECE_HEIGHT,
  200. SRCCOPY,0);
  201. StretchDibBlt(memDC,
  202. pViewRect->right - PIECE_WIDTH,
  203. pViewRect->top,
  204. PIECE_WIDTH,
  205. pViewRect->bottom - pViewRect->top,
  206. hbmpFrame,
  207. RIGHT_STRIP_VIEW*PIECE_WIDTH+nSmallOffset,0,
  208. PIECE_WIDTH,
  209. PIECE_HEIGHT,
  210. SRCCOPY,0);
  211. StretchDibBlt(memDC,
  212. pViewRect->left,
  213. pViewRect->bottom - PIECE_HEIGHT,
  214. pViewRect->right - pViewRect->left,
  215. PIECE_HEIGHT,
  216. hbmpFrame,
  217. BOTTOM_STRIP_VIEW*PIECE_WIDTH+nSmallOffset,0,
  218. PIECE_WIDTH,
  219. PIECE_HEIGHT,
  220. SRCCOPY,0);
  221. //draw each corner of the interior viewport
  222. DibBlt(memDC,
  223. pViewRect->left,
  224. pViewRect->top,
  225. PIECE_WIDTH,
  226. PIECE_HEIGHT,
  227. hbmpFrame,
  228. TOP_LEFT_CORNER_VIEW*PIECE_WIDTH+nSmallOffset,0,
  229. SRCCOPY,0);
  230. DibBlt(memDC,
  231. pViewRect->right-PIECE_WIDTH,
  232. pViewRect->top,
  233. PIECE_WIDTH,
  234. PIECE_HEIGHT,
  235. hbmpFrame,
  236. TOP_RIGHT_CORNER_VIEW*PIECE_WIDTH+nSmallOffset,0,
  237. SRCCOPY,0);
  238. DibBlt(memDC,
  239. pViewRect->left,
  240. pViewRect->bottom - PIECE_HEIGHT,
  241. PIECE_WIDTH,
  242. PIECE_HEIGHT,
  243. hbmpFrame,
  244. BOTTOM_LEFT_CORNER_VIEW*PIECE_WIDTH+nSmallOffset,0,
  245. SRCCOPY,0);
  246. DibBlt(memDC,
  247. pViewRect->right - PIECE_WIDTH,
  248. pViewRect->bottom - PIECE_HEIGHT,
  249. PIECE_WIDTH,
  250. PIECE_HEIGHT,
  251. hbmpFrame,
  252. BOTTOM_RIGHT_CORNER_VIEW*PIECE_WIDTH+nSmallOffset,0,
  253. SRCCOPY,0);
  254. if ((nViewMode == VIEW_MODE_NORMAL) || (nViewMode == VIEW_MODE_NOBAR))
  255. {
  256. //draw the interiors of the viewport
  257. StretchDibBlt(memDC,
  258. pViewRect->left + LEFT_INNER_X_OFFSET,
  259. pViewRect->top + LEFT_INNER_Y_OFFSET,
  260. PIECE_WIDTH,
  261. (pViewRect->bottom - PIECE_HEIGHT) - (pViewRect->top + LEFT_INNER_Y_OFFSET),
  262. hbmpFrame,
  263. LEFT_INNER_STRIP_VIEW*PIECE_WIDTH,0,
  264. PIECE_WIDTH,
  265. PIECE_HEIGHT,
  266. SRCCOPY,0);
  267. StretchDibBlt(memDC,
  268. (pViewRect->right - RIGHT_INNER_X_OFFSET) - PIECE_WIDTH,
  269. pViewRect->top + RIGHT_INNER_Y_OFFSET,
  270. PIECE_WIDTH,
  271. (pViewRect->bottom - PIECE_HEIGHT) - (pViewRect->top + RIGHT_INNER_Y_OFFSET),
  272. hbmpFrame,
  273. RIGHT_INNER_STRIP_VIEW*PIECE_WIDTH,0,
  274. PIECE_WIDTH,
  275. PIECE_HEIGHT,
  276. SRCCOPY,0);
  277. //draw the "notch" for the volume knob in this mode
  278. nBitmap = IDB_NOTCH;
  279. switch (g_nColorMode)
  280. {
  281. case COLOR_16 : nBitmap = IDB_NOTCH_16; break;
  282. case COLOR_HICONTRAST : nBitmap = IDB_NOTCH_HI; break;
  283. }
  284. HBITMAP hbmpNotch = (HBITMAP)LoadImage(hInst,MAKEINTRESOURCE(nBitmap),IMAGE_BITMAP,0,0,LR_CREATEDIBSECTION);
  285. HDC memDC2 = CreateCompatibleDC(memDC);
  286. HBITMAP hbmpOld2 = (HBITMAP)SelectObject(memDC2,hbmpNotch);
  287. BITMAP bm;
  288. GetObject(hbmpNotch,sizeof(bm),&bm);
  289. BitBlt(memDC,
  290. pViewRect->right - bm.bmWidth,
  291. (pViewRect->bottom - PIECE_HEIGHT) - VOLUME_X_OFFSET,
  292. bm.bmWidth,
  293. bm.bmHeight,
  294. memDC2,
  295. 0,0,SRCCOPY);
  296. SelectObject(memDC2,hbmpOld2);
  297. DeleteObject(hbmpNotch);
  298. DeleteDC(memDC2);
  299. }
  300. //blit the system menu onto the picture, from the button toolkit bitmap
  301. if (nViewMode < VIEW_MODE_SMALL)
  302. {
  303. nBitmap = IDB_BUTTON_TOOLKIT;
  304. switch (g_nColorMode)
  305. {
  306. case COLOR_16 : nBitmap = IDB_BUTTON_TOOLKIT_16; break;
  307. case COLOR_HICONTRAST : nBitmap = IDB_BUTTON_TOOLKIT_HI; break;
  308. }
  309. HBITMAP hbmpSys = (HBITMAP)LoadImage(hInst,MAKEINTRESOURCE(nBitmap),IMAGE_BITMAP,0,0,LR_CREATEDIBSECTION);
  310. HDC memDC2 = CreateCompatibleDC(memDC);
  311. HBITMAP hbmpOld2 = (HBITMAP)SelectObject(memDC2,hbmpSys);
  312. BitBlt(memDC,
  313. pSysMenuPt->x,
  314. pSysMenuPt->y,
  315. SYSTEM_MENU_WIDTH,
  316. SYSTEM_MENU_HEIGHT,
  317. memDC2,
  318. SYSTEM_MENU_INDEX,0,
  319. SRCCOPY);
  320. SelectObject(memDC2,hbmpOld2);
  321. DeleteObject(hbmpSys);
  322. DeleteDC(memDC2);
  323. }
  324. SelectObject(memDC,hbmpOld);
  325. SelectPalette(memDC, hpalOld, TRUE);
  326. DeleteDC(memDC);
  327. GlobalFree(hbmpFrame);
  328. if (pBM)
  329. {
  330. GetObject(hbmpFinal,sizeof(BITMAP),pBM);
  331. }
  332. HANDLE hdib = DibFromBitmap((HBITMAP)hbmpFinal,0,0,hpalMain,0);
  333. DeleteObject(hbmpFinal);
  334. return hdib;
  335. }