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
,
1292 BOOL Hook
= FALSE
, MsgOverride
= FALSE
, Dialog
;
1293 LRESULT Result
= 0, PreResult
= 0;
1296 if (WndProc
== NULL
)
1298 WARN("IntCallWindowsProcW() called with WndProc = NULL!\n");
1302 // Safeguard against excessive recursions.
1303 LowLimit
= (ULONG_PTR
)NtCurrentTeb()->NtTib
.StackLimit
;
1304 if (((ULONG_PTR
)&lParam
- LowLimit
) < PAGE_SIZE
)
1306 ERR("IntCallWindowsProcW() Exceeded Stack!\n");
1311 Dialog
= (pWnd
->fnid
== FNID_DIALOG
);
1315 Hook
= BeginIfHookedUserApiHook();
1319 MsgOverride
= IsMsgOverride( Msg
, &guah
.WndProcArray
);
1321 MsgOverride
= IsMsgOverride( Msg
, &guah
.DlgProcArray
);
1326 UnicodeMsg
.hwnd
= hWnd
;
1327 UnicodeMsg
.message
= Msg
;
1328 UnicodeMsg
.wParam
= wParam
;
1329 UnicodeMsg
.lParam
= lParam
;
1330 if (! MsgiUnicodeToAnsiMessage(hWnd
, &AnsiMsg
, &UnicodeMsg
))
1335 if (Hook
&& MsgOverride
)
1340 PreResult
= guah
.PreWndProc(AnsiMsg
.hwnd
, AnsiMsg
.message
, AnsiMsg
.wParam
, AnsiMsg
.lParam
, (ULONG_PTR
)&Result
, &Data
);
1342 PreResult
= guah
.PreDefDlgProc(AnsiMsg
.hwnd
, AnsiMsg
.message
, AnsiMsg
.wParam
, AnsiMsg
.lParam
, (ULONG_PTR
)&Result
, &Data
);
1344 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1350 if (PreResult
) goto Exit
;
1352 _SEH2_TRY
// wine does this.
1354 Result
= WndProc(AnsiMsg
.hwnd
, AnsiMsg
.message
, AnsiMsg
.wParam
, AnsiMsg
.lParam
);
1356 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1358 ERR("Got exception when calling Ansi WndProc %p Msg %d \n",WndProc
,Msg
);
1362 if (Hook
&& MsgOverride
)
1367 guah
.PostWndProc(AnsiMsg
.hwnd
, AnsiMsg
.message
, AnsiMsg
.wParam
, AnsiMsg
.lParam
, (ULONG_PTR
)&Result
, &Data
);
1369 guah
.PostDefDlgProc(AnsiMsg
.hwnd
, AnsiMsg
.message
, AnsiMsg
.wParam
, AnsiMsg
.lParam
, (ULONG_PTR
)&Result
, &Data
);
1371 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1377 if (! MsgiUnicodeToAnsiReply(&AnsiMsg
, &UnicodeMsg
, &Result
))
1384 if (Hook
&& MsgOverride
)
1389 PreResult
= guah
.PreWndProc(hWnd
, Msg
, wParam
, lParam
, (ULONG_PTR
)&Result
, &Data
);
1391 PreResult
= guah
.PreDefDlgProc(hWnd
, Msg
, wParam
, lParam
, (ULONG_PTR
)&Result
, &Data
);
1393 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1399 if (PreResult
) goto Exit
;
1403 Result
= WndProc(hWnd
, Msg
, wParam
, lParam
);
1405 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1407 ERR("Got exception when calling unicode WndProc %p Msg %d \n",WndProc
, Msg
);
1411 if (Hook
&& MsgOverride
)
1416 guah
.PostWndProc(hWnd
, Msg
, wParam
, lParam
, (ULONG_PTR
)&Result
, &Data
);
1418 guah
.PostDefDlgProc(hWnd
, Msg
, wParam
, lParam
, (ULONG_PTR
)&Result
, &Data
);
1420 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1428 if (Hook
) EndUserApiHook();
1432 static LRESULT FASTCALL
1433 IntCallWindowProcA(BOOL IsAnsiProc
,
1444 BOOL Hook
= FALSE
, MsgOverride
= FALSE
, Dialog
;
1445 LRESULT Result
= 0, PreResult
= 0;
1448 if (WndProc
== NULL
)
1450 WARN("IntCallWindowsProcA() called with WndProc = NULL!\n");
1454 LowLimit
= (ULONG_PTR
)NtCurrentTeb()->NtTib
.StackLimit
;
1455 if (((ULONG_PTR
)&lParam
- LowLimit
) < PAGE_SIZE
)
1457 ERR("IntCallWindowsProcA() Exceeded Stack!\n");
1462 Dialog
= (pWnd
->fnid
== FNID_DIALOG
);
1466 Hook
= BeginIfHookedUserApiHook();
1470 MsgOverride
= IsMsgOverride( Msg
, &guah
.WndProcArray
);
1472 MsgOverride
= IsMsgOverride( Msg
, &guah
.DlgProcArray
);
1477 if (Hook
&& MsgOverride
)
1482 PreResult
= guah
.PreWndProc(hWnd
, Msg
, wParam
, lParam
, (ULONG_PTR
)&Result
, &Data
);
1484 PreResult
= guah
.PreDefDlgProc(hWnd
, Msg
, wParam
, lParam
, (ULONG_PTR
)&Result
, &Data
);
1486 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1492 if (PreResult
) goto Exit
;
1496 Result
= WndProc(hWnd
, Msg
, wParam
, lParam
);
1498 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1500 ERR("Got exception when calling Ansi WndProc %p Msg %d \n",WndProc
,Msg
);
1504 if (Hook
&& MsgOverride
)
1509 guah
.PostWndProc(hWnd
, Msg
, wParam
, lParam
, (ULONG_PTR
)&Result
, &Data
);
1511 guah
.PostDefDlgProc(hWnd
, Msg
, wParam
, lParam
, (ULONG_PTR
)&Result
, &Data
);
1513 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1521 AnsiMsg
.hwnd
= hWnd
;
1522 AnsiMsg
.message
= Msg
;
1523 AnsiMsg
.wParam
= wParam
;
1524 AnsiMsg
.lParam
= lParam
;
1525 if (! MsgiAnsiToUnicodeMessage(hWnd
, &UnicodeMsg
, &AnsiMsg
))
1530 if (Hook
&& MsgOverride
)
1535 PreResult
= guah
.PreWndProc(UnicodeMsg
.hwnd
, UnicodeMsg
.message
, UnicodeMsg
.wParam
, UnicodeMsg
.lParam
, (ULONG_PTR
)&Result
, &Data
);
1537 PreResult
= guah
.PreDefDlgProc(UnicodeMsg
.hwnd
, UnicodeMsg
.message
, UnicodeMsg
.wParam
, UnicodeMsg
.lParam
, (ULONG_PTR
)&Result
, &Data
);
1539 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1545 if (PreResult
) goto Exit
;
1549 Result
= WndProc(UnicodeMsg
.hwnd
, UnicodeMsg
.message
,
1550 UnicodeMsg
.wParam
, UnicodeMsg
.lParam
);
1552 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1554 ERR("Got exception when calling unicode WndProc %p Msg %d \n",WndProc
, Msg
);
1558 if (Hook
&& MsgOverride
)
1563 guah
.PostWndProc(UnicodeMsg
.hwnd
, UnicodeMsg
.message
, UnicodeMsg
.wParam
, UnicodeMsg
.lParam
, (ULONG_PTR
)&Result
, &Data
);
1565 guah
.PostDefDlgProc(UnicodeMsg
.hwnd
, UnicodeMsg
.message
, UnicodeMsg
.wParam
, UnicodeMsg
.lParam
, (ULONG_PTR
)&Result
, &Data
);
1567 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1573 if (! MsgiAnsiToUnicodeReply(&UnicodeMsg
, &AnsiMsg
, &Result
))
1580 if (Hook
) EndUserApiHook();
1585 static LRESULT WINAPI
1586 IntCallMessageProc(IN PWND Wnd
, IN HWND hWnd
, IN UINT Msg
, IN WPARAM wParam
, IN LPARAM lParam
, IN BOOL Ansi
)
1592 Class
= DesktopPtrToUser(Wnd
->pcls
);
1595 if ( Wnd
->head
.pti
!= GetW32ThreadInfo())
1596 { // Must be inside the same thread!
1597 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
1601 This is the message exchange for user32. If there's a need to monitor messages,
1604 TRACE("HWND %p, MSG %u, WPARAM %p, LPARAM %p, Ansi %d\n", hWnd
, Msg
, wParam
, lParam
, Ansi
);
1605 // if (Class->fnid <= FNID_GHOST && Class->fnid >= FNID_BUTTON )
1606 if (Class
->fnid
<= FNID_GHOST
&& Class
->fnid
>= FNID_FIRST
)
1610 if (GETPFNCLIENTW(Class
->fnid
) == Wnd
->lpfnWndProc
)
1611 WndProc
= GETPFNCLIENTA(Class
->fnid
);
1615 if (GETPFNCLIENTA(Class
->fnid
) == Wnd
->lpfnWndProc
)
1616 WndProc
= GETPFNCLIENTW(Class
->fnid
);
1623 IsAnsi
= !Wnd
->Unicode
;
1624 WndProc
= Wnd
->lpfnWndProc
;
1629 IsAnsi
= !Wnd
->Unicode
;
1630 WndProc
= Wnd
->lpfnWndProc
;
1633 Message caller can be Ansi/Unicode and the receiver can be Unicode/Ansi or
1637 return IntCallWindowProcW(IsAnsi
, WndProc
, Wnd
, hWnd
, Msg
, wParam
, lParam
);
1639 return IntCallWindowProcA(IsAnsi
, WndProc
, Wnd
, hWnd
, Msg
, wParam
, lParam
);
1647 CallWindowProcA(WNDPROC lpPrevWndFunc
,
1654 PCALLPROCDATA CallProc
;
1656 if (lpPrevWndFunc
== NULL
)
1658 WARN("CallWindowProcA: lpPrevWndFunc == NULL!\n");
1662 pWnd
= ValidateHwnd(hWnd
);
1664 if (!IsCallProcHandle(lpPrevWndFunc
))
1665 return IntCallWindowProcA(TRUE
, lpPrevWndFunc
, pWnd
, hWnd
, Msg
, wParam
, lParam
);
1668 CallProc
= ValidateCallProc((HANDLE
)lpPrevWndFunc
);
1669 if (CallProc
!= NULL
)
1671 return IntCallWindowProcA(!(CallProc
->wType
& UserGetCPDA2U
),
1672 CallProc
->pfnClientPrevious
,
1681 WARN("CallWindowProcA: can not dereference WndProcHandle\n");
1692 CallWindowProcW(WNDPROC lpPrevWndFunc
,
1699 PCALLPROCDATA CallProc
;
1701 /* FIXME - can the first parameter be NULL? */
1702 if (lpPrevWndFunc
== NULL
)
1704 WARN("CallWindowProcA: lpPrevWndFunc == NULL!\n");
1708 pWnd
= ValidateHwnd(hWnd
);
1710 if (!IsCallProcHandle(lpPrevWndFunc
))
1711 return IntCallWindowProcW(FALSE
, lpPrevWndFunc
, pWnd
, hWnd
, Msg
, wParam
, lParam
);
1714 CallProc
= ValidateCallProc((HANDLE
)lpPrevWndFunc
);
1715 if (CallProc
!= NULL
)
1717 return IntCallWindowProcW(!(CallProc
->wType
& UserGetCPDA2U
),
1718 CallProc
->pfnClientPrevious
,
1727 WARN("CallWindowProcW: can not dereference WndProcHandle\n");
1738 DispatchMessageA(CONST MSG
*lpmsg
)
1745 if ( lpmsg
->message
& ~WM_MAXIMUM
)
1747 SetLastError( ERROR_INVALID_PARAMETER
);
1751 if (lpmsg
->hwnd
!= NULL
)
1753 Wnd
= ValidateHwnd(lpmsg
->hwnd
);
1759 if (is_pointer_message(lpmsg
->message
))
1761 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
1765 if ((lpmsg
->message
== WM_TIMER
|| lpmsg
->message
== WM_SYSTIMER
) && lpmsg
->lParam
!= 0)
1767 WNDPROC WndProc
= (WNDPROC
)lpmsg
->lParam
;
1769 if ( lpmsg
->message
== WM_SYSTIMER
)
1770 return NtUserDispatchMessage( (PMSG
)lpmsg
);
1772 if (!NtUserValidateTimerCallback(lpmsg
->hwnd
, lpmsg
->wParam
, lpmsg
->lParam
))
1774 WARN("Validating Timer Callback failed!\n");
1778 _SEH2_TRY
// wine does this. Hint: Prevents call to another thread....
1780 Ret
= WndProc(lpmsg
->hwnd
,
1785 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1791 else if (Wnd
!= NULL
)
1793 if ( (lpmsg
->message
!= WM_PAINT
) && !(Wnd
->state
& WNDS_SERVERSIDEWINDOWPROC
) )
1795 Ret
= IntCallMessageProc(Wnd
,
1804 if (!MsgiAnsiToUnicodeMessage(lpmsg
->hwnd
, &UnicodeMsg
, (LPMSG
)lpmsg
))
1809 Ret
= NtUserDispatchMessage(&UnicodeMsg
);
1811 if (!MsgiAnsiToUnicodeReply(&UnicodeMsg
, (LPMSG
)lpmsg
, &Ret
))
1820 WARN("Exception in Timer Callback WndProcA!\n");
1830 DispatchMessageW(CONST MSG
*lpmsg
)
1836 if ( lpmsg
->message
& ~WM_MAXIMUM
)
1838 SetLastError( ERROR_INVALID_PARAMETER
);
1842 if (lpmsg
->hwnd
!= NULL
)
1844 Wnd
= ValidateHwnd(lpmsg
->hwnd
);
1850 if (is_pointer_message(lpmsg
->message
))
1852 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
1856 if ((lpmsg
->message
== WM_TIMER
|| lpmsg
->message
== WM_SYSTIMER
) && lpmsg
->lParam
!= 0)
1858 WNDPROC WndProc
= (WNDPROC
)lpmsg
->lParam
;
1860 if ( lpmsg
->message
== WM_SYSTIMER
)
1861 return NtUserDispatchMessage( (PMSG
) lpmsg
);
1863 if (!NtUserValidateTimerCallback(lpmsg
->hwnd
, lpmsg
->wParam
, lpmsg
->lParam
))
1865 WARN("Validating Timer Callback failed!\n");
1871 Ret
= WndProc(lpmsg
->hwnd
,
1876 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1882 else if (Wnd
!= NULL
)
1884 if ( (lpmsg
->message
!= WM_PAINT
) && !(Wnd
->state
& WNDS_SERVERSIDEWINDOWPROC
) )
1886 Ret
= IntCallMessageProc(Wnd
,
1894 Ret
= NtUserDispatchMessage( (PMSG
) lpmsg
);
1899 WARN("Exception in Timer Callback WndProcW!\n");
1905 IntConvertMsgToAnsi(LPMSG lpMsg
)
1910 switch (lpMsg
->message
)
1915 case WM_SYSDEADCHAR
:
1917 wch
[0] = LOWORD(lpMsg
->wParam
);
1918 wch
[1] = HIWORD(lpMsg
->wParam
);
1920 WideCharToMultiByte(CP_THREAD_ACP
, 0, wch
, 2, ch
, 2, NULL
, NULL
);
1921 lpMsg
->wParam
= MAKEWPARAM(ch
[0] | (ch
[1] << 8), 0);
1930 GetMessageA(LPMSG lpMsg
,
1937 if ( (wMsgFilterMin
|wMsgFilterMax
) & ~WM_MAXIMUM
)
1939 SetLastError( ERROR_INVALID_PARAMETER
);
1943 Res
= NtUserGetMessage(lpMsg
, hWnd
, wMsgFilterMin
, wMsgFilterMax
);
1944 if (-1 == (int) Res
)
1949 IntConvertMsgToAnsi(lpMsg
);
1958 GetMessageW(LPMSG lpMsg
,
1965 if ( (wMsgFilterMin
|wMsgFilterMax
) & ~WM_MAXIMUM
)
1967 SetLastError( ERROR_INVALID_PARAMETER
);
1971 Res
= NtUserGetMessage(lpMsg
, hWnd
, wMsgFilterMin
, wMsgFilterMax
);
1972 if (-1 == (int) Res
)
1981 PeekMessageWorker( PMSG pMsg
,
1988 PCLIENTTHREADINFO pcti
;
1989 pci
= GetWin32ClientInfo();
1990 pcti
= pci
->pClientThreadInfo
;
1992 if (!hWnd
&& pci
&& pcti
)
1996 if ((pci
->cSpins
>= 100) && (pci
->dwTIFlags
& TIF_SPINNING
))
1997 { // Yield after 100 spin cycles and ready to swap vinyl.
1998 if (!(pci
->dwTIFlags
& TIF_WAITFORINPUTIDLE
))
1999 { // Not waiting for idle event.
2000 if (!pcti
->fsChangeBits
&& !pcti
->fsWakeBits
)
2001 { // No messages are available.
2002 if ((GetTickCount() - pcti
->tickLastMsgChecked
) > 1000)
2003 { // Up the msg read count if over 1 sec.
2004 NtUserGetThreadState(THREADSTATE_UPTIMELASTREAD
);
2008 FIXME("seeSpins!\n");
2014 return NtUserPeekMessage(pMsg
, hWnd
, wMsgFilterMin
, wMsgFilterMax
, wRemoveMsg
);
2021 PeekMessageA(LPMSG lpMsg
,
2029 Res
= PeekMessageWorker(lpMsg
, hWnd
, wMsgFilterMin
, wMsgFilterMax
, wRemoveMsg
);
2030 if (-1 == (int) Res
|| !Res
)
2035 IntConvertMsgToAnsi(lpMsg
);
2055 Res
= PeekMessageWorker(lpMsg
, hWnd
, wMsgFilterMin
, wMsgFilterMax
, wRemoveMsg
);
2056 if (-1 == (int) Res
|| !Res
)
2077 /* Check for combo box or a list box to send names. */
2078 if (Msg
== CB_DIR
|| Msg
== LB_DIR
)
2081 Set DDL_POSTMSGS, so use the PostMessage function to send messages to the
2082 combo/list box. Forces a call like DlgDirListComboBox.
2084 //wParam |= DDL_POSTMSGS;
2085 return NtUserPostMessage(hWnd
, Msg
, wParam
, lParam
);
2088 /* No drop files or current Process, just post message. */
2089 if ( (Msg
!= WM_DROPFILES
) ||
2090 ( NtUserQueryWindow( hWnd
, QUERY_WINDOW_UNIQUE_PROCESS_ID
) ==
2091 PtrToUint(NtCurrentTeb()->ClientId
.UniqueProcess
) ) )
2093 return NtUserPostMessage(hWnd
, Msg
, wParam
, lParam
);
2096 /* We have drop files and this is not the same process for this window. */
2098 /* Just incase, check wParam for Global memory handle and send size. */
2099 Ret
= SendMessageA( hWnd
,
2101 (WPARAM
)GlobalSize((HGLOBAL
)wParam
), // Zero if not a handle.
2102 (LPARAM
)wParam
); // Send wParam as lParam.
2104 if ( Ret
) return NtUserPostMessage(hWnd
, Msg
, (WPARAM
)Ret
, lParam
);
2122 /* Check for combo box or a list box to send names. */
2123 if (Msg
== CB_DIR
|| Msg
== LB_DIR
)
2126 Set DDL_POSTMSGS, so use the PostMessage function to send messages to the
2127 combo/list box. Forces a call like DlgDirListComboBox.
2129 //wParam |= DDL_POSTMSGS;
2130 return NtUserPostMessage(hWnd
, Msg
, wParam
, lParam
);
2133 /* No drop files or current Process, just post message. */
2134 if ( (Msg
!= WM_DROPFILES
) ||
2135 ( NtUserQueryWindow( hWnd
, QUERY_WINDOW_UNIQUE_PROCESS_ID
) ==
2136 PtrToUint(NtCurrentTeb()->ClientId
.UniqueProcess
) ) )
2138 return NtUserPostMessage(hWnd
, Msg
, wParam
, lParam
);
2141 /* We have drop files and this is not the same process for this window. */
2143 /* Just incase, check wParam for Global memory handle and send size. */
2144 Ret
= SendMessageW( hWnd
,
2146 (WPARAM
)GlobalSize((HGLOBAL
)wParam
), // Zero if not a handle.
2147 (LPARAM
)wParam
); // Send wParam as lParam.
2149 if ( Ret
) return NtUserPostMessage(hWnd
, Msg
, (WPARAM
)Ret
, lParam
);
2162 NtUserxPostQuitMessage(nExitCode
);
2177 return NtUserPostThreadMessage(idThread
, Msg
, wParam
, lParam
);
2192 return NtUserPostThreadMessage(idThread
, Msg
, wParam
, lParam
);
2200 SendMessageW(HWND Wnd
,
2208 PTHREADINFO ti
= GetW32ThreadInfo();
2210 if ( Msg
& ~WM_MAXIMUM
)
2212 SetLastError( ERROR_INVALID_PARAMETER
);
2216 if (Wnd
!= HWND_TOPMOST
&& Wnd
!= HWND_BROADCAST
&& (Msg
< WM_DDE_FIRST
|| Msg
> WM_DDE_LAST
))
2218 Window
= ValidateHwnd(Wnd
);
2220 if ( Window
!= NULL
&&
2221 Window
->head
.pti
== ti
&&
2222 // !IsThreadHooked(GetWin32ClientInfo()) && // Enable to test message system bug.
2223 !ISITHOOKED(WH_CALLWNDPROC
) &&
2224 !ISITHOOKED(WH_CALLWNDPROCRET
) &&
2225 !(Window
->state
& WNDS_SERVERSIDEWINDOWPROC
) )
2227 /* NOTE: We can directly send messages to the window procedure
2228 if *all* the following conditions are met:
2230 * Window belongs to calling thread
2231 * The calling thread is not being hooked for CallWndProc
2232 * Not calling a server side proc:
2233 Desktop, Switch, ScrollBar, Menu, IconTitle, or hWndMessage
2236 return IntCallMessageProc(Window
, Wnd
, Msg
, wParam
, lParam
, FALSE
);
2241 UMMsg
.message
= Msg
;
2242 UMMsg
.wParam
= wParam
;
2243 UMMsg
.lParam
= lParam
;
2245 if (! MsgiUMToKMMessage(&UMMsg
, &KMMsg
, FALSE
))
2250 Result
= NtUserMessageCall( Wnd
,
2258 MsgiUMToKMCleanup(&UMMsg
, &KMMsg
);
2268 SendMessageA(HWND Wnd
, UINT Msg
, WPARAM wParam
, LPARAM lParam
)
2270 MSG AnsiMsg
, UcMsg
, KMMsg
;
2273 PTHREADINFO ti
= GetW32ThreadInfo();
2275 if ( Msg
& ~WM_MAXIMUM
)
2277 SetLastError( ERROR_INVALID_PARAMETER
);
2281 if (Wnd
!= HWND_TOPMOST
&& Wnd
!= HWND_BROADCAST
&& (Msg
< WM_DDE_FIRST
|| Msg
> WM_DDE_LAST
))
2283 Window
= ValidateHwnd(Wnd
);
2285 if ( Window
!= NULL
&&
2286 Window
->head
.pti
== ti
&&
2287 // !IsThreadHooked(GetWin32ClientInfo()) && // Enable to test message system bug.
2288 !ISITHOOKED(WH_CALLWNDPROC
) &&
2289 !ISITHOOKED(WH_CALLWNDPROCRET
) &&
2290 !(Window
->state
& WNDS_SERVERSIDEWINDOWPROC
) )
2292 /* NOTE: We can directly send messages to the window procedure
2293 if *all* the following conditions are met:
2295 * Window belongs to calling thread
2296 * The calling thread is not being hooked for CallWndProc
2297 * Not calling a server side proc:
2298 Desktop, Switch, ScrollBar, Menu, IconTitle, or hWndMessage
2301 return IntCallMessageProc(Window
, Wnd
, Msg
, wParam
, lParam
, TRUE
);
2306 AnsiMsg
.message
= Msg
;
2307 AnsiMsg
.wParam
= wParam
;
2308 AnsiMsg
.lParam
= lParam
;
2310 if (!MsgiAnsiToUnicodeMessage(Wnd
, &UcMsg
, &AnsiMsg
))
2315 if (!MsgiUMToKMMessage(&UcMsg
, &KMMsg
, FALSE
))
2317 MsgiAnsiToUnicodeCleanup(&UcMsg
, &AnsiMsg
);
2321 Result
= NtUserMessageCall( Wnd
,
2329 MsgiUMToKMCleanup(&UcMsg
, &KMMsg
);
2330 MsgiAnsiToUnicodeReply(&UcMsg
, &AnsiMsg
, &Result
);
2340 SendMessageCallbackA(
2345 SENDASYNCPROC lpCallBack
,
2350 CALL_BACK_INFO CallBackInfo
;
2352 if (is_pointer_message(Msg
))
2354 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
2358 CallBackInfo
.CallBack
= lpCallBack
;
2359 CallBackInfo
.Context
= dwData
;
2361 AnsiMsg
.hwnd
= hWnd
;
2362 AnsiMsg
.message
= Msg
;
2363 AnsiMsg
.wParam
= wParam
;
2364 AnsiMsg
.lParam
= lParam
;
2366 if (!MsgiAnsiToUnicodeMessage(hWnd
, &UcMsg
, &AnsiMsg
))
2371 Result
= NtUserMessageCall( hWnd
,
2375 (ULONG_PTR
)&CallBackInfo
,
2376 FNID_SENDMESSAGECALLBACK
,
2379 MsgiAnsiToUnicodeCleanup(&UcMsg
, &AnsiMsg
);
2389 SendMessageCallbackW(
2394 SENDASYNCPROC lpCallBack
,
2397 CALL_BACK_INFO CallBackInfo
;
2399 if (is_pointer_message(Msg
))
2401 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
2405 CallBackInfo
.CallBack
= lpCallBack
;
2406 CallBackInfo
.Context
= dwData
;
2408 return NtUserMessageCall(hWnd
,
2412 (ULONG_PTR
)&CallBackInfo
,
2413 FNID_SENDMESSAGECALLBACK
,
2422 SendMessageTimeoutA(
2429 PDWORD_PTR lpdwResult
)
2435 PTHREADINFO ti
= GetW32ThreadInfo();
2437 if ( Msg
& ~WM_MAXIMUM
|| fuFlags
& ~(SMTO_NOTIMEOUTIFNOTHUNG
|SMTO_ABORTIFHUNG
|SMTO_BLOCK
))
2439 SetLastError( ERROR_INVALID_PARAMETER
);
2443 if (lpdwResult
) *lpdwResult
= 0;
2445 //// This is due to message system bug.
2446 if (hWnd
!= HWND_TOPMOST
&& hWnd
!= HWND_BROADCAST
&& (Msg
< WM_DDE_FIRST
|| Msg
> WM_DDE_LAST
))
2448 Window
= ValidateHwnd(hWnd
);
2450 if ( Window
!= NULL
&&
2451 Window
->head
.pti
== ti
&&
2452 !ISITHOOKED(WH_CALLWNDPROC
) &&
2453 !ISITHOOKED(WH_CALLWNDPROCRET
) &&
2454 !(Window
->state
& WNDS_SERVERSIDEWINDOWPROC
) )
2456 Result
= IntCallMessageProc(Window
, hWnd
, Msg
, wParam
, lParam
, TRUE
);
2457 if (lpdwResult
) *lpdwResult
= Result
;
2462 SPY_EnterMessage(SPY_SENDMESSAGE
, hWnd
, Msg
, wParam
, lParam
);
2464 dsm
.uFlags
= fuFlags
;
2465 dsm
.uTimeout
= uTimeout
;
2467 AnsiMsg
.hwnd
= hWnd
;
2468 AnsiMsg
.message
= Msg
;
2469 AnsiMsg
.wParam
= wParam
;
2470 AnsiMsg
.lParam
= lParam
;
2472 if (! MsgiAnsiToUnicodeMessage(hWnd
, &UcMsg
, &AnsiMsg
))
2477 Result
= NtUserMessageCall( hWnd
,
2482 FNID_SENDMESSAGEWTOOPTION
,
2485 MsgiAnsiToUnicodeReply(&UcMsg
, &AnsiMsg
, &Result
);
2487 if (lpdwResult
) *lpdwResult
= dsm
.Result
;
2489 SPY_ExitMessage(SPY_RESULT_OK
, hWnd
, Msg
, Result
, wParam
, lParam
);
2500 SendMessageTimeoutW(
2507 PDWORD_PTR lpdwResult
)
2512 PTHREADINFO ti
= GetW32ThreadInfo();
2514 if ( Msg
& ~WM_MAXIMUM
|| fuFlags
& ~(SMTO_NOTIMEOUTIFNOTHUNG
|SMTO_ABORTIFHUNG
|SMTO_BLOCK
))
2516 SetLastError( ERROR_INVALID_PARAMETER
);
2520 if (lpdwResult
) *lpdwResult
= 0;
2522 //// This is due to message system bug.
2523 if (hWnd
!= HWND_TOPMOST
&& hWnd
!= HWND_BROADCAST
&& (Msg
< WM_DDE_FIRST
|| Msg
> WM_DDE_LAST
))
2525 Window
= ValidateHwnd(hWnd
);
2527 if ( Window
!= NULL
&&
2528 Window
->head
.pti
== ti
&&
2529 !ISITHOOKED(WH_CALLWNDPROC
) &&
2530 !ISITHOOKED(WH_CALLWNDPROCRET
) &&
2531 !(Window
->state
& WNDS_SERVERSIDEWINDOWPROC
) )
2533 Result
= IntCallMessageProc(Window
, hWnd
, Msg
, wParam
, lParam
, FALSE
);
2534 if (lpdwResult
) *lpdwResult
= Result
;
2539 SPY_EnterMessage(SPY_SENDMESSAGE
, hWnd
, Msg
, wParam
, lParam
);
2541 dsm
.uFlags
= fuFlags
;
2542 dsm
.uTimeout
= uTimeout
;
2544 Result
= NtUserMessageCall( hWnd
,
2549 FNID_SENDMESSAGEWTOOPTION
,
2552 if (lpdwResult
) *lpdwResult
= dsm
.Result
;
2554 SPY_ExitMessage(SPY_RESULT_OK
, hWnd
, Msg
, Result
, wParam
, lParam
);
2573 if (is_pointer_message(Msg
))
2575 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
2579 AnsiMsg
.hwnd
= hWnd
;
2580 AnsiMsg
.message
= Msg
;
2581 AnsiMsg
.wParam
= wParam
;
2582 AnsiMsg
.lParam
= lParam
;
2583 if (! MsgiAnsiToUnicodeMessage(hWnd
, &UcMsg
, &AnsiMsg
))
2587 Ret
= SendNotifyMessageW(hWnd
, UcMsg
.message
, UcMsg
.wParam
, UcMsg
.lParam
);
2589 MsgiAnsiToUnicodeCleanup(&UcMsg
, &AnsiMsg
);
2608 if (is_pointer_message(Msg
))
2610 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
2615 UMMsg
.message
= Msg
;
2616 UMMsg
.wParam
= wParam
;
2617 UMMsg
.lParam
= lParam
;
2618 if (! MsgiUMToKMMessage(&UMMsg
, &KMMsg
, TRUE
))
2622 Result
= NtUserMessageCall( hWnd
,
2627 FNID_SENDNOTIFYMESSAGE
,
2630 MsgiUMToKMCleanup(&UMMsg
, &KMMsg
);
2639 TranslateMessageEx(CONST MSG
*lpMsg
, UINT Flags
)
2641 switch (lpMsg
->message
)
2647 return(NtUserTranslateMessage((LPMSG
)lpMsg
, Flags
));
2650 if ( lpMsg
->message
& ~WM_MAXIMUM
)
2651 SetLastError(ERROR_INVALID_PARAMETER
);
2661 TranslateMessage(CONST MSG
*lpMsg
)
2665 // Ref: msdn ImmGetVirtualKey:
2666 // http://msdn.microsoft.com/en-us/library/aa912145.aspx
2668 if ( (LOWORD(lpMsg->wParam) != VK_PROCESSKEY) ||
2669 !(Ret = IMM_ImmTranslateMessage( lpMsg->hwnd,
2674 Ret
= TranslateMessageEx((LPMSG
)lpMsg
, 0);
2684 RegisterWindowMessageA(LPCSTR lpString
)
2686 UNICODE_STRING String
;
2690 Result
= RtlCreateUnicodeStringFromAsciiz(&String
, (PCSZ
)lpString
);
2695 Atom
= NtUserRegisterWindowMessage(&String
);
2696 RtlFreeUnicodeString(&String
);
2705 RegisterWindowMessageW(LPCWSTR lpString
)
2707 UNICODE_STRING String
;
2709 RtlInitUnicodeString(&String
, lpString
);
2710 return(NtUserRegisterWindowMessage(&String
));
2719 return (HWND
)NtUserGetThreadState(THREADSTATE_CAPTUREWINDOW
);
2726 ReleaseCapture(VOID
)
2728 return NtUserxReleaseCapture();
2737 RealGetQueueStatus(UINT flags
)
2739 #define QS_TEMPALLINPUT 255 // ATM, do not support QS_RAWINPUT
2740 if (flags
& ~(QS_SMRESULT
|QS_ALLPOSTMESSAGE
|QS_TEMPALLINPUT
))
2742 SetLastError( ERROR_INVALID_FLAGS
);
2745 return NtUserxGetQueueStatus(flags
);
2752 BOOL WINAPI
GetInputState(VOID
)
2754 PCLIENTTHREADINFO pcti
= GetWin32ClientInfo()->pClientThreadInfo
;
2756 if ((!pcti
) || (pcti
->fsChangeBits
& (QS_KEY
|QS_MOUSEBUTTON
)))
2757 return (BOOL
)NtUserGetThreadState(THREADSTATE_GETINPUTSTATE
);
2764 User32CallWindowProcFromKernel(PVOID Arguments
, ULONG ArgumentLength
)
2766 PWINDOWPROC_CALLBACK_ARGUMENTS CallbackArgs
;
2770 PCLIENTINFO pci
= GetWin32ClientInfo();
2772 /* Make sure we don't try to access mem beyond what we were given */
2773 if (ArgumentLength
< sizeof(WINDOWPROC_CALLBACK_ARGUMENTS
))
2775 return STATUS_INFO_LENGTH_MISMATCH
;
2778 LowLimit
= (ULONG_PTR
)NtCurrentTeb()->NtTib
.StackLimit
;
2779 if (((ULONG_PTR
)&ArgumentLength
- LowLimit
) < PAGE_SIZE
)
2781 ERR("Callback from Win32k Exceeded Stack!\n");
2782 return STATUS_BAD_STACK
;
2785 CallbackArgs
= (PWINDOWPROC_CALLBACK_ARGUMENTS
) Arguments
;
2786 KMMsg
.hwnd
= CallbackArgs
->Wnd
;
2787 KMMsg
.message
= CallbackArgs
->Msg
;
2788 KMMsg
.wParam
= CallbackArgs
->wParam
;
2789 /* Check if lParam is really a pointer and adjust it if it is */
2790 if (0 <= CallbackArgs
->lParamBufferSize
)
2792 if (ArgumentLength
!= sizeof(WINDOWPROC_CALLBACK_ARGUMENTS
)
2793 + CallbackArgs
->lParamBufferSize
)
2795 return STATUS_INFO_LENGTH_MISMATCH
;
2797 KMMsg
.lParam
= (LPARAM
) ((char *) CallbackArgs
+ sizeof(WINDOWPROC_CALLBACK_ARGUMENTS
));
2801 if (ArgumentLength
!= sizeof(WINDOWPROC_CALLBACK_ARGUMENTS
))
2803 return STATUS_INFO_LENGTH_MISMATCH
;
2805 KMMsg
.lParam
= CallbackArgs
->lParam
;
2808 if (WM_NCCALCSIZE
== CallbackArgs
->Msg
&& CallbackArgs
->wParam
)
2810 NCCALCSIZE_PARAMS
*Params
= (NCCALCSIZE_PARAMS
*) KMMsg
.lParam
;
2811 Params
->lppos
= (PWINDOWPOS
) (Params
+ 1);
2814 if (! MsgiKMToUMMessage(&KMMsg
, &UMMsg
))
2818 if (pci
->CallbackWnd
.hWnd
== UMMsg
.hwnd
)
2819 pWnd
= pci
->CallbackWnd
.pWnd
;
2821 CallbackArgs
->Result
= IntCallWindowProcW( CallbackArgs
->IsAnsiProc
,
2829 if (! MsgiKMToUMReply(&KMMsg
, &UMMsg
, &CallbackArgs
->Result
))
2833 return ZwCallbackReturn(CallbackArgs
, ArgumentLength
, STATUS_SUCCESS
);
2839 BOOL WINAPI
SetMessageQueue(int cMessagesMax
)
2841 /* Function does nothing on 32 bit windows */
2844 typedef DWORD (WINAPI
* RealGetQueueStatusProc
)(UINT flags
);
2845 typedef DWORD (WINAPI
* RealMsgWaitForMultipleObjectsExProc
)(DWORD nCount
, CONST HANDLE
*lpHandles
, DWORD dwMilliseconds
, DWORD dwWakeMask
, DWORD dwFlags
);
2846 typedef BOOL (WINAPI
* RealInternalGetMessageProc
)(LPMSG
,HWND
,UINT
,UINT
,UINT
,BOOL
);
2847 typedef BOOL (WINAPI
* RealWaitMessageExProc
)(DWORD
,UINT
);
2849 typedef struct _USER_MESSAGE_PUMP_ADDRESSES
{
2851 RealInternalGetMessageProc NtUserRealInternalGetMessage
;
2852 RealWaitMessageExProc NtUserRealWaitMessageEx
;
2853 RealGetQueueStatusProc RealGetQueueStatus
;
2854 RealMsgWaitForMultipleObjectsExProc RealMsgWaitForMultipleObjectsEx
;
2855 } USER_MESSAGE_PUMP_ADDRESSES
, * PUSER_MESSAGE_PUMP_ADDRESSES
;
2859 RealMsgWaitForMultipleObjectsEx(
2861 CONST HANDLE
*pHandles
,
2862 DWORD dwMilliseconds
,
2866 typedef BOOL (WINAPI
* MESSAGEPUMPHOOKPROC
)(BOOL Unregistering
,PUSER_MESSAGE_PUMP_ADDRESSES MessagePumpAddresses
);
2868 CRITICAL_SECTION gcsMPH
;
2869 MESSAGEPUMPHOOKPROC gpfnInitMPH
;
2870 DWORD gcLoadMPH
= 0;
2871 USER_MESSAGE_PUMP_ADDRESSES gmph
= {sizeof(USER_MESSAGE_PUMP_ADDRESSES
),
2872 NtUserRealInternalGetMessage
,
2873 NtUserRealWaitMessageEx
,
2875 RealMsgWaitForMultipleObjectsEx
2878 DWORD gfMessagePumpHook
= 0;
2880 BOOL WINAPI
IsInsideMessagePumpHook()
2881 { // FF uses this and polls it when Min/Max
2882 PCLIENTTHREADINFO pcti
= GetWin32ClientInfo()->pClientThreadInfo
;
2883 return (gfMessagePumpHook
&& pcti
&& (pcti
->dwcPumpHook
> 0));
2886 void WINAPI
ResetMessagePumpHook(PUSER_MESSAGE_PUMP_ADDRESSES Addresses
)
2888 Addresses
->cbSize
= sizeof(USER_MESSAGE_PUMP_ADDRESSES
);
2889 Addresses
->NtUserRealInternalGetMessage
= NtUserRealInternalGetMessage
;
2890 Addresses
->NtUserRealWaitMessageEx
= NtUserRealWaitMessageEx
;
2891 Addresses
->RealGetQueueStatus
= RealGetQueueStatus
;
2892 Addresses
->RealMsgWaitForMultipleObjectsEx
= RealMsgWaitForMultipleObjectsEx
;
2895 BOOL WINAPI
RegisterMessagePumpHook(MESSAGEPUMPHOOKPROC Hook
)
2897 EnterCriticalSection(&gcsMPH
);
2899 SetLastError(ERROR_INVALID_PARAMETER
);
2900 LeaveCriticalSection(&gcsMPH
);
2904 USER_MESSAGE_PUMP_ADDRESSES Addresses
;
2906 ResetMessagePumpHook(&Addresses
);
2907 if(!Hook(FALSE
, &Addresses
) || !Addresses
.cbSize
) {
2908 LeaveCriticalSection(&gcsMPH
);
2911 memcpy(&gmph
, &Addresses
, Addresses
.cbSize
);
2913 if(gpfnInitMPH
!= Hook
) {
2914 LeaveCriticalSection(&gcsMPH
);
2918 if(NtUserxInitMessagePump()) {
2919 LeaveCriticalSection(&gcsMPH
);
2923 InterlockedExchange((PLONG
)&gfMessagePumpHook
, 1);
2925 LeaveCriticalSection(&gcsMPH
);
2929 BOOL WINAPI
UnregisterMessagePumpHook(VOID
)
2931 EnterCriticalSection(&gcsMPH
);
2933 if(NtUserxUnInitMessagePump()) {
2936 InterlockedExchange((PLONG
)&gfMessagePumpHook
, 0);
2937 gpfnInitMPH(TRUE
, NULL
);
2938 ResetMessagePumpHook(&gmph
);
2941 LeaveCriticalSection(&gcsMPH
);
2945 LeaveCriticalSection(&gcsMPH
);
2949 DWORD WINAPI
GetQueueStatus(UINT flags
)
2951 return IsInsideMessagePumpHook() ? gmph
.RealGetQueueStatus(flags
) : RealGetQueueStatus(flags
);
2955 * @name RealMsgWaitForMultipleObjectsEx
2957 * Wait either for either message arrival or for one of the passed events
2961 * Number of handles in the pHandles array.
2963 * Handles of events to wait for.
2964 * @param dwMilliseconds
2967 * Mask specifying on which message events we should wakeup.
2969 * Wait type (see MWMO_* constants).
2975 RealMsgWaitForMultipleObjectsEx(
2977 const HANDLE
*pHandles
,
2978 DWORD dwMilliseconds
,
2982 LPHANDLE RealHandles
;
2983 HANDLE MessageQueueHandle
;
2986 PCLIENTTHREADINFO pcti
;
2988 if (dwFlags
& ~(MWMO_WAITALL
| MWMO_ALERTABLE
| MWMO_INPUTAVAILABLE
))
2990 SetLastError(ERROR_INVALID_PARAMETER
);
2994 pci
= GetWin32ClientInfo();
2995 if (!pci
) return WAIT_FAILED
;
2997 pcti
= pci
->pClientThreadInfo
;
2998 if (pcti
&& ( !nCount
|| !(dwFlags
& MWMO_WAITALL
) ))
3000 if ( (pcti
->fsChangeBits
& LOWORD(dwWakeMask
)) ||
3001 ( (dwFlags
& MWMO_INPUTAVAILABLE
) && (pcti
->fsWakeBits
& LOWORD(dwWakeMask
)) ) )
3003 //FIXME("Chg 0x%x Wake 0x%x Mask 0x%x nCnt %d\n",pcti->fsChangeBits, pcti->fsWakeBits, dwWakeMask, nCount);
3008 MessageQueueHandle
= NtUserxMsqSetWakeMask(MAKELONG(dwWakeMask
, dwFlags
));
3009 if (MessageQueueHandle
== NULL
)
3011 SetLastError(0); /* ? */
3015 RealHandles
= HeapAlloc(GetProcessHeap(), 0, (nCount
+ 1) * sizeof(HANDLE
));
3016 if (RealHandles
== NULL
)
3018 NtUserxMsqClearWakeMask();
3019 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
3023 RtlCopyMemory(RealHandles
, pHandles
, nCount
* sizeof(HANDLE
));
3024 RealHandles
[nCount
] = MessageQueueHandle
;
3026 Result
= WaitForMultipleObjectsEx(nCount
+ 1, RealHandles
,
3027 dwFlags
& MWMO_WAITALL
,
3028 dwMilliseconds
, dwFlags
& MWMO_ALERTABLE
);
3030 HeapFree(GetProcessHeap(), 0, RealHandles
);
3031 NtUserxMsqClearWakeMask();
3032 //FIXME("Result 0X%x\n",Result);
3040 MsgWaitForMultipleObjectsEx(
3042 CONST HANDLE
*lpHandles
,
3043 DWORD dwMilliseconds
,
3047 return IsInsideMessagePumpHook() ? gmph
.RealMsgWaitForMultipleObjectsEx(nCount
, lpHandles
, dwMilliseconds
, dwWakeMask
, dwFlags
) : RealMsgWaitForMultipleObjectsEx(nCount
, lpHandles
,dwMilliseconds
, dwWakeMask
, dwFlags
);
3054 MsgWaitForMultipleObjects(
3056 CONST HANDLE
*lpHandles
,
3058 DWORD dwMilliseconds
,
3061 return MsgWaitForMultipleObjectsEx(nCount
, lpHandles
, dwMilliseconds
,
3062 dwWakeMask
, fWaitAll
? MWMO_WAITALL
: 0);
3066 BOOL FASTCALL
MessageInit(VOID
)
3068 InitializeCriticalSection(&DdeCrst
);
3069 InitializeCriticalSection(&gcsMPH
);
3074 VOID FASTCALL
MessageCleanup(VOID
)
3076 DeleteCriticalSection(&DdeCrst
);
3077 DeleteCriticalSection(&gcsMPH
);
3084 IsDialogMessageA( HWND hwndDlg
, LPMSG pmsg
)
3087 msg
.wParam
= map_wparam_AtoW( msg
.message
, msg
.wParam
);
3088 return IsDialogMessageW( hwndDlg
, &msg
);
3093 IntBroadcastSystemMessage(
3095 LPDWORD lpdwRecipients
,
3103 DWORD recips
= BSM_ALLCOMPONENTS
;
3104 BOOL ret
= -1; // Set to return fail
3105 static const DWORD all_flags
= ( BSF_QUERY
| BSF_IGNORECURRENTTASK
| BSF_FLUSHDISK
| BSF_NOHANG
3106 | BSF_POSTMESSAGE
| BSF_FORCEIFHUNG
| BSF_NOTIMEOUTIFNOTHUNG
3107 | BSF_ALLOWSFW
| BSF_SENDNOTIFYMESSAGE
| BSF_RETURNHDESK
| BSF_LUID
);
3109 if ((dwflags
& ~all_flags
) ||
3110 (!pBSMInfo
&& (dwflags
& (BSF_RETURNHDESK
|BSF_LUID
))) )
3112 SetLastError(ERROR_INVALID_PARAMETER
);
3116 if(uiMessage
>= WM_USER
&& uiMessage
< 0xC000)
3118 SetLastError(ERROR_INVALID_PARAMETER
);
3122 if (dwflags
& BSF_FORCEIFHUNG
) dwflags
|= BSF_NOHANG
;
3124 if (dwflags
& BSF_QUERY
) dwflags
&= ~BSF_SENDNOTIFYMESSAGE
|BSF_POSTMESSAGE
;
3126 if (!lpdwRecipients
)
3127 lpdwRecipients
= &recips
;
3129 if (*lpdwRecipients
& ~(BSM_APPLICATIONS
|BSM_ALLDESKTOPS
|BSM_INSTALLABLEDRIVERS
|BSM_NETDRIVER
|BSM_VXDS
))
3131 SetLastError(ERROR_INVALID_PARAMETER
);
3135 if ( pBSMInfo
&& (dwflags
& BSF_QUERY
) )
3137 if (pBSMInfo
->cbSize
!= sizeof(BSMINFO
))
3139 SetLastError(ERROR_INVALID_PARAMETER
);
3146 parm
.flags
= dwflags
;
3147 parm
.recipients
= *lpdwRecipients
;
3149 if (dwflags
& BSF_LUID
) parm
.luid
= pBSMInfo
->luid
;
3151 ret
= NtUserMessageCall(GetDesktopWindow(),
3156 FNID_BROADCASTSYSTEMMESSAGE
,
3161 if ( pBSMInfo
&& (dwflags
& BSF_QUERY
) )
3163 pBSMInfo
->hdesk
= parm
.hDesk
;
3164 pBSMInfo
->hwnd
= parm
.hWnd
;
3175 BroadcastSystemMessageA(
3177 LPDWORD lpdwRecipients
,
3182 return IntBroadcastSystemMessage( dwFlags
, lpdwRecipients
, uiMessage
, wParam
, lParam
, NULL
, TRUE
);
3190 BroadcastSystemMessageW(
3192 LPDWORD lpdwRecipients
,
3197 return IntBroadcastSystemMessage( dwFlags
, lpdwRecipients
, uiMessage
, wParam
, lParam
, NULL
, FALSE
);
3205 BroadcastSystemMessageExA(
3207 LPDWORD lpdwRecipients
,
3213 return IntBroadcastSystemMessage( dwflags
, lpdwRecipients
, uiMessage
, wParam
, lParam
, pBSMInfo
, TRUE
);
3221 BroadcastSystemMessageExW(
3223 LPDWORD lpdwRecipients
,
3229 return IntBroadcastSystemMessage( dwflags
, lpdwRecipients
, uiMessage
, wParam
, lParam
, pBSMInfo
, FALSE
);