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.

381 lines
9.9 KiB

  1. //==========================================================================//
  2. // Constants //
  3. //==========================================================================//
  4. #define ThreeDPad 2
  5. #define NOCHANGE -1
  6. #define MENUCLOSING (0xFFFF0000)
  7. #define WM_DLGSETFOCUS (WM_USER + 0x201)
  8. #define WM_DLGKILLFOCUS (WM_USER + 0x202)
  9. //==========================================================================//
  10. // Macros //
  11. //==========================================================================//
  12. #define PinInclusive(x, lo, hi) \
  13. (max (lo, min (x, hi)))
  14. #define PinExclusive(x, lo, hi) \
  15. (max ((lo) + 1, min (x, (hi) - 1)))
  16. #define BoolEqual(a, b) \
  17. ((a == 0) == (b == 0))
  18. //=============================//
  19. // Window Instance Accessors //
  20. //=============================//
  21. #define WindowParent(hWnd) \
  22. ((HWND) GetWindowLongPtr (hWnd, GWLP_HWNDPARENT))
  23. #define WindowID(hWnd) \
  24. GetWindowLong (hWnd, GWL_ID)
  25. #define WindowInstance(hWnd) \
  26. GetWindowWord (hWnd, GWW_HINSTANCE)
  27. #define WindowStyle(hWnd) \
  28. GetWindowLong (hWnd, GWL_STYLE)
  29. #define WindowSetStyle(hWnd, lStyle) \
  30. SetWindowLong (hWnd, GWL_STYLE, lStyle)
  31. #define WindowExStyle(hWnd) \
  32. GetWindowLong (hWnd, GWL_EXSTYLE)
  33. #define WindowSetID(hWnd, wID) \
  34. SetWindowLong (hWnd, GWL_ID, wID)
  35. // All modeless dialogs need to be dispatched separately in the WinMain
  36. // message loop, but only if the dialog exists.
  37. #define ModelessDispatch(hDlg, lpMsg) \
  38. (hDlg ? IsDialogMessage (hDlg, lpMsg) : FALSE)
  39. #define strclr(szString) \
  40. (szString [0] = TEXT('\0'))
  41. #define strempty(lpszString) \
  42. (!(lpszString) || !(lpszString[0]))
  43. #define pstrsame(lpsz1, lpsz2) \
  44. ((!lpsz1 && !lpsz2) || (lpsz1 && lpsz2 && strsame (lpsz1, lpsz2)))
  45. #define pstrsamei(lpsz1, lpsz2) \
  46. ((!lpsz1 && !lpsz2) || (lpsz1 && lpsz2 && strsamei (lpsz1, lpsz2)))
  47. #define StringLoad(wID, szText) \
  48. (LoadString (hInstance, wID, \
  49. szText, (sizeof (szText) / sizeof(TCHAR)) - 1))
  50. #define WindowInvalidate(hWnd) \
  51. (InvalidateRect (hWnd, NULL, TRUE))
  52. #define WindowShow(hWnd, bShow) \
  53. (ShowWindow (hWnd, (bShow) ? SW_SHOW : SW_HIDE))
  54. #define MenuCheck(hMenu, wID, bCheck) \
  55. (CheckMenuItem (hMenu, wID, (bCheck) ? \
  56. (MF_BYCOMMAND | MF_CHECKED) : (MF_BYCOMMAND | MF_UNCHECKED)))
  57. #define DeleteFont(hFont) \
  58. (DeleteObject (hFont))
  59. #define DeleteBitmap(hBitmap) \
  60. (DeleteObject (hBitmap))
  61. #define DialogControl(hDlg, wControlID) \
  62. GetDlgItem (hDlg, wControlID)
  63. #define DialogSetInt(hDlg, wControlID, iValue) \
  64. (SetDlgItemInt (hDlg, wControlID, iValue, TRUE))
  65. #define DialogText(hDlg, wControlID, szText) \
  66. (GetDlgItemText (hDlg, wControlID, szText, sizeof (szText) / sizeof(TCHAR) - 1))
  67. #define DialogInt(hDlg, wControlID) \
  68. (GetDlgItemInt (hDlg, wControlID, NULL, TRUE))
  69. #define strsame(szText1, szText2) \
  70. (!lstrcmp (szText1, szText2))
  71. #define strsamei(szText1, szText2) \
  72. (!lstrcmpi (szText1, szText2))
  73. #define strnsame(szText1, szText2, iLen) \
  74. (!lstrncmp (szText1, szText2, iLen))
  75. #define CreateScreenDC() \
  76. CreateDC (TEXT("DISPLAY"), NULL, NULL, NULL)
  77. #define RectContract(lpRect, xAmt, yAmt) \
  78. { \
  79. (lpRect)->left += (xAmt) ; \
  80. (lpRect)->top += (yAmt) ; \
  81. (lpRect)->right -= (xAmt) ; \
  82. (lpRect)->bottom -= (yAmt) ; \
  83. }
  84. #define IsBW(hDC) \
  85. (DeviceNumColors (hDC) <= 2)
  86. #ifdef KEEP_PRINT
  87. #define IsPrinterDC(hDC) \
  88. (GetDeviceCaps (hDC, TECHNOLOGY) != DT_RASDISPLAY)
  89. #else
  90. #define IsPrinterDC(hDC) \
  91. (FALSE)
  92. #endif
  93. #define VertInchPixels(hDC, iNumerator, iDenominator) \
  94. ((iNumerator * GetDeviceCaps (hDC, LOGPIXELSY)) / iDenominator)
  95. #define HorzInchPixels(hDC, iNumerator, iDenominator) \
  96. ((iNumerator * GetDeviceCaps (hDC, LOGPIXELSX)) / iDenominator)
  97. #define VertPointPixels(hDC, iPoints) \
  98. ((iPoints * GetDeviceCaps (hDC, LOGPIXELSY)) / 72)
  99. #define SimulateButtonPush(hDlg, wControlID) \
  100. (PostMessage (hDlg, WM_COMMAND, \
  101. (WPARAM) MAKELONG (wControlID, BN_CLICKED), \
  102. (LPARAM) DialogControl (hDlg, wControlID)))
  103. // convert an unicode string to OEM string
  104. #define ConvertUnicodeStr(pOemStr, pUnicodeStr) \
  105. CharToOemBuff(pUnicodeStr, pOemStr, lstrlen(pUnicodeStr) + 1)
  106. #define CallWinHelp(ContextID, WND) \
  107. if (*pszHelpFile != 0) { \
  108. WinHelp(hWndMain, pszHelpFile, HELP_CONTEXT, ContextID); \
  109. } else { \
  110. DlgErrorBox (WND, ERR_HELP_NOT_AVAILABLE); \
  111. }
  112. //==========================================================================//
  113. // Exported Functions //
  114. //==========================================================================//
  115. void Fill (HDC hDC,
  116. DWORD rgbColor,
  117. LPRECT lpRect) ;
  118. void ScreenRectToClient (HWND hWnd,
  119. LPRECT lpRect) ;
  120. int TextWidth (HDC hDC, LPTSTR lpszText) ;
  121. void ThreeDConcave (HDC hDC,
  122. int x1, int y1,
  123. int x2, int y2,
  124. BOOL bFace) ;
  125. void ThreeDConvex (HDC hDC,
  126. int x1, int y1,
  127. int x2, int y2) ;
  128. void ThreeDConcave1 (HDC hDC,
  129. int x1, int y1,
  130. int x2, int y2) ;
  131. void ThreeDConvex1 (HDC hDC,
  132. int x1, int y1,
  133. int x2, int y2) ;
  134. int _cdecl mike (TCHAR *szFormat, ...) ;
  135. int _cdecl DlgErrorBox (HWND hDlg, UINT id, ...) ;
  136. int _cdecl mike1 (TCHAR *szFormat, ...) ;
  137. int _cdecl mike2 (TCHAR *szFormat, ...) ;
  138. int FontHeight (HDC hDC,
  139. BOOL bIncludeLeading) ;
  140. int TextAvgWidth (HDC hDC,
  141. int iNumChars) ;
  142. void WindowCenter (HWND hWnd) ;
  143. BOOL DialogMove (HDLG hDlg,
  144. WORD wControlID,
  145. int xPos,
  146. int yPos,
  147. int xWidth,
  148. int yHeight) ;
  149. int DialogWidth (HDLG hDlg,
  150. WORD wControlID) ;
  151. int DialogXPos (HDLG hDlg,
  152. WORD wControlID) ;
  153. int DialogYPos (HDLG hDlg,
  154. WORD wControlID) ;
  155. void DialogShow (HDLG hDlg,
  156. WORD wID,
  157. BOOL bShow) ;
  158. BOOL _cdecl DialogSetText (HDLG hDlg,
  159. WORD wControlID,
  160. WORD wStringID,
  161. ...) ;
  162. #if 0
  163. BOOL _cdecl DialogSetString (HDLG hDlg,
  164. WORD wControlID,
  165. LPTSTR lpszFormat,
  166. ...) ;
  167. #endif
  168. #define DialogSetString(hDlg, wControlID, lpszFormat) \
  169. SetDlgItemText (hDlg, wControlID, lpszFormat)
  170. LPTSTR LongToCommaString (LONG lNumber,
  171. LPTSTR lpszText) ;
  172. BOOL MenuSetPopup (HWND hWnd,
  173. int iPosition,
  174. WORD wControlID,
  175. LPTSTR lpszResourceID) ;
  176. void DialogEnable (HDLG hDlg,
  177. WORD wID,
  178. BOOL bEnable) ;
  179. LPTSTR FileCombine (LPTSTR lpszFileSpec,
  180. LPTSTR lpszFileDirectory,
  181. LPTSTR lpszFileName) ;
  182. LPTSTR ExtractFileName (LPTSTR pFileSpec) ;
  183. int CBAddInt (HWND hWndCB,
  184. int iValue) ;
  185. FLOAT DialogFloat (HDLG hDlg,
  186. WORD wControlID,
  187. BOOL *pbOK) ;
  188. LPTSTR StringAllocate (LPTSTR lpszText1) ;
  189. int DivRound (int iNumerator, int iDenominator) ;
  190. BOOL MenuEnableItem (HMENU hMenu,
  191. WORD wID,
  192. BOOL bEnable) ;
  193. void DrawBitmap (HDC hDC,
  194. HBITMAP hBitmap,
  195. int xPos,
  196. int yPos,
  197. LONG lROPCode) ;
  198. void BitmapDimemsion (HBITMAP hBitmap, int *pHeight, int *pWidth) ;
  199. void WindowResize (HWND hWnd,
  200. int xWidth,
  201. int yHeight) ;
  202. int WindowHeight (HWND hWnd) ;
  203. void WindowSetTopmost (HWND hWnd, BOOL bTopmost) ;
  204. void WindowEnableTitle (HWND hWnd, BOOL bTitle) ;
  205. void Line (HDC hDC,
  206. HPEN hPen,
  207. int x1, int y1,
  208. int x2, int y2) ;
  209. #define HLine(hDC, hPen, x1, x2, y) \
  210. Line (hDC, hPen, x1, y, x2, y) ;
  211. #define VLine(hDC, hPen, x, y1, y2) \
  212. Line (hDC, hPen, x, y1, x, y2) ;
  213. int DialogHeight (HDLG hDlg,
  214. WORD wControlID) ;
  215. void DialogSetFloat (HDLG hDlg,
  216. WORD wControlID,
  217. FLOAT eValue) ;
  218. void DialogSetInterval (HDLG hDlg,
  219. WORD wControlID,
  220. int IntervalMSec ) ;
  221. int MessageBoxResource (HWND hWndParent,
  222. WORD wTextID,
  223. WORD wTitleID,
  224. UINT uiStyle) ;
  225. void WindowPlacementToString (PWINDOWPLACEMENT pWP,
  226. LPTSTR lpszText) ;
  227. void StringToWindowPlacement (LPTSTR lpszText,
  228. PWINDOWPLACEMENT pWP) ;
  229. DWORD MenuIDToHelpID (DWORD MenuID) ;