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
);
239 DWORD FASTCALL
get_input_codepage( void )
243 HKL hkl
= GetKeyboardLayout( 0 );
244 ret
= GetLocaleInfoW( LOWORD(hkl
), LOCALE_IDEFAULTANSICODEPAGE
| LOCALE_RETURN_NUMBER
, (WCHAR
*)&cp
, sizeof(cp
) / sizeof(WCHAR
) );
245 if (!ret
) cp
= CP_ACP
;
249 static WPARAM FASTCALL
map_wparam_char_WtoA( WPARAM wParam
, DWORD len
)
253 DWORD cp
= get_input_codepage();
255 len
= WideCharToMultiByte( cp
, 0, &wch
, 1, (LPSTR
)ch
, len
, NULL
, NULL
);
257 return MAKEWPARAM( (ch
[0] << 8) | ch
[1], HIWORD(wParam
) );
259 return MAKEWPARAM( ch
[0], HIWORD(wParam
) );
262 /***********************************************************************
265 * Convert the wparam of an ASCII message to Unicode.
267 static WPARAM FASTCALL
268 map_wparam_AtoW( UINT message
, WPARAM wparam
)
277 /* WM_CHAR is magic: a DBCS char can be sent/posted as two consecutive WM_CHAR
278 * messages, in which case the first char is stored, and the conversion
279 * to Unicode only takes place once the second char is sent/posted.
282 if (mapping
!= WMCHAR_MAP_NOMAPPING
) // NlsMbCodePageTag
284 PCLIENTINFO pci
= GetWin32ClientInfo();
286 struct wm_char_mapping_data
*data
= get_user_thread_info()->wmchar_data
;
288 BYTE low
= LOBYTE(wparam
);
293 ch
[1] = HIBYTE(wparam
);
294 RtlMultiByteToUnicodeN( wch
, sizeof(wch
), NULL
, ch
, 2 );
295 TRACE( "map %02x,%02x -> %04x mapping %u\n", (BYTE
)ch
[0], (BYTE
)ch
[1], wch
[0], mapping
);
296 if (data
) data
->lead_byte
[mapping
] = 0;
298 else if (data
&& data
->lead_byte
[mapping
])
300 ch
[0] = data
->lead_byte
[mapping
];
302 RtlMultiByteToUnicodeN( wch
, sizeof(wch
), NULL
, ch
, 2 );
303 TRACE( "map stored %02x,%02x -> %04x mapping %u\n", (BYTE
)ch
[0], (BYTE
)ch
[1], wch
[0], mapping
);
304 data
->lead_byte
[mapping
] = 0;
306 else if (!IsDBCSLeadByte( low
))
309 RtlMultiByteToUnicodeN( wch
, sizeof(wch
), NULL
, ch
, 1 );
310 TRACE( "map %02x -> %04x\n", (BYTE
)ch
[0], wch
[0] );
311 if (data
) data
->lead_byte
[mapping
] = 0;
313 else /* store it and wait for trail byte */
317 if (!(data
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*data
) )))
319 get_user_thread_info()->wmchar_data
= data
;
321 TRACE( "storing lead byte %02x mapping %u\n", low
, mapping
);
322 data
->lead_byte
[mapping
] = low
;
325 wparam
= MAKEWPARAM(wch
[0], wch
[1]);
329 /* else fall through */
331 case EM_SETPASSWORDCHAR
:
336 ch
[0] = LOBYTE(wparam
);
337 ch
[1] = HIBYTE(wparam
);
338 RtlMultiByteToUnicodeN( wch
, sizeof(wch
), NULL
, ch
, 2 );
339 wparam
= MAKEWPARAM(wch
[0], wch
[1]);
342 ch
[0] = HIBYTE(wparam
);
343 ch
[1] = LOBYTE(wparam
);
344 if (ch
[0]) RtlMultiByteToUnicodeN( wch
, sizeof(wch
[0]), NULL
, ch
, 2 );
345 else RtlMultiByteToUnicodeN( wch
, sizeof(wch
[0]), NULL
, ch
+ 1, 1 );
346 wparam
= MAKEWPARAM(wch
[0], HIWORD(wparam
));
354 MsgiUMToKMMessage(PMSG UMMsg
, PMSG KMMsg
, BOOL Posted
)
358 switch (UMMsg
->message
)
362 PKMDDELPARAM DdeLparam
;
363 DdeLparam
= HeapAlloc(GetProcessHeap(), 0, sizeof(KMDDELPARAM
));
365 !UnpackDDElParam( UMMsg
->message
, UMMsg
->lParam
, &DdeLparam
->uiLo
, &DdeLparam
->uiHi
))
368 If this is a reply to WM_DDE_EXECUTE then
369 uiHi will contain a hMem, hence >= 0x10000.
370 Otherwise, it will be be an atom, a 16-bit value.
372 if (!IS_ATOM(DdeLparam
->uiHi
))
374 HGLOBAL h
= DdeGetPair((HGLOBAL
)(ULONG_PTR
)DdeLparam
->uiHi
);
377 GlobalFree((HGLOBAL
)(ULONG_PTR
)DdeLparam
->uiHi
);
378 DdeLparam
->uiHi
= (UINT_PTR
) h
;
381 FreeDDElParam(UMMsg
->message
, UMMsg
->lParam
);
382 KMMsg
->lParam
= (LPARAM
) DdeLparam
;
389 PKMDDEEXECUTEDATA KMDdeExecuteData
;
392 Size
= GlobalSize((HGLOBAL
) UMMsg
->lParam
);
393 Data
= GlobalLock((HGLOBAL
) UMMsg
->lParam
);
396 SetLastError(ERROR_INVALID_HANDLE
);
399 KMDdeExecuteData
= HeapAlloc(GetProcessHeap(), 0, sizeof(KMDDEEXECUTEDATA
) + Size
);
400 if (!KMDdeExecuteData
)
402 SetLastError(ERROR_OUTOFMEMORY
);
405 KMDdeExecuteData
->Sender
= (HWND
) UMMsg
->wParam
;
406 KMDdeExecuteData
->ClientMem
= (HGLOBAL
) UMMsg
->lParam
;
407 memcpy((PVOID
) (KMDdeExecuteData
+ 1), Data
, Size
);
408 KMMsg
->wParam
= sizeof(KMDDEEXECUTEDATA
) + Size
;
409 KMMsg
->lParam
= (LPARAM
) KMDdeExecuteData
;
410 GlobalUnlock((HGLOBAL
) UMMsg
->lParam
);
416 PCOPYDATASTRUCT pUMCopyData
= (PCOPYDATASTRUCT
)UMMsg
->lParam
;
417 PCOPYDATASTRUCT pKMCopyData
;
419 pKMCopyData
= HeapAlloc(GetProcessHeap(), 0,
420 sizeof(COPYDATASTRUCT
) + pUMCopyData
->cbData
);
423 SetLastError(ERROR_OUTOFMEMORY
);
427 pKMCopyData
->dwData
= pUMCopyData
->dwData
;
428 pKMCopyData
->cbData
= pUMCopyData
->cbData
;
429 pKMCopyData
->lpData
= pKMCopyData
+ 1;
431 RtlCopyMemory(pKMCopyData
+ 1, pUMCopyData
->lpData
,
432 pUMCopyData
->cbData
);
434 KMMsg
->lParam
= (LPARAM
)pKMCopyData
;
447 MsgiUMToKMCleanup(PMSG UMMsg
, PMSG KMMsg
)
449 switch (KMMsg
->message
)
454 HeapFree(GetProcessHeap(), 0, (LPVOID
) KMMsg
->lParam
);
464 MsgiKMToUMMessage(PMSG KMMsg
, PMSG UMMsg
)
468 switch (UMMsg
->message
)
473 CREATESTRUCTW
*Cs
= (CREATESTRUCTW
*) KMMsg
->lParam
;
475 Cs
->lpszName
= (LPCWSTR
) ((PCHAR
) Cs
+ (DWORD_PTR
) Cs
->lpszName
);
476 Class
= (PCHAR
) Cs
+ (DWORD_PTR
) Cs
->lpszClass
;
477 if (L
'A' == *((WCHAR
*) Class
))
479 Class
+= sizeof(WCHAR
);
480 Cs
->lpszClass
= (LPCWSTR
)(DWORD_PTR
) (*((ATOM
*) Class
));
484 ASSERT(L
'S' == *((WCHAR
*) Class
));
485 Class
+= sizeof(WCHAR
);
486 Cs
->lpszClass
= (LPCWSTR
) Class
;
493 PKMDDELPARAM DdeLparam
= (PKMDDELPARAM
) KMMsg
->lParam
;
494 UMMsg
->lParam
= PackDDElParam(KMMsg
->message
, DdeLparam
->uiLo
, DdeLparam
->uiHi
);
500 PKMDDEEXECUTEDATA KMDdeExecuteData
;
504 KMDdeExecuteData
= (PKMDDEEXECUTEDATA
) KMMsg
->lParam
;
505 GlobalData
= GlobalAlloc(GMEM_MOVEABLE
, KMMsg
->wParam
- sizeof(KMDDEEXECUTEDATA
));
510 Data
= GlobalLock(GlobalData
);
513 GlobalFree(GlobalData
);
516 memcpy(Data
, (PVOID
) (KMDdeExecuteData
+ 1), KMMsg
->wParam
- sizeof(KMDDEEXECUTEDATA
));
517 GlobalUnlock(GlobalData
);
518 if (!DdeAddPair(KMDdeExecuteData
->ClientMem
, GlobalData
))
520 GlobalFree(GlobalData
);
523 UMMsg
->wParam
= (WPARAM
) KMDdeExecuteData
->Sender
;
524 UMMsg
->lParam
= (LPARAM
) GlobalData
;
530 PCOPYDATASTRUCT pKMCopyData
= (PCOPYDATASTRUCT
)KMMsg
->lParam
;
531 pKMCopyData
->lpData
= pKMCopyData
+ 1;
543 MsgiKMToUMCleanup(PMSG KMMsg
, PMSG UMMsg
)
545 switch (KMMsg
->message
)
549 HeapFree(GetProcessHeap(), 0, (LPVOID
) KMMsg
->lParam
);
550 GlobalUnlock((HGLOBAL
) UMMsg
->lParam
);
561 MsgiKMToUMReply(PMSG KMMsg
, PMSG UMMsg
, LRESULT
*Result
)
563 MsgiKMToUMCleanup(KMMsg
, UMMsg
);
569 MsgiAnsiToUnicodeMessage(HWND hwnd
, LPMSG UnicodeMsg
, LPMSG AnsiMsg
)
571 UNICODE_STRING UnicodeString
;
573 *UnicodeMsg
= *AnsiMsg
;
575 switch (AnsiMsg
->message
)
578 case WM_ASKCBFORMATNAME
:
581 if (!AnsiMsg
->lParam
) break;
582 Buffer
= RtlAllocateHeap(GetProcessHeap(), 0, AnsiMsg
->wParam
* sizeof(WCHAR
));
583 if (!Buffer
) return FALSE
;
584 UnicodeMsg
->lParam
= (LPARAM
)Buffer
;
591 if (!AnsiMsg
->lParam
|| !listbox_has_strings( AnsiMsg
->hwnd
)) break;
592 Size
= SendMessageW( AnsiMsg
->hwnd
, LB_GETTEXTLEN
, AnsiMsg
->wParam
, 0 );
595 ERR("LB_GETTEXT LB_ERR\n");
596 Size
= sizeof(ULONG_PTR
);
598 Size
= (Size
+ 1) * sizeof(WCHAR
);
599 UnicodeMsg
->lParam
= (LPARAM
) RtlAllocateHeap(GetProcessHeap(), 0, Size
);
600 if (!UnicodeMsg
->lParam
) return FALSE
;
607 if (!AnsiMsg
->lParam
|| !combobox_has_strings( AnsiMsg
->hwnd
)) break;
608 Size
= SendMessageW( AnsiMsg
->hwnd
, CB_GETLBTEXTLEN
, AnsiMsg
->wParam
, 0 );
611 ERR("CB_GETTEXT LB_ERR\n");
612 Size
= sizeof(ULONG_PTR
);
614 Size
= (Size
+ 1) * sizeof(WCHAR
);
615 UnicodeMsg
->lParam
= (LPARAM
) RtlAllocateHeap(GetProcessHeap(), 0, Size
);
616 if (!UnicodeMsg
->lParam
) return FALSE
;
620 /* AnsiMsg->lParam is string (0-terminated) */
622 case WM_WININICHANGE
:
623 case WM_DEVMODECHANGE
:
629 if (!AnsiMsg
->lParam
) break;
630 RtlCreateUnicodeStringFromAsciiz(&UnicodeString
, (LPSTR
)AnsiMsg
->lParam
);
631 UnicodeMsg
->lParam
= (LPARAM
)UnicodeString
.Buffer
;
636 case LB_ADDSTRING_LOWER
:
637 case LB_ADDSTRING_UPPER
:
638 case LB_INSERTSTRING
:
639 case LB_INSERTSTRING_UPPER
:
640 case LB_INSERTSTRING_LOWER
:
642 case LB_FINDSTRINGEXACT
:
643 case LB_SELECTSTRING
:
645 if (AnsiMsg
->lParam
&& listbox_has_strings(AnsiMsg
->hwnd
))
647 RtlCreateUnicodeStringFromAsciiz(&UnicodeString
, (LPSTR
)AnsiMsg
->lParam
);
648 UnicodeMsg
->lParam
= (LPARAM
)UnicodeString
.Buffer
;
654 case CB_INSERTSTRING
:
656 case CB_FINDSTRINGEXACT
:
657 case CB_SELECTSTRING
:
659 if (AnsiMsg
->lParam
&& combobox_has_strings(AnsiMsg
->hwnd
))
661 RtlCreateUnicodeStringFromAsciiz(&UnicodeString
, (LPSTR
)AnsiMsg
->lParam
);
662 UnicodeMsg
->lParam
= (LPARAM
)UnicodeString
.Buffer
;
670 MDICREATESTRUCTW mdi_cs
;
673 CREATESTRUCTW cs
; /* new structure */
674 LPCWSTR lpszName
; /* allocated Name */
675 LPCWSTR lpszClass
; /* allocated Class */
678 struct s
*xs
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(struct s
));
683 xs
->cs
= *(CREATESTRUCTW
*)AnsiMsg
->lParam
;
684 if (!IS_INTRESOURCE(xs
->cs
.lpszName
))
686 RtlCreateUnicodeStringFromAsciiz(&UnicodeString
, (LPSTR
)xs
->cs
.lpszName
);
687 xs
->lpszName
= xs
->cs
.lpszName
= UnicodeString
.Buffer
;
689 if (!IS_ATOM(xs
->cs
.lpszClass
))
691 RtlCreateUnicodeStringFromAsciiz(&UnicodeString
, (LPSTR
)xs
->cs
.lpszClass
);
692 xs
->lpszClass
= xs
->cs
.lpszClass
= UnicodeString
.Buffer
;
695 if (GetWindowLongW(hwnd
, GWL_EXSTYLE
) & WS_EX_MDICHILD
)
697 mdi_cs
= *(MDICREATESTRUCTW
*)xs
->cs
.lpCreateParams
;
698 mdi_cs
.szTitle
= xs
->cs
.lpszName
;
699 mdi_cs
.szClass
= xs
->cs
.lpszClass
;
700 xs
->cs
.lpCreateParams
= &mdi_cs
;
703 UnicodeMsg
->lParam
= (LPARAM
)xs
;
709 MDICREATESTRUCTW
*cs
=
710 (MDICREATESTRUCTW
*)HeapAlloc(GetProcessHeap(), 0, sizeof(*cs
));
717 *cs
= *(MDICREATESTRUCTW
*)AnsiMsg
->lParam
;
719 if (!IS_ATOM(cs
->szClass
))
721 RtlCreateUnicodeStringFromAsciiz(&UnicodeString
, (LPSTR
)cs
->szClass
);
722 cs
->szClass
= UnicodeString
.Buffer
;
725 RtlCreateUnicodeStringFromAsciiz(&UnicodeString
, (LPSTR
)cs
->szTitle
);
726 cs
->szTitle
= UnicodeString
.Buffer
;
728 UnicodeMsg
->lParam
= (LPARAM
)cs
;
733 if (UnicodeMsg
->lParam
)
735 MSG newmsg
= *(MSG
*)UnicodeMsg
->lParam
;
736 newmsg
.wParam
= map_wparam_AtoW( newmsg
.message
, newmsg
.wParam
);
746 case EM_SETPASSWORDCHAR
:
748 UnicodeMsg
->wParam
= map_wparam_AtoW( AnsiMsg
->message
, AnsiMsg
->wParam
);
756 MsgiAnsiToUnicodeCleanup(LPMSG UnicodeMsg
, LPMSG AnsiMsg
)
758 UNICODE_STRING UnicodeString
;
760 switch (AnsiMsg
->message
)
763 if (!listbox_has_strings( UnicodeMsg
->hwnd
)) break;
765 if (UnicodeMsg
->message
== CB_GETLBTEXT
&& !combobox_has_strings( UnicodeMsg
->hwnd
)) break;
767 case WM_ASKCBFORMATNAME
:
769 if (!UnicodeMsg
->lParam
) break;
770 RtlFreeHeap(GetProcessHeap(), 0, (PVOID
) UnicodeMsg
->lParam
);
775 case WM_WININICHANGE
:
776 case WM_DEVMODECHANGE
:
782 if (!UnicodeMsg
->lParam
) break;
783 RtlInitUnicodeString(&UnicodeString
, (PCWSTR
)UnicodeMsg
->lParam
);
784 RtlFreeUnicodeString(&UnicodeString
);
789 case LB_ADDSTRING_LOWER
:
790 case LB_ADDSTRING_UPPER
:
791 case LB_INSERTSTRING
:
792 case LB_INSERTSTRING_UPPER
:
793 case LB_INSERTSTRING_LOWER
:
795 case LB_FINDSTRINGEXACT
:
796 case LB_SELECTSTRING
:
798 if (UnicodeMsg
->lParam
&& listbox_has_strings(AnsiMsg
->hwnd
))
800 RtlInitUnicodeString(&UnicodeString
, (PCWSTR
)UnicodeMsg
->lParam
);
801 RtlFreeUnicodeString(&UnicodeString
);
807 case CB_INSERTSTRING
:
809 case CB_FINDSTRINGEXACT
:
810 case CB_SELECTSTRING
:
812 if (UnicodeMsg
->lParam
&& combobox_has_strings(AnsiMsg
->hwnd
))
814 RtlInitUnicodeString(&UnicodeString
, (PCWSTR
)UnicodeMsg
->lParam
);
815 RtlFreeUnicodeString(&UnicodeString
);
825 CREATESTRUCTW cs
; /* new structure */
826 LPWSTR lpszName
; /* allocated Name */
827 LPWSTR lpszClass
; /* allocated Class */
830 struct s
*xs
= (struct s
*)UnicodeMsg
->lParam
;
833 RtlInitUnicodeString(&UnicodeString
, (PCWSTR
)xs
->lpszName
);
834 RtlFreeUnicodeString(&UnicodeString
);
838 RtlInitUnicodeString(&UnicodeString
, (PCWSTR
)xs
->lpszClass
);
839 RtlFreeUnicodeString(&UnicodeString
);
841 HeapFree(GetProcessHeap(), 0, xs
);
847 MDICREATESTRUCTW
*cs
= (MDICREATESTRUCTW
*)UnicodeMsg
->lParam
;
848 RtlInitUnicodeString(&UnicodeString
, (PCWSTR
)cs
->szTitle
);
849 RtlFreeUnicodeString(&UnicodeString
);
850 if (!IS_ATOM(cs
->szClass
))
852 RtlInitUnicodeString(&UnicodeString
, (PCWSTR
)cs
->szClass
);
853 RtlFreeUnicodeString(&UnicodeString
);
855 HeapFree(GetProcessHeap(), 0, cs
);
864 * Unicode Result to Ansi Result
867 MsgiAnsiToUnicodeReply(LPMSG UnicodeMsg
, LPMSG AnsiMsg
, LRESULT
*Result
)
869 LPWSTR Buffer
= (LPWSTR
)UnicodeMsg
->lParam
;
870 LPSTR AnsiBuffer
= (LPSTR
)AnsiMsg
->lParam
;
872 switch (AnsiMsg
->message
)
875 case WM_ASKCBFORMATNAME
:
877 if (UnicodeMsg
->wParam
)
880 if (*Result
) RtlUnicodeToMultiByteN( AnsiBuffer
, UnicodeMsg
->wParam
- 1, &len
, Buffer
, strlenW(Buffer
) * sizeof(WCHAR
) );
888 if (!AnsiBuffer
|| !listbox_has_strings( UnicodeMsg
->hwnd
)) break;
892 RtlUnicodeToMultiByteN( AnsiBuffer
, ~0u, &len
, Buffer
, (strlenW(Buffer
) + 1) * sizeof(WCHAR
) );
899 if (!AnsiBuffer
|| !combobox_has_strings( UnicodeMsg
->hwnd
)) break;
903 RtlUnicodeToMultiByteN( AnsiBuffer
, ~0u, &len
, Buffer
, (strlenW(Buffer
) + 1) * sizeof(WCHAR
) );
910 MsgiAnsiToUnicodeCleanup(UnicodeMsg
, AnsiMsg
);
916 MsgiUnicodeToAnsiMessage(HWND hwnd
, LPMSG AnsiMsg
, LPMSG UnicodeMsg
)
918 ANSI_STRING AnsiString
;
919 UNICODE_STRING UnicodeString
;
921 *AnsiMsg
= *UnicodeMsg
;
923 switch(UnicodeMsg
->message
)
928 MDICREATESTRUCTA
*pmdi_cs
;
933 CsW
= (CREATESTRUCTW
*)(UnicodeMsg
->lParam
);
934 CsA
= RtlAllocateHeap(GetProcessHeap(), 0, sizeof(CREATESTRUCTA
) + sizeof(MDICREATESTRUCTA
));
939 memcpy(CsA
, CsW
, sizeof(CREATESTRUCTW
));
941 /* pmdi_cs starts right after CsA */
942 pmdi_cs
= (MDICREATESTRUCTA
*)(CsA
+ 1);
944 RtlInitUnicodeString(&UnicodeString
, CsW
->lpszName
);
945 Status
= RtlUnicodeStringToAnsiString(&AnsiString
, &UnicodeString
, TRUE
);
946 if (! NT_SUCCESS(Status
))
948 RtlFreeHeap(GetProcessHeap(), 0, CsA
);
951 CsA
->lpszName
= AnsiString
.Buffer
;
952 if (HIWORD((ULONG_PTR
)CsW
->lpszClass
) != 0)
954 RtlInitUnicodeString(&UnicodeString
, CsW
->lpszClass
);
955 Status
= RtlUnicodeStringToAnsiString(&AnsiString
, &UnicodeString
, TRUE
);
956 if (! NT_SUCCESS(Status
))
958 RtlInitAnsiString(&AnsiString
, CsA
->lpszName
);
959 RtlFreeAnsiString(&AnsiString
);
960 RtlFreeHeap(GetProcessHeap(), 0, CsA
);
963 CsA
->lpszClass
= AnsiString
.Buffer
;
966 if (GetWindowLongW(hwnd
, GWL_EXSTYLE
) & WS_EX_MDICHILD
)
968 *pmdi_cs
= *(MDICREATESTRUCTA
*)CsW
->lpCreateParams
;
969 pmdi_cs
->szTitle
= CsA
->lpszName
;
970 pmdi_cs
->szClass
= CsA
->lpszClass
;
971 CsA
->lpCreateParams
= pmdi_cs
;
974 AnsiMsg
->lParam
= (LPARAM
)CsA
;
978 case WM_ASKCBFORMATNAME
:
980 if (!UnicodeMsg
->lParam
) break;
981 /* Ansi string might contain MBCS chars so we need 2 * the number of chars */
982 AnsiMsg
->wParam
= UnicodeMsg
->wParam
* 2;
983 AnsiMsg
->lParam
= (LPARAM
) RtlAllocateHeap(GetProcessHeap(), 0, AnsiMsg
->wParam
);
984 if (!AnsiMsg
->lParam
) return FALSE
;
991 if (!UnicodeMsg
->lParam
|| !listbox_has_strings( UnicodeMsg
->hwnd
)) break;
992 Size
= SendMessageA( UnicodeMsg
->hwnd
, LB_GETTEXTLEN
, UnicodeMsg
->wParam
, 0 );
995 ERR("LB_GETTEXT LB_ERR\n");
996 Size
= sizeof(ULONG_PTR
);
998 Size
= (Size
+ 1) * sizeof(WCHAR
);
999 AnsiMsg
->lParam
= (LPARAM
) RtlAllocateHeap(GetProcessHeap(), 0, Size
);
1000 if (!AnsiMsg
->lParam
) return FALSE
;
1007 if (!UnicodeMsg
->lParam
|| !combobox_has_strings( UnicodeMsg
->hwnd
)) break;
1008 Size
= SendMessageA( UnicodeMsg
->hwnd
, CB_GETLBTEXTLEN
, UnicodeMsg
->wParam
, 0 );
1011 ERR("CB_GETTEXT LB_ERR\n");
1012 Size
= sizeof(ULONG_PTR
);
1014 Size
= (Size
+ 1) * sizeof(WCHAR
);
1015 AnsiMsg
->lParam
= (LPARAM
) RtlAllocateHeap(GetProcessHeap(), 0, Size
);
1016 if (!AnsiMsg
->lParam
) return FALSE
;
1021 case WM_WININICHANGE
:
1022 case WM_DEVMODECHANGE
:
1028 if (!UnicodeMsg
->lParam
) break;
1029 RtlInitUnicodeString(&UnicodeString
, (PWSTR
) UnicodeMsg
->lParam
);
1030 if (! NT_SUCCESS(RtlUnicodeStringToAnsiString(&AnsiString
,
1036 AnsiMsg
->lParam
= (LPARAM
) AnsiString
.Buffer
;
1041 case LB_ADDSTRING_LOWER
:
1042 case LB_ADDSTRING_UPPER
:
1043 case LB_INSERTSTRING
:
1044 case LB_INSERTSTRING_UPPER
:
1045 case LB_INSERTSTRING_LOWER
:
1047 case LB_FINDSTRINGEXACT
:
1048 case LB_SELECTSTRING
:
1050 if (UnicodeMsg
->lParam
&& listbox_has_strings(AnsiMsg
->hwnd
))
1052 RtlInitUnicodeString(&UnicodeString
, (PWSTR
) UnicodeMsg
->lParam
);
1053 if (! NT_SUCCESS(RtlUnicodeStringToAnsiString(&AnsiString
,
1059 AnsiMsg
->lParam
= (LPARAM
) AnsiString
.Buffer
;
1065 case CB_INSERTSTRING
:
1067 case CB_FINDSTRINGEXACT
:
1068 case CB_SELECTSTRING
:
1070 if (UnicodeMsg
->lParam
&& combobox_has_strings(AnsiMsg
->hwnd
))
1072 RtlInitUnicodeString(&UnicodeString
, (PWSTR
) UnicodeMsg
->lParam
);
1073 if (! NT_SUCCESS(RtlUnicodeStringToAnsiString(&AnsiString
,
1079 AnsiMsg
->lParam
= (LPARAM
) AnsiString
.Buffer
;
1086 MDICREATESTRUCTA
*cs
=
1087 (MDICREATESTRUCTA
*)HeapAlloc(GetProcessHeap(), 0, sizeof(*cs
));
1094 *cs
= *(MDICREATESTRUCTA
*)UnicodeMsg
->lParam
;
1096 if (!IS_ATOM(cs
->szClass
))
1098 RtlInitUnicodeString(&UnicodeString
, (LPCWSTR
)cs
->szClass
);
1099 if (! NT_SUCCESS(RtlUnicodeStringToAnsiString(&AnsiString
,
1103 HeapFree(GetProcessHeap(), 0, cs
);
1106 cs
->szClass
= AnsiString
.Buffer
;
1109 RtlInitUnicodeString(&UnicodeString
, (LPCWSTR
)cs
->szTitle
);
1110 if (! NT_SUCCESS(RtlUnicodeStringToAnsiString(&AnsiString
,
1114 if (!IS_ATOM(cs
->szClass
))
1116 RtlInitAnsiString(&AnsiString
, cs
->szClass
);
1117 RtlFreeAnsiString(&AnsiString
);
1120 HeapFree(GetProcessHeap(), 0, cs
);
1123 cs
->szTitle
= AnsiString
.Buffer
;
1125 AnsiMsg
->lParam
= (LPARAM
)cs
;
1130 if (UnicodeMsg
->lParam
)
1132 MSG newmsg
= *(MSG
*)UnicodeMsg
->lParam
;
1133 switch(newmsg
.message
)
1138 case WM_SYSDEADCHAR
:
1139 newmsg
.wParam
= map_wparam_char_WtoA( newmsg
.wParam
, 1 );
1142 newmsg
.wParam
= map_wparam_char_WtoA( newmsg
.wParam
, 2 );
1150 WCHAR wch
= UnicodeMsg
->wParam
;
1152 DWORD cp
= get_input_codepage();
1153 DWORD len
= WideCharToMultiByte( cp
, 0, &wch
, 1, ch
, 2, NULL
, NULL
);
1154 AnsiMsg
->wParam
= (BYTE
)ch
[0];
1155 if (len
== 2) AnsiMsg
->wParam
= (BYTE
)ch
[1];
1163 case WM_SYSDEADCHAR
:
1164 case EM_SETPASSWORDCHAR
:
1165 AnsiMsg
->wParam
= map_wparam_char_WtoA(UnicodeMsg
->wParam
,1);
1169 AnsiMsg
->wParam
= map_wparam_char_WtoA(UnicodeMsg
->wParam
,2);
1175 static BOOL FASTCALL
1176 MsgiUnicodeToAnsiCleanup(LPMSG AnsiMsg
, LPMSG UnicodeMsg
)
1178 ANSI_STRING AnsiString
;
1180 switch(UnicodeMsg
->message
)
1183 if (!listbox_has_strings( AnsiMsg
->hwnd
)) break;
1185 if (AnsiMsg
->message
== CB_GETLBTEXT
&& !combobox_has_strings( AnsiMsg
->hwnd
)) break;
1187 case WM_ASKCBFORMATNAME
:
1189 if (!AnsiMsg
->lParam
) break;
1190 RtlFreeHeap(GetProcessHeap(), 0, (PVOID
) AnsiMsg
->lParam
);
1198 Cs
= (CREATESTRUCTA
*) AnsiMsg
->lParam
;
1199 RtlInitAnsiString(&AnsiString
, Cs
->lpszName
);
1200 RtlFreeAnsiString(&AnsiString
);
1201 if (HIWORD((ULONG_PTR
)Cs
->lpszClass
) != 0)
1203 RtlInitAnsiString(&AnsiString
, Cs
->lpszClass
);
1204 RtlFreeAnsiString(&AnsiString
);
1206 RtlFreeHeap(GetProcessHeap(), 0, Cs
);
1211 case WM_WININICHANGE
:
1212 case WM_DEVMODECHANGE
:
1218 if (!AnsiMsg
->lParam
) break;
1219 RtlInitAnsiString(&AnsiString
, (PSTR
) AnsiMsg
->lParam
);
1220 RtlFreeAnsiString(&AnsiString
);
1225 case LB_ADDSTRING_LOWER
:
1226 case LB_ADDSTRING_UPPER
:
1227 case LB_INSERTSTRING
:
1228 case LB_INSERTSTRING_UPPER
:
1229 case LB_INSERTSTRING_LOWER
:
1231 case LB_FINDSTRINGEXACT
:
1232 case LB_SELECTSTRING
:
1234 if (AnsiMsg
->lParam
&& listbox_has_strings(AnsiMsg
->hwnd
))
1236 RtlInitAnsiString(&AnsiString
, (PSTR
) AnsiMsg
->lParam
);
1237 RtlFreeAnsiString(&AnsiString
);
1243 case CB_INSERTSTRING
:
1245 case CB_FINDSTRINGEXACT
:
1246 case CB_SELECTSTRING
:
1248 if (AnsiMsg
->lParam
&& combobox_has_strings(AnsiMsg
->hwnd
))
1250 RtlInitAnsiString(&AnsiString
, (PSTR
) AnsiMsg
->lParam
);
1251 RtlFreeAnsiString(&AnsiString
);
1258 MDICREATESTRUCTA
*cs
= (MDICREATESTRUCTA
*)AnsiMsg
->lParam
;
1259 RtlInitAnsiString(&AnsiString
, (PCSTR
)cs
->szTitle
);
1260 RtlFreeAnsiString(&AnsiString
);
1261 if (!IS_ATOM(cs
->szClass
))
1263 RtlInitAnsiString(&AnsiString
, (PCSTR
)cs
->szClass
);
1264 RtlFreeAnsiString(&AnsiString
);
1266 HeapFree(GetProcessHeap(), 0, cs
);
1276 * Ansi Result to Unicode Result
1278 static BOOL FASTCALL
1279 MsgiUnicodeToAnsiReply(LPMSG AnsiMsg
, LPMSG UnicodeMsg
, LRESULT
*Result
)
1281 LPSTR Buffer
= (LPSTR
) AnsiMsg
->lParam
;
1282 LPWSTR UBuffer
= (LPWSTR
) UnicodeMsg
->lParam
;
1284 switch (UnicodeMsg
->message
)
1287 case WM_ASKCBFORMATNAME
:
1289 DWORD len
= AnsiMsg
->wParam
* 2;
1294 RtlMultiByteToUnicodeN( UBuffer
, AnsiMsg
->wParam
*sizeof(WCHAR
), &len
, Buffer
, strlen(Buffer
)+1 );
1295 *Result
= len
/sizeof(WCHAR
) - 1; /* do not count terminating null */
1297 UBuffer
[*Result
] = 0;
1303 if (!UBuffer
|| !listbox_has_strings( UnicodeMsg
->hwnd
)) break;
1307 RtlMultiByteToUnicodeN( UBuffer
, ~0u, &len
, Buffer
, strlen(Buffer
) + 1 );
1308 *Result
= len
/ sizeof(WCHAR
) - 1;
1314 if (!UBuffer
|| !combobox_has_strings( UnicodeMsg
->hwnd
)) break;
1318 RtlMultiByteToUnicodeN( UBuffer
, ~0u, &len
, Buffer
, strlen(Buffer
) + 1 );
1319 *Result
= len
/ sizeof(WCHAR
) - 1;
1325 MsgiUnicodeToAnsiCleanup(AnsiMsg
, UnicodeMsg
);
1333 DesktopWndProcA( HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1338 TRACE("Desktop A Class Atom! hWnd 0x%x, Msg %d\n", hwnd
, message
);
1340 AnsiMsg
.hwnd
= hwnd
;
1341 AnsiMsg
.message
= message
;
1342 AnsiMsg
.wParam
= wParam
;
1343 AnsiMsg
.lParam
= lParam
;
1345 // Desktop is always Unicode so convert Ansi here.
1346 if (!MsgiAnsiToUnicodeMessage(hwnd
, &UcMsg
, &AnsiMsg
))
1351 Result
= DesktopWndProcW(hwnd
, message
, UcMsg
.wParam
, UcMsg
.lParam
);
1353 MsgiAnsiToUnicodeCleanup(&UcMsg
, &AnsiMsg
);
1363 GetMessageExtraInfo(VOID
)
1365 return NtUserxGetMessageExtraInfo();
1376 return NtUserxGetMessagePos();
1384 GetMessageTime(VOID
)
1386 return NtUserGetThreadState(THREADSTATE_GETMESSAGETIME
);
1397 PCLIENTTHREADINFO pcti
= GetWin32ClientInfo()->pClientThreadInfo
;
1400 if (pcti
->CTI_flags
& CTI_INSENDMESSAGE
)
1405 return(NtUserGetThreadState(THREADSTATE_INSENDMESSAGE
) != ISMEX_NOSEND
);
1417 PCLIENTTHREADINFO pcti
= GetWin32ClientInfo()->pClientThreadInfo
;
1418 if (pcti
&& !(pcti
->CTI_flags
& CTI_INSENDMESSAGE
))
1419 return ISMEX_NOSEND
;
1421 return NtUserGetThreadState(THREADSTATE_INSENDMESSAGE
);
1430 ReplyMessage(LRESULT lResult
)
1432 return NtUserxReplyMessage(lResult
);
1441 SetMessageExtraInfo(
1444 return NtUserxSetMessageExtraInfo(lParam
);
1448 IntCallWindowProcW(BOOL IsAnsiProc
,
1458 BOOL Hook
= FALSE
, MsgOverride
= FALSE
, Dialog
;
1459 LRESULT Result
= 0, PreResult
= 0;
1462 if (WndProc
== NULL
)
1464 WARN("IntCallWindowsProcW() called with WndProc = NULL!\n");
1469 Dialog
= (pWnd
->fnid
== FNID_DIALOG
);
1473 Hook
= BeginIfHookedUserApiHook();
1477 MsgOverride
= IsMsgOverride( Msg
, &guah
.WndProcArray
);
1479 MsgOverride
= IsMsgOverride( Msg
, &guah
.DlgProcArray
);
1484 UnicodeMsg
.hwnd
= hWnd
;
1485 UnicodeMsg
.message
= Msg
;
1486 UnicodeMsg
.wParam
= wParam
;
1487 UnicodeMsg
.lParam
= lParam
;
1488 if (! MsgiUnicodeToAnsiMessage(hWnd
, &AnsiMsg
, &UnicodeMsg
))
1493 if (Hook
&& MsgOverride
)
1498 PreResult
= guah
.PreWndProc(AnsiMsg
.hwnd
, AnsiMsg
.message
, AnsiMsg
.wParam
, AnsiMsg
.lParam
, (ULONG_PTR
)&Result
, &Data
);
1500 PreResult
= guah
.PreDefDlgProc(AnsiMsg
.hwnd
, AnsiMsg
.message
, AnsiMsg
.wParam
, AnsiMsg
.lParam
, (ULONG_PTR
)&Result
, &Data
);
1502 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1508 if (PreResult
) goto Exit
;
1510 _SEH2_TRY
// wine does this.
1512 Result
= WndProc(AnsiMsg
.hwnd
, AnsiMsg
.message
, AnsiMsg
.wParam
, AnsiMsg
.lParam
);
1514 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1516 ERR("Exception when calling Ansi WndProc %p Msg %d pti %p Wndpti %p\n",WndProc
,Msg
,GetW32ThreadInfo(),pWnd
->head
.pti
);
1520 if (Hook
&& MsgOverride
)
1525 guah
.PostWndProc(AnsiMsg
.hwnd
, AnsiMsg
.message
, AnsiMsg
.wParam
, AnsiMsg
.lParam
, (ULONG_PTR
)&Result
, &Data
);
1527 guah
.PostDefDlgProc(AnsiMsg
.hwnd
, AnsiMsg
.message
, AnsiMsg
.wParam
, AnsiMsg
.lParam
, (ULONG_PTR
)&Result
, &Data
);
1529 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1535 if (! MsgiUnicodeToAnsiReply(&AnsiMsg
, &UnicodeMsg
, &Result
))
1542 if (Hook
&& MsgOverride
)
1547 PreResult
= guah
.PreWndProc(hWnd
, Msg
, wParam
, lParam
, (ULONG_PTR
)&Result
, &Data
);
1549 PreResult
= guah
.PreDefDlgProc(hWnd
, Msg
, wParam
, lParam
, (ULONG_PTR
)&Result
, &Data
);
1551 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1557 if (PreResult
) goto Exit
;
1561 Result
= WndProc(hWnd
, Msg
, wParam
, lParam
);
1563 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1565 ERR("Exception when calling unicode WndProc %p Msg %d pti %p Wndpti %p\n",WndProc
, Msg
,GetW32ThreadInfo(),pWnd
->head
.pti
);
1569 if (Hook
&& MsgOverride
)
1574 guah
.PostWndProc(hWnd
, Msg
, wParam
, lParam
, (ULONG_PTR
)&Result
, &Data
);
1576 guah
.PostDefDlgProc(hWnd
, Msg
, wParam
, lParam
, (ULONG_PTR
)&Result
, &Data
);
1578 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1586 if (Hook
) EndUserApiHook();
1590 static LRESULT FASTCALL
1591 IntCallWindowProcA(BOOL IsAnsiProc
,
1601 //ULONG_PTR LowLimit;
1602 BOOL Hook
= FALSE
, MsgOverride
= FALSE
, Dialog
;
1603 LRESULT Result
= 0, PreResult
= 0;
1606 if (WndProc
== NULL
)
1608 WARN("IntCallWindowsProcA() called with WndProc = NULL!\n");
1612 LowLimit
= (ULONG_PTR
)NtCurrentTeb()->NtTib
.StackLimit
;
1613 if (((ULONG_PTR
)&lParam
- LowLimit
) < PAGE_SIZE
)
1615 ERR("IntCallWindowsProcA() Exceeded Stack!\n");
1620 Dialog
= (pWnd
->fnid
== FNID_DIALOG
);
1624 Hook
= BeginIfHookedUserApiHook();
1628 MsgOverride
= IsMsgOverride( Msg
, &guah
.WndProcArray
);
1630 MsgOverride
= IsMsgOverride( Msg
, &guah
.DlgProcArray
);
1635 if (Hook
&& MsgOverride
)
1640 PreResult
= guah
.PreWndProc(hWnd
, Msg
, wParam
, lParam
, (ULONG_PTR
)&Result
, &Data
);
1642 PreResult
= guah
.PreDefDlgProc(hWnd
, Msg
, wParam
, lParam
, (ULONG_PTR
)&Result
, &Data
);
1644 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1650 if (PreResult
) goto Exit
;
1654 Result
= WndProc(hWnd
, Msg
, wParam
, lParam
);
1656 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1658 ERR("Exception when calling Ansi WndProc %p Msg %d pti %p Wndpti %p\n",WndProc
,Msg
,GetW32ThreadInfo(),pWnd
->head
.pti
);
1662 if (Hook
&& MsgOverride
)
1667 guah
.PostWndProc(hWnd
, Msg
, wParam
, lParam
, (ULONG_PTR
)&Result
, &Data
);
1669 guah
.PostDefDlgProc(hWnd
, Msg
, wParam
, lParam
, (ULONG_PTR
)&Result
, &Data
);
1671 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1679 AnsiMsg
.hwnd
= hWnd
;
1680 AnsiMsg
.message
= Msg
;
1681 AnsiMsg
.wParam
= wParam
;
1682 AnsiMsg
.lParam
= lParam
;
1683 if (! MsgiAnsiToUnicodeMessage(hWnd
, &UnicodeMsg
, &AnsiMsg
))
1688 if (Hook
&& MsgOverride
)
1693 PreResult
= guah
.PreWndProc(UnicodeMsg
.hwnd
, UnicodeMsg
.message
, UnicodeMsg
.wParam
, UnicodeMsg
.lParam
, (ULONG_PTR
)&Result
, &Data
);
1695 PreResult
= guah
.PreDefDlgProc(UnicodeMsg
.hwnd
, UnicodeMsg
.message
, UnicodeMsg
.wParam
, UnicodeMsg
.lParam
, (ULONG_PTR
)&Result
, &Data
);
1697 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1703 if (PreResult
) goto Exit
;
1707 Result
= WndProc(UnicodeMsg
.hwnd
, UnicodeMsg
.message
,
1708 UnicodeMsg
.wParam
, UnicodeMsg
.lParam
);
1710 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1712 ERR("Exception when calling unicode WndProc %p Msg %d pti %p Wndpti %p\n",WndProc
, Msg
,GetW32ThreadInfo(),pWnd
->head
.pti
);
1716 if (Hook
&& MsgOverride
)
1721 guah
.PostWndProc(UnicodeMsg
.hwnd
, UnicodeMsg
.message
, UnicodeMsg
.wParam
, UnicodeMsg
.lParam
, (ULONG_PTR
)&Result
, &Data
);
1723 guah
.PostDefDlgProc(UnicodeMsg
.hwnd
, UnicodeMsg
.message
, UnicodeMsg
.wParam
, UnicodeMsg
.lParam
, (ULONG_PTR
)&Result
, &Data
);
1725 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1731 if (! MsgiAnsiToUnicodeReply(&UnicodeMsg
, &AnsiMsg
, &Result
))
1738 if (Hook
) EndUserApiHook();
1743 static LRESULT WINAPI
1744 IntCallMessageProc(IN PWND Wnd
, IN HWND hWnd
, IN UINT Msg
, IN WPARAM wParam
, IN LPARAM lParam
, IN BOOL Ansi
)
1750 Class
= DesktopPtrToUser(Wnd
->pcls
);
1753 if ( Wnd
->head
.pti
!= GetW32ThreadInfo())
1754 { // Must be inside the same thread!
1755 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
1759 This is the message exchange for user32. If there's a need to monitor messages,
1762 TRACE("HWND %p, MSG %u, WPARAM %p, LPARAM %p, Ansi %d\n", hWnd
, Msg
, wParam
, lParam
, Ansi
);
1763 // if (Class->fnid <= FNID_GHOST && Class->fnid >= FNID_BUTTON )
1764 if (Class
->fnid
<= FNID_GHOST
&& Class
->fnid
>= FNID_FIRST
)
1768 if (GETPFNCLIENTW(Class
->fnid
) == Wnd
->lpfnWndProc
)
1769 WndProc
= GETPFNCLIENTA(Class
->fnid
);
1773 if (GETPFNCLIENTA(Class
->fnid
) == Wnd
->lpfnWndProc
)
1774 WndProc
= GETPFNCLIENTW(Class
->fnid
);
1781 IsAnsi
= !Wnd
->Unicode
;
1782 WndProc
= Wnd
->lpfnWndProc
;
1787 IsAnsi
= !Wnd
->Unicode
;
1788 WndProc
= Wnd
->lpfnWndProc
;
1791 Message caller can be Ansi/Unicode and the receiver can be Unicode/Ansi or
1795 return IntCallWindowProcW(IsAnsi
, WndProc
, Wnd
, hWnd
, Msg
, wParam
, lParam
);
1797 return IntCallWindowProcA(IsAnsi
, WndProc
, Wnd
, hWnd
, Msg
, wParam
, lParam
);
1805 CallWindowProcA(WNDPROC lpPrevWndFunc
,
1812 PCALLPROCDATA CallProc
;
1814 if (lpPrevWndFunc
== NULL
)
1816 WARN("CallWindowProcA: lpPrevWndFunc == NULL!\n");
1820 pWnd
= ValidateHwnd(hWnd
);
1822 if (!IsCallProcHandle(lpPrevWndFunc
))
1823 return IntCallWindowProcA(TRUE
, lpPrevWndFunc
, pWnd
, hWnd
, Msg
, wParam
, lParam
);
1826 CallProc
= ValidateCallProc((HANDLE
)lpPrevWndFunc
);
1827 if (CallProc
!= NULL
)
1829 return IntCallWindowProcA(!(CallProc
->wType
& UserGetCPDA2U
),
1830 CallProc
->pfnClientPrevious
,
1839 WARN("CallWindowProcA: can not dereference WndProcHandle\n");
1850 CallWindowProcW(WNDPROC lpPrevWndFunc
,
1857 PCALLPROCDATA CallProc
;
1859 /* FIXME - can the first parameter be NULL? */
1860 if (lpPrevWndFunc
== NULL
)
1862 WARN("CallWindowProcA: lpPrevWndFunc == NULL!\n");
1866 pWnd
= ValidateHwnd(hWnd
);
1868 if (!IsCallProcHandle(lpPrevWndFunc
))
1869 return IntCallWindowProcW(FALSE
, lpPrevWndFunc
, pWnd
, hWnd
, Msg
, wParam
, lParam
);
1872 CallProc
= ValidateCallProc((HANDLE
)lpPrevWndFunc
);
1873 if (CallProc
!= NULL
)
1875 return IntCallWindowProcW(!(CallProc
->wType
& UserGetCPDA2U
),
1876 CallProc
->pfnClientPrevious
,
1885 WARN("CallWindowProcW: can not dereference WndProcHandle\n");
1896 DispatchMessageA(CONST MSG
*lpmsg
)
1903 if ( lpmsg
->message
& ~WM_MAXIMUM
)
1905 SetLastError( ERROR_INVALID_PARAMETER
);
1909 if (lpmsg
->hwnd
!= NULL
)
1911 Wnd
= ValidateHwnd(lpmsg
->hwnd
);
1917 if (is_pointer_message(lpmsg
->message
))
1919 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
1923 if ((lpmsg
->message
== WM_TIMER
|| lpmsg
->message
== WM_SYSTIMER
) && lpmsg
->lParam
!= 0)
1925 WNDPROC WndProc
= (WNDPROC
)lpmsg
->lParam
;
1927 if ( lpmsg
->message
== WM_SYSTIMER
)
1928 return NtUserDispatchMessage( (PMSG
)lpmsg
);
1930 if (!NtUserValidateTimerCallback(lpmsg
->hwnd
, lpmsg
->wParam
, lpmsg
->lParam
))
1932 WARN("Validating Timer Callback failed!\n");
1936 _SEH2_TRY
// wine does this. Hint: Prevents call to another thread....
1938 Ret
= WndProc(lpmsg
->hwnd
,
1943 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1949 else if (Wnd
!= NULL
)
1951 if ( (lpmsg
->message
!= WM_PAINT
) && !(Wnd
->state
& WNDS_SERVERSIDEWINDOWPROC
) )
1953 Ret
= IntCallMessageProc(Wnd
,
1962 if (!MsgiAnsiToUnicodeMessage(lpmsg
->hwnd
, &UnicodeMsg
, (LPMSG
)lpmsg
))
1967 Ret
= NtUserDispatchMessage(&UnicodeMsg
);
1969 if (!MsgiAnsiToUnicodeReply(&UnicodeMsg
, (LPMSG
)lpmsg
, &Ret
))
1978 WARN("Exception in Timer Callback WndProcA!\n");
1988 DispatchMessageW(CONST MSG
*lpmsg
)
1994 if ( lpmsg
->message
& ~WM_MAXIMUM
)
1996 SetLastError( ERROR_INVALID_PARAMETER
);
2000 if (lpmsg
->hwnd
!= NULL
)
2002 Wnd
= ValidateHwnd(lpmsg
->hwnd
);
2008 if (is_pointer_message(lpmsg
->message
))
2010 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
2014 if ((lpmsg
->message
== WM_TIMER
|| lpmsg
->message
== WM_SYSTIMER
) && lpmsg
->lParam
!= 0)
2016 WNDPROC WndProc
= (WNDPROC
)lpmsg
->lParam
;
2018 if ( lpmsg
->message
== WM_SYSTIMER
)
2019 return NtUserDispatchMessage( (PMSG
) lpmsg
);
2021 if (!NtUserValidateTimerCallback(lpmsg
->hwnd
, lpmsg
->wParam
, lpmsg
->lParam
))
2023 WARN("Validating Timer Callback failed!\n");
2029 Ret
= WndProc(lpmsg
->hwnd
,
2034 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2040 else if (Wnd
!= NULL
)
2042 if ( (lpmsg
->message
!= WM_PAINT
) && !(Wnd
->state
& WNDS_SERVERSIDEWINDOWPROC
) )
2044 Ret
= IntCallMessageProc(Wnd
,
2052 Ret
= NtUserDispatchMessage( (PMSG
) lpmsg
);
2057 WARN("Exception in Timer Callback WndProcW!\n");
2063 IntConvertMsgToAnsi(LPMSG lpMsg
)
2068 switch (lpMsg
->message
)
2073 case WM_SYSDEADCHAR
:
2075 wch
[0] = LOWORD(lpMsg
->wParam
);
2076 wch
[1] = HIWORD(lpMsg
->wParam
);
2078 WideCharToMultiByte(CP_THREAD_ACP
, 0, wch
, 2, ch
, 2, NULL
, NULL
);
2079 lpMsg
->wParam
= MAKEWPARAM(ch
[0] | (ch
[1] << 8), 0);
2088 GetMessageA(LPMSG lpMsg
,
2095 if ( (wMsgFilterMin
|wMsgFilterMax
) & ~WM_MAXIMUM
)
2097 SetLastError( ERROR_INVALID_PARAMETER
);
2101 Res
= NtUserGetMessage(lpMsg
, hWnd
, wMsgFilterMin
, wMsgFilterMax
);
2102 if (-1 == (int) Res
)
2107 IntConvertMsgToAnsi(lpMsg
);
2116 GetMessageW(LPMSG lpMsg
,
2123 if ( (wMsgFilterMin
|wMsgFilterMax
) & ~WM_MAXIMUM
)
2125 SetLastError( ERROR_INVALID_PARAMETER
);
2129 Res
= NtUserGetMessage(lpMsg
, hWnd
, wMsgFilterMin
, wMsgFilterMax
);
2130 if (-1 == (int) Res
)
2139 PeekMessageWorker( PMSG pMsg
,
2146 PCLIENTTHREADINFO pcti
;
2147 pci
= GetWin32ClientInfo();
2148 pcti
= pci
->pClientThreadInfo
;
2150 if (!hWnd
&& pci
&& pcti
)
2154 if ((pci
->cSpins
>= 100) && (pci
->dwTIFlags
& TIF_SPINNING
))
2155 { // Yield after 100 spin cycles and ready to swap vinyl.
2156 if (!(pci
->dwTIFlags
& TIF_WAITFORINPUTIDLE
))
2157 { // Not waiting for idle event.
2158 if (!pcti
->fsChangeBits
&& !pcti
->fsWakeBits
)
2159 { // No messages are available.
2160 if ((GetTickCount() - pcti
->tickLastMsgChecked
) > 1000)
2161 { // Up the msg read count if over 1 sec.
2162 NtUserGetThreadState(THREADSTATE_UPTIMELASTREAD
);
2166 FIXME("seeSpins!\n");
2172 return NtUserPeekMessage(pMsg
, hWnd
, wMsgFilterMin
, wMsgFilterMax
, wRemoveMsg
);
2179 PeekMessageA(LPMSG lpMsg
,
2187 Res
= PeekMessageWorker(lpMsg
, hWnd
, wMsgFilterMin
, wMsgFilterMax
, wRemoveMsg
);
2188 if (-1 == (int) Res
|| !Res
)
2193 IntConvertMsgToAnsi(lpMsg
);
2213 Res
= PeekMessageWorker(lpMsg
, hWnd
, wMsgFilterMin
, wMsgFilterMax
, wRemoveMsg
);
2214 if (-1 == (int) Res
|| !Res
)
2235 /* Check for combo box or a list box to send names. */
2236 if (Msg
== CB_DIR
|| Msg
== LB_DIR
)
2239 Set DDL_POSTMSGS, so use the PostMessage function to send messages to the
2240 combo/list box. Forces a call like DlgDirListComboBox.
2242 //wParam |= DDL_POSTMSGS;
2243 return NtUserPostMessage(hWnd
, Msg
, wParam
, lParam
);
2246 /* No drop files or current Process, just post message. */
2247 if ( (Msg
!= WM_DROPFILES
) ||
2248 ( NtUserQueryWindow( hWnd
, QUERY_WINDOW_UNIQUE_PROCESS_ID
) ==
2249 PtrToUint(NtCurrentTeb()->ClientId
.UniqueProcess
) ) )
2251 return NtUserPostMessage(hWnd
, Msg
, wParam
, lParam
);
2254 /* We have drop files and this is not the same process for this window. */
2256 /* Just incase, check wParam for Global memory handle and send size. */
2257 Ret
= SendMessageA( hWnd
,
2259 (WPARAM
)GlobalSize((HGLOBAL
)wParam
), // Zero if not a handle.
2260 (LPARAM
)wParam
); // Send wParam as lParam.
2262 if ( Ret
) return NtUserPostMessage(hWnd
, Msg
, (WPARAM
)Ret
, lParam
);
2280 /* Check for combo box or a list box to send names. */
2281 if (Msg
== CB_DIR
|| Msg
== LB_DIR
)
2284 Set DDL_POSTMSGS, so use the PostMessage function to send messages to the
2285 combo/list box. Forces a call like DlgDirListComboBox.
2287 //wParam |= DDL_POSTMSGS;
2288 return NtUserPostMessage(hWnd
, Msg
, wParam
, lParam
);
2291 /* No drop files or current Process, just post message. */
2292 if ( (Msg
!= WM_DROPFILES
) ||
2293 ( NtUserQueryWindow( hWnd
, QUERY_WINDOW_UNIQUE_PROCESS_ID
) ==
2294 PtrToUint(NtCurrentTeb()->ClientId
.UniqueProcess
) ) )
2296 return NtUserPostMessage(hWnd
, Msg
, wParam
, lParam
);
2299 /* We have drop files and this is not the same process for this window. */
2301 /* Just incase, check wParam for Global memory handle and send size. */
2302 Ret
= SendMessageW( hWnd
,
2304 (WPARAM
)GlobalSize((HGLOBAL
)wParam
), // Zero if not a handle.
2305 (LPARAM
)wParam
); // Send wParam as lParam.
2307 if ( Ret
) return NtUserPostMessage(hWnd
, Msg
, (WPARAM
)Ret
, lParam
);
2320 NtUserxPostQuitMessage(nExitCode
);
2335 return NtUserPostThreadMessage(idThread
, Msg
, wParam
, lParam
);
2350 return NtUserPostThreadMessage(idThread
, Msg
, wParam
, lParam
);
2358 SendMessageW(HWND Wnd
,
2366 PTHREADINFO ti
= GetW32ThreadInfo();
2368 if ( Msg
& ~WM_MAXIMUM
)
2370 SetLastError( ERROR_INVALID_PARAMETER
);
2374 if (Wnd
!= HWND_TOPMOST
&& Wnd
!= HWND_BROADCAST
&& (Msg
< WM_DDE_FIRST
|| Msg
> WM_DDE_LAST
))
2376 Window
= ValidateHwnd(Wnd
);
2378 if ( Window
!= NULL
&&
2379 Window
->head
.pti
== ti
&&
2380 !IsThreadHooked(GetWin32ClientInfo()) && // This is why HOOKs are bad! They slow the system down!
2381 !(Window
->state
& WNDS_SERVERSIDEWINDOWPROC
) )
2383 /* NOTE: We can directly send messages to the window procedure
2384 if *all* the following conditions are met:
2386 * Window belongs to calling thread
2387 * The calling thread is not being hooked for CallWndProc
2388 * Not calling a server side proc:
2389 Desktop, Switch, ScrollBar, Menu, IconTitle, or hWndMessage
2392 return IntCallMessageProc(Window
, Wnd
, Msg
, wParam
, lParam
, FALSE
);
2397 UMMsg
.message
= Msg
;
2398 UMMsg
.wParam
= wParam
;
2399 UMMsg
.lParam
= lParam
;
2401 if (! MsgiUMToKMMessage(&UMMsg
, &KMMsg
, FALSE
))
2406 Result
= NtUserMessageCall( Wnd
,
2414 MsgiUMToKMCleanup(&UMMsg
, &KMMsg
);
2424 SendMessageA(HWND Wnd
, UINT Msg
, WPARAM wParam
, LPARAM lParam
)
2426 MSG AnsiMsg
, UcMsg
, KMMsg
;
2429 PTHREADINFO ti
= GetW32ThreadInfo();
2431 if ( Msg
& ~WM_MAXIMUM
)
2433 SetLastError( ERROR_INVALID_PARAMETER
);
2437 if (Wnd
!= HWND_TOPMOST
&& Wnd
!= HWND_BROADCAST
&& (Msg
< WM_DDE_FIRST
|| Msg
> WM_DDE_LAST
))
2439 Window
= ValidateHwnd(Wnd
);
2441 if ( Window
!= NULL
&&
2442 Window
->head
.pti
== ti
&&
2443 !IsThreadHooked(GetWin32ClientInfo()) && // This is why HOOKs are bad! They slow the system down!
2444 !(Window
->state
& WNDS_SERVERSIDEWINDOWPROC
) )
2446 /* NOTE: We can directly send messages to the window procedure
2447 if *all* the following conditions are met:
2449 * Window belongs to calling thread
2450 * The calling thread is not being hooked for CallWndProc
2451 * Not calling a server side proc:
2452 Desktop, Switch, ScrollBar, Menu, IconTitle, or hWndMessage
2455 return IntCallMessageProc(Window
, Wnd
, Msg
, wParam
, lParam
, TRUE
);
2460 AnsiMsg
.message
= Msg
;
2461 AnsiMsg
.wParam
= wParam
;
2462 AnsiMsg
.lParam
= lParam
;
2464 if (!MsgiAnsiToUnicodeMessage(Wnd
, &UcMsg
, &AnsiMsg
))
2469 if (!MsgiUMToKMMessage(&UcMsg
, &KMMsg
, FALSE
))
2471 MsgiAnsiToUnicodeCleanup(&UcMsg
, &AnsiMsg
);
2475 Result
= NtUserMessageCall( Wnd
,
2483 MsgiUMToKMCleanup(&UcMsg
, &KMMsg
);
2484 MsgiAnsiToUnicodeReply(&UcMsg
, &AnsiMsg
, &Result
);
2494 SendMessageCallbackA(
2499 SENDASYNCPROC lpCallBack
,
2504 CALL_BACK_INFO CallBackInfo
;
2506 if (is_pointer_message(Msg
))
2508 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
2512 CallBackInfo
.CallBack
= lpCallBack
;
2513 CallBackInfo
.Context
= dwData
;
2515 AnsiMsg
.hwnd
= hWnd
;
2516 AnsiMsg
.message
= Msg
;
2517 AnsiMsg
.wParam
= wParam
;
2518 AnsiMsg
.lParam
= lParam
;
2520 if (!MsgiAnsiToUnicodeMessage(hWnd
, &UcMsg
, &AnsiMsg
))
2525 Result
= NtUserMessageCall( hWnd
,
2529 (ULONG_PTR
)&CallBackInfo
,
2530 FNID_SENDMESSAGECALLBACK
,
2533 MsgiAnsiToUnicodeCleanup(&UcMsg
, &AnsiMsg
);
2543 SendMessageCallbackW(
2548 SENDASYNCPROC lpCallBack
,
2551 CALL_BACK_INFO CallBackInfo
;
2553 if (is_pointer_message(Msg
))
2555 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
2559 CallBackInfo
.CallBack
= lpCallBack
;
2560 CallBackInfo
.Context
= dwData
;
2562 return NtUserMessageCall(hWnd
,
2566 (ULONG_PTR
)&CallBackInfo
,
2567 FNID_SENDMESSAGECALLBACK
,
2576 SendMessageTimeoutA(
2583 PDWORD_PTR lpdwResult
)
2589 if ( Msg
& ~WM_MAXIMUM
|| fuFlags
& ~(SMTO_NOTIMEOUTIFNOTHUNG
|SMTO_ABORTIFHUNG
|SMTO_BLOCK
))
2591 SetLastError( ERROR_INVALID_PARAMETER
);
2595 if (lpdwResult
) *lpdwResult
= 0;
2597 SPY_EnterMessage(SPY_SENDMESSAGE
, hWnd
, Msg
, wParam
, lParam
);
2599 dsm
.uFlags
= fuFlags
;
2600 dsm
.uTimeout
= uTimeout
;
2602 AnsiMsg
.hwnd
= hWnd
;
2603 AnsiMsg
.message
= Msg
;
2604 AnsiMsg
.wParam
= wParam
;
2605 AnsiMsg
.lParam
= lParam
;
2607 if (! MsgiAnsiToUnicodeMessage(hWnd
, &UcMsg
, &AnsiMsg
))
2612 Result
= NtUserMessageCall( hWnd
,
2617 FNID_SENDMESSAGEWTOOPTION
,
2620 MsgiAnsiToUnicodeReply(&UcMsg
, &AnsiMsg
, &Result
);
2622 if (lpdwResult
) *lpdwResult
= dsm
.Result
;
2624 SPY_ExitMessage(SPY_RESULT_OK
, hWnd
, Msg
, Result
, wParam
, lParam
);
2635 SendMessageTimeoutW(
2642 PDWORD_PTR lpdwResult
)
2647 if ( Msg
& ~WM_MAXIMUM
|| fuFlags
& ~(SMTO_NOTIMEOUTIFNOTHUNG
|SMTO_ABORTIFHUNG
|SMTO_BLOCK
))
2649 SetLastError( ERROR_INVALID_PARAMETER
);
2653 if (lpdwResult
) *lpdwResult
= 0;
2655 SPY_EnterMessage(SPY_SENDMESSAGE
, hWnd
, Msg
, wParam
, lParam
);
2657 dsm
.uFlags
= fuFlags
;
2658 dsm
.uTimeout
= uTimeout
;
2660 Result
= NtUserMessageCall( hWnd
,
2665 FNID_SENDMESSAGEWTOOPTION
,
2668 if (lpdwResult
) *lpdwResult
= dsm
.Result
;
2670 SPY_ExitMessage(SPY_RESULT_OK
, hWnd
, Msg
, Result
, wParam
, lParam
);
2689 if (is_pointer_message(Msg
))
2691 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
2695 AnsiMsg
.hwnd
= hWnd
;
2696 AnsiMsg
.message
= Msg
;
2697 AnsiMsg
.wParam
= wParam
;
2698 AnsiMsg
.lParam
= lParam
;
2699 if (! MsgiAnsiToUnicodeMessage(hWnd
, &UcMsg
, &AnsiMsg
))
2703 Ret
= SendNotifyMessageW(hWnd
, UcMsg
.message
, UcMsg
.wParam
, UcMsg
.lParam
);
2705 MsgiAnsiToUnicodeCleanup(&UcMsg
, &AnsiMsg
);
2724 if (is_pointer_message(Msg
))
2726 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
2731 UMMsg
.message
= Msg
;
2732 UMMsg
.wParam
= wParam
;
2733 UMMsg
.lParam
= lParam
;
2734 if (! MsgiUMToKMMessage(&UMMsg
, &KMMsg
, TRUE
))
2738 Result
= NtUserMessageCall( hWnd
,
2743 FNID_SENDNOTIFYMESSAGE
,
2746 MsgiUMToKMCleanup(&UMMsg
, &KMMsg
);
2755 TranslateMessageEx(CONST MSG
*lpMsg
, UINT Flags
)
2757 switch (lpMsg
->message
)
2763 return(NtUserTranslateMessage((LPMSG
)lpMsg
, Flags
));
2766 if ( lpMsg
->message
& ~WM_MAXIMUM
)
2767 SetLastError(ERROR_INVALID_PARAMETER
);
2777 TranslateMessage(CONST MSG
*lpMsg
)
2781 // Ref: msdn ImmGetVirtualKey:
2782 // http://msdn.microsoft.com/en-us/library/aa912145.aspx
2784 if ( (LOWORD(lpMsg->wParam) != VK_PROCESSKEY) ||
2785 !(Ret = IMM_ImmTranslateMessage( lpMsg->hwnd,
2790 Ret
= TranslateMessageEx((LPMSG
)lpMsg
, 0);
2800 RegisterWindowMessageA(LPCSTR lpString
)
2802 UNICODE_STRING String
;
2805 if (!RtlCreateUnicodeStringFromAsciiz(&String
, (PCSZ
)lpString
))
2809 Atom
= NtUserRegisterWindowMessage(&String
);
2810 RtlFreeUnicodeString(&String
);
2819 RegisterWindowMessageW(LPCWSTR lpString
)
2821 UNICODE_STRING String
;
2823 RtlInitUnicodeString(&String
, lpString
);
2824 return(NtUserRegisterWindowMessage(&String
));
2833 return (HWND
)NtUserGetThreadState(THREADSTATE_CAPTUREWINDOW
);
2840 ReleaseCapture(VOID
)
2842 return NtUserxReleaseCapture();
2851 RealGetQueueStatus(UINT flags
)
2853 #define QS_TEMPALLINPUT 255 // ATM, do not support QS_RAWINPUT
2854 if (flags
& ~(QS_SMRESULT
|QS_ALLPOSTMESSAGE
|QS_TEMPALLINPUT
))
2856 SetLastError( ERROR_INVALID_FLAGS
);
2859 return NtUserxGetQueueStatus(flags
);
2866 BOOL WINAPI
GetInputState(VOID
)
2868 PCLIENTTHREADINFO pcti
= GetWin32ClientInfo()->pClientThreadInfo
;
2870 if ((!pcti
) || (pcti
->fsChangeBits
& (QS_KEY
|QS_MOUSEBUTTON
)))
2871 return (BOOL
)NtUserGetThreadState(THREADSTATE_GETINPUTSTATE
);
2878 User32CallWindowProcFromKernel(PVOID Arguments
, ULONG ArgumentLength
)
2880 PWINDOWPROC_CALLBACK_ARGUMENTS CallbackArgs
;
2883 PCLIENTINFO pci
= GetWin32ClientInfo();
2885 /* Make sure we don't try to access mem beyond what we were given */
2886 if (ArgumentLength
< sizeof(WINDOWPROC_CALLBACK_ARGUMENTS
))
2888 return STATUS_INFO_LENGTH_MISMATCH
;
2891 CallbackArgs
= (PWINDOWPROC_CALLBACK_ARGUMENTS
) Arguments
;
2892 KMMsg
.hwnd
= CallbackArgs
->Wnd
;
2893 KMMsg
.message
= CallbackArgs
->Msg
;
2894 KMMsg
.wParam
= CallbackArgs
->wParam
;
2895 /* Check if lParam is really a pointer and adjust it if it is */
2896 if (0 <= CallbackArgs
->lParamBufferSize
)
2898 if (ArgumentLength
!= sizeof(WINDOWPROC_CALLBACK_ARGUMENTS
)
2899 + CallbackArgs
->lParamBufferSize
)
2901 return STATUS_INFO_LENGTH_MISMATCH
;
2903 KMMsg
.lParam
= (LPARAM
) ((char *) CallbackArgs
+ sizeof(WINDOWPROC_CALLBACK_ARGUMENTS
));
2907 if (ArgumentLength
!= sizeof(WINDOWPROC_CALLBACK_ARGUMENTS
))
2909 return STATUS_INFO_LENGTH_MISMATCH
;
2911 KMMsg
.lParam
= CallbackArgs
->lParam
;
2914 if (WM_NCCALCSIZE
== CallbackArgs
->Msg
&& CallbackArgs
->wParam
)
2916 NCCALCSIZE_PARAMS
*Params
= (NCCALCSIZE_PARAMS
*) KMMsg
.lParam
;
2917 Params
->lppos
= (PWINDOWPOS
) (Params
+ 1);
2920 if (! MsgiKMToUMMessage(&KMMsg
, &UMMsg
))
2924 if (pci
->CallbackWnd
.hWnd
== UMMsg
.hwnd
)
2925 pWnd
= pci
->CallbackWnd
.pWnd
;
2927 CallbackArgs
->Result
= IntCallWindowProcW( CallbackArgs
->IsAnsiProc
,
2935 if (! MsgiKMToUMReply(&KMMsg
, &UMMsg
, &CallbackArgs
->Result
))
2939 return ZwCallbackReturn(CallbackArgs
, ArgumentLength
, STATUS_SUCCESS
);
2945 BOOL WINAPI
SetMessageQueue(int cMessagesMax
)
2947 /* Function does nothing on 32 bit windows */
2950 typedef DWORD (WINAPI
* RealGetQueueStatusProc
)(UINT flags
);
2951 typedef DWORD (WINAPI
* RealMsgWaitForMultipleObjectsExProc
)(DWORD nCount
, CONST HANDLE
*lpHandles
, DWORD dwMilliseconds
, DWORD dwWakeMask
, DWORD dwFlags
);
2952 typedef BOOL (WINAPI
* RealInternalGetMessageProc
)(LPMSG
,HWND
,UINT
,UINT
,UINT
,BOOL
);
2953 typedef BOOL (WINAPI
* RealWaitMessageExProc
)(DWORD
,UINT
);
2955 typedef struct _USER_MESSAGE_PUMP_ADDRESSES
{
2957 RealInternalGetMessageProc NtUserRealInternalGetMessage
;
2958 RealWaitMessageExProc NtUserRealWaitMessageEx
;
2959 RealGetQueueStatusProc RealGetQueueStatus
;
2960 RealMsgWaitForMultipleObjectsExProc RealMsgWaitForMultipleObjectsEx
;
2961 } USER_MESSAGE_PUMP_ADDRESSES
, * PUSER_MESSAGE_PUMP_ADDRESSES
;
2965 RealMsgWaitForMultipleObjectsEx(
2967 CONST HANDLE
*pHandles
,
2968 DWORD dwMilliseconds
,
2972 typedef BOOL (WINAPI
* MESSAGEPUMPHOOKPROC
)(BOOL Unregistering
,PUSER_MESSAGE_PUMP_ADDRESSES MessagePumpAddresses
);
2974 CRITICAL_SECTION gcsMPH
;
2975 MESSAGEPUMPHOOKPROC gpfnInitMPH
;
2976 DWORD gcLoadMPH
= 0;
2977 USER_MESSAGE_PUMP_ADDRESSES gmph
= {sizeof(USER_MESSAGE_PUMP_ADDRESSES
),
2978 NtUserRealInternalGetMessage
,
2979 NtUserRealWaitMessageEx
,
2981 RealMsgWaitForMultipleObjectsEx
2984 DWORD gfMessagePumpHook
= 0;
2986 BOOL WINAPI
IsInsideMessagePumpHook()
2987 { // FF uses this and polls it when Min/Max
2988 PCLIENTTHREADINFO pcti
= GetWin32ClientInfo()->pClientThreadInfo
;
2989 return (gfMessagePumpHook
&& pcti
&& (pcti
->dwcPumpHook
> 0));
2992 void WINAPI
ResetMessagePumpHook(PUSER_MESSAGE_PUMP_ADDRESSES Addresses
)
2994 Addresses
->cbSize
= sizeof(USER_MESSAGE_PUMP_ADDRESSES
);
2995 Addresses
->NtUserRealInternalGetMessage
= NtUserRealInternalGetMessage
;
2996 Addresses
->NtUserRealWaitMessageEx
= NtUserRealWaitMessageEx
;
2997 Addresses
->RealGetQueueStatus
= RealGetQueueStatus
;
2998 Addresses
->RealMsgWaitForMultipleObjectsEx
= RealMsgWaitForMultipleObjectsEx
;
3001 BOOL WINAPI
RegisterMessagePumpHook(MESSAGEPUMPHOOKPROC Hook
)
3003 EnterCriticalSection(&gcsMPH
);
3005 SetLastError(ERROR_INVALID_PARAMETER
);
3006 LeaveCriticalSection(&gcsMPH
);
3010 USER_MESSAGE_PUMP_ADDRESSES Addresses
;
3012 ResetMessagePumpHook(&Addresses
);
3013 if(!Hook(FALSE
, &Addresses
) || !Addresses
.cbSize
) {
3014 LeaveCriticalSection(&gcsMPH
);
3017 memcpy(&gmph
, &Addresses
, Addresses
.cbSize
);
3019 if(gpfnInitMPH
!= Hook
) {
3020 LeaveCriticalSection(&gcsMPH
);
3024 if(NtUserxInitMessagePump()) {
3025 LeaveCriticalSection(&gcsMPH
);
3029 InterlockedExchange((PLONG
)&gfMessagePumpHook
, 1);
3031 LeaveCriticalSection(&gcsMPH
);
3035 BOOL WINAPI
UnregisterMessagePumpHook(VOID
)
3037 EnterCriticalSection(&gcsMPH
);
3039 if(NtUserxUnInitMessagePump()) {
3042 InterlockedExchange((PLONG
)&gfMessagePumpHook
, 0);
3043 gpfnInitMPH(TRUE
, NULL
);
3044 ResetMessagePumpHook(&gmph
);
3047 LeaveCriticalSection(&gcsMPH
);
3051 LeaveCriticalSection(&gcsMPH
);
3055 DWORD WINAPI
GetQueueStatus(UINT flags
)
3057 return IsInsideMessagePumpHook() ? gmph
.RealGetQueueStatus(flags
) : RealGetQueueStatus(flags
);
3061 * @name RealMsgWaitForMultipleObjectsEx
3063 * Wait either for either message arrival or for one of the passed events
3067 * Number of handles in the pHandles array.
3069 * Handles of events to wait for.
3070 * @param dwMilliseconds
3073 * Mask specifying on which message events we should wakeup.
3075 * Wait type (see MWMO_* constants).
3081 RealMsgWaitForMultipleObjectsEx(
3083 const HANDLE
*pHandles
,
3084 DWORD dwMilliseconds
,
3088 LPHANDLE RealHandles
;
3089 HANDLE MessageQueueHandle
;
3092 PCLIENTTHREADINFO pcti
;
3094 if (dwFlags
& ~(MWMO_WAITALL
| MWMO_ALERTABLE
| MWMO_INPUTAVAILABLE
))
3096 SetLastError(ERROR_INVALID_PARAMETER
);
3100 pci
= GetWin32ClientInfo();
3101 if (!pci
) return WAIT_FAILED
;
3103 pcti
= pci
->pClientThreadInfo
;
3104 if (pcti
&& ( !nCount
|| !(dwFlags
& MWMO_WAITALL
) ))
3106 if ( (pcti
->fsChangeBits
& LOWORD(dwWakeMask
)) ||
3107 ( (dwFlags
& MWMO_INPUTAVAILABLE
) && (pcti
->fsWakeBits
& LOWORD(dwWakeMask
)) ) )
3109 //FIXME("Chg 0x%x Wake 0x%x Mask 0x%x nCnt %d\n",pcti->fsChangeBits, pcti->fsWakeBits, dwWakeMask, nCount);
3114 MessageQueueHandle
= NtUserxMsqSetWakeMask(MAKELONG(dwWakeMask
, dwFlags
));
3115 if (MessageQueueHandle
== NULL
)
3117 SetLastError(0); /* ? */
3121 RealHandles
= HeapAlloc(GetProcessHeap(), 0, (nCount
+ 1) * sizeof(HANDLE
));
3122 if (RealHandles
== NULL
)
3124 NtUserxMsqClearWakeMask();
3125 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
3129 RtlCopyMemory(RealHandles
, pHandles
, nCount
* sizeof(HANDLE
));
3130 RealHandles
[nCount
] = MessageQueueHandle
;
3132 Result
= WaitForMultipleObjectsEx(nCount
+ 1, RealHandles
,
3133 dwFlags
& MWMO_WAITALL
,
3134 dwMilliseconds
, dwFlags
& MWMO_ALERTABLE
);
3136 HeapFree(GetProcessHeap(), 0, RealHandles
);
3137 NtUserxMsqClearWakeMask();
3138 //FIXME("Result 0X%x\n",Result);
3146 MsgWaitForMultipleObjectsEx(
3148 CONST HANDLE
*lpHandles
,
3149 DWORD dwMilliseconds
,
3153 return IsInsideMessagePumpHook() ? gmph
.RealMsgWaitForMultipleObjectsEx(nCount
, lpHandles
, dwMilliseconds
, dwWakeMask
, dwFlags
) : RealMsgWaitForMultipleObjectsEx(nCount
, lpHandles
,dwMilliseconds
, dwWakeMask
, dwFlags
);
3160 MsgWaitForMultipleObjects(
3162 CONST HANDLE
*lpHandles
,
3164 DWORD dwMilliseconds
,
3167 return MsgWaitForMultipleObjectsEx(nCount
, lpHandles
, dwMilliseconds
,
3168 dwWakeMask
, fWaitAll
? MWMO_WAITALL
: 0);
3172 BOOL FASTCALL
MessageInit(VOID
)
3174 InitializeCriticalSection(&DdeCrst
);
3175 InitializeCriticalSection(&gcsMPH
);
3180 VOID FASTCALL
MessageCleanup(VOID
)
3182 DeleteCriticalSection(&DdeCrst
);
3183 DeleteCriticalSection(&gcsMPH
);
3190 IsDialogMessageA( HWND hwndDlg
, LPMSG pmsg
)
3193 msg
.wParam
= map_wparam_AtoW( msg
.message
, msg
.wParam
);
3194 return IsDialogMessageW( hwndDlg
, &msg
);
3199 IntBroadcastSystemMessage(
3201 LPDWORD lpdwRecipients
,
3209 DWORD recips
= BSM_ALLCOMPONENTS
;
3210 BOOL ret
= -1; // Set to return fail
3211 static const DWORD all_flags
= ( BSF_QUERY
| BSF_IGNORECURRENTTASK
| BSF_FLUSHDISK
| BSF_NOHANG
3212 | BSF_POSTMESSAGE
| BSF_FORCEIFHUNG
| BSF_NOTIMEOUTIFNOTHUNG
3213 | BSF_ALLOWSFW
| BSF_SENDNOTIFYMESSAGE
| BSF_RETURNHDESK
| BSF_LUID
);
3215 if ((dwflags
& ~all_flags
) ||
3216 (!pBSMInfo
&& (dwflags
& (BSF_RETURNHDESK
|BSF_LUID
))) )
3218 SetLastError(ERROR_INVALID_PARAMETER
);
3222 if(uiMessage
>= WM_USER
&& uiMessage
< 0xC000)
3224 SetLastError(ERROR_INVALID_PARAMETER
);
3228 if (dwflags
& BSF_FORCEIFHUNG
) dwflags
|= BSF_NOHANG
;
3230 if (dwflags
& BSF_QUERY
) dwflags
&= ~BSF_SENDNOTIFYMESSAGE
|BSF_POSTMESSAGE
;
3232 if (!lpdwRecipients
)
3233 lpdwRecipients
= &recips
;
3235 if (*lpdwRecipients
& ~(BSM_APPLICATIONS
|BSM_ALLDESKTOPS
|BSM_INSTALLABLEDRIVERS
|BSM_NETDRIVER
|BSM_VXDS
))
3237 SetLastError(ERROR_INVALID_PARAMETER
);
3241 if ( pBSMInfo
&& (dwflags
& BSF_QUERY
) )
3243 if (pBSMInfo
->cbSize
!= sizeof(BSMINFO
))
3245 SetLastError(ERROR_INVALID_PARAMETER
);
3252 parm
.flags
= dwflags
;
3253 parm
.recipients
= *lpdwRecipients
;
3255 if (dwflags
& BSF_LUID
) parm
.luid
= pBSMInfo
->luid
;
3257 ret
= NtUserMessageCall(GetDesktopWindow(),
3262 FNID_BROADCASTSYSTEMMESSAGE
,
3267 if ( pBSMInfo
&& (dwflags
& BSF_QUERY
) )
3269 pBSMInfo
->hdesk
= parm
.hDesk
;
3270 pBSMInfo
->hwnd
= parm
.hWnd
;
3281 BroadcastSystemMessageA(
3283 LPDWORD lpdwRecipients
,
3288 return IntBroadcastSystemMessage( dwFlags
, lpdwRecipients
, uiMessage
, wParam
, lParam
, NULL
, TRUE
);
3296 BroadcastSystemMessageW(
3298 LPDWORD lpdwRecipients
,
3303 return IntBroadcastSystemMessage( dwFlags
, lpdwRecipients
, uiMessage
, wParam
, lParam
, NULL
, FALSE
);
3311 BroadcastSystemMessageExA(
3313 LPDWORD lpdwRecipients
,
3319 return IntBroadcastSystemMessage( dwflags
, lpdwRecipients
, uiMessage
, wParam
, lParam
, pBSMInfo
, TRUE
);
3327 BroadcastSystemMessageExW(
3329 LPDWORD lpdwRecipients
,
3335 return IntBroadcastSystemMessage( dwflags
, lpdwRecipients
, uiMessage
, wParam
, lParam
, pBSMInfo
, FALSE
);