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.

234 lines
7.7 KiB

  1. /*++
  2. Copyright (C) 1992-1999 Microsoft Corporation
  3. Module Name:
  4. winhelpr.h
  5. Abstract:
  6. This file contains macros for more easily dealing with windows
  7. messages and objects. Think of it as an extension to windows.h.
  8. --*/
  9. //==========================================================================//
  10. // Macros //
  11. //==========================================================================//
  12. #define SetFont(hWnd, hFont) \
  13. (SendMessage ((hWnd), WM_SETFONT, (WPARAM)hFont, (LPARAM)0))
  14. #define GetFont(hWnd) \
  15. (HFONT)(SendMessage((hWnd), WM_GETFONT, (WPARAM)0, (LPARAM)0))
  16. #define PrintClient(hWnd, hDC, uFlags) \
  17. (SendMessage((hWnd), WM_PRINTCLIENT, (WPARAM)hDC, (LPARAM)(uFlags)) )
  18. //======================================//
  19. // Object-differentiation routines //
  20. //======================================//
  21. // Windows APIs deal with all GDI objects the same. There's a SelectObject,
  22. // no SelectBitmap, SelectFont, etc. We use these instead to make the code
  23. // easier to read. Also, you can redefine one of these to check the
  24. // validity of a particular GDI object type.
  25. #define SelectBitmap(hDC, hBitmap) \
  26. ((HBITMAP)SelectObject (hDC, hBitmap))
  27. #define SelectFont(hDC, hFont) \
  28. ((HFONT)SelectObject (hDC, hFont))
  29. #define SelectBrush(hDC, hBrush) \
  30. ((HBRUSH)SelectObject (hDC, hBrush))
  31. #define DeleteBrush(hBrush) \
  32. (DeleteObject (hBrush))
  33. #define SelectPen(hDC, hPen) \
  34. ((HPEN)SelectObject (hDC, hPen))
  35. #define DeletePen(hPen) \
  36. (DeleteObject (hPen))
  37. //======================================//
  38. // //
  39. //======================================//
  40. #define CBData(hWndCB, iIndex) \
  41. (SendMessage (hWndCB, CB_GETITEMDATA, (WPARAM)iIndex, (LPARAM)0))
  42. #define CBSetData(hWndCB, iIndex, lData) \
  43. (SendMessage (hWndCB, CB_SETITEMDATA, (WPARAM)iIndex, (LPARAM)lData))
  44. #define CBAdd(hWndCB, lpszText) \
  45. ((INT)(DWORD)SendMessage((hWndCB), CB_ADDSTRING, \
  46. (WPARAM)0, (LPARAM)(LPCTSTR)(lpszText)))
  47. #define CBDelete(hWndCB, iIndex) \
  48. ((INT)(DWORD)SendMessage((hWndCB), CB_DELETESTRING, \
  49. (WPARAM)iIndex, (LPARAM)0))
  50. #define CBFind(hWndCB, lpszText) \
  51. (SendMessage (hWndCB, CB_FINDSTRING, (WPARAM)(-1), (LPARAM) lpszText))
  52. #define CBInsert(hWndCB, iIndex, lpszText) \
  53. (SendMessage (hWndCB, CB_INSERTSTRING, (WPARAM)iIndex, (LPARAM) lpszText))
  54. #define CBNumItems(hWndCB) \
  55. ((INT) SendMessage (hWndCB, CB_GETCOUNT, (WPARAM)0, (LPARAM)0))
  56. #define CBReset(hWndCB) \
  57. ((INT)(DWORD)SendMessage((hWndCB), CB_RESETCONTENT,\
  58. (WPARAM)0, (LPARAM)0))
  59. #define CBSelection(hWndCB) \
  60. ((INT)(DWORD)(SendMessage (hWndCB, CB_GETCURSEL, (WPARAM)0, (LPARAM)0)))
  61. #define CBSetSelection(hWndCB, iIndex) \
  62. ((INT)(DWORD)SendMessage ((hWndCB), CB_SETCURSEL, \
  63. (WPARAM)iIndex, (LPARAM)0))
  64. #define CBString(hWndCB, iIndex, lpszText) \
  65. (SendMessage (hWndCB, CB_GETLBTEXT, (WPARAM)iIndex, (LPARAM)lpszText))
  66. #define CBStringLen(hWndCB, iIndex) \
  67. (SendMessage (hWndCB, CB_GETLBTEXTLEN, (WPARAM)iIndex, (LPARAM)0))
  68. //======================================//
  69. // Listbox helpers //
  70. //======================================//
  71. #define LBAdd(hWndLB, lpszText) \
  72. (SendMessage (hWndLB, LB_ADDSTRING, (WPARAM)0, (LPARAM)lpszText))
  73. #define LBData(hWndLB, iIndex) \
  74. (SendMessage (hWndLB, LB_GETITEMDATA, (WPARAM)iIndex, (LPARAM)0))
  75. #define LBDelete(hWndLB, iIndex) \
  76. (SendMessage (hWndLB, LB_DELETESTRING, (WPARAM)iIndex, (LPARAM)0))
  77. #define LBFind(hWndLB, lpszText) \
  78. (SendMessage (hWndLB, LB_FINDSTRING, (WPARAM)-1, (LPARAM)lpszText))
  79. #define LBFocus(hWndLB) \
  80. ((INT)SendMessage (hWndLB, LB_GETCARETINDEX, (WPARAM)0, (LPARAM)0))
  81. #define LBInsert(hWndLB, iIndex, lpszText) \
  82. (SendMessage (hWndLB, LB_INSERTSTRING, (WPARAM)iIndex, (LPARAM)lpszText))
  83. #define LBNumItems(hWndLB) \
  84. ((INT) SendMessage (hWndLB, LB_GETCOUNT, (WPARAM)0, (LPARAM)0))
  85. #define LBReset(hWndLB) \
  86. ((INT)(DWORD)SendMessage((hWndLB), LB_RESETCONTENT,\
  87. (WPARAM)0, (LPARAM)0))
  88. #define LBSelected(hwndLB, index) \
  89. ((INT)(DWORD)SendMessage((hwndLB), LB_GETSEL, \
  90. (WPARAM)(INT)(index), (LPARAM)0))
  91. #define LBSelection(hWndLB) \
  92. ((INT)(DWORD)SendMessage (hWndLB, LB_GETCURSEL, (WPARAM)0, (LPARAM)0))
  93. #define LBSetData(hWndLB, iIndex, lData) \
  94. (SendMessage (hWndLB, LB_SETITEMDATA, (WPARAM)iIndex, (LPARAM)lData))
  95. #define LBSetSelection(hWndLB, iIndex) \
  96. (SendMessage (hWndLB, LB_SETCURSEL, (WPARAM)iIndex, (LPARAM)0))
  97. #define MLBSetSelection(hWndMLB, iIndex, bSet) \
  98. (SendMessage (hWndMLB, LB_SETSEL, (WPARAM)bSet, (LPARAM)iIndex))
  99. #define LBSetVisible(hWndLB, iIndex) \
  100. (SendMessage (hWndLB, LB_SETCARETINDEX, (WPARAM)iIndex, (LPARAM)0))
  101. #define LBSetRedraw(hWndLB, bDrawOnOff) \
  102. (SendMessage (hWndLB, WM_SETREDRAW, (WPARAM)bDrawOnOff, (LPARAM)0))
  103. #define LBSetHorzExtent(hWndLB, wExtent) \
  104. (SendMessage (hWndLB, LB_SETHORIZONTALEXTENT, (WPARAM)wExtent, (LPARAM)0))
  105. #define LBSetItemHeight(hWndLB, iHeight) \
  106. (SendMessage (hWndLB, LB_SETITEMHEIGHT, (WPARAM)0, (LPARAM)iHeight))
  107. #define LBGetTextLen(hWndLB, iIndex) \
  108. (SendMessage (hWndLB, LB_GETTEXTLEN, (WPARAM)iIndex, (LPARAM)0))
  109. #define LBGetText(hWndLB, iIndex, szPath) \
  110. (SendMessage (hWndLB, LB_GETTEXT, (WPARAM)iIndex, (LPARAM)szPath))
  111. #define LBSelectCount(hWndLB) \
  112. ((INT)SendMessage (hWndLB, LB_GETSELCOUNT, (WPARAM)0, (LPARAM)0))
  113. #define LBSetSel(hWndLB, fSelected, iIndex) \
  114. (SendMessage (hWndLB, LB_SETSEL, (WPARAM)fSelected, (LPARAM)iIndex))
  115. #define LBGetSelItems(hWndLB, nMax, pBuffer) \
  116. ((INT)SendMessage (hWndLB, LB_GETSELITEMS, (WPARAM)nMax, (LPARAM)pBuffer))
  117. //======================================//
  118. // Edit helpers //
  119. //======================================//
  120. #define EditModified(hWndEdit) \
  121. (SendMessage ((hWndEdit), EM_GETMODIFY, (WPARAM)0, (LPARAM)0))
  122. #define EditSetModified(hWndEdit, bModified) \
  123. (SendMessage ((hWndEdit), EM_SETMODIFY, (WPARAM)bModified, (LPARAM)0))
  124. #define EditSetLimit(hWndEdit, iLimit) \
  125. (SendMessage ((hWndEdit), EM_LIMITTEXT, (WPARAM)iLimit, (LPARAM)0))
  126. #define EditSetTextPos(hWnd, idControl, iStartPos, iEndPos) \
  127. (SendMessage (GetDlgItem(hWnd, idControl), EM_SETSEL, (WPARAM)iStartPos, (LPARAM)iEndPos))
  128. #define EditSetTextEndPos(hWnd, idControl) \
  129. EditSetTextPos(hWnd, idControl, (WPARAM)0, (LPARAM)32767)
  130. //======================================//
  131. // Cursor helpers //
  132. //======================================//
  133. #define SetHourglassCursor() \
  134. (SetCursor(LoadCursor(NULL, IDC_WAIT)))
  135. #define SetArrowCursor() \
  136. (SetCursor(LoadCursor(NULL, IDC_ARROW)))