Fixed bug in WINSOCK_accept when no event is present.
[wine] / include / windowsx.h
1 /* Copyright (C) 1999 Corel Corporation (Paul Quinn) */
2
3 #ifndef _INC_WINDOWSX
4 #define _INC_WINDOWSX
5         
6 #ifdef __cplusplus
7 extern "C" {
8 #endif
9
10 #define GET_WM_VSCROLL_CODE(wp, lp)         LOWORD(wp)
11 #define GET_WM_VSCROLL_POS(wp, lp)          HIWORD(wp)
12 #define GET_WM_VSCROLL_HWND(wp, lp)         (HWND)(lp)
13 #define GET_WM_VSCROLL_MPS(code, pos, hwnd) (WPARAM)MAKELONG(code, pos), (LONG)(hwnd)
14
15
16 #define GET_WM_COMMAND_ID(wp, lp)           LOWORD(wp)
17 #define GET_WM_COMMAND_HWND(wp, lp)         (HWND)(lp)
18 #define GET_WM_COMMAND_CMD(wp, lp)          HIWORD(wp)
19 #define GET_WM_COMMAND_MPS(id, hwnd, cmd)   (WPARAM)MAKELONG(id, cmd), (LONG)(hwnd)
20
21 #define WM_CTLCOLOR                             0x0019
22
23 #define GET_WM_CTLCOLOR_HDC(wp, lp, msg)        (HDC)(wp)
24 #define GET_WM_CTLCOLOR_HWND(wp, lp, msg)       (HWND)(lp)
25 #define GET_WM_CTLCOLOR_TYPE(wp, lp, msg)       (WORD)(msg - WM_CTLCOLORMSGBOX)
26 #define GET_WM_CTLCOLOR_MSG(type)               (WORD)(WM_CTLCOLORMSGBOX+(type))
27 #define GET_WM_CTLCOLOR_MPS(hdc, hwnd, type)    (WPARAM)(hdc), (LONG)(hwnd)
28
29 #define GET_WM_VKEYTOITEM_CODE(wp, lp)          (int)(short)LOWORD(wp)
30 #define GET_WM_VKEYTOITEM_ITEM(wp, lp)          HIWORD(wp)
31 #define GET_WM_VKEYTOITEM_HWND(wp, lp)          (HWND)(lp)
32 #define GET_WM_VKEYTOITEM_MPS(code, item, hwnd) (WPARAM)MAKELONG(item, code), (LONG)(hwnd)
33
34 /****** KERNEL Macro APIs ******************************************************/
35
36 #define     GetInstanceModule(hInst) (GetModuleHandle((LPCSTR)MAKELP(0, hInst)))
37 #define     GlobalPtrHandle(lp)      ((HGLOBAL)LOWORD(GlobalHandle(SELECTOROF(lp))))
38 #define     GlobalLockPtr(lp)        ((BOOL)SELECTOROF(GlobalLock(GlobalPtrHandle(lp))))
39 #define     GlobalUnlockPtr(lp)      (GlobalUnlock(GlobalPtrHandle(lp)))
40 #define     GlobalAllocPtr(flags,cb) (GlobalLock(GlobalAlloc((flags), (cb))))
41 #define     GlobalReAllocPtr(lp, cbNew, flags) (GlobalUnlockPtr(lp), \
42                                GlobalLock(GlobalReAlloc(GlobalPtrHandle(lp) , (cbNew), (flags))))
43 #define     GlobalFreePtr(lp)        (GlobalUnlockPtr(lp), (BOOL)GlobalFree(GlobalPtrHandle(lp)))
44
45 /****** USER Macro APIs ******************************************************/
46
47 #define     GetWindowInstance(hwnd) ((HMODULE)GetWindowLong(hwnd, GWL_HINSTANCE))
48
49 #define     GetWindowStyle(hwnd)    ((DWORD)GetWindowLong(hwnd, GWL_STYLE))
50 #define     GetWindowExStyle(hwnd)  ((DWORD)GetWindowLong(hwnd, GWL_EXSTYLE))
51
52 #define     GetWindowOwner(hwnd)    GetWindow(hwnd, GW_OWNER)
53
54 #define     GetFirstChild(hwnd)     GetTopWindow(hwnd)
55 #define     GetFirstSibling(hwnd)   GetWindow(hwnd, GW_HWNDFIRST)
56 #define     GetLastSibling(hwnd)    GetWindow(hwnd, GW_HWNDLAST)
57 #define     GetNextSibling(hwnd)    GetWindow(hwnd, GW_HWNDNEXT)
58 #define     GetPrevSibling(hwnd)    GetWindow(hwnd, GW_HWNDPREV)
59
60 #define     GetWindowID(hwnd)       GetDlgCtrlID(hwnd)
61
62 #define     SetWindowRedraw(hwnd, fRedraw)  \
63                 ((void)SendMessage(hwnd, WM_SETREDRAW, (WPARAM)(BOOL)(fRedraw), 0L))
64 #define     SubclassWindow(hwnd, lpfn)      \
65                 ((WNDPROC)SetWindowLong((hwnd), GWL_WNDPROC, (LPARAM)(WNDPROC)(lpfn)))
66
67 #define     IsMinimized(hwnd)        IsIconic(hwnd)
68 #define     IsMaximized(hwnd)        IsZoomed(hwnd)
69 #define     IsRestored(hwnd)    ((GetWindowStyle(hwnd) & (WS_MINIMIZE | WS_MAXIMIZE)) == 0L)
70 #define     SetWindowFont(hwnd, hfont, fRedraw) \
71                 FORWARD_WM_SETFONT((hwnd), (hfont), (fRedraw), SendMessage)
72
73 #define     GetWindowFont(hwnd)      FORWARD_WM_GETFONT((hwnd), SendMessage)
74
75 #define     MapWindowRect(hwndFrom, hwndTo, lprc) \
76                 MapWindowPoints((hwndFrom), (hwndTo), (POINT *)(lprc), 2)
77
78 #define     IsLButtonDown()  (GetKeyState(VK_LBUTTON) < 0)
79 #define     IsRButtonDown()  (GetKeyState(VK_RBUTTON) < 0)
80 #define     IsMButtonDown()  (GetKeyState(VK_MBUTTON) < 0)
81
82 #define     SubclassDialog(hwndDlg, lpfn) \
83                 ((DLGPROC)SetWindowLong(hwndDlg, DWL_DLGPROC, (LPARAM)(DLGPROC)(lpfn)))
84
85 #define     DeletePen(hpen)      DeleteObject((HGDIOBJ)(HPEN)(hpen))
86 #define     SelectPen(hdc, hpen)    ((HPEN)SelectObject((hdc), (HGDIOBJ)(HPEN)(hpen)))
87 #define     GetStockPen(i)       ((HPEN)GetStockObject(i))
88
89 #define     DeleteBrush(hbr)     DeleteObject((HGDIOBJ)(HBRUSH)(hbr))
90 #define     SelectBrush(hdc, hbr)   ((HBRUSH)SelectObject((hdc), (HGDIOBJ)(HBRUSH)(hbr)))
91 #define     GetStockBrush(i)     ((HBRUSH)GetStockObject(i))
92
93 #define     DeletePalette(hpal)     DeleteObject((HGDIOBJ)(HPALETTE)(hpal))
94
95 #define     DeleteFont(hfont)       DeleteObject((HGDIOBJ)(HFONT)(hfont))
96 #define     SelectFont(hdc, hfont)  ((HFONT)SelectObject((hdc), (HGDIOBJ)(HFONT) (hfont)))
97 #define     GetStockFont(i)         ((HFONT)GetStockObject(i))
98 #define     DeleteBitmap(hbm)       DeleteObject((HGDIOBJ)(HBITMAP)(hbm))
99 #define     SelectBitmap(hdc, hbm)  ((HBITMAP)SelectObject((hdc), (HGDIOBJ)(HBITMAP)(hbm)))
100 #define     InsetRect(lprc, dx, dy) InflateRect((lprc), -(dx), -(dy))
101
102 /* COMBOBOX Message APIs */
103 #define ComboBox_GetCount(hwndCtl)            \
104                 ((int)(DWORD)SendMessage((hwndCtl), CB_GETCOUNT, 0L, 0L))
105
106 #define ComboBox_GetCurSel(hwndCtl)           \
107                 ((int)(DWORD)SendMessage((hwndCtl), CB_GETCURSEL, 0L, 0L))
108
109 #define ComboBox_SetCurSel(hwndCtl, index)    \
110                 ((int)(DWORD)SendMessage((hwndCtl), CB_SETCURSEL, (WPARAM)(int)(index), 0L))
111
112 #define ComboBox_GetLBTextLen(hwndCtl, index) \
113                 ((int)(DWORD)SendMessage((hwndCtl), CB_GETLBTEXTLEN, (WPARAM)(int)(index), 0L))
114
115 #define ComboBox_DeleteString(hwndCtl, index) \
116                 ((int)(DWORD)SendMessage((hwndCtl), CB_DELETESTRING, (WPARAM)(int)(index), 0L))
117
118 #define ComboBox_FindString(hwndCtl, indexStart, lpszFind) \
119                 ((int)(DWORD)SendMessage((hwndCtl), CB_FINDSTRING, (WPARAM)(int)(indexStart), (LPARAM)(LPCTSTR)(lpszFind))) 
120
121 #define ComboBox_ResetContent(hwndCtl)      \
122                 ((int)(DWORD)SendMessage((hwndCtl), CB_RESETCONTENT, 0L, 0L))
123                  
124 #define ComboBox_AddString(hwndCtl, lpsz)   \
125                 ((int)(DWORD)SendMessage((hwndCtl), CB_ADDSTRING, 0L, (LPARAM)(LPCTSTR)(lpsz)))    
126 #define ComboBox_GetLBTextLen(hwndCtl, index)       \
127                 ((int)(DWORD)SendMessage((hwndCtl), CB_GETLBTEXTLEN, (WPARAM)(int)(index), 0L))
128 #define ComboBox_GetLBText(hwndCtl, index, lpszBuffer) \
129                 ((int)(DWORD)SendMessage((hwndCtl), CB_GETLBTEXT, (WPARAM)(int)(index), (LPARAM)(LPCTSTR)(lpszBuffer)))
130
131 #define ComboBox_GetDroppedState(hwndCtl)             \
132            ((BOOL)(DWORD)SendMessage((hwndCtl), CB_GETDROPPEDSTATE, 0L, 0L))
133 #define ComboBox_GetDroppedControlRect(hwndCtl, lprc) \
134            ((void)SendMessage((hwndCtl), CB_GETDROPPEDCONTROLRECT, 0L, (LPARAM)(RECT *)(lprc)))
135
136 /****** ListBox control message APIs *****************************************/
137
138 #define ListBox_Enable(hwndCtl, fEnable)            EnableWindow((hwndCtl), (fEnable))
139 #define ListBox_GetCount(hwndCtl)          \
140            ((int)(DWORD)SendMessage((hwndCtl), LB_GETCOUNT, 0L, 0L))
141 #define ListBox_ResetContent(hwndCtl)      \
142            ((BOOL)(DWORD)SendMessage((hwndCtl), LB_RESETCONTENT, 0L, 0L))
143
144 #define ListBox_GetItemData(hwndCtl, index)     \
145         ((LRESULT)(DWORD)SendMessage((hwndCtl), LB_GETITEMDATA, (WPARAM)(int)(index), 0L))
146
147 #define ListBox_GetCurSel(hwndCtl)        \
148         ((int)(DWORD)SendMessage((hwndCtl), LB_GETCURSEL, 0L, 0L))
149 #define ListBox_SetCurSel(hwndCtl, index) \
150         ((int)(DWORD)SendMessage((hwndCtl), LB_SETCURSEL, (WPARAM)(int)(index), 0L))
151
152 #define ListBox_AddString(hwndCtl, lpsz)           \
153         ((int)(DWORD)SendMessage((hwndCtl), LB_ADDSTRING, 0L, (LPARAM)(LPCTSTR)(lpsz)))
154 #define ListBox_InsertString(hwndCtl, index, lpsz) \
155         ((int)(DWORD)SendMessage((hwndCtl), LB_INSERTSTRING, (WPARAM)(int)(index), (LPARAM)(LPCTSTR)(lpsz)))
156          
157 #define ListBox_AddItemData(hwndCtl, data) \
158         ((int)(DWORD)SendMessage((hwndCtl), LB_ADDSTRING, 0L, (LPARAM)(data)))
159 #define ListBox_InsertItemData(hwndCtl, index, data) \
160         ((int)(DWORD)SendMessage((hwndCtl), LB_INSERTSTRING, (WPARAM)(int)(index), (LPARAM)(data)))
161
162 #define ListBox_FindString(hwndCtl, indexStart, lpszFind) \
163         ((int)(DWORD)SendMessage((hwndCtl), LB_FINDSTRING, (WPARAM)(int)(indexStart), (LPARAM)(LPCTSTR)(lpszFind)))
164 #define ListBox_FindStringExact(hwndCtl, indexStart, lpszFind) \
165         ((int)(DWORD)SendMessage((hwndCtl), LB_FINDSTRINGEXACT, (WPARAM)(int)(indexStart), (LPARAM)(LPCTSTR)(lpszFind)))
166
167 #define Edit_LineFromChar(hwndCtl, ich)   \
168         ((int)(DWORD)SendMessage((hwndCtl), EM_LINEFROMCHAR, (WPARAM)(int)(ich), 0L))
169 #define Edit_LineIndex(hwndCtl, line)     \
170         ((int)(DWORD)SendMessage((hwndCtl), EM_LINEINDEX, (WPARAM)(int)(line), 0L))
171 #define Edit_LineLength(hwndCtl, line)    \
172         ((int)(DWORD)SendMessage((hwndCtl), EM_LINELENGTH, (WPARAM)(int)(line), 0L))
173          
174 /****** Edit control message APIs ********************************************/
175
176 #define Edit_SetSel(hwndCtl, ichStart, ichEnd)   \
177         ((void)SendMessage((hwndCtl), EM_SETSEL, (ichStart), (ichEnd)))
178
179 #define Edit_GetText(hwndCtl, lpch, cchMax)     GetWindowText((hwndCtl), (lpch), (cchMax))
180 #define Edit_GetTextLength(hwndCtl)             GetWindowTextLength(hwndCtl)
181 #define Edit_SetText(hwndCtl, lpsz)             SetWindowText((hwndCtl), (lpsz))
182          
183 #define Edit_GetModify(hwndCtl)            \
184         ((BOOL)(DWORD)SendMessage((hwndCtl), EM_GETMODIFY, 0L, 0L))
185 #define Edit_SetModify(hwndCtl, fModified) \
186         ((void)SendMessage((hwndCtl), EM_SETMODIFY, (WPARAM)(UINT)(fModified), 0L))
187          
188 /* void Cls_OnMeasureItem(HWND hwnd, MEASUREITEMSTRUCT * lpMeasureItem) */
189 #define HANDLE_WM_MEASUREITEM(hwnd, wParam, lParam, fn) \
190             ((fn)((hwnd), (MEASUREITEMSTRUCT *)(lParam)), 0L)
191 #define FORWARD_WM_MEASUREITEM(hwnd, lpMeasureItem, fn) \
192             (void)(fn)((hwnd), WM_MEASUREITEM, (WPARAM)(((MEASUREITEMSTRUCT *)lpMeasureItem)->CtlID), (LPARAM)(MEASUREITEMSTRUCT *)(lpMeasureItem))
193
194 /* void Cls_OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify) */
195 #define HANDLE_WM_COMMAND(hwnd, wParam, lParam, fn) \
196             ((fn)((hwnd), (int)(LOWORD(wParam)), (HWND)(lParam), (UINT)HIWORD(wParam)), 0L)
197 #define FORWARD_WM_COMMAND(hwnd, id, hwndCtl, codeNotify, fn) \
198             (void)(fn)((hwnd), WM_COMMAND, MAKEWPARAM((UINT)(id),(UINT)(codeNotify)), (LPARAM)(HWND)(hwndCtl))
199
200 /* void Cls_OnTimer(HWND hwnd, UINT id) */
201 #define HANDLE_WM_TIMER(hwnd, wParam, lParam, fn) ((fn)((hwnd), (UINT)(wParam)), 0L)
202 #define FORWARD_WM_TIMER(hwnd, id, fn) (void)(fn)((hwnd), WM_TIMER, (WPARAM)(UINT)(id), 0L)
203
204 /* void Cls_OnInitMenuPopup(HWND hwnd, HMENU hMenu, UINT item, BOOL fSystemMenu) */
205 #define HANDLE_WM_INITMENUPOPUP(hwnd, wParam, lParam, fn) \
206         ((fn)((hwnd), (HMENU)(wParam), (UINT)LOWORD(lParam), (BOOL)HIWORD(lParam)), 0L)
207 #define FORWARD_WM_INITMENUPOPUP(hwnd, hMenu, item, fSystemMenu, fn) \
208         (void)(fn)((hwnd), WM_INITMENUPOPUP, (WPARAM)(HMENU)(hMenu), MAKELPARAM((item),(fSystemMenu)))
209
210 /* UINT Cls_OnNCHitTest(HWND hwnd, int x, int y) */
211 #define HANDLE_WM_NCHITTEST(hwnd, wParam, lParam, fn) \
212         (LRESULT)(DWORD)(UINT)(fn)((hwnd), (int)(short)LOWORD(lParam), (int)(short)HIWORD(lParam))
213 #define FORWARD_WM_NCHITTEST(hwnd, x, y, fn) \
214         (UINT)(DWORD)(fn)((hwnd), WM_NCHITTEST, 0L, MAKELPARAM((x), (y)))
215
216 /* HFONT Cls_OnGetFont(HWND hwnd) */
217 #define HANDLE_WM_GETFONT(hwnd, wParam, lParam, fn)  (LRESULT)(DWORD)(UINT)(HFONT)(fn)(hwnd)
218 #define FORWARD_WM_GETFONT(hwnd, fn)  (HFONT)(UINT)(DWORD)(fn)((hwnd), WM_GETFONT, 0L, 0L)
219
220 /* void Cls_OnSetFont(HWND hwndCtl, HFONT hfont, BOOL fRedraw) */
221 #define HANDLE_WM_SETFONT(hwnd, wParam, lParam, fn) \
222             ((fn)((hwnd), (HFONT)(wParam), (BOOL)(lParam)), 0L)
223 #define FORWARD_WM_SETFONT(hwnd, hfont, fRedraw, fn) \
224                          (void)(fn)((hwnd), WM_SETFONT, (WPARAM)(HFONT)(hfont), (LPARAM)(BOOL)(fRedraw))
225
226 /* void Cls_OnGetMinMaxInfo(HWND hwnd, LPMINMAXINFO lpMinMaxInfo) */
227 #define HANDLE_WM_GETMINMAXINFO(hwnd, wParam, lParam, fn) \
228                          ((fn)((hwnd), (LPMINMAXINFO)(lParam)), 0L)
229 #define FORWARD_WM_GETMINMAXINFO(hwnd, lpMinMaxInfo, fn) \
230                         (void)(fn)((hwnd), WM_GETMINMAXINFO, 0L, (LPARAM)(LPMINMAXINFO)(lpMinMaxInfo))
231
232 /* void Cls_OnDrawItem(HWND hwnd, const DRAWITEMSTRUCT lpDrawItem) */
233 #define HANDLE_WM_DRAWITEM(hwnd, wParam, lParam, fn) \
234             ((fn)((hwnd), (const DRAWITEMSTRUCT *)(lParam)), 0L)
235 #define FORWARD_WM_DRAWITEM(hwnd, lpDrawItem, fn) \
236         (void)(fn)((hwnd), WM_DRAWITEM, (WPARAM)(((const DRAWITEMSTRUCT *)lpDrawItem)->CtlID), (LPARAM)(const DRAWITEMSTRUCT *)(lpDrawItem))
237                                  
238 /****** C runtime porting macros ****************************************/
239
240 #define _ncalloc    calloc
241 #define _nexpand    _expand
242 #define _ffree      free
243 #define _fmalloc    malloc
244 #define _fmemccpy   _memccpy
245 #define _fmemchr    memchr
246 #define _fmemcmp    memcmp
247 #define _fmemcpy    memcpy
248 #define _fmemicmp   _memicmp
249 #define _fmemmove   memmove
250 #define _fmemset    memset
251 #define _fmsize     _msize
252 #define _frealloc   realloc
253 #define _fstrcat    strcat
254 #define _fstrchr    strchr
255 #define _fstrcmp    strcmp
256 #define _fstrcpy    strcpy
257 #define _fstrcspn   strcspn
258 #define _fstrdup    _strdup
259 #define _fstricmp   _stricmp
260 #define _fstrlen    strlen
261 #define _fstrlwr    _strlwr
262 #define _fstrncat   strncat
263 #define _fstrncmp   strncmp
264 #define _fstrncpy   strncpy
265 #define _fstrnicmp  _strnicmp
266 #define _fstrnset   _strnset
267 #define _fstrpbrk   strpbrk
268 #define _fstrrchr   strrchr
269 #define _fstrrev    _strrev
270 #define _fstrset    _strset
271 #define _fstrspn    strspn
272 #define _fstrstr    strstr
273 #define _fstrtok    strtok
274 #define _fstrupr    _strupr
275 #define _nfree      free
276 #define _nmalloc    malloc
277 #define _nmsize     _msize
278 #define _nrealloc   realloc
279 #define _nstrdup    _strdup
280 #define hmemcpy16     MoveMemory
281
282 #ifdef __cplusplus
283 }
284 #endif
285                                 
286 #endif
287