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.

303 lines
11 KiB

  1. /*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
  2. **
  3. ** FILE: POV.CPP
  4. ** DATE: 3/31/97
  5. ** PROJ: ATLAS
  6. ** PROG: JKH
  7. ** COMMENTS:
  8. **
  9. ** DESCRIPTION: Window class for a 360 degree Point Of View control
  10. **
  11. **
  12. **
  13. ** NOTE: There are some issues with using extern "C" in this file.
  14. ** If you don't understand why they are there, you're not
  15. ** alone. For now, and probably for a while they will be
  16. ** here though, because I can't get this file and others
  17. ** that use these services to compile without them.
  18. ** Unfortunately the dynamics of this project don't really
  19. ** afford me the time at present to figure this out.
  20. ** TODO: figure this out
  21. **
  22. ** HISTORY:
  23. ** DATE WHO WHAT
  24. ** ---- --- ----
  25. ** 3/31/97 a-kirkh Wrote it.
  26. **
  27. **
  28. **
  29. **
  30. ** Copyright (C) Microsoft 1997. All Rights Reserved.
  31. **
  32. **~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
  33. #include "cplsvr1.h" // for ghInst
  34. #include "dicputil.h" // for MAX_POVS
  35. #include "POV.H" //This module's stuff.
  36. #include "resrc1.h"
  37. //static HWND hPOVWnd = NULL;
  38. #define NUM_ARROW_POINTS 8
  39. //static VERTICEINFO *paptVInfo;
  40. static const VERTICEINFO VInfo[] = {XARROWPOINT, YARROWPOINT, XARROWRIGHTOUT, YARROWRIGHTOUT, XARROWRIGHTIN, YARROWRIGHTIN,
  41. XARROWRIGHTBOTTOM, YARROWRIGHTBOTTOM, XARROWLEFTBOTTOM, YARROWLEFTBOTTOM, XARROWLEFTIN,
  42. YARROWLEFTIN, XARROWLEFTOUT, YARROWLEFTOUT, XARROWPOINT, YARROWPOINT};
  43. static LPRECT prcOldRegionBox[MAX_POVS];
  44. static LPRECT prcNewRegionBox[MAX_POVS];
  45. #define DEF_POV_POS -1
  46. static double degrees[MAX_POVS] = {DEF_POV_POS, DEF_POV_POS, DEF_POV_POS, DEF_POV_POS};
  47. static BYTE nPOV = MAX_POVS;
  48. static HBRUSH hBrush[MAX_POVS];
  49. static HRGN hRegion[MAX_POVS];
  50. extern HINSTANCE ghInst;
  51. void SetDegrees(BYTE nPov, short *nDegrees, HWND hPOVWnd)
  52. {
  53. nPOV = nPov -= 1;
  54. POINT paptPoints[NUM_ARROW_POINTS];
  55. // Create the proper brush for the axis!
  56. do {
  57. degrees[nPov] = (double)nDegrees[nPov] / DI_DEGREES; // if angle == 180, degrees comes in as 18000
  58. paptPoints[0].x = GETXCOORD(VInfo[0].y, VInfo[0].x, degrees[nPov]);
  59. paptPoints[0].y = GETYCOORD(VInfo[0].y, VInfo[0].x, degrees[nPov]);
  60. paptPoints[1].x = GETXCOORD(VInfo[1].y, VInfo[1].x, degrees[nPov]);
  61. paptPoints[1].y = GETYCOORD(VInfo[1].y, VInfo[1].x, degrees[nPov]);
  62. paptPoints[2].x = GETXCOORD(VInfo[2].y, VInfo[2].x, degrees[nPov]);
  63. paptPoints[2].y = GETYCOORD(VInfo[2].y, VInfo[2].x, degrees[nPov]);
  64. paptPoints[3].x = GETXCOORD(VInfo[3].y, VInfo[3].x, degrees[nPov]);
  65. paptPoints[3].y = GETYCOORD(VInfo[3].y, VInfo[3].x, degrees[nPov]);
  66. paptPoints[4].x = GETXCOORD(VInfo[4].y, VInfo[4].x, degrees[nPov]);
  67. paptPoints[4].y = GETYCOORD(VInfo[4].y, VInfo[4].x, degrees[nPov]);
  68. paptPoints[5].x = GETXCOORD(VInfo[5].y, VInfo[5].x, degrees[nPov]);
  69. paptPoints[5].y = GETYCOORD(VInfo[5].y, VInfo[5].x, degrees[nPov]);
  70. paptPoints[6].x = GETXCOORD(VInfo[6].y, VInfo[6].x, degrees[nPov]);
  71. paptPoints[6].y = GETYCOORD(VInfo[6].y, VInfo[6].x, degrees[nPov]);
  72. paptPoints[7].x = GETXCOORD(VInfo[7].y, VInfo[7].x, degrees[nPov]);
  73. paptPoints[7].y = GETYCOORD(VInfo[7].y, VInfo[7].x, degrees[nPov]);
  74. if(hRegion[nPov])
  75. {
  76. DeleteObject(hRegion[nPov]);
  77. hRegion[nPov]=NULL;
  78. }
  79. hRegion[nPov] = CreatePolygonRgn(paptPoints, NUM_ARROW_POINTS, WINDING);
  80. //hBrush[nPov] = CreateSolidBrush((nPov < 1) ? POV1_COLOUR :
  81. // (nPov < 2) ? POV2_COLOUR :
  82. // (nPov < 3) ? POV3_COLOUR : POV4_COLOUR); */
  83. //if (hRegion[nPov] && hBrush[nPov])
  84. //{
  85. // GetRgnBox(hRegion[nPov], prcNewRegionBox[nPov]);
  86. //
  87. // //RedrawWindow(hPOVWnd, NULL, NULL, RDW_INTERNALPAINT | RDW_INVALIDATE | RDW_ERASE);
  88. // InvalidateRect(hPOVWnd, prcOldRegionBox[nPov], TRUE);
  89. // InvalidateRect(hPOVWnd, prcNewRegionBox[nPov], TRUE);
  90. //}
  91. RECT R;
  92. GetClientRect(hPOVWnd,&R);
  93. POINT Pnt[2];
  94. Pnt[0].x=R.left;
  95. Pnt[0].y=R.top;
  96. Pnt[1].x=R.right;
  97. Pnt[1].y=R.bottom;
  98. MapWindowPoints(hPOVWnd,GetParent(hPOVWnd),Pnt,2);
  99. R.left=Pnt[0].x;
  100. R.top=Pnt[0].y;
  101. R.right=Pnt[1].x;
  102. R.bottom=Pnt[1].y;
  103. InvalidateRect(GetParent(hPOVWnd), &R, TRUE);
  104. } while( nPov-- );
  105. }
  106. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  107. //
  108. // FUNCTION : POVWndProc
  109. // REMARKS : The callback function for the POVHat Window.
  110. //
  111. // PARAMS : The usual callback funcs for message handling
  112. //
  113. // RETURNS : LRESULT - Depends on the message
  114. // CALLS :
  115. // NOTES :
  116. // WM_PAINT - Just calls DrawControl
  117. //
  118. // PM_MYJOYPOSCHANGED - This is a private (WM_USER) message that is
  119. // called whenever a change in the POV hat occurs.
  120. //
  121. LRESULT CALLBACK POVWndProc(HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
  122. {
  123. switch( iMsg ) {
  124. // case WM_CREATE:
  125. // hPOVWnd = hWnd;
  126. // return FALSE;
  127. // case WM_DESTROY:
  128. // return FALSE;
  129. case WM_DESTROY:
  130. {
  131. BYTE nPov=nPOV;
  132. do
  133. {
  134. if(hRegion[nPov])
  135. {
  136. DeleteObject(hRegion[nPov]);
  137. hRegion[nPov]=NULL;
  138. }
  139. }while(nPov--);
  140. }
  141. return 0;
  142. case WM_PAINT:
  143. {
  144. PAINTSTRUCT ps;
  145. HDC hDC = BeginPaint(hWnd, &ps);
  146. // 1) Get client size information
  147. SetMapMode(hDC, MM_TEXT);
  148. RECT rClient;
  149. GetClientRect(hWnd, &rClient);
  150. BYTE nSizeX = (BYTE)rClient.right>>1;
  151. BYTE nSizeY = (BYTE)rClient.bottom>>1;
  152. // 2) Load the hub bitmap and display it
  153. //PREFIX #WI226648. False positive. There is no leak. DeleteObject frees.
  154. HBITMAP hPOVHubBitmap = (HBITMAP)LoadImage(ghInst, MAKEINTRESOURCE(IDB_POVHUB), IMAGE_BITMAP, 0, 0, NULL);
  155. assert(hPOVHubBitmap);
  156. DrawBitmap(hDC, hPOVHubBitmap, nSizeX-8, nSizeY-8);
  157. DeleteObject(hPOVHubBitmap);
  158. // 3) Setup the window to use symmetrical units on a 1000 X 1000 cartesian grid
  159. SetMapMode(hDC, MM_ISOTROPIC);
  160. SetWindowExtEx (hDC, 1000, 1000, NULL);
  161. SetViewportExtEx(hDC, nSizeX, -nSizeY, NULL);
  162. SetViewportOrgEx(hDC, nSizeX, nSizeY, NULL);
  163. // 4) Draw the circle upon which the arrow seems to rotate
  164. SelectObject(hDC, (HBRUSH)GetStockObject(NULL_BRUSH));
  165. HPEN hPenOld = (HPEN)SelectObject(hDC, (HGDIOBJ)GetStockObject(DC_PEN));
  166. SetDCPenColor( hDC, GetSysColor(COLOR_WINDOWTEXT) );
  167. Ellipse(hDC, -CIRCLERADIUS, CIRCLERADIUS, CIRCLERADIUS, -CIRCLERADIUS);
  168. SelectObject(hDC, hPenOld);
  169. // 5) Paint the Arrow at the correct angle if POV active
  170. BYTE nPov = nPOV;
  171. HBRUSH hBrushOld;
  172. do {
  173. if( degrees[nPov] >= 0 ) {
  174. hBrush[nPov] = CreateSolidBrush((nPov < 1) ? POV1_COLOUR :
  175. (nPov < 2) ? POV2_COLOUR :
  176. (nPov < 3) ? POV3_COLOUR : POV4_COLOUR);
  177. hBrushOld = (HBRUSH)SelectObject(hDC, (HGDIOBJ)hBrush[nPov]);
  178. assert(hBrushOld);
  179. PaintRgn(hDC, hRegion[nPov]);
  180. // GetRgnBox returns zero if it fails...
  181. GetRgnBox(hRegion[nPov], prcOldRegionBox[nPov]);
  182. SelectObject(hDC, hBrushOld);
  183. if(hRegion[nPov])
  184. {
  185. DeleteObject(hRegion[nPov]);
  186. hRegion[nPov]=NULL;
  187. }
  188. DeleteObject(hBrush[nPov] );
  189. }
  190. } while( nPov-- );
  191. EndPaint(hWnd, &ps);
  192. }
  193. //PREFIX #WI226648. False positive. See above.
  194. return(0);
  195. default:
  196. return(DefWindowProc(hWnd, iMsg,wParam, lParam));
  197. }
  198. }
  199. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  200. //
  201. // FUNCTION : RegisterPOVClass
  202. // REMARKS : Registers the POV Hat window.
  203. //
  204. // PARAMS : hInstance - Used for the call to RegisterClassEx
  205. //
  206. // RETURNS : TRUE - if successfully registered
  207. // FALSE - failed to register
  208. // CALLS : RegisterClassEx
  209. // NOTES :
  210. //
  211. extern ATOM RegisterPOVClass()
  212. {
  213. WNDCLASSEX POVWndClass;
  214. ZeroMemory(&POVWndClass, sizeof(WNDCLASSEX));
  215. POVWndClass.cbSize = sizeof(WNDCLASSEX);
  216. POVWndClass.style = CS_HREDRAW; // | CS_VREDRAW;
  217. POVWndClass.lpfnWndProc = POVWndProc;
  218. POVWndClass.hInstance = ghInst;
  219. POVWndClass.hbrBackground = NULL;
  220. POVWndClass.lpszClassName = TEXT("POVHAT");
  221. return(RegisterClassEx( &POVWndClass ));
  222. }
  223. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  224. //
  225. // FUNCTION : DrawBitmap
  226. // REMARKS : Copied verbatim from Petzold (WIN95 pg 190)
  227. // PARAMS : HDC - dc for drawing
  228. // HBITMAP - bitmap to draw
  229. // int xstart, ystart - where to place the bitmap
  230. //
  231. // RETURNS : void
  232. // CALLS :
  233. // NOTES :
  234. //
  235. void DrawBitmap(HDC hDC, HBITMAP hBitmap, BYTE xStart, BYTE yStart)
  236. {
  237. HDC hdcMem = CreateCompatibleDC(hDC);
  238. // Found by prefix: Millen Bug129155. manbugs 29339
  239. // If CreateCompatibleDC fails, we should'nt proceed.
  240. if( hdcMem == NULL ) return;
  241. SelectObject(hdcMem, hBitmap);
  242. SetMapMode(hdcMem,GetMapMode(hDC));
  243. // Be aware! This is the size of the current BITMAP...
  244. // IF IT CHANGES THIS WILL FAIL!!!
  245. POINT ptSize = {16, 16};
  246. DPtoLP(hDC, &ptSize, 1);
  247. POINT ptOrg = {0,0};
  248. DPtoLP(hdcMem, &ptOrg, 1);
  249. BitBlt(hDC, xStart, yStart, ptSize.x, ptSize.y, hdcMem, ptOrg.x, ptOrg.y, SRCAND);
  250. DeleteDC(hdcMem);
  251. }
  252. //~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=EOF=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=