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.

283 lines
6.5 KiB

  1. /*
  2. ** DRAGSIZE.C
  3. **
  4. ** Drag size bar code
  5. **
  6. */
  7. #include "priv.h"
  8. #pragma hdrstop
  9. typedef struct tagDRAGSIZEINFO
  10. {
  11. DWORD_PTR lpData;
  12. BOOL bDragging;
  13. POINT ptNow;
  14. HFONT hFont;
  15. } DRAGSIZEINFO, *PDRAGSIZEINFO;
  16. static TCHAR szDragSizeClass[] = DRAGSIZECLASSNAME;
  17. LRESULT NEAR PASCAL InitDragSizeWnd(HWND hWnd, LPCREATESTRUCT lpCreate)
  18. {
  19. PDRAGSIZEINFO pDragSizeInfo;
  20. /* Create the status info struct; abort if it does not exist,
  21. ** otherwise save it in the window structure
  22. */
  23. pDragSizeInfo = ALLOCWINDOWPOINTER(PDRAGSIZEINFO, sizeof(DRAGSIZEINFO));
  24. if (!pDragSizeInfo)
  25. {
  26. return(-1);
  27. }
  28. SETWINDOWPOINTER(hWnd, PDRAGSIZEINFO, pDragSizeInfo);
  29. pDragSizeInfo->lpData = (DWORD_PTR)lpCreate->lpCreateParams;
  30. pDragSizeInfo->bDragging = FALSE;
  31. return(0);
  32. }
  33. /* Track the mouse and send messages to the parent whenever it moves.
  34. */
  35. void NEAR PASCAL DragSize(HWND hWnd, PDRAGSIZEINFO pDragSizeInfo, POINT ptStart)
  36. {
  37. MSG msg;
  38. HWND hwndParent;
  39. LONG wID;
  40. if (!pDragSizeInfo || pDragSizeInfo->bDragging)
  41. {
  42. return;
  43. }
  44. pDragSizeInfo->bDragging = TRUE;
  45. pDragSizeInfo->ptNow = ptStart;
  46. SetCapture(hWnd);
  47. hwndParent = GetParent(hWnd);
  48. wID = GETWINDOWID(hWnd);
  49. SendMessage(hwndParent, WM_COMMAND, MAKEWPARAM(wID, DSN_BEGINDRAG), (LPARAM)hWnd);
  50. for ( ; ; )
  51. {
  52. if (GetCapture() != hWnd)
  53. {
  54. EndAbort:
  55. /* Abort the process.
  56. */
  57. pDragSizeInfo->ptNow = ptStart;
  58. SendMessage(hwndParent, WM_COMMAND, MAKEWPARAM(wID, DSN_DRAGGING), (LPARAM)hWnd);
  59. goto EndAdjust;
  60. }
  61. if (!PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
  62. {
  63. continue;
  64. }
  65. switch (msg.message)
  66. {
  67. case WM_KEYDOWN:
  68. switch (msg.wParam)
  69. {
  70. case VK_ESCAPE:
  71. AbortAdjust:
  72. SetCapture(NULL);
  73. goto EndAbort;
  74. default:
  75. break;
  76. }
  77. break;
  78. case WM_KEYUP:
  79. case WM_CHAR:
  80. break;
  81. case WM_LBUTTONDOWN:
  82. /* This shouldn't happen.
  83. */
  84. goto AbortAdjust;
  85. case WM_MOUSEMOVE:
  86. LPARAM2POINT( msg.lParam, &(pDragSizeInfo->ptNow) );
  87. TraceMsg(TF_GENERAL, "DragSize: ptNow = (%d, %d)\n", pDragSizeInfo->ptNow.x, pDragSizeInfo->ptNow.y);
  88. SendMessage(hwndParent, WM_COMMAND, MAKEWPARAM(wID, DSN_DRAGGING), (LPARAM)hWnd);
  89. break;
  90. case WM_LBUTTONUP:
  91. /* All done.
  92. */
  93. SetCapture(NULL);
  94. goto EndAdjust;
  95. case WM_RBUTTONDOWN:
  96. goto AbortAdjust;
  97. default:
  98. TranslateMessage(&msg);
  99. DispatchMessage(&msg);
  100. break;
  101. }
  102. }
  103. EndAdjust:
  104. SendMessage(hwndParent, WM_COMMAND, MAKEWPARAM(wID, DSN_ENDDRAG), (LPARAM)hWnd);
  105. pDragSizeInfo->bDragging = FALSE;
  106. }
  107. /* Ask the parent to paint the window.
  108. */
  109. void NEAR PASCAL PaintDragSizeWnd(HWND hWnd, PDRAGSIZEINFO pDragSizeInfo)
  110. {
  111. PAINTSTRUCT ps;
  112. DRAWITEMSTRUCT dis;
  113. HDC hDC;
  114. HFONT hOldFont = NULL;
  115. if (!pDragSizeInfo)
  116. {
  117. return;
  118. }
  119. hDC = BeginPaint(hWnd, &ps);
  120. if (pDragSizeInfo->hFont)
  121. {
  122. hOldFont = (HFONT) SelectObject(hDC, pDragSizeInfo->hFont);
  123. }
  124. /* Fill in the DRAWITEMSTRUCT. Note that some of the fields are
  125. ** undefined.
  126. */
  127. dis.CtlID = GetDlgCtrlID(hWnd);
  128. dis.hwndItem = hWnd;
  129. dis.hDC = hDC;
  130. GetClientRect(hWnd, &dis.rcItem);
  131. dis.itemData = pDragSizeInfo->lpData;
  132. SendMessage(GetParent(hWnd), WM_DRAWITEM, GetDlgCtrlID(hWnd),
  133. (LPARAM)(LPDRAWITEMSTRUCT)&dis);
  134. if (hOldFont)
  135. {
  136. SelectObject(hDC, hOldFont);
  137. }
  138. EndPaint(hWnd, &ps);
  139. }
  140. LRESULT CALLBACK DragSizeWndProc(HWND hWnd, UINT uMessage, WPARAM wParam, LPARAM lParam)
  141. {
  142. #define lpCreate ((LPCREATESTRUCT)lParam)
  143. PDRAGSIZEINFO pDragSizeInfo;
  144. pDragSizeInfo = GETWINDOWPOINTER(hWnd, PDRAGSIZEINFO);
  145. switch (uMessage)
  146. {
  147. case WM_NCCREATE:
  148. SendMessage(lpCreate->hwndParent, WM_COMMAND,
  149. MAKEWPARAM((SHORT)(lpCreate->hMenu), DSN_NCCREATE), (LPARAM)hWnd);
  150. break;
  151. case WM_CREATE:
  152. InitDragSizeWnd(hWnd, (LPCREATESTRUCT)lParam);
  153. break;
  154. case WM_DESTROY:
  155. if (pDragSizeInfo)
  156. {
  157. FREEWINDOWPOINTER(pDragSizeInfo);
  158. SETWINDOWPOINTER(hWnd, PDRAGSIZEINFO, NULL);
  159. }
  160. break;
  161. case WM_LBUTTONDOWN:
  162. {
  163. POINT pt;
  164. LPARAM2POINT( lParam, &pt );
  165. DragSize(hWnd, pDragSizeInfo, pt);
  166. }
  167. break;
  168. case WM_PAINT:
  169. PaintDragSizeWnd(hWnd, pDragSizeInfo);
  170. return(0);
  171. case WM_SETFONT:
  172. if (!pDragSizeInfo)
  173. {
  174. return(1L);
  175. }
  176. pDragSizeInfo->hFont = (HFONT)wParam;
  177. if (LOWORD(lParam))
  178. {
  179. InvalidateRect(hWnd, NULL, TRUE);
  180. UpdateWindow(hWnd);
  181. }
  182. return(0L);
  183. case WM_GETFONT:
  184. if (!pDragSizeInfo)
  185. {
  186. return(LRESULT)(NULL);
  187. }
  188. return(MAKELRESULT(pDragSizeInfo->hFont, 0));
  189. case DSM_DRAGPOS:
  190. {
  191. LPPOINT lppt = (LPPOINT)lParam;
  192. if (!pDragSizeInfo || !pDragSizeInfo->bDragging || lppt == NULL)
  193. {
  194. return(-1L);
  195. }
  196. *lppt = pDragSizeInfo->ptNow;
  197. return(0);
  198. }
  199. break;
  200. default:
  201. break;
  202. }
  203. return(DefWindowProc(hWnd, uMessage, wParam, lParam));
  204. }
  205. BOOL FAR PASCAL InitDragSizeClass(void)
  206. {
  207. WNDCLASS rClass;
  208. if (GetClassInfo(HINST_THISDLL, szDragSizeClass, &rClass))
  209. {
  210. return(TRUE);
  211. }
  212. rClass.style = 0;
  213. rClass.lpfnWndProc = DragSizeWndProc;
  214. rClass.cbClsExtra = 0;
  215. rClass.cbWndExtra = sizeof(PDRAGSIZEINFO);
  216. rClass.hInstance = HINST_THISDLL;
  217. rClass.hIcon = NULL;
  218. rClass.hCursor = LoadCursor(NULL, IDC_ARROW);
  219. rClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
  220. rClass.lpszMenuName = NULL;
  221. rClass.lpszClassName = szDragSizeClass;
  222. return(RegisterClass(&rClass));
  223. }