2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS user32.dll
4 * FILE: lib/user32/windows/message.c
6 * PROGRAMMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
8 * 06-06-2001 CSH Created
13 #include <wine/debug.h>
14 WINE_DEFAULT_DEBUG_CHANNEL(user32
);
17 /* flag for messages that contain pointers */
18 /* 32 messages per entry, messages 0..31 map to bits 0..31 */
20 #define SET(msg) (1 << ((msg) & 31))
22 static const unsigned int message_pointer_flags
[] =
25 SET(WM_CREATE
) | SET(WM_SETTEXT
) | SET(WM_GETTEXT
) |
26 SET(WM_WININICHANGE
) | SET(WM_DEVMODECHANGE
),
28 SET(WM_GETMINMAXINFO
) | SET(WM_DRAWITEM
) | SET(WM_MEASUREITEM
) | SET(WM_DELETEITEM
) |
31 SET(WM_WINDOWPOSCHANGING
) | SET(WM_WINDOWPOSCHANGED
) | SET(WM_COPYDATA
) |
32 SET(WM_COPYGLOBALDATA
) | SET(WM_NOTIFY
) | SET(WM_HELP
),
34 SET(WM_STYLECHANGING
) | SET(WM_STYLECHANGED
),
36 SET(WM_NCCREATE
) | SET(WM_NCCALCSIZE
) | SET(WM_GETDLGCODE
),
38 SET(EM_GETSEL
) | SET(EM_GETRECT
) | SET(EM_SETRECT
) | SET(EM_SETRECTNP
),
40 SET(EM_REPLACESEL
) | SET(EM_GETLINE
) | SET(EM_SETTABSTOPS
),
42 SET(SBM_GETRANGE
) | SET(SBM_SETSCROLLINFO
) | SET(SBM_GETSCROLLINFO
) | SET(SBM_GETSCROLLBARINFO
),
48 SET(CB_GETEDITSEL
) | SET(CB_ADDSTRING
) | SET(CB_DIR
) | SET(CB_GETLBTEXT
) |
49 SET(CB_INSERTSTRING
) | SET(CB_FINDSTRING
) | SET(CB_SELECTSTRING
) |
50 SET(CB_GETDROPPEDCONTROLRECT
) | SET(CB_FINDSTRINGEXACT
),
54 SET(LB_ADDSTRING
) | SET(LB_INSERTSTRING
) | SET(LB_GETTEXT
) | SET(LB_SELECTSTRING
) |
55 SET(LB_DIR
) | SET(LB_FINDSTRING
) |
56 SET(LB_GETSELITEMS
) | SET(LB_SETTABSTOPS
) | SET(LB_ADDFILE
) | SET(LB_GETITEMRECT
),
58 SET(LB_FINDSTRINGEXACT
),
64 SET(WM_NEXTMENU
) | SET(WM_SIZING
) | SET(WM_MOVING
) | SET(WM_DEVICECHANGE
),
66 SET(WM_MDICREATE
) | SET(WM_MDIGETACTIVE
) | SET(WM_DROPOBJECT
) |
67 SET(WM_QUERYDROPOBJECT
) | SET(WM_DRAGLOOP
) | SET(WM_DRAGSELECT
) | SET(WM_DRAGMOVE
),
81 SET(WM_ASKCBFORMATNAME
)
84 /* check whether a given message type includes pointers */
85 static inline int is_pointer_message( UINT message
)
87 if (message
>= 8*sizeof(message_pointer_flags
)) return FALSE
;
88 return (message_pointer_flags
[message
/ 32] & SET(message
)) != 0;
93 /* check whether a combobox expects strings or ids in CB_ADDSTRING/CB_INSERTSTRING */
94 static BOOL FASTCALL
combobox_has_strings( HWND hwnd
)
96 DWORD style
= GetWindowLongA( hwnd
, GWL_STYLE
);
97 return (!(style
& (CBS_OWNERDRAWFIXED
| CBS_OWNERDRAWVARIABLE
)) || (style
& CBS_HASSTRINGS
));
100 /* check whether a listbox expects strings or ids in LB_ADDSTRING/LB_INSERTSTRING */
101 static BOOL FASTCALL
listbox_has_strings( HWND hwnd
)
103 DWORD style
= GetWindowLongA( hwnd
, GWL_STYLE
);
104 return (!(style
& (LBS_OWNERDRAWFIXED
| LBS_OWNERDRAWVARIABLE
)) || (style
& LBS_HASSTRINGS
));
107 /* DDE message exchange
109 * - Session initialization
110 * Client sends a WM_DDE_INITIATE message, usually a broadcast message. lParam of
111 * this message contains a pair of global atoms, the Application and Topic atoms.
112 * The client must destroy the atoms.
113 * Server window proc handles the WM_DDE_INITIATE message and if the Application
114 * and Topic atoms are recognized sends a WM_DDE_ACK message to the client. lParam
115 * of the reply message contains another pair of global atoms (Application and
116 * Topic again), which must be destroyed by the server.
119 * Client posts a WM_DDE_EXECUTE message to the server window. lParam of that message
120 * is a global memory handle containing the string to execute. After the command has
121 * been executed the server posts a WM_DDE_ACK message to the client, which contains
122 * a packed lParam which in turn contains that global memory handle. The client takes
123 * ownership of both the packed lParam (meaning it needs to call FreeDDElParam() on
124 * it and the global memory handle.
125 * This might work nice and easy in Win3.1, but things are more complicated for NT.
126 * Global memory handles in NT are not really global, they're still local to the
127 * process. So, what happens under the hood is that PostMessage must handle the
128 * WM_DDE_EXECUTE message specially. It will obtain the contents of the global memory
129 * area, repack that into a new structure together with the original memory handle
130 * and pass that off to the win32k. Win32k will marshall that data over to the target
131 * (server) process where it will be unpacked and stored in a newly allocated global
132 * memory area. The handle of that area will then be sent to the window proc, after
133 * storing it together with the "original" (client) handle in a table.
134 * The server will eventually post the WM_DDE_ACK response, containing the global
135 * memory handle it received. PostMessage must then lookup that memory handle (only
136 * valid in the server process) and replace it with the corresponding client memory
137 * handle. To avoid memory leaks, the server-side global memory block must be freed.
138 * Also, the WM_DDE_ACK lParam (a PackDDElParam() result) is unpacked and the
139 * individual components are handed to win32k.sys to post to the client side. Since
140 * the server side app hands over ownership of the packed lParam when it calls
141 * PostMessage(), the packed lParam needs to be freed on the server side too.
142 * When the WM_DDE_ACK message (containing the client-side global memory handle)
143 * arrives at the client side a new lParam is PackDDElParam()'ed and this is handed
144 * to the client side window proc which is expected to free/reuse it.
147 /* since the WM_DDE_ACK response to a WM_DDE_EXECUTE message should contain the handle
148 * to the memory handle, we keep track (in the server side) of all pairs of handle
149 * used (the client passes its value and the content of the memory handle), and
150 * the server stored both values (the client, and the local one, created after the
151 * content). When a ACK message is generated, the list of pair is searched for a
152 * matching pair, so that the client memory handle can be returned.
155 typedef struct tagDDEPAIR
159 } DDEPAIR
, *PDDEPAIR
;
161 static PDDEPAIR DdePairs
= NULL
;
162 static unsigned DdeNumAlloc
= 0;
163 static unsigned DdeNumUsed
= 0;
164 static CRITICAL_SECTION DdeCrst
;
167 DdeAddPair(HGLOBAL ClientMem
, HGLOBAL ServerMem
)
171 EnterCriticalSection(&DdeCrst
);
173 /* now remember the pair of hMem on both sides */
174 if (DdeNumUsed
== DdeNumAlloc
)
178 if (NULL
!= DdePairs
)
180 New
= HeapReAlloc(GetProcessHeap(), 0, DdePairs
,
181 (DdeNumAlloc
+ GROWBY
) * sizeof(DDEPAIR
));
185 New
= HeapAlloc(GetProcessHeap(), 0,
186 (DdeNumAlloc
+ GROWBY
) * sizeof(DDEPAIR
));
191 LeaveCriticalSection(&DdeCrst
);
195 /* zero out newly allocated part */
196 memset(&DdePairs
[DdeNumAlloc
], 0, GROWBY
* sizeof(DDEPAIR
));
197 DdeNumAlloc
+= GROWBY
;
201 for (i
= 0; i
< DdeNumAlloc
; i
++)
203 if (NULL
== DdePairs
[i
].ServerMem
)
205 DdePairs
[i
].ClientMem
= ClientMem
;
206 DdePairs
[i
].ServerMem
= ServerMem
;
211 LeaveCriticalSection(&DdeCrst
);
216 static HGLOBAL FASTCALL
217 DdeGetPair(HGLOBAL ServerMem
)
222 EnterCriticalSection(&DdeCrst
);
223 for (i
= 0; i
< DdeNumAlloc
; i
++)
225 if (DdePairs
[i
].ServerMem
== ServerMem
)
228 DdePairs
[i
].ServerMem
= 0;
230 Ret
= DdePairs
[i
].ClientMem
;
234 LeaveCriticalSection(&DdeCrst
);
241 MsgiUMToKMMessage(PMSG UMMsg
, PMSG KMMsg
, BOOL Posted
)
245 switch (UMMsg
->message
)
249 PKMDDELPARAM DdeLparam
;
250 DdeLparam
= HeapAlloc(GetProcessHeap(), 0, sizeof(KMDDELPARAM
));
252 !UnpackDDElParam( UMMsg
->message
, UMMsg
->lParam
, &DdeLparam
->uiLo
, &DdeLparam
->uiHi
))
255 If this is a reply to WM_DDE_EXECUTE then
256 uiHi will contain a hMem, hence >= 0x10000.
257 Otherwise, it will be be an atom, a 16-bit value.
259 if (!IS_ATOM(DdeLparam
->uiHi
))
261 HGLOBAL h
= DdeGetPair((HGLOBAL
)(ULONG_PTR
)DdeLparam
->uiHi
);
264 GlobalFree((HGLOBAL
)(ULONG_PTR
)DdeLparam
->uiHi
);
265 DdeLparam
->uiHi
= (UINT_PTR
) h
;
268 FreeDDElParam(UMMsg
->message
, UMMsg
->lParam
);
269 KMMsg
->lParam
= (LPARAM
) DdeLparam
;
276 PKMDDEEXECUTEDATA KMDdeExecuteData
;
279 Size
= GlobalSize((HGLOBAL
) UMMsg
->lParam
);
280 Data
= GlobalLock((HGLOBAL
) UMMsg
->lParam
);
283 SetLastError(ERROR_INVALID_HANDLE
);
286 KMDdeExecuteData
= HeapAlloc(GetProcessHeap(), 0, sizeof(KMDDEEXECUTEDATA
) + Size
);
287 if (!KMDdeExecuteData
)
289 SetLastError(ERROR_OUTOFMEMORY
);
292 KMDdeExecuteData
->Sender
= (HWND
) UMMsg
->wParam
;
293 KMDdeExecuteData
->ClientMem
= (HGLOBAL
) UMMsg
->lParam
;
294 memcpy((PVOID
) (KMDdeExecuteData
+ 1), Data
, Size
);
295 KMMsg
->wParam
= sizeof(KMDDEEXECUTEDATA
) + Size
;
296 KMMsg
->lParam
= (LPARAM
) KMDdeExecuteData
;
297 GlobalUnlock((HGLOBAL
) UMMsg
->lParam
);
303 PCOPYDATASTRUCT pUMCopyData
= (PCOPYDATASTRUCT
)UMMsg
->lParam
;
304 PCOPYDATASTRUCT pKMCopyData
;
306 pKMCopyData
= HeapAlloc(GetProcessHeap(), 0,
307 sizeof(COPYDATASTRUCT
) + pUMCopyData
->cbData
);
310 SetLastError(ERROR_OUTOFMEMORY
);
314 pKMCopyData
->dwData
= pUMCopyData
->dwData
;
315 pKMCopyData
->cbData
= pUMCopyData
->cbData
;
316 pKMCopyData
->lpData
= pKMCopyData
+ 1;
318 RtlCopyMemory(pKMCopyData
+ 1, pUMCopyData
->lpData
,
319 pUMCopyData
->cbData
);
321 KMMsg
->lParam
= (LPARAM
)pKMCopyData
;
334 MsgiUMToKMCleanup(PMSG UMMsg
, PMSG KMMsg
)
336 switch (KMMsg
->message
)
341 HeapFree(GetProcessHeap(), 0, (LPVOID
) KMMsg
->lParam
);
351 MsgiKMToUMMessage(PMSG KMMsg
, PMSG UMMsg
)
355 switch (UMMsg
->message
)
360 CREATESTRUCTW
*Cs
= (CREATESTRUCTW
*) KMMsg
->lParam
;
362 Cs
->lpszName
= (LPCWSTR
) ((PCHAR
) Cs
+ (DWORD_PTR
) Cs
->lpszName
);
363 Class
= (PCHAR
) Cs
+ (DWORD_PTR
) Cs
->lpszClass
;
364 if (L
'A' == *((WCHAR
*) Class
))
366 Class
+= sizeof(WCHAR
);
367 Cs
->lpszClass
= (LPCWSTR
)(DWORD_PTR
) (*((ATOM
*) Class
));
371 ASSERT(L
'S' == *((WCHAR
*) Class
));
372 Class
+= sizeof(WCHAR
);
373 Cs
->lpszClass
= (LPCWSTR
) Class
;
380 PKMDDELPARAM DdeLparam
= (PKMDDELPARAM
) KMMsg
->lParam
;
381 UMMsg
->lParam
= PackDDElParam(KMMsg
->message
, DdeLparam
->uiLo
, DdeLparam
->uiHi
);
387 PKMDDEEXECUTEDATA KMDdeExecuteData
;
391 KMDdeExecuteData
= (PKMDDEEXECUTEDATA
) KMMsg
->lParam
;
392 GlobalData
= GlobalAlloc(GMEM_MOVEABLE
, KMMsg
->wParam
- sizeof(KMDDEEXECUTEDATA
));
397 Data
= GlobalLock(GlobalData
);
400 GlobalFree(GlobalData
);
403 memcpy(Data
, (PVOID
) (KMDdeExecuteData
+ 1), KMMsg
->wParam
- sizeof(KMDDEEXECUTEDATA
));
404 GlobalUnlock(GlobalData
);
405 if (!DdeAddPair(KMDdeExecuteData
->ClientMem
, GlobalData
))
407 GlobalFree(GlobalData
);
410 UMMsg
->wParam
= (WPARAM
) KMDdeExecuteData
->Sender
;
411 UMMsg
->lParam
= (LPARAM
) GlobalData
;
417 PCOPYDATASTRUCT pKMCopyData
= (PCOPYDATASTRUCT
)KMMsg
->lParam
;
418 pKMCopyData
->lpData
= pKMCopyData
+ 1;
430 MsgiKMToUMCleanup(PMSG KMMsg
, PMSG UMMsg
)
432 switch (KMMsg
->message
)
436 HeapFree(GetProcessHeap(), 0, (LPVOID
) KMMsg
->lParam
);
437 GlobalUnlock((HGLOBAL
) UMMsg
->lParam
);
448 MsgiKMToUMReply(PMSG KMMsg
, PMSG UMMsg
, LRESULT
*Result
)
450 MsgiKMToUMCleanup(KMMsg
, UMMsg
);
456 MsgiAnsiToUnicodeMessage(HWND hwnd
, LPMSG UnicodeMsg
, LPMSG AnsiMsg
)
458 UNICODE_STRING UnicodeString
;
460 *UnicodeMsg
= *AnsiMsg
;
462 switch (AnsiMsg
->message
)
465 case WM_ASKCBFORMATNAME
:
467 LPWSTR Buffer
= HeapAlloc(GetProcessHeap(), 0,
468 AnsiMsg
->wParam
* sizeof(WCHAR
));
473 UnicodeMsg
->lParam
= (LPARAM
)Buffer
;
477 /* AnsiMsg->lParam is string (0-terminated) */
479 case WM_WININICHANGE
:
480 case WM_DEVMODECHANGE
:
486 RtlCreateUnicodeStringFromAsciiz(&UnicodeString
, (LPSTR
)AnsiMsg
->lParam
);
487 UnicodeMsg
->lParam
= (LPARAM
)UnicodeString
.Buffer
;
492 case LB_ADDSTRING_LOWER
:
493 case LB_ADDSTRING_UPPER
:
494 case LB_INSERTSTRING
:
495 case LB_INSERTSTRING_UPPER
:
496 case LB_INSERTSTRING_LOWER
:
498 case LB_FINDSTRINGEXACT
:
499 case LB_SELECTSTRING
:
501 if (listbox_has_strings(AnsiMsg
->hwnd
))
503 RtlCreateUnicodeStringFromAsciiz(&UnicodeString
, (LPSTR
)AnsiMsg
->lParam
);
504 UnicodeMsg
->lParam
= (LPARAM
)UnicodeString
.Buffer
;
510 case CB_INSERTSTRING
:
512 case CB_FINDSTRINGEXACT
:
513 case CB_SELECTSTRING
:
515 if (combobox_has_strings(AnsiMsg
->hwnd
))
517 RtlCreateUnicodeStringFromAsciiz(&UnicodeString
, (LPSTR
)AnsiMsg
->lParam
);
518 UnicodeMsg
->lParam
= (LPARAM
)UnicodeString
.Buffer
;
526 MDICREATESTRUCTW mdi_cs
;
529 CREATESTRUCTW cs
; /* new structure */
530 LPCWSTR lpszName
; /* allocated Name */
531 LPCWSTR lpszClass
; /* allocated Class */
534 struct s
*xs
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(struct s
));
539 xs
->cs
= *(CREATESTRUCTW
*)AnsiMsg
->lParam
;
540 if (!IS_INTRESOURCE(xs
->cs
.lpszName
))
542 RtlCreateUnicodeStringFromAsciiz(&UnicodeString
, (LPSTR
)xs
->cs
.lpszName
);
543 xs
->lpszName
= xs
->cs
.lpszName
= UnicodeString
.Buffer
;
545 if (!IS_ATOM(xs
->cs
.lpszClass
))
547 RtlCreateUnicodeStringFromAsciiz(&UnicodeString
, (LPSTR
)xs
->cs
.lpszClass
);
548 xs
->lpszClass
= xs
->cs
.lpszClass
= UnicodeString
.Buffer
;
551 if (GetWindowLongW(hwnd
, GWL_EXSTYLE
) & WS_EX_MDICHILD
)
553 mdi_cs
= *(MDICREATESTRUCTW
*)xs
->cs
.lpCreateParams
;
554 mdi_cs
.szTitle
= xs
->cs
.lpszName
;
555 mdi_cs
.szClass
= xs
->cs
.lpszClass
;
556 xs
->cs
.lpCreateParams
= &mdi_cs
;
559 UnicodeMsg
->lParam
= (LPARAM
)xs
;
565 MDICREATESTRUCTW
*cs
=
566 (MDICREATESTRUCTW
*)HeapAlloc(GetProcessHeap(), 0, sizeof(*cs
));
573 *cs
= *(MDICREATESTRUCTW
*)AnsiMsg
->lParam
;
575 if (!IS_ATOM(cs
->szClass
))
577 RtlCreateUnicodeStringFromAsciiz(&UnicodeString
, (LPSTR
)cs
->szClass
);
578 cs
->szClass
= UnicodeString
.Buffer
;
581 RtlCreateUnicodeStringFromAsciiz(&UnicodeString
, (LPSTR
)cs
->szTitle
);
582 cs
->szTitle
= UnicodeString
.Buffer
;
584 UnicodeMsg
->lParam
= (LPARAM
)cs
;
593 MsgiAnsiToUnicodeCleanup(LPMSG UnicodeMsg
, LPMSG AnsiMsg
)
595 UNICODE_STRING UnicodeString
;
597 switch (AnsiMsg
->message
)
600 case WM_ASKCBFORMATNAME
:
602 HeapFree(GetProcessHeap(), 0, (PVOID
) UnicodeMsg
->lParam
);
607 case WM_WININICHANGE
:
608 case WM_DEVMODECHANGE
:
614 RtlInitUnicodeString(&UnicodeString
, (PCWSTR
)UnicodeMsg
->lParam
);
615 RtlFreeUnicodeString(&UnicodeString
);
620 case LB_ADDSTRING_LOWER
:
621 case LB_ADDSTRING_UPPER
:
622 case LB_INSERTSTRING
:
623 case LB_INSERTSTRING_UPPER
:
624 case LB_INSERTSTRING_LOWER
:
626 case LB_FINDSTRINGEXACT
:
627 case LB_SELECTSTRING
:
629 if (listbox_has_strings(AnsiMsg
->hwnd
))
631 RtlInitUnicodeString(&UnicodeString
, (PCWSTR
)UnicodeMsg
->lParam
);
632 RtlFreeUnicodeString(&UnicodeString
);
638 case CB_INSERTSTRING
:
640 case CB_FINDSTRINGEXACT
:
641 case CB_SELECTSTRING
:
643 if (combobox_has_strings(AnsiMsg
->hwnd
))
645 RtlInitUnicodeString(&UnicodeString
, (PCWSTR
)UnicodeMsg
->lParam
);
646 RtlFreeUnicodeString(&UnicodeString
);
656 CREATESTRUCTW cs
; /* new structure */
657 LPWSTR lpszName
; /* allocated Name */
658 LPWSTR lpszClass
; /* allocated Class */
661 struct s
*xs
= (struct s
*)UnicodeMsg
->lParam
;
664 RtlInitUnicodeString(&UnicodeString
, (PCWSTR
)xs
->lpszName
);
665 RtlFreeUnicodeString(&UnicodeString
);
669 RtlInitUnicodeString(&UnicodeString
, (PCWSTR
)xs
->lpszClass
);
670 RtlFreeUnicodeString(&UnicodeString
);
672 HeapFree(GetProcessHeap(), 0, xs
);
678 MDICREATESTRUCTW
*cs
= (MDICREATESTRUCTW
*)UnicodeMsg
->lParam
;
679 RtlInitUnicodeString(&UnicodeString
, (PCWSTR
)cs
->szTitle
);
680 RtlFreeUnicodeString(&UnicodeString
);
681 if (!IS_ATOM(cs
->szClass
))
683 RtlInitUnicodeString(&UnicodeString
, (PCWSTR
)cs
->szClass
);
684 RtlFreeUnicodeString(&UnicodeString
);
686 HeapFree(GetProcessHeap(), 0, cs
);
695 MsgiAnsiToUnicodeReply(LPMSG UnicodeMsg
, LPMSG AnsiMsg
, LRESULT
*Result
)
698 switch (AnsiMsg
->message
)
701 case WM_ASKCBFORMATNAME
:
703 LPWSTR Buffer
= (LPWSTR
)UnicodeMsg
->lParam
;
704 LPSTR AnsiBuffer
= (LPSTR
)AnsiMsg
->lParam
;
705 if (UnicodeMsg
->wParam
> 0 &&
706 !WideCharToMultiByte(CP_ACP
, 0, Buffer
, -1, AnsiBuffer
, UnicodeMsg
->wParam
, NULL
, NULL
))
708 AnsiBuffer
[UnicodeMsg
->wParam
- 1] = 0;
714 LPWSTR Buffer
= (LPWSTR
) UnicodeMsg
->lParam
;
715 LPSTR AnsiBuffer
= (LPSTR
) AnsiMsg
->lParam
;
716 if (!listbox_has_strings( UnicodeMsg
->hwnd
)) break;
717 Size
= SendMessageW( UnicodeMsg
->hwnd
, LB_GETTEXTLEN
, UnicodeMsg
->wParam
, 0 );
718 if (Size
== LB_ERR
) break;
721 !WideCharToMultiByte(CP_ACP
, 0, Buffer
, -1, AnsiBuffer
, Size
, NULL
, NULL
))
723 AnsiBuffer
[Size
- 1] = 0;
729 LPWSTR Buffer
= (LPWSTR
) UnicodeMsg
->lParam
;
730 LPSTR AnsiBuffer
= (LPSTR
) AnsiMsg
->lParam
;
731 if (!combobox_has_strings( UnicodeMsg
->hwnd
)) break;
732 Size
= SendMessageW( UnicodeMsg
->hwnd
, CB_GETLBTEXTLEN
, UnicodeMsg
->wParam
, 0 );
733 if (Size
== CB_ERR
) break;
736 !WideCharToMultiByte(CP_ACP
, 0, Buffer
, -1, AnsiBuffer
, Size
, NULL
, NULL
))
738 AnsiBuffer
[Size
- 1] = 0;
744 MsgiAnsiToUnicodeCleanup(UnicodeMsg
, AnsiMsg
);
750 MsgiUnicodeToAnsiMessage(HWND hwnd
, LPMSG AnsiMsg
, LPMSG UnicodeMsg
)
752 ANSI_STRING AnsiString
;
753 UNICODE_STRING UnicodeString
;
755 *AnsiMsg
= *UnicodeMsg
;
757 switch(UnicodeMsg
->message
)
762 MDICREATESTRUCTA
*pmdi_cs
;
767 CsW
= (CREATESTRUCTW
*)(UnicodeMsg
->lParam
);
768 CsA
= RtlAllocateHeap(GetProcessHeap(), 0, sizeof(CREATESTRUCTA
) + sizeof(MDICREATESTRUCTA
));
773 memcpy(CsA
, CsW
, sizeof(CREATESTRUCTW
));
775 /* pmdi_cs starts right after CsA */
776 pmdi_cs
= (MDICREATESTRUCTA
*)(CsA
+ 1);
778 RtlInitUnicodeString(&UnicodeString
, CsW
->lpszName
);
779 Status
= RtlUnicodeStringToAnsiString(&AnsiString
, &UnicodeString
, TRUE
);
780 if (! NT_SUCCESS(Status
))
782 RtlFreeHeap(GetProcessHeap(), 0, CsA
);
785 CsA
->lpszName
= AnsiString
.Buffer
;
786 if (HIWORD((ULONG_PTR
)CsW
->lpszClass
) != 0)
788 RtlInitUnicodeString(&UnicodeString
, CsW
->lpszClass
);
789 Status
= RtlUnicodeStringToAnsiString(&AnsiString
, &UnicodeString
, TRUE
);
790 if (! NT_SUCCESS(Status
))
792 RtlInitAnsiString(&AnsiString
, CsA
->lpszName
);
793 RtlFreeAnsiString(&AnsiString
);
794 RtlFreeHeap(GetProcessHeap(), 0, CsA
);
797 CsA
->lpszClass
= AnsiString
.Buffer
;
800 if (GetWindowLongW(hwnd
, GWL_EXSTYLE
) & WS_EX_MDICHILD
)
802 *pmdi_cs
= *(MDICREATESTRUCTA
*)CsW
->lpCreateParams
;
803 pmdi_cs
->szTitle
= CsA
->lpszName
;
804 pmdi_cs
->szClass
= CsA
->lpszClass
;
805 CsA
->lpCreateParams
= pmdi_cs
;
808 AnsiMsg
->lParam
= (LPARAM
)CsA
;
813 /* Ansi string might contain MBCS chars so we need 2 * the number of chars */
814 AnsiMsg
->wParam
= UnicodeMsg
->wParam
* 2;
815 AnsiMsg
->lParam
= (LPARAM
) RtlAllocateHeap(GetProcessHeap(), 0, AnsiMsg
->wParam
);
816 if (NULL
== (PVOID
) AnsiMsg
->lParam
)
827 RtlInitUnicodeString(&UnicodeString
, (PWSTR
) UnicodeMsg
->lParam
);
828 if (! NT_SUCCESS(RtlUnicodeStringToAnsiString(&AnsiString
,
834 AnsiMsg
->lParam
= (LPARAM
) AnsiString
.Buffer
;
839 case LB_ADDSTRING_LOWER
:
840 case LB_ADDSTRING_UPPER
:
841 case LB_INSERTSTRING
:
842 case LB_INSERTSTRING_UPPER
:
843 case LB_INSERTSTRING_LOWER
:
845 case LB_FINDSTRINGEXACT
:
846 case LB_SELECTSTRING
:
848 if (listbox_has_strings(AnsiMsg
->hwnd
))
850 RtlInitUnicodeString(&UnicodeString
, (PWSTR
) UnicodeMsg
->lParam
);
851 if (! NT_SUCCESS(RtlUnicodeStringToAnsiString(&AnsiString
,
857 AnsiMsg
->lParam
= (LPARAM
) AnsiString
.Buffer
;
863 case CB_INSERTSTRING
:
865 case CB_FINDSTRINGEXACT
:
866 case CB_SELECTSTRING
:
868 if (combobox_has_strings(AnsiMsg
->hwnd
))
870 RtlInitUnicodeString(&UnicodeString
, (PWSTR
) UnicodeMsg
->lParam
);
871 if (! NT_SUCCESS(RtlUnicodeStringToAnsiString(&AnsiString
,
877 AnsiMsg
->lParam
= (LPARAM
) AnsiString
.Buffer
;
884 MDICREATESTRUCTA
*cs
=
885 (MDICREATESTRUCTA
*)HeapAlloc(GetProcessHeap(), 0, sizeof(*cs
));
892 *cs
= *(MDICREATESTRUCTA
*)UnicodeMsg
->lParam
;
894 if (!IS_ATOM(cs
->szClass
))
896 RtlInitUnicodeString(&UnicodeString
, (LPCWSTR
)cs
->szClass
);
897 if (! NT_SUCCESS(RtlUnicodeStringToAnsiString(&AnsiString
,
901 HeapFree(GetProcessHeap(), 0, cs
);
904 cs
->szClass
= AnsiString
.Buffer
;
907 RtlInitUnicodeString(&UnicodeString
, (LPCWSTR
)cs
->szTitle
);
908 if (! NT_SUCCESS(RtlUnicodeStringToAnsiString(&AnsiString
,
912 if (!IS_ATOM(cs
->szClass
))
914 RtlInitAnsiString(&AnsiString
, cs
->szClass
);
915 RtlFreeAnsiString(&AnsiString
);
918 HeapFree(GetProcessHeap(), 0, cs
);
921 cs
->szTitle
= AnsiString
.Buffer
;
923 AnsiMsg
->lParam
= (LPARAM
)cs
;
932 MsgiUnicodeToAnsiCleanup(LPMSG AnsiMsg
, LPMSG UnicodeMsg
)
934 ANSI_STRING AnsiString
;
936 switch(UnicodeMsg
->message
)
940 RtlFreeHeap(GetProcessHeap(), 0, (PVOID
) AnsiMsg
->lParam
);
945 RtlInitAnsiString(&AnsiString
, (PSTR
) AnsiMsg
->lParam
);
946 RtlFreeAnsiString(&AnsiString
);
954 Cs
= (CREATESTRUCTA
*) AnsiMsg
->lParam
;
955 RtlInitAnsiString(&AnsiString
, Cs
->lpszName
);
956 RtlFreeAnsiString(&AnsiString
);
957 if (HIWORD((ULONG_PTR
)Cs
->lpszClass
) != 0)
959 RtlInitAnsiString(&AnsiString
, Cs
->lpszClass
);
960 RtlFreeAnsiString(&AnsiString
);
962 RtlFreeHeap(GetProcessHeap(), 0, Cs
);
967 case LB_ADDSTRING_LOWER
:
968 case LB_ADDSTRING_UPPER
:
969 case LB_INSERTSTRING
:
970 case LB_INSERTSTRING_UPPER
:
971 case LB_INSERTSTRING_LOWER
:
973 case LB_FINDSTRINGEXACT
:
974 case LB_SELECTSTRING
:
976 if (listbox_has_strings(AnsiMsg
->hwnd
))
978 RtlInitAnsiString(&AnsiString
, (PSTR
) AnsiMsg
->lParam
);
979 RtlFreeAnsiString(&AnsiString
);
985 case CB_INSERTSTRING
:
987 case CB_FINDSTRINGEXACT
:
988 case CB_SELECTSTRING
:
990 DWORD dwStyle
= GetWindowLongPtrW(AnsiMsg
->hwnd
, GWL_STYLE
);
991 if (!(dwStyle
& (CBS_OWNERDRAWFIXED
| CBS_OWNERDRAWVARIABLE
)) &&
992 (dwStyle
& CBS_HASSTRINGS
))
994 RtlInitAnsiString(&AnsiString
, (PSTR
) AnsiMsg
->lParam
);
995 RtlFreeAnsiString(&AnsiString
);
1002 MDICREATESTRUCTA
*cs
= (MDICREATESTRUCTA
*)AnsiMsg
->lParam
;
1003 RtlInitAnsiString(&AnsiString
, (PCSTR
)cs
->szTitle
);
1004 RtlFreeAnsiString(&AnsiString
);
1005 if (!IS_ATOM(cs
->szClass
))
1007 RtlInitAnsiString(&AnsiString
, (PCSTR
)cs
->szClass
);
1008 RtlFreeAnsiString(&AnsiString
);
1010 HeapFree(GetProcessHeap(), 0, cs
);
1019 static BOOL FASTCALL
1020 MsgiUnicodeToAnsiReply(LPMSG AnsiMsg
, LPMSG UnicodeMsg
, LRESULT
*Result
)
1023 switch (UnicodeMsg
->message
)
1026 case WM_ASKCBFORMATNAME
:
1028 LPSTR Buffer
= (LPSTR
) AnsiMsg
->lParam
;
1029 LPWSTR UBuffer
= (LPWSTR
) UnicodeMsg
->lParam
;
1030 if (0 < AnsiMsg
->wParam
&&
1031 ! MultiByteToWideChar(CP_ACP
, 0, Buffer
, -1, UBuffer
, UnicodeMsg
->wParam
))
1033 UBuffer
[UnicodeMsg
->wParam
- 1] = L
'\0';
1039 LPSTR Buffer
= (LPSTR
) AnsiMsg
->lParam
;
1040 LPWSTR UBuffer
= (LPWSTR
) UnicodeMsg
->lParam
;
1041 if (!listbox_has_strings( UnicodeMsg
->hwnd
)) break;
1042 Size
= SendMessageW( UnicodeMsg
->hwnd
, LB_GETTEXTLEN
, UnicodeMsg
->wParam
, 0 );
1043 if (Size
== LB_ERR
) break;
1046 ! MultiByteToWideChar(CP_ACP
, 0, Buffer
, -1, UBuffer
, Size
))
1048 UBuffer
[Size
- 1] = L
'\0';
1054 LPSTR Buffer
= (LPSTR
) AnsiMsg
->lParam
;
1055 LPWSTR UBuffer
= (LPWSTR
) UnicodeMsg
->lParam
;
1056 if (!combobox_has_strings( UnicodeMsg
->hwnd
)) break;
1057 Size
= SendMessageW( UnicodeMsg
->hwnd
, CB_GETLBTEXTLEN
, UnicodeMsg
->wParam
, 0 );
1058 if (Size
== CB_ERR
) break;
1061 ! MultiByteToWideChar(CP_ACP
, 0, Buffer
, -1, UBuffer
, Size
))
1063 UBuffer
[Size
- 1] = L
'\0';
1069 MsgiUnicodeToAnsiCleanup(AnsiMsg
, UnicodeMsg
);
1074 /***********************************************************************
1077 * Convert the wparam of an ASCII message to Unicode.
1080 map_wparam_AtoW( UINT message
, WPARAM wparam
)
1085 wch
[0] = wch
[1] = 0;
1089 /* WM_CHAR is magic: a DBCS char can be sent/posted as two consecutive WM_CHAR
1090 * messages, in which case the first char is stored, and the conversion
1091 * to Unicode only takes place once the second char is sent/posted.
1094 if (mapping
!= WMCHAR_MAP_NOMAPPING
) // NlsMbCodePageTag
1096 PCLIENTINFO pci
= GetWin32ClientInfo();
1098 struct wm_char_mapping_data
*data
= get_user_thread_info()->wmchar_data
;
1100 BYTE low
= LOBYTE(wparam
);
1105 ch
[1] = HIBYTE(wparam
);
1106 RtlMultiByteToUnicodeN( wch
, sizeof(wch
), NULL
, ch
, 2 );
1107 TRACE( "map %02x,%02x -> %04x mapping %u\n", (BYTE
)ch
[0], (BYTE
)ch
[1], wch
[0], mapping
);
1108 if (data
) data
->lead_byte
[mapping
] = 0;
1110 else if (data
&& data
->lead_byte
[mapping
])
1112 ch
[0] = data
->lead_byte
[mapping
];
1114 RtlMultiByteToUnicodeN( wch
, sizeof(wch
), NULL
, ch
, 2 );
1115 TRACE( "map stored %02x,%02x -> %04x mapping %u\n", (BYTE
)ch
[0], (BYTE
)ch
[1], wch
[0], mapping
);
1116 data
->lead_byte
[mapping
] = 0;
1118 else if (!IsDBCSLeadByte( low
))
1121 RtlMultiByteToUnicodeN( wch
, sizeof(wch
), NULL
, ch
, 1 );
1122 TRACE( "map %02x -> %04x\n", (BYTE
)ch
[0], wch
[0] );
1123 if (data
) data
->lead_byte
[mapping
] = 0;
1125 else /* store it and wait for trail byte */
1129 if (!(data
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*data
) )))
1131 get_user_thread_info()->wmchar_data
= data
;
1133 TRACE( "storing lead byte %02x mapping %u\n", low
, mapping
);
1134 data
->lead_byte
[mapping
] = low
;
1137 wparam
= MAKEWPARAM(wch
[0], wch
[1]);
1141 /* else fall through */
1143 case EM_SETPASSWORDCHAR
:
1146 case WM_SYSDEADCHAR
:
1148 ch
[0] = LOBYTE(wparam
);
1149 ch
[1] = HIBYTE(wparam
);
1150 RtlMultiByteToUnicodeN( wch
, sizeof(wch
), NULL
, ch
, 2 );
1151 wparam
= MAKEWPARAM(wch
[0], wch
[1]);
1154 ch
[0] = HIBYTE(wparam
);
1155 ch
[1] = LOBYTE(wparam
);
1156 if (ch
[0]) RtlMultiByteToUnicodeN( wch
, sizeof(wch
[0]), NULL
, ch
, 2 );
1157 else RtlMultiByteToUnicodeN( wch
, sizeof(wch
[0]), NULL
, ch
+ 1, 1 );
1158 wparam
= MAKEWPARAM(wch
[0], HIWORD(wparam
));
1166 DesktopWndProcA( HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1171 TRACE("Desktop A Class Atom! hWnd 0x%x, Msg %d\n", hwnd
, message
);
1173 AnsiMsg
.hwnd
= hwnd
;
1174 AnsiMsg
.message
= message
;
1175 AnsiMsg
.wParam
= wParam
;
1176 AnsiMsg
.lParam
= lParam
;
1178 // Desktop is always Unicode so convert Ansi here.
1179 if (!MsgiAnsiToUnicodeMessage(hwnd
, &UcMsg
, &AnsiMsg
))
1184 Result
= DesktopWndProcW(hwnd
, message
, UcMsg
.wParam
, UcMsg
.lParam
);
1186 MsgiAnsiToUnicodeCleanup(&UcMsg
, &AnsiMsg
);
1196 GetMessageExtraInfo(VOID
)
1198 return NtUserxGetMessageExtraInfo();
1209 return NtUserxGetMessagePos();
1217 GetMessageTime(VOID
)
1219 return NtUserGetThreadState(THREADSTATE_GETMESSAGETIME
);
1230 PCLIENTTHREADINFO pcti
= GetWin32ClientInfo()->pClientThreadInfo
;
1233 if (pcti
->CTI_flags
& CTI_INSENDMESSAGE
)
1238 return(NtUserGetThreadState(THREADSTATE_INSENDMESSAGE
) != ISMEX_NOSEND
);
1250 PCLIENTTHREADINFO pcti
= GetWin32ClientInfo()->pClientThreadInfo
;
1251 if (pcti
&& !(pcti
->CTI_flags
& CTI_INSENDMESSAGE
))
1252 return ISMEX_NOSEND
;
1254 return NtUserGetThreadState(THREADSTATE_INSENDMESSAGE
);
1263 ReplyMessage(LRESULT lResult
)
1265 return NtUserxReplyMessage(lResult
);
1274 SetMessageExtraInfo(
1277 return NtUserxSetMessageExtraInfo(lParam
);
1281 IntCallWindowProcW(BOOL IsAnsiProc
,
1291 BOOL Hook
= FALSE
, MsgOverride
= FALSE
, Dialog
;
1292 LRESULT Result
= 0, PreResult
= 0;
1295 if (WndProc
== NULL
)
1297 WARN("IntCallWindowsProcW() called with WndProc = NULL!\n");
1302 Dialog
= (pWnd
->fnid
== FNID_DIALOG
);
1306 Hook
= BeginIfHookedUserApiHook();
1310 MsgOverride
= IsMsgOverride( Msg
, &guah
.WndProcArray
);
1312 MsgOverride
= IsMsgOverride( Msg
, &guah
.DlgProcArray
);
1317 UnicodeMsg
.hwnd
= hWnd
;
1318 UnicodeMsg
.message
= Msg
;
1319 UnicodeMsg
.wParam
= wParam
;
1320 UnicodeMsg
.lParam
= lParam
;
1321 if (! MsgiUnicodeToAnsiMessage(hWnd
, &AnsiMsg
, &UnicodeMsg
))
1326 if (Hook
&& MsgOverride
)
1331 PreResult
= guah
.PreWndProc(AnsiMsg
.hwnd
, AnsiMsg
.message
, AnsiMsg
.wParam
, AnsiMsg
.lParam
, (ULONG_PTR
)&Result
, &Data
);
1333 PreResult
= guah
.PreDefDlgProc(AnsiMsg
.hwnd
, AnsiMsg
.message
, AnsiMsg
.wParam
, AnsiMsg
.lParam
, (ULONG_PTR
)&Result
, &Data
);
1335 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1341 if (PreResult
) goto Exit
;
1343 _SEH2_TRY
// wine does this.
1345 Result
= WndProc(AnsiMsg
.hwnd
, AnsiMsg
.message
, AnsiMsg
.wParam
, AnsiMsg
.lParam
);
1347 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1349 ERR("Got exception when calling Ansi WndProc %p Msg %d \n",WndProc
,Msg
);
1353 if (Hook
&& MsgOverride
)
1358 guah
.PostWndProc(AnsiMsg
.hwnd
, AnsiMsg
.message
, AnsiMsg
.wParam
, AnsiMsg
.lParam
, (ULONG_PTR
)&Result
, &Data
);
1360 guah
.PostDefDlgProc(AnsiMsg
.hwnd
, AnsiMsg
.message
, AnsiMsg
.wParam
, AnsiMsg
.lParam
, (ULONG_PTR
)&Result
, &Data
);
1362 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1368 if (! MsgiUnicodeToAnsiReply(&AnsiMsg
, &UnicodeMsg
, &Result
))
1375 if (Hook
&& MsgOverride
)
1380 PreResult
= guah
.PreWndProc(hWnd
, Msg
, wParam
, lParam
, (ULONG_PTR
)&Result
, &Data
);
1382 PreResult
= guah
.PreDefDlgProc(hWnd
, Msg
, wParam
, lParam
, (ULONG_PTR
)&Result
, &Data
);
1384 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1390 if (PreResult
) goto Exit
;
1394 Result
= WndProc(hWnd
, Msg
, wParam
, lParam
);
1396 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1398 ERR("Got exception when calling unicode WndProc %p Msg %d \n",WndProc
, Msg
);
1402 if (Hook
&& MsgOverride
)
1407 guah
.PostWndProc(hWnd
, Msg
, wParam
, lParam
, (ULONG_PTR
)&Result
, &Data
);
1409 guah
.PostDefDlgProc(hWnd
, Msg
, wParam
, lParam
, (ULONG_PTR
)&Result
, &Data
);
1411 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1419 if (Hook
) EndUserApiHook();
1423 static LRESULT FASTCALL
1424 IntCallWindowProcA(BOOL IsAnsiProc
,
1434 //ULONG_PTR LowLimit;
1435 BOOL Hook
= FALSE
, MsgOverride
= FALSE
, Dialog
;
1436 LRESULT Result
= 0, PreResult
= 0;
1439 if (WndProc
== NULL
)
1441 WARN("IntCallWindowsProcA() called with WndProc = NULL!\n");
1445 LowLimit
= (ULONG_PTR
)NtCurrentTeb()->NtTib
.StackLimit
;
1446 if (((ULONG_PTR
)&lParam
- LowLimit
) < PAGE_SIZE
)
1448 ERR("IntCallWindowsProcA() Exceeded Stack!\n");
1453 Dialog
= (pWnd
->fnid
== FNID_DIALOG
);
1457 Hook
= BeginIfHookedUserApiHook();
1461 MsgOverride
= IsMsgOverride( Msg
, &guah
.WndProcArray
);
1463 MsgOverride
= IsMsgOverride( Msg
, &guah
.DlgProcArray
);
1468 if (Hook
&& MsgOverride
)
1473 PreResult
= guah
.PreWndProc(hWnd
, Msg
, wParam
, lParam
, (ULONG_PTR
)&Result
, &Data
);
1475 PreResult
= guah
.PreDefDlgProc(hWnd
, Msg
, wParam
, lParam
, (ULONG_PTR
)&Result
, &Data
);
1477 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1483 if (PreResult
) goto Exit
;
1487 Result
= WndProc(hWnd
, Msg
, wParam
, lParam
);
1489 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1491 ERR("Got exception when calling Ansi WndProc %p Msg %d \n",WndProc
,Msg
);
1495 if (Hook
&& MsgOverride
)
1500 guah
.PostWndProc(hWnd
, Msg
, wParam
, lParam
, (ULONG_PTR
)&Result
, &Data
);
1502 guah
.PostDefDlgProc(hWnd
, Msg
, wParam
, lParam
, (ULONG_PTR
)&Result
, &Data
);
1504 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1512 AnsiMsg
.hwnd
= hWnd
;
1513 AnsiMsg
.message
= Msg
;
1514 AnsiMsg
.wParam
= wParam
;
1515 AnsiMsg
.lParam
= lParam
;
1516 if (! MsgiAnsiToUnicodeMessage(hWnd
, &UnicodeMsg
, &AnsiMsg
))
1521 if (Hook
&& MsgOverride
)
1526 PreResult
= guah
.PreWndProc(UnicodeMsg
.hwnd
, UnicodeMsg
.message
, UnicodeMsg
.wParam
, UnicodeMsg
.lParam
, (ULONG_PTR
)&Result
, &Data
);
1528 PreResult
= guah
.PreDefDlgProc(UnicodeMsg
.hwnd
, UnicodeMsg
.message
, UnicodeMsg
.wParam
, UnicodeMsg
.lParam
, (ULONG_PTR
)&Result
, &Data
);
1530 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1536 if (PreResult
) goto Exit
;
1540 Result
= WndProc(UnicodeMsg
.hwnd
, UnicodeMsg
.message
,
1541 UnicodeMsg
.wParam
, UnicodeMsg
.lParam
);
1543 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1545 ERR("Got exception when calling unicode WndProc %p Msg %d \n",WndProc
, Msg
);
1549 if (Hook
&& MsgOverride
)
1554 guah
.PostWndProc(UnicodeMsg
.hwnd
, UnicodeMsg
.message
, UnicodeMsg
.wParam
, UnicodeMsg
.lParam
, (ULONG_PTR
)&Result
, &Data
);
1556 guah
.PostDefDlgProc(UnicodeMsg
.hwnd
, UnicodeMsg
.message
, UnicodeMsg
.wParam
, UnicodeMsg
.lParam
, (ULONG_PTR
)&Result
, &Data
);
1558 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1564 if (! MsgiAnsiToUnicodeReply(&UnicodeMsg
, &AnsiMsg
, &Result
))
1571 if (Hook
) EndUserApiHook();
1576 static LRESULT WINAPI
1577 IntCallMessageProc(IN PWND Wnd
, IN HWND hWnd
, IN UINT Msg
, IN WPARAM wParam
, IN LPARAM lParam
, IN BOOL Ansi
)
1583 Class
= DesktopPtrToUser(Wnd
->pcls
);
1586 if ( Wnd
->head
.pti
!= GetW32ThreadInfo())
1587 { // Must be inside the same thread!
1588 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
1592 This is the message exchange for user32. If there's a need to monitor messages,
1595 TRACE("HWND %p, MSG %u, WPARAM %p, LPARAM %p, Ansi %d\n", hWnd
, Msg
, wParam
, lParam
, Ansi
);
1596 // if (Class->fnid <= FNID_GHOST && Class->fnid >= FNID_BUTTON )
1597 if (Class
->fnid
<= FNID_GHOST
&& Class
->fnid
>= FNID_FIRST
)
1601 if (GETPFNCLIENTW(Class
->fnid
) == Wnd
->lpfnWndProc
)
1602 WndProc
= GETPFNCLIENTA(Class
->fnid
);
1606 if (GETPFNCLIENTA(Class
->fnid
) == Wnd
->lpfnWndProc
)
1607 WndProc
= GETPFNCLIENTW(Class
->fnid
);
1614 IsAnsi
= !Wnd
->Unicode
;
1615 WndProc
= Wnd
->lpfnWndProc
;
1620 IsAnsi
= !Wnd
->Unicode
;
1621 WndProc
= Wnd
->lpfnWndProc
;
1624 Message caller can be Ansi/Unicode and the receiver can be Unicode/Ansi or
1628 return IntCallWindowProcW(IsAnsi
, WndProc
, Wnd
, hWnd
, Msg
, wParam
, lParam
);
1630 return IntCallWindowProcA(IsAnsi
, WndProc
, Wnd
, hWnd
, Msg
, wParam
, lParam
);
1638 CallWindowProcA(WNDPROC lpPrevWndFunc
,
1645 PCALLPROCDATA CallProc
;
1647 if (lpPrevWndFunc
== NULL
)
1649 WARN("CallWindowProcA: lpPrevWndFunc == NULL!\n");
1653 pWnd
= ValidateHwnd(hWnd
);
1655 if (!IsCallProcHandle(lpPrevWndFunc
))
1656 return IntCallWindowProcA(TRUE
, lpPrevWndFunc
, pWnd
, hWnd
, Msg
, wParam
, lParam
);
1659 CallProc
= ValidateCallProc((HANDLE
)lpPrevWndFunc
);
1660 if (CallProc
!= NULL
)
1662 return IntCallWindowProcA(!(CallProc
->wType
& UserGetCPDA2U
),
1663 CallProc
->pfnClientPrevious
,
1672 WARN("CallWindowProcA: can not dereference WndProcHandle\n");
1683 CallWindowProcW(WNDPROC lpPrevWndFunc
,
1690 PCALLPROCDATA CallProc
;
1692 /* FIXME - can the first parameter be NULL? */
1693 if (lpPrevWndFunc
== NULL
)
1695 WARN("CallWindowProcA: lpPrevWndFunc == NULL!\n");
1699 pWnd
= ValidateHwnd(hWnd
);
1701 if (!IsCallProcHandle(lpPrevWndFunc
))
1702 return IntCallWindowProcW(FALSE
, lpPrevWndFunc
, pWnd
, hWnd
, Msg
, wParam
, lParam
);
1705 CallProc
= ValidateCallProc((HANDLE
)lpPrevWndFunc
);
1706 if (CallProc
!= NULL
)
1708 return IntCallWindowProcW(!(CallProc
->wType
& UserGetCPDA2U
),
1709 CallProc
->pfnClientPrevious
,
1718 WARN("CallWindowProcW: can not dereference WndProcHandle\n");
1729 DispatchMessageA(CONST MSG
*lpmsg
)
1736 if ( lpmsg
->message
& ~WM_MAXIMUM
)
1738 SetLastError( ERROR_INVALID_PARAMETER
);
1742 if (lpmsg
->hwnd
!= NULL
)
1744 Wnd
= ValidateHwnd(lpmsg
->hwnd
);
1750 if (is_pointer_message(lpmsg
->message
))
1752 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
1756 if ((lpmsg
->message
== WM_TIMER
|| lpmsg
->message
== WM_SYSTIMER
) && lpmsg
->lParam
!= 0)
1758 WNDPROC WndProc
= (WNDPROC
)lpmsg
->lParam
;
1760 if ( lpmsg
->message
== WM_SYSTIMER
)
1761 return NtUserDispatchMessage( (PMSG
)lpmsg
);
1763 if (!NtUserValidateTimerCallback(lpmsg
->hwnd
, lpmsg
->wParam
, lpmsg
->lParam
))
1765 WARN("Validating Timer Callback failed!\n");
1769 _SEH2_TRY
// wine does this. Hint: Prevents call to another thread....
1771 Ret
= WndProc(lpmsg
->hwnd
,
1776 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1782 else if (Wnd
!= NULL
)
1784 if ( (lpmsg
->message
!= WM_PAINT
) && !(Wnd
->state
& WNDS_SERVERSIDEWINDOWPROC
) )
1786 Ret
= IntCallMessageProc(Wnd
,
1795 if (!MsgiAnsiToUnicodeMessage(lpmsg
->hwnd
, &UnicodeMsg
, (LPMSG
)lpmsg
))
1800 Ret
= NtUserDispatchMessage(&UnicodeMsg
);
1802 if (!MsgiAnsiToUnicodeReply(&UnicodeMsg
, (LPMSG
)lpmsg
, &Ret
))
1811 WARN("Exception in Timer Callback WndProcA!\n");
1821 DispatchMessageW(CONST MSG
*lpmsg
)
1827 if ( lpmsg
->message
& ~WM_MAXIMUM
)
1829 SetLastError( ERROR_INVALID_PARAMETER
);
1833 if (lpmsg
->hwnd
!= NULL
)
1835 Wnd
= ValidateHwnd(lpmsg
->hwnd
);
1841 if (is_pointer_message(lpmsg
->message
))
1843 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
1847 if ((lpmsg
->message
== WM_TIMER
|| lpmsg
->message
== WM_SYSTIMER
) && lpmsg
->lParam
!= 0)
1849 WNDPROC WndProc
= (WNDPROC
)lpmsg
->lParam
;
1851 if ( lpmsg
->message
== WM_SYSTIMER
)
1852 return NtUserDispatchMessage( (PMSG
) lpmsg
);
1854 if (!NtUserValidateTimerCallback(lpmsg
->hwnd
, lpmsg
->wParam
, lpmsg
->lParam
))
1856 WARN("Validating Timer Callback failed!\n");
1862 Ret
= WndProc(lpmsg
->hwnd
,
1867 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1873 else if (Wnd
!= NULL
)
1875 if ( (lpmsg
->message
!= WM_PAINT
) && !(Wnd
->state
& WNDS_SERVERSIDEWINDOWPROC
) )
1877 Ret
= IntCallMessageProc(Wnd
,
1885 Ret
= NtUserDispatchMessage( (PMSG
) lpmsg
);
1890 WARN("Exception in Timer Callback WndProcW!\n");
1896 IntConvertMsgToAnsi(LPMSG lpMsg
)
1901 switch (lpMsg
->message
)
1906 case WM_SYSDEADCHAR
:
1908 wch
[0] = LOWORD(lpMsg
->wParam
);
1909 wch
[1] = HIWORD(lpMsg
->wParam
);
1911 WideCharToMultiByte(CP_THREAD_ACP
, 0, wch
, 2, ch
, 2, NULL
, NULL
);
1912 lpMsg
->wParam
= MAKEWPARAM(ch
[0] | (ch
[1] << 8), 0);
1921 GetMessageA(LPMSG lpMsg
,
1928 if ( (wMsgFilterMin
|wMsgFilterMax
) & ~WM_MAXIMUM
)
1930 SetLastError( ERROR_INVALID_PARAMETER
);
1934 Res
= NtUserGetMessage(lpMsg
, hWnd
, wMsgFilterMin
, wMsgFilterMax
);
1935 if (-1 == (int) Res
)
1940 IntConvertMsgToAnsi(lpMsg
);
1949 GetMessageW(LPMSG lpMsg
,
1956 if ( (wMsgFilterMin
|wMsgFilterMax
) & ~WM_MAXIMUM
)
1958 SetLastError( ERROR_INVALID_PARAMETER
);
1962 Res
= NtUserGetMessage(lpMsg
, hWnd
, wMsgFilterMin
, wMsgFilterMax
);
1963 if (-1 == (int) Res
)
1972 PeekMessageWorker( PMSG pMsg
,
1979 PCLIENTTHREADINFO pcti
;
1980 pci
= GetWin32ClientInfo();
1981 pcti
= pci
->pClientThreadInfo
;
1983 if (!hWnd
&& pci
&& pcti
)
1987 if ((pci
->cSpins
>= 100) && (pci
->dwTIFlags
& TIF_SPINNING
))
1988 { // Yield after 100 spin cycles and ready to swap vinyl.
1989 if (!(pci
->dwTIFlags
& TIF_WAITFORINPUTIDLE
))
1990 { // Not waiting for idle event.
1991 if (!pcti
->fsChangeBits
&& !pcti
->fsWakeBits
)
1992 { // No messages are available.
1993 if ((GetTickCount() - pcti
->tickLastMsgChecked
) > 1000)
1994 { // Up the msg read count if over 1 sec.
1995 NtUserGetThreadState(THREADSTATE_UPTIMELASTREAD
);
1999 FIXME("seeSpins!\n");
2005 return NtUserPeekMessage(pMsg
, hWnd
, wMsgFilterMin
, wMsgFilterMax
, wRemoveMsg
);
2012 PeekMessageA(LPMSG lpMsg
,
2020 Res
= PeekMessageWorker(lpMsg
, hWnd
, wMsgFilterMin
, wMsgFilterMax
, wRemoveMsg
);
2021 if (-1 == (int) Res
|| !Res
)
2026 IntConvertMsgToAnsi(lpMsg
);
2046 Res
= PeekMessageWorker(lpMsg
, hWnd
, wMsgFilterMin
, wMsgFilterMax
, wRemoveMsg
);
2047 if (-1 == (int) Res
|| !Res
)
2068 /* Check for combo box or a list box to send names. */
2069 if (Msg
== CB_DIR
|| Msg
== LB_DIR
)
2072 Set DDL_POSTMSGS, so use the PostMessage function to send messages to the
2073 combo/list box. Forces a call like DlgDirListComboBox.
2075 //wParam |= DDL_POSTMSGS;
2076 return NtUserPostMessage(hWnd
, Msg
, wParam
, lParam
);
2079 /* No drop files or current Process, just post message. */
2080 if ( (Msg
!= WM_DROPFILES
) ||
2081 ( NtUserQueryWindow( hWnd
, QUERY_WINDOW_UNIQUE_PROCESS_ID
) ==
2082 PtrToUint(NtCurrentTeb()->ClientId
.UniqueProcess
) ) )
2084 return NtUserPostMessage(hWnd
, Msg
, wParam
, lParam
);
2087 /* We have drop files and this is not the same process for this window. */
2089 /* Just incase, check wParam for Global memory handle and send size. */
2090 Ret
= SendMessageA( hWnd
,
2092 (WPARAM
)GlobalSize((HGLOBAL
)wParam
), // Zero if not a handle.
2093 (LPARAM
)wParam
); // Send wParam as lParam.
2095 if ( Ret
) return NtUserPostMessage(hWnd
, Msg
, (WPARAM
)Ret
, lParam
);
2113 /* Check for combo box or a list box to send names. */
2114 if (Msg
== CB_DIR
|| Msg
== LB_DIR
)
2117 Set DDL_POSTMSGS, so use the PostMessage function to send messages to the
2118 combo/list box. Forces a call like DlgDirListComboBox.
2120 //wParam |= DDL_POSTMSGS;
2121 return NtUserPostMessage(hWnd
, Msg
, wParam
, lParam
);
2124 /* No drop files or current Process, just post message. */
2125 if ( (Msg
!= WM_DROPFILES
) ||
2126 ( NtUserQueryWindow( hWnd
, QUERY_WINDOW_UNIQUE_PROCESS_ID
) ==
2127 PtrToUint(NtCurrentTeb()->ClientId
.UniqueProcess
) ) )
2129 return NtUserPostMessage(hWnd
, Msg
, wParam
, lParam
);
2132 /* We have drop files and this is not the same process for this window. */
2134 /* Just incase, check wParam for Global memory handle and send size. */
2135 Ret
= SendMessageW( hWnd
,
2137 (WPARAM
)GlobalSize((HGLOBAL
)wParam
), // Zero if not a handle.
2138 (LPARAM
)wParam
); // Send wParam as lParam.
2140 if ( Ret
) return NtUserPostMessage(hWnd
, Msg
, (WPARAM
)Ret
, lParam
);
2153 NtUserxPostQuitMessage(nExitCode
);
2168 return NtUserPostThreadMessage(idThread
, Msg
, wParam
, lParam
);
2183 return NtUserPostThreadMessage(idThread
, Msg
, wParam
, lParam
);
2191 SendMessageW(HWND Wnd
,
2199 PTHREADINFO ti
= GetW32ThreadInfo();
2201 if ( Msg
& ~WM_MAXIMUM
)
2203 SetLastError( ERROR_INVALID_PARAMETER
);
2207 if (Wnd
!= HWND_TOPMOST
&& Wnd
!= HWND_BROADCAST
&& (Msg
< WM_DDE_FIRST
|| Msg
> WM_DDE_LAST
))
2209 Window
= ValidateHwnd(Wnd
);
2211 if ( Window
!= NULL
&&
2212 Window
->head
.pti
== ti
&&
2213 // !IsThreadHooked(GetWin32ClientInfo()) && // Enable to test message system bug.
2214 !ISITHOOKED(WH_CALLWNDPROC
) &&
2215 !ISITHOOKED(WH_CALLWNDPROCRET
) &&
2216 !(Window
->state
& WNDS_SERVERSIDEWINDOWPROC
) )
2218 /* NOTE: We can directly send messages to the window procedure
2219 if *all* the following conditions are met:
2221 * Window belongs to calling thread
2222 * The calling thread is not being hooked for CallWndProc
2223 * Not calling a server side proc:
2224 Desktop, Switch, ScrollBar, Menu, IconTitle, or hWndMessage
2227 return IntCallMessageProc(Window
, Wnd
, Msg
, wParam
, lParam
, FALSE
);
2232 UMMsg
.message
= Msg
;
2233 UMMsg
.wParam
= wParam
;
2234 UMMsg
.lParam
= lParam
;
2236 if (! MsgiUMToKMMessage(&UMMsg
, &KMMsg
, FALSE
))
2241 Result
= NtUserMessageCall( Wnd
,
2249 MsgiUMToKMCleanup(&UMMsg
, &KMMsg
);
2259 SendMessageA(HWND Wnd
, UINT Msg
, WPARAM wParam
, LPARAM lParam
)
2261 MSG AnsiMsg
, UcMsg
, KMMsg
;
2264 PTHREADINFO ti
= GetW32ThreadInfo();
2266 if ( Msg
& ~WM_MAXIMUM
)
2268 SetLastError( ERROR_INVALID_PARAMETER
);
2272 if (Wnd
!= HWND_TOPMOST
&& Wnd
!= HWND_BROADCAST
&& (Msg
< WM_DDE_FIRST
|| Msg
> WM_DDE_LAST
))
2274 Window
= ValidateHwnd(Wnd
);
2276 if ( Window
!= NULL
&&
2277 Window
->head
.pti
== ti
&&
2278 // !IsThreadHooked(GetWin32ClientInfo()) && // Enable to test message system bug.
2279 !ISITHOOKED(WH_CALLWNDPROC
) &&
2280 !ISITHOOKED(WH_CALLWNDPROCRET
) &&
2281 !(Window
->state
& WNDS_SERVERSIDEWINDOWPROC
) )
2283 /* NOTE: We can directly send messages to the window procedure
2284 if *all* the following conditions are met:
2286 * Window belongs to calling thread
2287 * The calling thread is not being hooked for CallWndProc
2288 * Not calling a server side proc:
2289 Desktop, Switch, ScrollBar, Menu, IconTitle, or hWndMessage
2292 return IntCallMessageProc(Window
, Wnd
, Msg
, wParam
, lParam
, TRUE
);
2297 AnsiMsg
.message
= Msg
;
2298 AnsiMsg
.wParam
= wParam
;
2299 AnsiMsg
.lParam
= lParam
;
2301 if (!MsgiAnsiToUnicodeMessage(Wnd
, &UcMsg
, &AnsiMsg
))
2306 if (!MsgiUMToKMMessage(&UcMsg
, &KMMsg
, FALSE
))
2308 MsgiAnsiToUnicodeCleanup(&UcMsg
, &AnsiMsg
);
2312 Result
= NtUserMessageCall( Wnd
,
2320 MsgiUMToKMCleanup(&UcMsg
, &KMMsg
);
2321 MsgiAnsiToUnicodeReply(&UcMsg
, &AnsiMsg
, &Result
);
2331 SendMessageCallbackA(
2336 SENDASYNCPROC lpCallBack
,
2341 CALL_BACK_INFO CallBackInfo
;
2343 if (is_pointer_message(Msg
))
2345 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
2349 CallBackInfo
.CallBack
= lpCallBack
;
2350 CallBackInfo
.Context
= dwData
;
2352 AnsiMsg
.hwnd
= hWnd
;
2353 AnsiMsg
.message
= Msg
;
2354 AnsiMsg
.wParam
= wParam
;
2355 AnsiMsg
.lParam
= lParam
;
2357 if (!MsgiAnsiToUnicodeMessage(hWnd
, &UcMsg
, &AnsiMsg
))
2362 Result
= NtUserMessageCall( hWnd
,
2366 (ULONG_PTR
)&CallBackInfo
,
2367 FNID_SENDMESSAGECALLBACK
,
2370 MsgiAnsiToUnicodeCleanup(&UcMsg
, &AnsiMsg
);
2380 SendMessageCallbackW(
2385 SENDASYNCPROC lpCallBack
,
2388 CALL_BACK_INFO CallBackInfo
;
2390 if (is_pointer_message(Msg
))
2392 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
2396 CallBackInfo
.CallBack
= lpCallBack
;
2397 CallBackInfo
.Context
= dwData
;
2399 return NtUserMessageCall(hWnd
,
2403 (ULONG_PTR
)&CallBackInfo
,
2404 FNID_SENDMESSAGECALLBACK
,
2413 SendMessageTimeoutA(
2420 PDWORD_PTR lpdwResult
)
2426 PTHREADINFO ti
= GetW32ThreadInfo();
2428 if ( Msg
& ~WM_MAXIMUM
|| fuFlags
& ~(SMTO_NOTIMEOUTIFNOTHUNG
|SMTO_ABORTIFHUNG
|SMTO_BLOCK
))
2430 SetLastError( ERROR_INVALID_PARAMETER
);
2434 if (lpdwResult
) *lpdwResult
= 0;
2436 //// This is due to message system bug.
2437 if (hWnd
!= HWND_TOPMOST
&& hWnd
!= HWND_BROADCAST
&& (Msg
< WM_DDE_FIRST
|| Msg
> WM_DDE_LAST
))
2439 Window
= ValidateHwnd(hWnd
);
2441 if ( Window
!= NULL
&&
2442 Window
->head
.pti
== ti
&&
2443 !ISITHOOKED(WH_CALLWNDPROC
) &&
2444 !ISITHOOKED(WH_CALLWNDPROCRET
) &&
2445 !(Window
->state
& WNDS_SERVERSIDEWINDOWPROC
) )
2447 Result
= IntCallMessageProc(Window
, hWnd
, Msg
, wParam
, lParam
, TRUE
);
2448 if (lpdwResult
) *lpdwResult
= Result
;
2453 SPY_EnterMessage(SPY_SENDMESSAGE
, hWnd
, Msg
, wParam
, lParam
);
2455 dsm
.uFlags
= fuFlags
;
2456 dsm
.uTimeout
= uTimeout
;
2458 AnsiMsg
.hwnd
= hWnd
;
2459 AnsiMsg
.message
= Msg
;
2460 AnsiMsg
.wParam
= wParam
;
2461 AnsiMsg
.lParam
= lParam
;
2463 if (! MsgiAnsiToUnicodeMessage(hWnd
, &UcMsg
, &AnsiMsg
))
2468 Result
= NtUserMessageCall( hWnd
,
2473 FNID_SENDMESSAGEWTOOPTION
,
2476 MsgiAnsiToUnicodeReply(&UcMsg
, &AnsiMsg
, &Result
);
2478 if (lpdwResult
) *lpdwResult
= dsm
.Result
;
2480 SPY_ExitMessage(SPY_RESULT_OK
, hWnd
, Msg
, Result
, wParam
, lParam
);
2491 SendMessageTimeoutW(
2498 PDWORD_PTR lpdwResult
)
2503 PTHREADINFO ti
= GetW32ThreadInfo();
2505 if ( Msg
& ~WM_MAXIMUM
|| fuFlags
& ~(SMTO_NOTIMEOUTIFNOTHUNG
|SMTO_ABORTIFHUNG
|SMTO_BLOCK
))
2507 SetLastError( ERROR_INVALID_PARAMETER
);
2511 if (lpdwResult
) *lpdwResult
= 0;
2513 //// This is due to message system bug.
2514 if (hWnd
!= HWND_TOPMOST
&& hWnd
!= HWND_BROADCAST
&& (Msg
< WM_DDE_FIRST
|| Msg
> WM_DDE_LAST
))
2516 Window
= ValidateHwnd(hWnd
);
2518 if ( Window
!= NULL
&&
2519 Window
->head
.pti
== ti
&&
2520 !ISITHOOKED(WH_CALLWNDPROC
) &&
2521 !ISITHOOKED(WH_CALLWNDPROCRET
) &&
2522 !(Window
->state
& WNDS_SERVERSIDEWINDOWPROC
) )
2524 Result
= IntCallMessageProc(Window
, hWnd
, Msg
, wParam
, lParam
, FALSE
);
2525 if (lpdwResult
) *lpdwResult
= Result
;
2530 SPY_EnterMessage(SPY_SENDMESSAGE
, hWnd
, Msg
, wParam
, lParam
);
2532 dsm
.uFlags
= fuFlags
;
2533 dsm
.uTimeout
= uTimeout
;
2535 Result
= NtUserMessageCall( hWnd
,
2540 FNID_SENDMESSAGEWTOOPTION
,
2543 if (lpdwResult
) *lpdwResult
= dsm
.Result
;
2545 SPY_ExitMessage(SPY_RESULT_OK
, hWnd
, Msg
, Result
, wParam
, lParam
);
2564 if (is_pointer_message(Msg
))
2566 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
2570 AnsiMsg
.hwnd
= hWnd
;
2571 AnsiMsg
.message
= Msg
;
2572 AnsiMsg
.wParam
= wParam
;
2573 AnsiMsg
.lParam
= lParam
;
2574 if (! MsgiAnsiToUnicodeMessage(hWnd
, &UcMsg
, &AnsiMsg
))
2578 Ret
= SendNotifyMessageW(hWnd
, UcMsg
.message
, UcMsg
.wParam
, UcMsg
.lParam
);
2580 MsgiAnsiToUnicodeCleanup(&UcMsg
, &AnsiMsg
);
2599 if (is_pointer_message(Msg
))
2601 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
2606 UMMsg
.message
= Msg
;
2607 UMMsg
.wParam
= wParam
;
2608 UMMsg
.lParam
= lParam
;
2609 if (! MsgiUMToKMMessage(&UMMsg
, &KMMsg
, TRUE
))
2613 Result
= NtUserMessageCall( hWnd
,
2618 FNID_SENDNOTIFYMESSAGE
,
2621 MsgiUMToKMCleanup(&UMMsg
, &KMMsg
);
2630 TranslateMessageEx(CONST MSG
*lpMsg
, UINT Flags
)
2632 switch (lpMsg
->message
)
2638 return(NtUserTranslateMessage((LPMSG
)lpMsg
, Flags
));
2641 if ( lpMsg
->message
& ~WM_MAXIMUM
)
2642 SetLastError(ERROR_INVALID_PARAMETER
);
2652 TranslateMessage(CONST MSG
*lpMsg
)
2656 // Ref: msdn ImmGetVirtualKey:
2657 // http://msdn.microsoft.com/en-us/library/aa912145.aspx
2659 if ( (LOWORD(lpMsg->wParam) != VK_PROCESSKEY) ||
2660 !(Ret = IMM_ImmTranslateMessage( lpMsg->hwnd,
2665 Ret
= TranslateMessageEx((LPMSG
)lpMsg
, 0);
2675 RegisterWindowMessageA(LPCSTR lpString
)
2677 UNICODE_STRING String
;
2680 if (!RtlCreateUnicodeStringFromAsciiz(&String
, (PCSZ
)lpString
))
2684 Atom
= NtUserRegisterWindowMessage(&String
);
2685 RtlFreeUnicodeString(&String
);
2694 RegisterWindowMessageW(LPCWSTR lpString
)
2696 UNICODE_STRING String
;
2698 RtlInitUnicodeString(&String
, lpString
);
2699 return(NtUserRegisterWindowMessage(&String
));
2708 return (HWND
)NtUserGetThreadState(THREADSTATE_CAPTUREWINDOW
);
2715 ReleaseCapture(VOID
)
2717 return NtUserxReleaseCapture();
2726 RealGetQueueStatus(UINT flags
)
2728 #define QS_TEMPALLINPUT 255 // ATM, do not support QS_RAWINPUT
2729 if (flags
& ~(QS_SMRESULT
|QS_ALLPOSTMESSAGE
|QS_TEMPALLINPUT
))
2731 SetLastError( ERROR_INVALID_FLAGS
);
2734 return NtUserxGetQueueStatus(flags
);
2741 BOOL WINAPI
GetInputState(VOID
)
2743 PCLIENTTHREADINFO pcti
= GetWin32ClientInfo()->pClientThreadInfo
;
2745 if ((!pcti
) || (pcti
->fsChangeBits
& (QS_KEY
|QS_MOUSEBUTTON
)))
2746 return (BOOL
)NtUserGetThreadState(THREADSTATE_GETINPUTSTATE
);
2753 User32CallWindowProcFromKernel(PVOID Arguments
, ULONG ArgumentLength
)
2755 PWINDOWPROC_CALLBACK_ARGUMENTS CallbackArgs
;
2758 PCLIENTINFO pci
= GetWin32ClientInfo();
2760 /* Make sure we don't try to access mem beyond what we were given */
2761 if (ArgumentLength
< sizeof(WINDOWPROC_CALLBACK_ARGUMENTS
))
2763 return STATUS_INFO_LENGTH_MISMATCH
;
2766 CallbackArgs
= (PWINDOWPROC_CALLBACK_ARGUMENTS
) Arguments
;
2767 KMMsg
.hwnd
= CallbackArgs
->Wnd
;
2768 KMMsg
.message
= CallbackArgs
->Msg
;
2769 KMMsg
.wParam
= CallbackArgs
->wParam
;
2770 /* Check if lParam is really a pointer and adjust it if it is */
2771 if (0 <= CallbackArgs
->lParamBufferSize
)
2773 if (ArgumentLength
!= sizeof(WINDOWPROC_CALLBACK_ARGUMENTS
)
2774 + CallbackArgs
->lParamBufferSize
)
2776 return STATUS_INFO_LENGTH_MISMATCH
;
2778 KMMsg
.lParam
= (LPARAM
) ((char *) CallbackArgs
+ sizeof(WINDOWPROC_CALLBACK_ARGUMENTS
));
2782 if (ArgumentLength
!= sizeof(WINDOWPROC_CALLBACK_ARGUMENTS
))
2784 return STATUS_INFO_LENGTH_MISMATCH
;
2786 KMMsg
.lParam
= CallbackArgs
->lParam
;
2789 if (WM_NCCALCSIZE
== CallbackArgs
->Msg
&& CallbackArgs
->wParam
)
2791 NCCALCSIZE_PARAMS
*Params
= (NCCALCSIZE_PARAMS
*) KMMsg
.lParam
;
2792 Params
->lppos
= (PWINDOWPOS
) (Params
+ 1);
2795 if (! MsgiKMToUMMessage(&KMMsg
, &UMMsg
))
2799 if (pci
->CallbackWnd
.hWnd
== UMMsg
.hwnd
)
2800 pWnd
= pci
->CallbackWnd
.pWnd
;
2802 CallbackArgs
->Result
= IntCallWindowProcW( CallbackArgs
->IsAnsiProc
,
2810 if (! MsgiKMToUMReply(&KMMsg
, &UMMsg
, &CallbackArgs
->Result
))
2814 return ZwCallbackReturn(CallbackArgs
, ArgumentLength
, STATUS_SUCCESS
);
2820 BOOL WINAPI
SetMessageQueue(int cMessagesMax
)
2822 /* Function does nothing on 32 bit windows */
2825 typedef DWORD (WINAPI
* RealGetQueueStatusProc
)(UINT flags
);
2826 typedef DWORD (WINAPI
* RealMsgWaitForMultipleObjectsExProc
)(DWORD nCount
, CONST HANDLE
*lpHandles
, DWORD dwMilliseconds
, DWORD dwWakeMask
, DWORD dwFlags
);
2827 typedef BOOL (WINAPI
* RealInternalGetMessageProc
)(LPMSG
,HWND
,UINT
,UINT
,UINT
,BOOL
);
2828 typedef BOOL (WINAPI
* RealWaitMessageExProc
)(DWORD
,UINT
);
2830 typedef struct _USER_MESSAGE_PUMP_ADDRESSES
{
2832 RealInternalGetMessageProc NtUserRealInternalGetMessage
;
2833 RealWaitMessageExProc NtUserRealWaitMessageEx
;
2834 RealGetQueueStatusProc RealGetQueueStatus
;
2835 RealMsgWaitForMultipleObjectsExProc RealMsgWaitForMultipleObjectsEx
;
2836 } USER_MESSAGE_PUMP_ADDRESSES
, * PUSER_MESSAGE_PUMP_ADDRESSES
;
2840 RealMsgWaitForMultipleObjectsEx(
2842 CONST HANDLE
*pHandles
,
2843 DWORD dwMilliseconds
,
2847 typedef BOOL (WINAPI
* MESSAGEPUMPHOOKPROC
)(BOOL Unregistering
,PUSER_MESSAGE_PUMP_ADDRESSES MessagePumpAddresses
);
2849 CRITICAL_SECTION gcsMPH
;
2850 MESSAGEPUMPHOOKPROC gpfnInitMPH
;
2851 DWORD gcLoadMPH
= 0;
2852 USER_MESSAGE_PUMP_ADDRESSES gmph
= {sizeof(USER_MESSAGE_PUMP_ADDRESSES
),
2853 NtUserRealInternalGetMessage
,
2854 NtUserRealWaitMessageEx
,
2856 RealMsgWaitForMultipleObjectsEx
2859 DWORD gfMessagePumpHook
= 0;
2861 BOOL WINAPI
IsInsideMessagePumpHook()
2862 { // FF uses this and polls it when Min/Max
2863 PCLIENTTHREADINFO pcti
= GetWin32ClientInfo()->pClientThreadInfo
;
2864 return (gfMessagePumpHook
&& pcti
&& (pcti
->dwcPumpHook
> 0));
2867 void WINAPI
ResetMessagePumpHook(PUSER_MESSAGE_PUMP_ADDRESSES Addresses
)
2869 Addresses
->cbSize
= sizeof(USER_MESSAGE_PUMP_ADDRESSES
);
2870 Addresses
->NtUserRealInternalGetMessage
= NtUserRealInternalGetMessage
;
2871 Addresses
->NtUserRealWaitMessageEx
= NtUserRealWaitMessageEx
;
2872 Addresses
->RealGetQueueStatus
= RealGetQueueStatus
;
2873 Addresses
->RealMsgWaitForMultipleObjectsEx
= RealMsgWaitForMultipleObjectsEx
;
2876 BOOL WINAPI
RegisterMessagePumpHook(MESSAGEPUMPHOOKPROC Hook
)
2878 EnterCriticalSection(&gcsMPH
);
2880 SetLastError(ERROR_INVALID_PARAMETER
);
2881 LeaveCriticalSection(&gcsMPH
);
2885 USER_MESSAGE_PUMP_ADDRESSES Addresses
;
2887 ResetMessagePumpHook(&Addresses
);
2888 if(!Hook(FALSE
, &Addresses
) || !Addresses
.cbSize
) {
2889 LeaveCriticalSection(&gcsMPH
);
2892 memcpy(&gmph
, &Addresses
, Addresses
.cbSize
);
2894 if(gpfnInitMPH
!= Hook
) {
2895 LeaveCriticalSection(&gcsMPH
);
2899 if(NtUserxInitMessagePump()) {
2900 LeaveCriticalSection(&gcsMPH
);
2904 InterlockedExchange((PLONG
)&gfMessagePumpHook
, 1);
2906 LeaveCriticalSection(&gcsMPH
);
2910 BOOL WINAPI
UnregisterMessagePumpHook(VOID
)
2912 EnterCriticalSection(&gcsMPH
);
2914 if(NtUserxUnInitMessagePump()) {
2917 InterlockedExchange((PLONG
)&gfMessagePumpHook
, 0);
2918 gpfnInitMPH(TRUE
, NULL
);
2919 ResetMessagePumpHook(&gmph
);
2922 LeaveCriticalSection(&gcsMPH
);
2926 LeaveCriticalSection(&gcsMPH
);
2930 DWORD WINAPI
GetQueueStatus(UINT flags
)
2932 return IsInsideMessagePumpHook() ? gmph
.RealGetQueueStatus(flags
) : RealGetQueueStatus(flags
);
2936 * @name RealMsgWaitForMultipleObjectsEx
2938 * Wait either for either message arrival or for one of the passed events
2942 * Number of handles in the pHandles array.
2944 * Handles of events to wait for.
2945 * @param dwMilliseconds
2948 * Mask specifying on which message events we should wakeup.
2950 * Wait type (see MWMO_* constants).
2956 RealMsgWaitForMultipleObjectsEx(
2958 const HANDLE
*pHandles
,
2959 DWORD dwMilliseconds
,
2963 LPHANDLE RealHandles
;
2964 HANDLE MessageQueueHandle
;
2967 PCLIENTTHREADINFO pcti
;
2969 if (dwFlags
& ~(MWMO_WAITALL
| MWMO_ALERTABLE
| MWMO_INPUTAVAILABLE
))
2971 SetLastError(ERROR_INVALID_PARAMETER
);
2975 pci
= GetWin32ClientInfo();
2976 if (!pci
) return WAIT_FAILED
;
2978 pcti
= pci
->pClientThreadInfo
;
2979 if (pcti
&& ( !nCount
|| !(dwFlags
& MWMO_WAITALL
) ))
2981 if ( (pcti
->fsChangeBits
& LOWORD(dwWakeMask
)) ||
2982 ( (dwFlags
& MWMO_INPUTAVAILABLE
) && (pcti
->fsWakeBits
& LOWORD(dwWakeMask
)) ) )
2984 //FIXME("Chg 0x%x Wake 0x%x Mask 0x%x nCnt %d\n",pcti->fsChangeBits, pcti->fsWakeBits, dwWakeMask, nCount);
2989 MessageQueueHandle
= NtUserxMsqSetWakeMask(MAKELONG(dwWakeMask
, dwFlags
));
2990 if (MessageQueueHandle
== NULL
)
2992 SetLastError(0); /* ? */
2996 RealHandles
= HeapAlloc(GetProcessHeap(), 0, (nCount
+ 1) * sizeof(HANDLE
));
2997 if (RealHandles
== NULL
)
2999 NtUserxMsqClearWakeMask();
3000 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
3004 RtlCopyMemory(RealHandles
, pHandles
, nCount
* sizeof(HANDLE
));
3005 RealHandles
[nCount
] = MessageQueueHandle
;
3007 Result
= WaitForMultipleObjectsEx(nCount
+ 1, RealHandles
,
3008 dwFlags
& MWMO_WAITALL
,
3009 dwMilliseconds
, dwFlags
& MWMO_ALERTABLE
);
3011 HeapFree(GetProcessHeap(), 0, RealHandles
);
3012 NtUserxMsqClearWakeMask();
3013 //FIXME("Result 0X%x\n",Result);
3021 MsgWaitForMultipleObjectsEx(
3023 CONST HANDLE
*lpHandles
,
3024 DWORD dwMilliseconds
,
3028 return IsInsideMessagePumpHook() ? gmph
.RealMsgWaitForMultipleObjectsEx(nCount
, lpHandles
, dwMilliseconds
, dwWakeMask
, dwFlags
) : RealMsgWaitForMultipleObjectsEx(nCount
, lpHandles
,dwMilliseconds
, dwWakeMask
, dwFlags
);
3035 MsgWaitForMultipleObjects(
3037 CONST HANDLE
*lpHandles
,
3039 DWORD dwMilliseconds
,
3042 return MsgWaitForMultipleObjectsEx(nCount
, lpHandles
, dwMilliseconds
,
3043 dwWakeMask
, fWaitAll
? MWMO_WAITALL
: 0);
3047 BOOL FASTCALL
MessageInit(VOID
)
3049 InitializeCriticalSection(&DdeCrst
);
3050 InitializeCriticalSection(&gcsMPH
);
3055 VOID FASTCALL
MessageCleanup(VOID
)
3057 DeleteCriticalSection(&DdeCrst
);
3058 DeleteCriticalSection(&gcsMPH
);
3065 IsDialogMessageA( HWND hwndDlg
, LPMSG pmsg
)
3068 msg
.wParam
= map_wparam_AtoW( msg
.message
, msg
.wParam
);
3069 return IsDialogMessageW( hwndDlg
, &msg
);
3074 IntBroadcastSystemMessage(
3076 LPDWORD lpdwRecipients
,
3084 DWORD recips
= BSM_ALLCOMPONENTS
;
3085 BOOL ret
= -1; // Set to return fail
3086 static const DWORD all_flags
= ( BSF_QUERY
| BSF_IGNORECURRENTTASK
| BSF_FLUSHDISK
| BSF_NOHANG
3087 | BSF_POSTMESSAGE
| BSF_FORCEIFHUNG
| BSF_NOTIMEOUTIFNOTHUNG
3088 | BSF_ALLOWSFW
| BSF_SENDNOTIFYMESSAGE
| BSF_RETURNHDESK
| BSF_LUID
);
3090 if ((dwflags
& ~all_flags
) ||
3091 (!pBSMInfo
&& (dwflags
& (BSF_RETURNHDESK
|BSF_LUID
))) )
3093 SetLastError(ERROR_INVALID_PARAMETER
);
3097 if(uiMessage
>= WM_USER
&& uiMessage
< 0xC000)
3099 SetLastError(ERROR_INVALID_PARAMETER
);
3103 if (dwflags
& BSF_FORCEIFHUNG
) dwflags
|= BSF_NOHANG
;
3105 if (dwflags
& BSF_QUERY
) dwflags
&= ~BSF_SENDNOTIFYMESSAGE
|BSF_POSTMESSAGE
;
3107 if (!lpdwRecipients
)
3108 lpdwRecipients
= &recips
;
3110 if (*lpdwRecipients
& ~(BSM_APPLICATIONS
|BSM_ALLDESKTOPS
|BSM_INSTALLABLEDRIVERS
|BSM_NETDRIVER
|BSM_VXDS
))
3112 SetLastError(ERROR_INVALID_PARAMETER
);
3116 if ( pBSMInfo
&& (dwflags
& BSF_QUERY
) )
3118 if (pBSMInfo
->cbSize
!= sizeof(BSMINFO
))
3120 SetLastError(ERROR_INVALID_PARAMETER
);
3127 parm
.flags
= dwflags
;
3128 parm
.recipients
= *lpdwRecipients
;
3130 if (dwflags
& BSF_LUID
) parm
.luid
= pBSMInfo
->luid
;
3132 ret
= NtUserMessageCall(GetDesktopWindow(),
3137 FNID_BROADCASTSYSTEMMESSAGE
,
3142 if ( pBSMInfo
&& (dwflags
& BSF_QUERY
) )
3144 pBSMInfo
->hdesk
= parm
.hDesk
;
3145 pBSMInfo
->hwnd
= parm
.hWnd
;
3156 BroadcastSystemMessageA(
3158 LPDWORD lpdwRecipients
,
3163 return IntBroadcastSystemMessage( dwFlags
, lpdwRecipients
, uiMessage
, wParam
, lParam
, NULL
, TRUE
);
3171 BroadcastSystemMessageW(
3173 LPDWORD lpdwRecipients
,
3178 return IntBroadcastSystemMessage( dwFlags
, lpdwRecipients
, uiMessage
, wParam
, lParam
, NULL
, FALSE
);
3186 BroadcastSystemMessageExA(
3188 LPDWORD lpdwRecipients
,
3194 return IntBroadcastSystemMessage( dwflags
, lpdwRecipients
, uiMessage
, wParam
, lParam
, pBSMInfo
, TRUE
);
3202 BroadcastSystemMessageExW(
3204 LPDWORD lpdwRecipients
,
3210 return IntBroadcastSystemMessage( dwflags
, lpdwRecipients
, uiMessage
, wParam
, lParam
, pBSMInfo
, FALSE
);