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.

225 lines
7.0 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. (SendMessage (hWndCB, CB_GETCURSEL, (WPARAM)0, (LPARAM)0))
  61. #define CBSetSelection(hWndCB, iIndex) \
  62. (SendMessage (hWndCB, CB_SETCURSEL, (WPARAM)iIndex, (LPARAM)0))
  63. #define CBString(hWndCB, iIndex, lpszText) \
  64. (SendMessage (hWndCB, CB_GETLBTEXT, (WPARAM)iIndex, (LPARAM)lpszText))
  65. #define CBStringLen(hWndCB, iIndex) \
  66. (SendMessage (hWndCB, CB_GETLBTEXTLEN, (WPARAM)iIndex, (LPARAM)0))
  67. //======================================//
  68. // Listbox helpers //
  69. //======================================//
  70. #define LBAdd(hWndLB, lpszText) \
  71. (SendMessage (hWndLB, LB_ADDSTRING, (WPARAM)0, (LPARAM)lpszText))
  72. #define LBData(hWndLB, iIndex) \
  73. (SendMessage (hWndLB, LB_GETITEMDATA, (WPARAM)iIndex, (LPARAM)0))
  74. #define LBDelete(hWndLB, iIndex) \
  75. (SendMessage (hWndLB, LB_DELETESTRING, (WPARAM)iIndex, (LPARAM)0))
  76. #define LBFind(hWndLB, lpszText) \
  77. (SendMessage (hWndLB, LB_FINDSTRING, (WPARAM)-1, (LPARAM)lpszText))
  78. #define LBFocus(hWndLB) \
  79. (SendMessage (hWndLB, LB_GETCARETINDEX, (WPARAM)0, (LPARAM)0))
  80. #define LBInsert(hWndLB, iIndex, lpszText) \
  81. (SendMessage (hWndLB, LB_INSERTSTRING, (WPARAM)iIndex, (LPARAM)lpszText))
  82. #define LBNumItems(hWndLB) \
  83. ((INT) SendMessage (hWndLB, LB_GETCOUNT, (WPARAM)0, (LPARAM)0))
  84. #define LBReset(hWndLB) \
  85. ((INT)(DWORD)SendMessage((hWndLB), LB_RESETCONTENT,\
  86. (WPARAM)0, (LPARAM)0))
  87. #define LBSelected(hwndLB, index) \
  88. ((INT)(DWORD)SendMessage((hwndLB), LB_GETSEL, \
  89. (WPARAM)(INT)(index), (LPARAM)0))
  90. #define LBSelection(hWndLB) \
  91. ((INT)(DWORD)SendMessage (hWndLB, LB_GETCURSEL, (WPARAM)0, (LPARAM)0))
  92. #define LBSetData(hWndLB, iIndex, lData) \
  93. (SendMessage (hWndLB, LB_SETITEMDATA, (WPARAM)iIndex, (LPARAM)lData))
  94. #define LBSetSelection(hWndLB, iIndex) \
  95. (SendMessage (hWndLB, LB_SETCURSEL, (WPARAM)iIndex, (LPARAM)0))
  96. #define MLBSetSelection(hWndMLB, iIndex, bSet) \
  97. (SendMessage (hWndMLB, LB_SETSEL, (WPARAM)bSet, (LPARAM)iIndex))
  98. #define LBSetVisible(hWndLB, iIndex) \
  99. (SendMessage (hWndLB, LB_SETCARETINDEX, (WPARAM)iIndex, (LPARAM)0))
  100. #define LBSetRedraw(hWndLB, bDrawOnOff) \
  101. (SendMessage (hWndLB, WM_SETREDRAW, (WPARAM)bDrawOnOff, (LPARAM)0))
  102. #define LBSetHorzExtent(hWndLB, wExtent) \
  103. (SendMessage (hWndLB, LB_SETHORIZONTALEXTENT, (WPARAM)wExtent, (LPARAM)0))
  104. #define LBSetItemHeight(hWndLB, iHeight) \
  105. (SendMessage (hWndLB, LB_SETITEMHEIGHT, (WPARAM)0, (LPARAM)iHeight))
  106. #define LBGetTextLen(hWndLB, iIndex) \
  107. (SendMessage (hWndLB, LB_GETTEXTLEN, (WPARAM)iIndex, (LPARAM)0))
  108. #define LBGetText(hWndLB, iIndex, szPath) \
  109. (SendMessage (hWndLB, LB_GETTEXT, (WPARAM)iIndex, (LPARAM)szPath))
  110. //======================================//
  111. // Edit helpers //
  112. //======================================//
  113. #define EditModified(hWndEdit) \
  114. (SendMessage ((hWndEdit), EM_GETMODIFY, (WPARAM)0, (LPARAM)0))
  115. #define EditSetModified(hWndEdit, bModified) \
  116. (SendMessage ((hWndEdit), EM_SETMODIFY, (WPARAM)bModified, (LPARAM)0))
  117. #define EditSetLimit(hWndEdit, iLimit) \
  118. (SendMessage ((hWndEdit), EM_LIMITTEXT, (WPARAM)iLimit, (LPARAM)0))
  119. #define EditSetTextPos(hWnd, idControl, iStartPos, iEndPos) \
  120. (SendMessage (GetDlgItem(hWnd, idControl), EM_SETSEL, (WPARAM)iStartPos, (LPARAM)iEndPos))
  121. #define EditSetTextEndPos(hWnd, idControl) \
  122. EditSetTextPos(hWnd, idControl, (WPARAM)0, (LPARAM)32767)
  123. //======================================//
  124. // Cursor helpers //
  125. //======================================//
  126. #define SetHourglassCursor() \
  127. (SetCursor(LoadCursor(NULL, IDC_WAIT)))
  128. #define SetArrowCursor() \
  129. (SetCursor(LoadCursor(NULL, IDC_ARROW)))