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
:
580 if (!AnsiMsg
->lParam
) break;
581 LPWSTR Buffer
= RtlAllocateHeap(GetProcessHeap(), 0, AnsiMsg
->wParam
* sizeof(WCHAR
));
582 if (!Buffer
) return FALSE
;
583 UnicodeMsg
->lParam
= (LPARAM
)Buffer
;
590 if (!AnsiMsg
->lParam
|| !listbox_has_strings( AnsiMsg
->hwnd
)) break;
591 Size
= SendMessageW( AnsiMsg
->hwnd
, LB_GETTEXTLEN
, AnsiMsg
->wParam
, 0 );
594 ERR("LB_GETTEXT LB_ERR\n");
595 Size
= sizeof(ULONG_PTR
);
597 Size
= (Size
+ 1) * sizeof(WCHAR
);
598 UnicodeMsg
->lParam
= (LPARAM
) RtlAllocateHeap(GetProcessHeap(), 0, Size
);
599 if (!UnicodeMsg
->lParam
) return FALSE
;
606 if (!AnsiMsg
->lParam
|| !combobox_has_strings( AnsiMsg
->hwnd
)) break;
607 Size
= SendMessageW( AnsiMsg
->hwnd
, CB_GETLBTEXTLEN
, AnsiMsg
->wParam
, 0 );
610 ERR("CB_GETTEXT LB_ERR\n");
611 Size
= sizeof(ULONG_PTR
);
613 Size
= (Size
+ 1) * sizeof(WCHAR
);
614 UnicodeMsg
->lParam
= (LPARAM
) RtlAllocateHeap(GetProcessHeap(), 0, Size
);
615 if (!UnicodeMsg
->lParam
) return FALSE
;
619 /* AnsiMsg->lParam is string (0-terminated) */
621 case WM_WININICHANGE
:
622 case WM_DEVMODECHANGE
:
628 if (!AnsiMsg
->lParam
) break;
629 RtlCreateUnicodeStringFromAsciiz(&UnicodeString
, (LPSTR
)AnsiMsg
->lParam
);
630 UnicodeMsg
->lParam
= (LPARAM
)UnicodeString
.Buffer
;
635 case LB_ADDSTRING_LOWER
:
636 case LB_ADDSTRING_UPPER
:
637 case LB_INSERTSTRING
:
638 case LB_INSERTSTRING_UPPER
:
639 case LB_INSERTSTRING_LOWER
:
641 case LB_FINDSTRINGEXACT
:
642 case LB_SELECTSTRING
:
644 if (AnsiMsg
->lParam
&& listbox_has_strings(AnsiMsg
->hwnd
))
646 RtlCreateUnicodeStringFromAsciiz(&UnicodeString
, (LPSTR
)AnsiMsg
->lParam
);
647 UnicodeMsg
->lParam
= (LPARAM
)UnicodeString
.Buffer
;
653 case CB_INSERTSTRING
:
655 case CB_FINDSTRINGEXACT
:
656 case CB_SELECTSTRING
:
658 if (AnsiMsg
->lParam
&& combobox_has_strings(AnsiMsg
->hwnd
))
660 RtlCreateUnicodeStringFromAsciiz(&UnicodeString
, (LPSTR
)AnsiMsg
->lParam
);
661 UnicodeMsg
->lParam
= (LPARAM
)UnicodeString
.Buffer
;
669 MDICREATESTRUCTW mdi_cs
;
672 CREATESTRUCTW cs
; /* new structure */
673 LPCWSTR lpszName
; /* allocated Name */
674 LPCWSTR lpszClass
; /* allocated Class */
677 struct s
*xs
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(struct s
));
682 xs
->cs
= *(CREATESTRUCTW
*)AnsiMsg
->lParam
;
683 if (!IS_INTRESOURCE(xs
->cs
.lpszName
))
685 RtlCreateUnicodeStringFromAsciiz(&UnicodeString
, (LPSTR
)xs
->cs
.lpszName
);
686 xs
->lpszName
= xs
->cs
.lpszName
= UnicodeString
.Buffer
;
688 if (!IS_ATOM(xs
->cs
.lpszClass
))
690 RtlCreateUnicodeStringFromAsciiz(&UnicodeString
, (LPSTR
)xs
->cs
.lpszClass
);
691 xs
->lpszClass
= xs
->cs
.lpszClass
= UnicodeString
.Buffer
;
694 if (GetWindowLongW(hwnd
, GWL_EXSTYLE
) & WS_EX_MDICHILD
)
696 mdi_cs
= *(MDICREATESTRUCTW
*)xs
->cs
.lpCreateParams
;
697 mdi_cs
.szTitle
= xs
->cs
.lpszName
;
698 mdi_cs
.szClass
= xs
->cs
.lpszClass
;
699 xs
->cs
.lpCreateParams
= &mdi_cs
;
702 UnicodeMsg
->lParam
= (LPARAM
)xs
;
708 MDICREATESTRUCTW
*cs
=
709 (MDICREATESTRUCTW
*)HeapAlloc(GetProcessHeap(), 0, sizeof(*cs
));
716 *cs
= *(MDICREATESTRUCTW
*)AnsiMsg
->lParam
;
718 if (!IS_ATOM(cs
->szClass
))
720 RtlCreateUnicodeStringFromAsciiz(&UnicodeString
, (LPSTR
)cs
->szClass
);
721 cs
->szClass
= UnicodeString
.Buffer
;
724 RtlCreateUnicodeStringFromAsciiz(&UnicodeString
, (LPSTR
)cs
->szTitle
);
725 cs
->szTitle
= UnicodeString
.Buffer
;
727 UnicodeMsg
->lParam
= (LPARAM
)cs
;
732 if (UnicodeMsg
->lParam
)
734 MSG newmsg
= *(MSG
*)UnicodeMsg
->lParam
;
735 newmsg
.wParam
= map_wparam_AtoW( newmsg
.message
, newmsg
.wParam
);
745 case EM_SETPASSWORDCHAR
:
747 UnicodeMsg
->wParam
= map_wparam_AtoW( AnsiMsg
->message
, AnsiMsg
->wParam
);
755 MsgiAnsiToUnicodeCleanup(LPMSG UnicodeMsg
, LPMSG AnsiMsg
)
757 UNICODE_STRING UnicodeString
;
759 switch (AnsiMsg
->message
)
762 if (!listbox_has_strings( UnicodeMsg
->hwnd
)) break;
764 if (UnicodeMsg
->message
== CB_GETLBTEXT
&& !combobox_has_strings( UnicodeMsg
->hwnd
)) break;
766 case WM_ASKCBFORMATNAME
:
768 if (!UnicodeMsg
->lParam
) break;
769 RtlFreeHeap(GetProcessHeap(), 0, (PVOID
) UnicodeMsg
->lParam
);
774 case WM_WININICHANGE
:
775 case WM_DEVMODECHANGE
:
781 if (!UnicodeMsg
->lParam
) break;
782 RtlInitUnicodeString(&UnicodeString
, (PCWSTR
)UnicodeMsg
->lParam
);
783 RtlFreeUnicodeString(&UnicodeString
);
788 case LB_ADDSTRING_LOWER
:
789 case LB_ADDSTRING_UPPER
:
790 case LB_INSERTSTRING
:
791 case LB_INSERTSTRING_UPPER
:
792 case LB_INSERTSTRING_LOWER
:
794 case LB_FINDSTRINGEXACT
:
795 case LB_SELECTSTRING
:
797 if (UnicodeMsg
->lParam
&& listbox_has_strings(AnsiMsg
->hwnd
))
799 RtlInitUnicodeString(&UnicodeString
, (PCWSTR
)UnicodeMsg
->lParam
);
800 RtlFreeUnicodeString(&UnicodeString
);
806 case CB_INSERTSTRING
:
808 case CB_FINDSTRINGEXACT
:
809 case CB_SELECTSTRING
:
811 if (UnicodeMsg
->lParam
&& combobox_has_strings(AnsiMsg
->hwnd
))
813 RtlInitUnicodeString(&UnicodeString
, (PCWSTR
)UnicodeMsg
->lParam
);
814 RtlFreeUnicodeString(&UnicodeString
);
824 CREATESTRUCTW cs
; /* new structure */
825 LPWSTR lpszName
; /* allocated Name */
826 LPWSTR lpszClass
; /* allocated Class */
829 struct s
*xs
= (struct s
*)UnicodeMsg
->lParam
;
832 RtlInitUnicodeString(&UnicodeString
, (PCWSTR
)xs
->lpszName
);
833 RtlFreeUnicodeString(&UnicodeString
);
837 RtlInitUnicodeString(&UnicodeString
, (PCWSTR
)xs
->lpszClass
);
838 RtlFreeUnicodeString(&UnicodeString
);
840 HeapFree(GetProcessHeap(), 0, xs
);
846 MDICREATESTRUCTW
*cs
= (MDICREATESTRUCTW
*)UnicodeMsg
->lParam
;
847 RtlInitUnicodeString(&UnicodeString
, (PCWSTR
)cs
->szTitle
);
848 RtlFreeUnicodeString(&UnicodeString
);
849 if (!IS_ATOM(cs
->szClass
))
851 RtlInitUnicodeString(&UnicodeString
, (PCWSTR
)cs
->szClass
);
852 RtlFreeUnicodeString(&UnicodeString
);
854 HeapFree(GetProcessHeap(), 0, cs
);
863 * Unicode Result to Ansi Result
866 MsgiAnsiToUnicodeReply(LPMSG UnicodeMsg
, LPMSG AnsiMsg
, LRESULT
*Result
)
868 LPWSTR Buffer
= (LPWSTR
)UnicodeMsg
->lParam
;
869 LPSTR AnsiBuffer
= (LPSTR
)AnsiMsg
->lParam
;
871 switch (AnsiMsg
->message
)
874 case WM_ASKCBFORMATNAME
:
876 if (UnicodeMsg
->wParam
)
879 if (*Result
) RtlUnicodeToMultiByteN( AnsiBuffer
, UnicodeMsg
->wParam
- 1, &len
, Buffer
, strlenW(Buffer
) * sizeof(WCHAR
) );
887 if (!AnsiBuffer
|| !listbox_has_strings( UnicodeMsg
->hwnd
)) break;
891 RtlUnicodeToMultiByteN( AnsiBuffer
, ~0u, &len
, Buffer
, (strlenW(Buffer
) + 1) * sizeof(WCHAR
) );
898 if (!AnsiBuffer
|| !combobox_has_strings( UnicodeMsg
->hwnd
)) break;
902 RtlUnicodeToMultiByteN( AnsiBuffer
, ~0u, &len
, Buffer
, (strlenW(Buffer
) + 1) * sizeof(WCHAR
) );
909 MsgiAnsiToUnicodeCleanup(UnicodeMsg
, AnsiMsg
);
915 MsgiUnicodeToAnsiMessage(HWND hwnd
, LPMSG AnsiMsg
, LPMSG UnicodeMsg
)
917 ANSI_STRING AnsiString
;
918 UNICODE_STRING UnicodeString
;
920 *AnsiMsg
= *UnicodeMsg
;
922 switch(UnicodeMsg
->message
)
927 MDICREATESTRUCTA
*pmdi_cs
;
932 CsW
= (CREATESTRUCTW
*)(UnicodeMsg
->lParam
);
933 CsA
= RtlAllocateHeap(GetProcessHeap(), 0, sizeof(CREATESTRUCTA
) + sizeof(MDICREATESTRUCTA
));
938 memcpy(CsA
, CsW
, sizeof(CREATESTRUCTW
));
940 /* pmdi_cs starts right after CsA */
941 pmdi_cs
= (MDICREATESTRUCTA
*)(CsA
+ 1);
943 RtlInitUnicodeString(&UnicodeString
, CsW
->lpszName
);
944 Status
= RtlUnicodeStringToAnsiString(&AnsiString
, &UnicodeString
, TRUE
);
945 if (! NT_SUCCESS(Status
))
947 RtlFreeHeap(GetProcessHeap(), 0, CsA
);
950 CsA
->lpszName
= AnsiString
.Buffer
;
951 if (HIWORD((ULONG_PTR
)CsW
->lpszClass
) != 0)
953 RtlInitUnicodeString(&UnicodeString
, CsW
->lpszClass
);
954 Status
= RtlUnicodeStringToAnsiString(&AnsiString
, &UnicodeString
, TRUE
);
955 if (! NT_SUCCESS(Status
))
957 RtlInitAnsiString(&AnsiString
, CsA
->lpszName
);
958 RtlFreeAnsiString(&AnsiString
);
959 RtlFreeHeap(GetProcessHeap(), 0, CsA
);
962 CsA
->lpszClass
= AnsiString
.Buffer
;
965 if (GetWindowLongW(hwnd
, GWL_EXSTYLE
) & WS_EX_MDICHILD
)
967 *pmdi_cs
= *(MDICREATESTRUCTA
*)CsW
->lpCreateParams
;
968 pmdi_cs
->szTitle
= CsA
->lpszName
;
969 pmdi_cs
->szClass
= CsA
->lpszClass
;
970 CsA
->lpCreateParams
= pmdi_cs
;
973 AnsiMsg
->lParam
= (LPARAM
)CsA
;
977 case WM_ASKCBFORMATNAME
:
979 if (!UnicodeMsg
->lParam
) break;
980 /* Ansi string might contain MBCS chars so we need 2 * the number of chars */
981 AnsiMsg
->wParam
= UnicodeMsg
->wParam
* 2;
982 AnsiMsg
->lParam
= (LPARAM
) RtlAllocateHeap(GetProcessHeap(), 0, AnsiMsg
->wParam
);
983 if (!AnsiMsg
->lParam
) return FALSE
;
990 if (!UnicodeMsg
->lParam
|| !listbox_has_strings( UnicodeMsg
->hwnd
)) break;
991 Size
= SendMessageA( UnicodeMsg
->hwnd
, LB_GETTEXTLEN
, UnicodeMsg
->wParam
, 0 );
994 ERR("LB_GETTEXT LB_ERR\n");
995 Size
= sizeof(ULONG_PTR
);
997 Size
= (Size
+ 1) * sizeof(WCHAR
);
998 AnsiMsg
->lParam
= (LPARAM
) RtlAllocateHeap(GetProcessHeap(), 0, Size
);
999 if (!AnsiMsg
->lParam
) return FALSE
;
1006 if (!UnicodeMsg
->lParam
|| !combobox_has_strings( UnicodeMsg
->hwnd
)) break;
1007 Size
= SendMessageA( UnicodeMsg
->hwnd
, CB_GETLBTEXTLEN
, UnicodeMsg
->wParam
, 0 );
1010 ERR("CB_GETTEXT LB_ERR\n");
1011 Size
= sizeof(ULONG_PTR
);
1013 Size
= (Size
+ 1) * sizeof(WCHAR
);
1014 AnsiMsg
->lParam
= (LPARAM
) RtlAllocateHeap(GetProcessHeap(), 0, Size
);
1015 if (!AnsiMsg
->lParam
) return FALSE
;
1020 case WM_WININICHANGE
:
1021 case WM_DEVMODECHANGE
:
1027 if (!UnicodeMsg
->lParam
) break;
1028 RtlInitUnicodeString(&UnicodeString
, (PWSTR
) UnicodeMsg
->lParam
);
1029 if (! NT_SUCCESS(RtlUnicodeStringToAnsiString(&AnsiString
,
1035 AnsiMsg
->lParam
= (LPARAM
) AnsiString
.Buffer
;
1040 case LB_ADDSTRING_LOWER
:
1041 case LB_ADDSTRING_UPPER
:
1042 case LB_INSERTSTRING
:
1043 case LB_INSERTSTRING_UPPER
:
1044 case LB_INSERTSTRING_LOWER
:
1046 case LB_FINDSTRINGEXACT
:
1047 case LB_SELECTSTRING
:
1049 if (UnicodeMsg
->lParam
&& listbox_has_strings(AnsiMsg
->hwnd
))
1051 RtlInitUnicodeString(&UnicodeString
, (PWSTR
) UnicodeMsg
->lParam
);
1052 if (! NT_SUCCESS(RtlUnicodeStringToAnsiString(&AnsiString
,
1058 AnsiMsg
->lParam
= (LPARAM
) AnsiString
.Buffer
;
1064 case CB_INSERTSTRING
:
1066 case CB_FINDSTRINGEXACT
:
1067 case CB_SELECTSTRING
:
1069 if (UnicodeMsg
->lParam
&& combobox_has_strings(AnsiMsg
->hwnd
))
1071 RtlInitUnicodeString(&UnicodeString
, (PWSTR
) UnicodeMsg
->lParam
);
1072 if (! NT_SUCCESS(RtlUnicodeStringToAnsiString(&AnsiString
,
1078 AnsiMsg
->lParam
= (LPARAM
) AnsiString
.Buffer
;
1085 MDICREATESTRUCTA
*cs
=
1086 (MDICREATESTRUCTA
*)HeapAlloc(GetProcessHeap(), 0, sizeof(*cs
));
1093 *cs
= *(MDICREATESTRUCTA
*)UnicodeMsg
->lParam
;
1095 if (!IS_ATOM(cs
->szClass
))
1097 RtlInitUnicodeString(&UnicodeString
, (LPCWSTR
)cs
->szClass
);
1098 if (! NT_SUCCESS(RtlUnicodeStringToAnsiString(&AnsiString
,
1102 HeapFree(GetProcessHeap(), 0, cs
);
1105 cs
->szClass
= AnsiString
.Buffer
;
1108 RtlInitUnicodeString(&UnicodeString
, (LPCWSTR
)cs
->szTitle
);
1109 if (! NT_SUCCESS(RtlUnicodeStringToAnsiString(&AnsiString
,
1113 if (!IS_ATOM(cs
->szClass
))
1115 RtlInitAnsiString(&AnsiString
, cs
->szClass
);
1116 RtlFreeAnsiString(&AnsiString
);
1119 HeapFree(GetProcessHeap(), 0, cs
);
1122 cs
->szTitle
= AnsiString
.Buffer
;
1124 AnsiMsg
->lParam
= (LPARAM
)cs
;
1129 if (UnicodeMsg
->lParam
)
1131 MSG newmsg
= *(MSG
*)UnicodeMsg
->lParam
;
1132 switch(newmsg
.message
)
1137 case WM_SYSDEADCHAR
:
1138 newmsg
.wParam
= map_wparam_char_WtoA( newmsg
.wParam
, 1 );
1141 newmsg
.wParam
= map_wparam_char_WtoA( newmsg
.wParam
, 2 );
1149 WCHAR wch
= UnicodeMsg
->wParam
;
1151 DWORD cp
= get_input_codepage();
1152 DWORD len
= WideCharToMultiByte( cp
, 0, &wch
, 1, ch
, 2, NULL
, NULL
);
1153 AnsiMsg
->wParam
= (BYTE
)ch
[0];
1154 if (len
== 2) AnsiMsg
->wParam
= (BYTE
)ch
[1];
1162 case WM_SYSDEADCHAR
:
1163 case EM_SETPASSWORDCHAR
:
1164 AnsiMsg
->wParam
= map_wparam_char_WtoA(UnicodeMsg
->wParam
,1);
1168 AnsiMsg
->wParam
= map_wparam_char_WtoA(UnicodeMsg
->wParam
,2);
1174 static BOOL FASTCALL
1175 MsgiUnicodeToAnsiCleanup(LPMSG AnsiMsg
, LPMSG UnicodeMsg
)
1177 ANSI_STRING AnsiString
;
1179 switch(UnicodeMsg
->message
)
1182 if (!listbox_has_strings( AnsiMsg
->hwnd
)) break;
1184 if (AnsiMsg
->message
== CB_GETLBTEXT
&& !combobox_has_strings( AnsiMsg
->hwnd
)) break;
1186 case WM_ASKCBFORMATNAME
:
1188 if (!AnsiMsg
->lParam
) break;
1189 RtlFreeHeap(GetProcessHeap(), 0, (PVOID
) AnsiMsg
->lParam
);
1197 Cs
= (CREATESTRUCTA
*) AnsiMsg
->lParam
;
1198 RtlInitAnsiString(&AnsiString
, Cs
->lpszName
);
1199 RtlFreeAnsiString(&AnsiString
);
1200 if (HIWORD((ULONG_PTR
)Cs
->lpszClass
) != 0)
1202 RtlInitAnsiString(&AnsiString
, Cs
->lpszClass
);
1203 RtlFreeAnsiString(&AnsiString
);
1205 RtlFreeHeap(GetProcessHeap(), 0, Cs
);
1210 case WM_WININICHANGE
:
1211 case WM_DEVMODECHANGE
:
1217 if (!AnsiMsg
->lParam
) break;
1218 RtlInitAnsiString(&AnsiString
, (PSTR
) AnsiMsg
->lParam
);
1219 RtlFreeAnsiString(&AnsiString
);
1224 case LB_ADDSTRING_LOWER
:
1225 case LB_ADDSTRING_UPPER
:
1226 case LB_INSERTSTRING
:
1227 case LB_INSERTSTRING_UPPER
:
1228 case LB_INSERTSTRING_LOWER
:
1230 case LB_FINDSTRINGEXACT
:
1231 case LB_SELECTSTRING
:
1233 if (AnsiMsg
->lParam
&& listbox_has_strings(AnsiMsg
->hwnd
))
1235 RtlInitAnsiString(&AnsiString
, (PSTR
) AnsiMsg
->lParam
);
1236 RtlFreeAnsiString(&AnsiString
);
1242 case CB_INSERTSTRING
:
1244 case CB_FINDSTRINGEXACT
:
1245 case CB_SELECTSTRING
:
1247 if (AnsiMsg
->lParam
&& combobox_has_strings(AnsiMsg
->hwnd
))
1249 RtlInitAnsiString(&AnsiString
, (PSTR
) AnsiMsg
->lParam
);
1250 RtlFreeAnsiString(&AnsiString
);
1257 MDICREATESTRUCTA
*cs
= (MDICREATESTRUCTA
*)AnsiMsg
->lParam
;
1258 RtlInitAnsiString(&AnsiString
, (PCSTR
)cs
->szTitle
);
1259 RtlFreeAnsiString(&AnsiString
);
1260 if (!IS_ATOM(cs
->szClass
))
1262 RtlInitAnsiString(&AnsiString
, (PCSTR
)cs
->szClass
);
1263 RtlFreeAnsiString(&AnsiString
);
1265 HeapFree(GetProcessHeap(), 0, cs
);
1275 * Ansi Result to Unicode Result
1277 static BOOL FASTCALL
1278 MsgiUnicodeToAnsiReply(LPMSG AnsiMsg
, LPMSG UnicodeMsg
, LRESULT
*Result
)
1280 LPSTR Buffer
= (LPSTR
) AnsiMsg
->lParam
;
1281 LPWSTR UBuffer
= (LPWSTR
) UnicodeMsg
->lParam
;
1283 switch (UnicodeMsg
->message
)
1286 case WM_ASKCBFORMATNAME
:
1288 DWORD len
= AnsiMsg
->wParam
* 2;
1293 RtlMultiByteToUnicodeN( UBuffer
, AnsiMsg
->wParam
*sizeof(WCHAR
), &len
, Buffer
, strlen(Buffer
)+1 );
1294 *Result
= len
/sizeof(WCHAR
) - 1; /* do not count terminating null */
1296 UBuffer
[*Result
] = 0;
1302 if (!UBuffer
|| !listbox_has_strings( UnicodeMsg
->hwnd
)) break;
1306 RtlMultiByteToUnicodeN( UBuffer
, ~0u, &len
, Buffer
, strlen(Buffer
) + 1 );
1307 *Result
= len
/ sizeof(WCHAR
) - 1;
1313 if (!UBuffer
|| !combobox_has_strings( UnicodeMsg
->hwnd
)) break;
1317 RtlMultiByteToUnicodeN( UBuffer
, ~0u, &len
, Buffer
, strlen(Buffer
) + 1 );
1318 *Result
= len
/ sizeof(WCHAR
) - 1;
1324 MsgiUnicodeToAnsiCleanup(AnsiMsg
, UnicodeMsg
);
1332 DesktopWndProcA( HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1337 TRACE("Desktop A Class Atom! hWnd 0x%x, Msg %d\n", hwnd
, message
);
1339 AnsiMsg
.hwnd
= hwnd
;
1340 AnsiMsg
.message
= message
;
1341 AnsiMsg
.wParam
= wParam
;
1342 AnsiMsg
.lParam
= lParam
;
1344 // Desktop is always Unicode so convert Ansi here.
1345 if (!MsgiAnsiToUnicodeMessage(hwnd
, &UcMsg
, &AnsiMsg
))
1350 Result
= DesktopWndProcW(hwnd
, message
, UcMsg
.wParam
, UcMsg
.lParam
);
1352 MsgiAnsiToUnicodeCleanup(&UcMsg
, &AnsiMsg
);
1362 GetMessageExtraInfo(VOID
)
1364 return NtUserxGetMessageExtraInfo();
1375 return NtUserxGetMessagePos();
1383 GetMessageTime(VOID
)
1385 return NtUserGetThreadState(THREADSTATE_GETMESSAGETIME
);
1396 PCLIENTTHREADINFO pcti
= GetWin32ClientInfo()->pClientThreadInfo
;
1399 if (pcti
->CTI_flags
& CTI_INSENDMESSAGE
)
1404 return(NtUserGetThreadState(THREADSTATE_INSENDMESSAGE
) != ISMEX_NOSEND
);
1416 PCLIENTTHREADINFO pcti
= GetWin32ClientInfo()->pClientThreadInfo
;
1417 if (pcti
&& !(pcti
->CTI_flags
& CTI_INSENDMESSAGE
))
1418 return ISMEX_NOSEND
;
1420 return NtUserGetThreadState(THREADSTATE_INSENDMESSAGE
);
1429 ReplyMessage(LRESULT lResult
)
1431 return NtUserxReplyMessage(lResult
);
1440 SetMessageExtraInfo(
1443 return NtUserxSetMessageExtraInfo(lParam
);
1447 IntCallWindowProcW(BOOL IsAnsiProc
,
1457 BOOL Hook
= FALSE
, MsgOverride
= FALSE
, Dialog
;
1458 LRESULT Result
= 0, PreResult
= 0;
1461 if (WndProc
== NULL
)
1463 WARN("IntCallWindowsProcW() called with WndProc = NULL!\n");
1468 Dialog
= (pWnd
->fnid
== FNID_DIALOG
);
1472 Hook
= BeginIfHookedUserApiHook();
1476 MsgOverride
= IsMsgOverride( Msg
, &guah
.WndProcArray
);
1478 MsgOverride
= IsMsgOverride( Msg
, &guah
.DlgProcArray
);
1483 UnicodeMsg
.hwnd
= hWnd
;
1484 UnicodeMsg
.message
= Msg
;
1485 UnicodeMsg
.wParam
= wParam
;
1486 UnicodeMsg
.lParam
= lParam
;
1487 if (! MsgiUnicodeToAnsiMessage(hWnd
, &AnsiMsg
, &UnicodeMsg
))
1492 if (Hook
&& MsgOverride
)
1497 PreResult
= guah
.PreWndProc(AnsiMsg
.hwnd
, AnsiMsg
.message
, AnsiMsg
.wParam
, AnsiMsg
.lParam
, (ULONG_PTR
)&Result
, &Data
);
1499 PreResult
= guah
.PreDefDlgProc(AnsiMsg
.hwnd
, AnsiMsg
.message
, AnsiMsg
.wParam
, AnsiMsg
.lParam
, (ULONG_PTR
)&Result
, &Data
);
1501 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1507 if (PreResult
) goto Exit
;
1509 _SEH2_TRY
// wine does this.
1511 Result
= WndProc(AnsiMsg
.hwnd
, AnsiMsg
.message
, AnsiMsg
.wParam
, AnsiMsg
.lParam
);
1513 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1515 ERR("Exception when calling Ansi WndProc %p Msg %d pti %p Wndpti %p\n",WndProc
,Msg
,GetW32ThreadInfo(),pWnd
->head
.pti
);
1519 if (Hook
&& MsgOverride
)
1524 guah
.PostWndProc(AnsiMsg
.hwnd
, AnsiMsg
.message
, AnsiMsg
.wParam
, AnsiMsg
.lParam
, (ULONG_PTR
)&Result
, &Data
);
1526 guah
.PostDefDlgProc(AnsiMsg
.hwnd
, AnsiMsg
.message
, AnsiMsg
.wParam
, AnsiMsg
.lParam
, (ULONG_PTR
)&Result
, &Data
);
1528 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1534 if (! MsgiUnicodeToAnsiReply(&AnsiMsg
, &UnicodeMsg
, &Result
))
1541 if (Hook
&& MsgOverride
)
1546 PreResult
= guah
.PreWndProc(hWnd
, Msg
, wParam
, lParam
, (ULONG_PTR
)&Result
, &Data
);
1548 PreResult
= guah
.PreDefDlgProc(hWnd
, Msg
, wParam
, lParam
, (ULONG_PTR
)&Result
, &Data
);
1550 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1556 if (PreResult
) goto Exit
;
1560 Result
= WndProc(hWnd
, Msg
, wParam
, lParam
);
1562 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1564 ERR("Exception when calling unicode WndProc %p Msg %d pti %p Wndpti %p\n",WndProc
, Msg
,GetW32ThreadInfo(),pWnd
->head
.pti
);
1568 if (Hook
&& MsgOverride
)
1573 guah
.PostWndProc(hWnd
, Msg
, wParam
, lParam
, (ULONG_PTR
)&Result
, &Data
);
1575 guah
.PostDefDlgProc(hWnd
, Msg
, wParam
, lParam
, (ULONG_PTR
)&Result
, &Data
);
1577 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1585 if (Hook
) EndUserApiHook();
1589 static LRESULT FASTCALL
1590 IntCallWindowProcA(BOOL IsAnsiProc
,
1600 //ULONG_PTR LowLimit;
1601 BOOL Hook
= FALSE
, MsgOverride
= FALSE
, Dialog
;
1602 LRESULT Result
= 0, PreResult
= 0;
1605 if (WndProc
== NULL
)
1607 WARN("IntCallWindowsProcA() called with WndProc = NULL!\n");
1611 LowLimit
= (ULONG_PTR
)NtCurrentTeb()->NtTib
.StackLimit
;
1612 if (((ULONG_PTR
)&lParam
- LowLimit
) < PAGE_SIZE
)
1614 ERR("IntCallWindowsProcA() Exceeded Stack!\n");
1619 Dialog
= (pWnd
->fnid
== FNID_DIALOG
);
1623 Hook
= BeginIfHookedUserApiHook();
1627 MsgOverride
= IsMsgOverride( Msg
, &guah
.WndProcArray
);
1629 MsgOverride
= IsMsgOverride( Msg
, &guah
.DlgProcArray
);
1634 if (Hook
&& MsgOverride
)
1639 PreResult
= guah
.PreWndProc(hWnd
, Msg
, wParam
, lParam
, (ULONG_PTR
)&Result
, &Data
);
1641 PreResult
= guah
.PreDefDlgProc(hWnd
, Msg
, wParam
, lParam
, (ULONG_PTR
)&Result
, &Data
);
1643 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1649 if (PreResult
) goto Exit
;
1653 Result
= WndProc(hWnd
, Msg
, wParam
, lParam
);
1655 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1657 ERR("Exception when calling Ansi WndProc %p Msg %d pti %p Wndpti %p\n",WndProc
,Msg
,GetW32ThreadInfo(),pWnd
->head
.pti
);
1661 if (Hook
&& MsgOverride
)
1666 guah
.PostWndProc(hWnd
, Msg
, wParam
, lParam
, (ULONG_PTR
)&Result
, &Data
);
1668 guah
.PostDefDlgProc(hWnd
, Msg
, wParam
, lParam
, (ULONG_PTR
)&Result
, &Data
);
1670 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1678 AnsiMsg
.hwnd
= hWnd
;
1679 AnsiMsg
.message
= Msg
;
1680 AnsiMsg
.wParam
= wParam
;
1681 AnsiMsg
.lParam
= lParam
;
1682 if (! MsgiAnsiToUnicodeMessage(hWnd
, &UnicodeMsg
, &AnsiMsg
))
1687 if (Hook
&& MsgOverride
)
1692 PreResult
= guah
.PreWndProc(UnicodeMsg
.hwnd
, UnicodeMsg
.message
, UnicodeMsg
.wParam
, UnicodeMsg
.lParam
, (ULONG_PTR
)&Result
, &Data
);
1694 PreResult
= guah
.PreDefDlgProc(UnicodeMsg
.hwnd
, UnicodeMsg
.message
, UnicodeMsg
.wParam
, UnicodeMsg
.lParam
, (ULONG_PTR
)&Result
, &Data
);
1696 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1702 if (PreResult
) goto Exit
;
1706 Result
= WndProc(UnicodeMsg
.hwnd
, UnicodeMsg
.message
,
1707 UnicodeMsg
.wParam
, UnicodeMsg
.lParam
);
1709 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1711 ERR("Exception when calling unicode WndProc %p Msg %d pti %p Wndpti %p\n",WndProc
, Msg
,GetW32ThreadInfo(),pWnd
->head
.pti
);
1715 if (Hook
&& MsgOverride
)
1720 guah
.PostWndProc(UnicodeMsg
.hwnd
, UnicodeMsg
.message
, UnicodeMsg
.wParam
, UnicodeMsg
.lParam
, (ULONG_PTR
)&Result
, &Data
);
1722 guah
.PostDefDlgProc(UnicodeMsg
.hwnd
, UnicodeMsg
.message
, UnicodeMsg
.wParam
, UnicodeMsg
.lParam
, (ULONG_PTR
)&Result
, &Data
);
1724 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1730 if (! MsgiAnsiToUnicodeReply(&UnicodeMsg
, &AnsiMsg
, &Result
))
1737 if (Hook
) EndUserApiHook();
1742 static LRESULT WINAPI
1743 IntCallMessageProc(IN PWND Wnd
, IN HWND hWnd
, IN UINT Msg
, IN WPARAM wParam
, IN LPARAM lParam
, IN BOOL Ansi
)
1749 Class
= DesktopPtrToUser(Wnd
->pcls
);
1752 if ( Wnd
->head
.pti
!= GetW32ThreadInfo())
1753 { // Must be inside the same thread!
1754 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
1758 This is the message exchange for user32. If there's a need to monitor messages,
1761 TRACE("HWND %p, MSG %u, WPARAM %p, LPARAM %p, Ansi %d\n", hWnd
, Msg
, wParam
, lParam
, Ansi
);
1762 // if (Class->fnid <= FNID_GHOST && Class->fnid >= FNID_BUTTON )
1763 if (Class
->fnid
<= FNID_GHOST
&& Class
->fnid
>= FNID_FIRST
)
1767 if (GETPFNCLIENTW(Class
->fnid
) == Wnd
->lpfnWndProc
)
1768 WndProc
= GETPFNCLIENTA(Class
->fnid
);
1772 if (GETPFNCLIENTA(Class
->fnid
) == Wnd
->lpfnWndProc
)
1773 WndProc
= GETPFNCLIENTW(Class
->fnid
);
1780 IsAnsi
= !Wnd
->Unicode
;
1781 WndProc
= Wnd
->lpfnWndProc
;
1786 IsAnsi
= !Wnd
->Unicode
;
1787 WndProc
= Wnd
->lpfnWndProc
;
1790 Message caller can be Ansi/Unicode and the receiver can be Unicode/Ansi or
1794 return IntCallWindowProcW(IsAnsi
, WndProc
, Wnd
, hWnd
, Msg
, wParam
, lParam
);
1796 return IntCallWindowProcA(IsAnsi
, WndProc
, Wnd
, hWnd
, Msg
, wParam
, lParam
);
1804 CallWindowProcA(WNDPROC lpPrevWndFunc
,
1811 PCALLPROCDATA CallProc
;
1813 if (lpPrevWndFunc
== NULL
)
1815 WARN("CallWindowProcA: lpPrevWndFunc == NULL!\n");
1819 pWnd
= ValidateHwnd(hWnd
);
1821 if (!IsCallProcHandle(lpPrevWndFunc
))
1822 return IntCallWindowProcA(TRUE
, lpPrevWndFunc
, pWnd
, hWnd
, Msg
, wParam
, lParam
);
1825 CallProc
= ValidateCallProc((HANDLE
)lpPrevWndFunc
);
1826 if (CallProc
!= NULL
)
1828 return IntCallWindowProcA(!(CallProc
->wType
& UserGetCPDA2U
),
1829 CallProc
->pfnClientPrevious
,
1838 WARN("CallWindowProcA: can not dereference WndProcHandle\n");
1849 CallWindowProcW(WNDPROC lpPrevWndFunc
,
1856 PCALLPROCDATA CallProc
;
1858 /* FIXME - can the first parameter be NULL? */
1859 if (lpPrevWndFunc
== NULL
)
1861 WARN("CallWindowProcA: lpPrevWndFunc == NULL!\n");
1865 pWnd
= ValidateHwnd(hWnd
);
1867 if (!IsCallProcHandle(lpPrevWndFunc
))
1868 return IntCallWindowProcW(FALSE
, lpPrevWndFunc
, pWnd
, hWnd
, Msg
, wParam
, lParam
);
1871 CallProc
= ValidateCallProc((HANDLE
)lpPrevWndFunc
);
1872 if (CallProc
!= NULL
)
1874 return IntCallWindowProcW(!(CallProc
->wType
& UserGetCPDA2U
),
1875 CallProc
->pfnClientPrevious
,
1884 WARN("CallWindowProcW: can not dereference WndProcHandle\n");
1895 DispatchMessageA(CONST MSG
*lpmsg
)
1902 if ( lpmsg
->message
& ~WM_MAXIMUM
)
1904 SetLastError( ERROR_INVALID_PARAMETER
);
1908 if (lpmsg
->hwnd
!= NULL
)
1910 Wnd
= ValidateHwnd(lpmsg
->hwnd
);
1916 if (is_pointer_message(lpmsg
->message
))
1918 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
1922 if ((lpmsg
->message
== WM_TIMER
|| lpmsg
->message
== WM_SYSTIMER
) && lpmsg
->lParam
!= 0)
1924 WNDPROC WndProc
= (WNDPROC
)lpmsg
->lParam
;
1926 if ( lpmsg
->message
== WM_SYSTIMER
)
1927 return NtUserDispatchMessage( (PMSG
)lpmsg
);
1929 if (!NtUserValidateTimerCallback(lpmsg
->hwnd
, lpmsg
->wParam
, lpmsg
->lParam
))
1931 WARN("Validating Timer Callback failed!\n");
1935 _SEH2_TRY
// wine does this. Hint: Prevents call to another thread....
1937 Ret
= WndProc(lpmsg
->hwnd
,
1942 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1948 else if (Wnd
!= NULL
)
1950 if ( (lpmsg
->message
!= WM_PAINT
) && !(Wnd
->state
& WNDS_SERVERSIDEWINDOWPROC
) )
1952 Ret
= IntCallMessageProc(Wnd
,
1961 if (!MsgiAnsiToUnicodeMessage(lpmsg
->hwnd
, &UnicodeMsg
, (LPMSG
)lpmsg
))
1966 Ret
= NtUserDispatchMessage(&UnicodeMsg
);
1968 if (!MsgiAnsiToUnicodeReply(&UnicodeMsg
, (LPMSG
)lpmsg
, &Ret
))
1977 WARN("Exception in Timer Callback WndProcA!\n");
1987 DispatchMessageW(CONST MSG
*lpmsg
)
1993 if ( lpmsg
->message
& ~WM_MAXIMUM
)
1995 SetLastError( ERROR_INVALID_PARAMETER
);
1999 if (lpmsg
->hwnd
!= NULL
)
2001 Wnd
= ValidateHwnd(lpmsg
->hwnd
);
2007 if (is_pointer_message(lpmsg
->message
))
2009 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
2013 if ((lpmsg
->message
== WM_TIMER
|| lpmsg
->message
== WM_SYSTIMER
) && lpmsg
->lParam
!= 0)
2015 WNDPROC WndProc
= (WNDPROC
)lpmsg
->lParam
;
2017 if ( lpmsg
->message
== WM_SYSTIMER
)
2018 return NtUserDispatchMessage( (PMSG
) lpmsg
);
2020 if (!NtUserValidateTimerCallback(lpmsg
->hwnd
, lpmsg
->wParam
, lpmsg
->lParam
))
2022 WARN("Validating Timer Callback failed!\n");
2028 Ret
= WndProc(lpmsg
->hwnd
,
2033 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2039 else if (Wnd
!= NULL
)
2041 if ( (lpmsg
->message
!= WM_PAINT
) && !(Wnd
->state
& WNDS_SERVERSIDEWINDOWPROC
) )
2043 Ret
= IntCallMessageProc(Wnd
,
2051 Ret
= NtUserDispatchMessage( (PMSG
) lpmsg
);
2056 WARN("Exception in Timer Callback WndProcW!\n");
2062 IntConvertMsgToAnsi(LPMSG lpMsg
)
2067 switch (lpMsg
->message
)
2072 case WM_SYSDEADCHAR
:
2074 wch
[0] = LOWORD(lpMsg
->wParam
);
2075 wch
[1] = HIWORD(lpMsg
->wParam
);
2077 WideCharToMultiByte(CP_THREAD_ACP
, 0, wch
, 2, ch
, 2, NULL
, NULL
);
2078 lpMsg
->wParam
= MAKEWPARAM(ch
[0] | (ch
[1] << 8), 0);
2087 GetMessageA(LPMSG lpMsg
,
2094 if ( (wMsgFilterMin
|wMsgFilterMax
) & ~WM_MAXIMUM
)
2096 SetLastError( ERROR_INVALID_PARAMETER
);
2100 Res
= NtUserGetMessage(lpMsg
, hWnd
, wMsgFilterMin
, wMsgFilterMax
);
2101 if (-1 == (int) Res
)
2106 IntConvertMsgToAnsi(lpMsg
);
2115 GetMessageW(LPMSG lpMsg
,
2122 if ( (wMsgFilterMin
|wMsgFilterMax
) & ~WM_MAXIMUM
)
2124 SetLastError( ERROR_INVALID_PARAMETER
);
2128 Res
= NtUserGetMessage(lpMsg
, hWnd
, wMsgFilterMin
, wMsgFilterMax
);
2129 if (-1 == (int) Res
)
2138 PeekMessageWorker( PMSG pMsg
,
2145 PCLIENTTHREADINFO pcti
;
2146 pci
= GetWin32ClientInfo();
2147 pcti
= pci
->pClientThreadInfo
;
2149 if (!hWnd
&& pci
&& pcti
)
2153 if ((pci
->cSpins
>= 100) && (pci
->dwTIFlags
& TIF_SPINNING
))
2154 { // Yield after 100 spin cycles and ready to swap vinyl.
2155 if (!(pci
->dwTIFlags
& TIF_WAITFORINPUTIDLE
))
2156 { // Not waiting for idle event.
2157 if (!pcti
->fsChangeBits
&& !pcti
->fsWakeBits
)
2158 { // No messages are available.
2159 if ((GetTickCount() - pcti
->tickLastMsgChecked
) > 1000)
2160 { // Up the msg read count if over 1 sec.
2161 NtUserGetThreadState(THREADSTATE_UPTIMELASTREAD
);
2165 FIXME("seeSpins!\n");
2171 return NtUserPeekMessage(pMsg
, hWnd
, wMsgFilterMin
, wMsgFilterMax
, wRemoveMsg
);
2178 PeekMessageA(LPMSG lpMsg
,
2186 Res
= PeekMessageWorker(lpMsg
, hWnd
, wMsgFilterMin
, wMsgFilterMax
, wRemoveMsg
);
2187 if (-1 == (int) Res
|| !Res
)
2192 IntConvertMsgToAnsi(lpMsg
);
2212 Res
= PeekMessageWorker(lpMsg
, hWnd
, wMsgFilterMin
, wMsgFilterMax
, wRemoveMsg
);
2213 if (-1 == (int) Res
|| !Res
)
2234 /* Check for combo box or a list box to send names. */
2235 if (Msg
== CB_DIR
|| Msg
== LB_DIR
)
2238 Set DDL_POSTMSGS, so use the PostMessage function to send messages to the
2239 combo/list box. Forces a call like DlgDirListComboBox.
2241 //wParam |= DDL_POSTMSGS;
2242 return NtUserPostMessage(hWnd
, Msg
, wParam
, lParam
);
2245 /* No drop files or current Process, just post message. */
2246 if ( (Msg
!= WM_DROPFILES
) ||
2247 ( NtUserQueryWindow( hWnd
, QUERY_WINDOW_UNIQUE_PROCESS_ID
) ==
2248 PtrToUint(NtCurrentTeb()->ClientId
.UniqueProcess
) ) )
2250 return NtUserPostMessage(hWnd
, Msg
, wParam
, lParam
);
2253 /* We have drop files and this is not the same process for this window. */
2255 /* Just incase, check wParam for Global memory handle and send size. */
2256 Ret
= SendMessageA( hWnd
,
2258 (WPARAM
)GlobalSize((HGLOBAL
)wParam
), // Zero if not a handle.
2259 (LPARAM
)wParam
); // Send wParam as lParam.
2261 if ( Ret
) return NtUserPostMessage(hWnd
, Msg
, (WPARAM
)Ret
, lParam
);
2279 /* Check for combo box or a list box to send names. */
2280 if (Msg
== CB_DIR
|| Msg
== LB_DIR
)
2283 Set DDL_POSTMSGS, so use the PostMessage function to send messages to the
2284 combo/list box. Forces a call like DlgDirListComboBox.
2286 //wParam |= DDL_POSTMSGS;
2287 return NtUserPostMessage(hWnd
, Msg
, wParam
, lParam
);
2290 /* No drop files or current Process, just post message. */
2291 if ( (Msg
!= WM_DROPFILES
) ||
2292 ( NtUserQueryWindow( hWnd
, QUERY_WINDOW_UNIQUE_PROCESS_ID
) ==
2293 PtrToUint(NtCurrentTeb()->ClientId
.UniqueProcess
) ) )
2295 return NtUserPostMessage(hWnd
, Msg
, wParam
, lParam
);
2298 /* We have drop files and this is not the same process for this window. */
2300 /* Just incase, check wParam for Global memory handle and send size. */
2301 Ret
= SendMessageW( hWnd
,
2303 (WPARAM
)GlobalSize((HGLOBAL
)wParam
), // Zero if not a handle.
2304 (LPARAM
)wParam
); // Send wParam as lParam.
2306 if ( Ret
) return NtUserPostMessage(hWnd
, Msg
, (WPARAM
)Ret
, lParam
);
2319 NtUserxPostQuitMessage(nExitCode
);
2334 return NtUserPostThreadMessage(idThread
, Msg
, wParam
, lParam
);
2349 return NtUserPostThreadMessage(idThread
, Msg
, wParam
, lParam
);
2357 SendMessageW(HWND Wnd
,
2365 PTHREADINFO ti
= GetW32ThreadInfo();
2367 if ( Msg
& ~WM_MAXIMUM
)
2369 SetLastError( ERROR_INVALID_PARAMETER
);
2373 if (Wnd
!= HWND_TOPMOST
&& Wnd
!= HWND_BROADCAST
&& (Msg
< WM_DDE_FIRST
|| Msg
> WM_DDE_LAST
))
2375 Window
= ValidateHwnd(Wnd
);
2377 if ( Window
!= NULL
&&
2378 Window
->head
.pti
== ti
&&
2379 !IsThreadHooked(GetWin32ClientInfo()) && // This is why HOOKs are bad! They slow the system down!
2380 !(Window
->state
& WNDS_SERVERSIDEWINDOWPROC
) )
2382 /* NOTE: We can directly send messages to the window procedure
2383 if *all* the following conditions are met:
2385 * Window belongs to calling thread
2386 * The calling thread is not being hooked for CallWndProc
2387 * Not calling a server side proc:
2388 Desktop, Switch, ScrollBar, Menu, IconTitle, or hWndMessage
2391 return IntCallMessageProc(Window
, Wnd
, Msg
, wParam
, lParam
, FALSE
);
2396 UMMsg
.message
= Msg
;
2397 UMMsg
.wParam
= wParam
;
2398 UMMsg
.lParam
= lParam
;
2400 if (! MsgiUMToKMMessage(&UMMsg
, &KMMsg
, FALSE
))
2405 Result
= NtUserMessageCall( Wnd
,
2413 MsgiUMToKMCleanup(&UMMsg
, &KMMsg
);
2423 SendMessageA(HWND Wnd
, UINT Msg
, WPARAM wParam
, LPARAM lParam
)
2425 MSG AnsiMsg
, UcMsg
, KMMsg
;
2428 PTHREADINFO ti
= GetW32ThreadInfo();
2430 if ( Msg
& ~WM_MAXIMUM
)
2432 SetLastError( ERROR_INVALID_PARAMETER
);
2436 if (Wnd
!= HWND_TOPMOST
&& Wnd
!= HWND_BROADCAST
&& (Msg
< WM_DDE_FIRST
|| Msg
> WM_DDE_LAST
))
2438 Window
= ValidateHwnd(Wnd
);
2440 if ( Window
!= NULL
&&
2441 Window
->head
.pti
== ti
&&
2442 !IsThreadHooked(GetWin32ClientInfo()) && // This is why HOOKs are bad! They slow the system down!
2443 !(Window
->state
& WNDS_SERVERSIDEWINDOWPROC
) )
2445 /* NOTE: We can directly send messages to the window procedure
2446 if *all* the following conditions are met:
2448 * Window belongs to calling thread
2449 * The calling thread is not being hooked for CallWndProc
2450 * Not calling a server side proc:
2451 Desktop, Switch, ScrollBar, Menu, IconTitle, or hWndMessage
2454 return IntCallMessageProc(Window
, Wnd
, Msg
, wParam
, lParam
, TRUE
);
2459 AnsiMsg
.message
= Msg
;
2460 AnsiMsg
.wParam
= wParam
;
2461 AnsiMsg
.lParam
= lParam
;
2463 if (!MsgiAnsiToUnicodeMessage(Wnd
, &UcMsg
, &AnsiMsg
))
2468 if (!MsgiUMToKMMessage(&UcMsg
, &KMMsg
, FALSE
))
2470 MsgiAnsiToUnicodeCleanup(&UcMsg
, &AnsiMsg
);
2474 Result
= NtUserMessageCall( Wnd
,
2482 MsgiUMToKMCleanup(&UcMsg
, &KMMsg
);
2483 MsgiAnsiToUnicodeReply(&UcMsg
, &AnsiMsg
, &Result
);
2493 SendMessageCallbackA(
2498 SENDASYNCPROC lpCallBack
,
2503 CALL_BACK_INFO CallBackInfo
;
2505 if (is_pointer_message(Msg
))
2507 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
2511 CallBackInfo
.CallBack
= lpCallBack
;
2512 CallBackInfo
.Context
= dwData
;
2514 AnsiMsg
.hwnd
= hWnd
;
2515 AnsiMsg
.message
= Msg
;
2516 AnsiMsg
.wParam
= wParam
;
2517 AnsiMsg
.lParam
= lParam
;
2519 if (!MsgiAnsiToUnicodeMessage(hWnd
, &UcMsg
, &AnsiMsg
))
2524 Result
= NtUserMessageCall( hWnd
,
2528 (ULONG_PTR
)&CallBackInfo
,
2529 FNID_SENDMESSAGECALLBACK
,
2532 MsgiAnsiToUnicodeCleanup(&UcMsg
, &AnsiMsg
);
2542 SendMessageCallbackW(
2547 SENDASYNCPROC lpCallBack
,
2550 CALL_BACK_INFO CallBackInfo
;
2552 if (is_pointer_message(Msg
))
2554 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
2558 CallBackInfo
.CallBack
= lpCallBack
;
2559 CallBackInfo
.Context
= dwData
;
2561 return NtUserMessageCall(hWnd
,
2565 (ULONG_PTR
)&CallBackInfo
,
2566 FNID_SENDMESSAGECALLBACK
,
2575 SendMessageTimeoutA(
2582 PDWORD_PTR lpdwResult
)
2588 if ( Msg
& ~WM_MAXIMUM
|| fuFlags
& ~(SMTO_NOTIMEOUTIFNOTHUNG
|SMTO_ABORTIFHUNG
|SMTO_BLOCK
))
2590 SetLastError( ERROR_INVALID_PARAMETER
);
2594 if (lpdwResult
) *lpdwResult
= 0;
2596 SPY_EnterMessage(SPY_SENDMESSAGE
, hWnd
, Msg
, wParam
, lParam
);
2598 dsm
.uFlags
= fuFlags
;
2599 dsm
.uTimeout
= uTimeout
;
2601 AnsiMsg
.hwnd
= hWnd
;
2602 AnsiMsg
.message
= Msg
;
2603 AnsiMsg
.wParam
= wParam
;
2604 AnsiMsg
.lParam
= lParam
;
2606 if (! MsgiAnsiToUnicodeMessage(hWnd
, &UcMsg
, &AnsiMsg
))
2611 Result
= NtUserMessageCall( hWnd
,
2616 FNID_SENDMESSAGEWTOOPTION
,
2619 MsgiAnsiToUnicodeReply(&UcMsg
, &AnsiMsg
, &Result
);
2621 if (lpdwResult
) *lpdwResult
= dsm
.Result
;
2623 SPY_ExitMessage(SPY_RESULT_OK
, hWnd
, Msg
, Result
, wParam
, lParam
);
2634 SendMessageTimeoutW(
2641 PDWORD_PTR lpdwResult
)
2646 if ( Msg
& ~WM_MAXIMUM
|| fuFlags
& ~(SMTO_NOTIMEOUTIFNOTHUNG
|SMTO_ABORTIFHUNG
|SMTO_BLOCK
))
2648 SetLastError( ERROR_INVALID_PARAMETER
);
2652 if (lpdwResult
) *lpdwResult
= 0;
2654 SPY_EnterMessage(SPY_SENDMESSAGE
, hWnd
, Msg
, wParam
, lParam
);
2656 dsm
.uFlags
= fuFlags
;
2657 dsm
.uTimeout
= uTimeout
;
2659 Result
= NtUserMessageCall( hWnd
,
2664 FNID_SENDMESSAGEWTOOPTION
,
2667 if (lpdwResult
) *lpdwResult
= dsm
.Result
;
2669 SPY_ExitMessage(SPY_RESULT_OK
, hWnd
, Msg
, Result
, wParam
, lParam
);
2688 if (is_pointer_message(Msg
))
2690 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
2694 AnsiMsg
.hwnd
= hWnd
;
2695 AnsiMsg
.message
= Msg
;
2696 AnsiMsg
.wParam
= wParam
;
2697 AnsiMsg
.lParam
= lParam
;
2698 if (! MsgiAnsiToUnicodeMessage(hWnd
, &UcMsg
, &AnsiMsg
))
2702 Ret
= SendNotifyMessageW(hWnd
, UcMsg
.message
, UcMsg
.wParam
, UcMsg
.lParam
);
2704 MsgiAnsiToUnicodeCleanup(&UcMsg
, &AnsiMsg
);
2723 if (is_pointer_message(Msg
))
2725 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
2730 UMMsg
.message
= Msg
;
2731 UMMsg
.wParam
= wParam
;
2732 UMMsg
.lParam
= lParam
;
2733 if (! MsgiUMToKMMessage(&UMMsg
, &KMMsg
, TRUE
))
2737 Result
= NtUserMessageCall( hWnd
,
2742 FNID_SENDNOTIFYMESSAGE
,
2745 MsgiUMToKMCleanup(&UMMsg
, &KMMsg
);
2754 TranslateMessageEx(CONST MSG
*lpMsg
, UINT Flags
)
2756 switch (lpMsg
->message
)
2762 return(NtUserTranslateMessage((LPMSG
)lpMsg
, Flags
));
2765 if ( lpMsg
->message
& ~WM_MAXIMUM
)
2766 SetLastError(ERROR_INVALID_PARAMETER
);
2776 TranslateMessage(CONST MSG
*lpMsg
)
2780 // Ref: msdn ImmGetVirtualKey:
2781 // http://msdn.microsoft.com/en-us/library/aa912145.aspx
2783 if ( (LOWORD(lpMsg->wParam) != VK_PROCESSKEY) ||
2784 !(Ret = IMM_ImmTranslateMessage( lpMsg->hwnd,
2789 Ret
= TranslateMessageEx((LPMSG
)lpMsg
, 0);
2799 RegisterWindowMessageA(LPCSTR lpString
)
2801 UNICODE_STRING String
;
2804 if (!RtlCreateUnicodeStringFromAsciiz(&String
, (PCSZ
)lpString
))
2808 Atom
= NtUserRegisterWindowMessage(&String
);
2809 RtlFreeUnicodeString(&String
);
2818 RegisterWindowMessageW(LPCWSTR lpString
)
2820 UNICODE_STRING String
;
2822 RtlInitUnicodeString(&String
, lpString
);
2823 return(NtUserRegisterWindowMessage(&String
));
2832 return (HWND
)NtUserGetThreadState(THREADSTATE_CAPTUREWINDOW
);
2839 ReleaseCapture(VOID
)
2841 return NtUserxReleaseCapture();
2850 RealGetQueueStatus(UINT flags
)
2852 #define QS_TEMPALLINPUT 255 // ATM, do not support QS_RAWINPUT
2853 if (flags
& ~(QS_SMRESULT
|QS_ALLPOSTMESSAGE
|QS_TEMPALLINPUT
))
2855 SetLastError( ERROR_INVALID_FLAGS
);
2858 return NtUserxGetQueueStatus(flags
);
2865 BOOL WINAPI
GetInputState(VOID
)
2867 PCLIENTTHREADINFO pcti
= GetWin32ClientInfo()->pClientThreadInfo
;
2869 if ((!pcti
) || (pcti
->fsChangeBits
& (QS_KEY
|QS_MOUSEBUTTON
)))
2870 return (BOOL
)NtUserGetThreadState(THREADSTATE_GETINPUTSTATE
);
2877 User32CallWindowProcFromKernel(PVOID Arguments
, ULONG ArgumentLength
)
2879 PWINDOWPROC_CALLBACK_ARGUMENTS CallbackArgs
;
2882 PCLIENTINFO pci
= GetWin32ClientInfo();
2884 /* Make sure we don't try to access mem beyond what we were given */
2885 if (ArgumentLength
< sizeof(WINDOWPROC_CALLBACK_ARGUMENTS
))
2887 return STATUS_INFO_LENGTH_MISMATCH
;
2890 CallbackArgs
= (PWINDOWPROC_CALLBACK_ARGUMENTS
) Arguments
;
2891 KMMsg
.hwnd
= CallbackArgs
->Wnd
;
2892 KMMsg
.message
= CallbackArgs
->Msg
;
2893 KMMsg
.wParam
= CallbackArgs
->wParam
;
2894 /* Check if lParam is really a pointer and adjust it if it is */
2895 if (0 <= CallbackArgs
->lParamBufferSize
)
2897 if (ArgumentLength
!= sizeof(WINDOWPROC_CALLBACK_ARGUMENTS
)
2898 + CallbackArgs
->lParamBufferSize
)
2900 return STATUS_INFO_LENGTH_MISMATCH
;
2902 KMMsg
.lParam
= (LPARAM
) ((char *) CallbackArgs
+ sizeof(WINDOWPROC_CALLBACK_ARGUMENTS
));
2906 if (ArgumentLength
!= sizeof(WINDOWPROC_CALLBACK_ARGUMENTS
))
2908 return STATUS_INFO_LENGTH_MISMATCH
;
2910 KMMsg
.lParam
= CallbackArgs
->lParam
;
2913 if (WM_NCCALCSIZE
== CallbackArgs
->Msg
&& CallbackArgs
->wParam
)
2915 NCCALCSIZE_PARAMS
*Params
= (NCCALCSIZE_PARAMS
*) KMMsg
.lParam
;
2916 Params
->lppos
= (PWINDOWPOS
) (Params
+ 1);
2919 if (! MsgiKMToUMMessage(&KMMsg
, &UMMsg
))
2923 if (pci
->CallbackWnd
.hWnd
== UMMsg
.hwnd
)
2924 pWnd
= pci
->CallbackWnd
.pWnd
;
2926 CallbackArgs
->Result
= IntCallWindowProcW( CallbackArgs
->IsAnsiProc
,
2934 if (! MsgiKMToUMReply(&KMMsg
, &UMMsg
, &CallbackArgs
->Result
))
2938 return ZwCallbackReturn(CallbackArgs
, ArgumentLength
, STATUS_SUCCESS
);
2944 BOOL WINAPI
SetMessageQueue(int cMessagesMax
)
2946 /* Function does nothing on 32 bit windows */
2949 typedef DWORD (WINAPI
* RealGetQueueStatusProc
)(UINT flags
);
2950 typedef DWORD (WINAPI
* RealMsgWaitForMultipleObjectsExProc
)(DWORD nCount
, CONST HANDLE
*lpHandles
, DWORD dwMilliseconds
, DWORD dwWakeMask
, DWORD dwFlags
);
2951 typedef BOOL (WINAPI
* RealInternalGetMessageProc
)(LPMSG
,HWND
,UINT
,UINT
,UINT
,BOOL
);
2952 typedef BOOL (WINAPI
* RealWaitMessageExProc
)(DWORD
,UINT
);
2954 typedef struct _USER_MESSAGE_PUMP_ADDRESSES
{
2956 RealInternalGetMessageProc NtUserRealInternalGetMessage
;
2957 RealWaitMessageExProc NtUserRealWaitMessageEx
;
2958 RealGetQueueStatusProc RealGetQueueStatus
;
2959 RealMsgWaitForMultipleObjectsExProc RealMsgWaitForMultipleObjectsEx
;
2960 } USER_MESSAGE_PUMP_ADDRESSES
, * PUSER_MESSAGE_PUMP_ADDRESSES
;
2964 RealMsgWaitForMultipleObjectsEx(
2966 CONST HANDLE
*pHandles
,
2967 DWORD dwMilliseconds
,
2971 typedef BOOL (WINAPI
* MESSAGEPUMPHOOKPROC
)(BOOL Unregistering
,PUSER_MESSAGE_PUMP_ADDRESSES MessagePumpAddresses
);
2973 CRITICAL_SECTION gcsMPH
;
2974 MESSAGEPUMPHOOKPROC gpfnInitMPH
;
2975 DWORD gcLoadMPH
= 0;
2976 USER_MESSAGE_PUMP_ADDRESSES gmph
= {sizeof(USER_MESSAGE_PUMP_ADDRESSES
),
2977 NtUserRealInternalGetMessage
,
2978 NtUserRealWaitMessageEx
,
2980 RealMsgWaitForMultipleObjectsEx
2983 DWORD gfMessagePumpHook
= 0;
2985 BOOL WINAPI
IsInsideMessagePumpHook()
2986 { // FF uses this and polls it when Min/Max
2987 PCLIENTTHREADINFO pcti
= GetWin32ClientInfo()->pClientThreadInfo
;
2988 return (gfMessagePumpHook
&& pcti
&& (pcti
->dwcPumpHook
> 0));
2991 void WINAPI
ResetMessagePumpHook(PUSER_MESSAGE_PUMP_ADDRESSES Addresses
)
2993 Addresses
->cbSize
= sizeof(USER_MESSAGE_PUMP_ADDRESSES
);
2994 Addresses
->NtUserRealInternalGetMessage
= NtUserRealInternalGetMessage
;
2995 Addresses
->NtUserRealWaitMessageEx
= NtUserRealWaitMessageEx
;
2996 Addresses
->RealGetQueueStatus
= RealGetQueueStatus
;
2997 Addresses
->RealMsgWaitForMultipleObjectsEx
= RealMsgWaitForMultipleObjectsEx
;
3000 BOOL WINAPI
RegisterMessagePumpHook(MESSAGEPUMPHOOKPROC Hook
)
3002 EnterCriticalSection(&gcsMPH
);
3004 SetLastError(ERROR_INVALID_PARAMETER
);
3005 LeaveCriticalSection(&gcsMPH
);
3009 USER_MESSAGE_PUMP_ADDRESSES Addresses
;
3011 ResetMessagePumpHook(&Addresses
);
3012 if(!Hook(FALSE
, &Addresses
) || !Addresses
.cbSize
) {
3013 LeaveCriticalSection(&gcsMPH
);
3016 memcpy(&gmph
, &Addresses
, Addresses
.cbSize
);
3018 if(gpfnInitMPH
!= Hook
) {
3019 LeaveCriticalSection(&gcsMPH
);
3023 if(NtUserxInitMessagePump()) {
3024 LeaveCriticalSection(&gcsMPH
);
3028 InterlockedExchange((PLONG
)&gfMessagePumpHook
, 1);
3030 LeaveCriticalSection(&gcsMPH
);
3034 BOOL WINAPI
UnregisterMessagePumpHook(VOID
)
3036 EnterCriticalSection(&gcsMPH
);
3038 if(NtUserxUnInitMessagePump()) {
3041 InterlockedExchange((PLONG
)&gfMessagePumpHook
, 0);
3042 gpfnInitMPH(TRUE
, NULL
);
3043 ResetMessagePumpHook(&gmph
);
3046 LeaveCriticalSection(&gcsMPH
);
3050 LeaveCriticalSection(&gcsMPH
);
3054 DWORD WINAPI
GetQueueStatus(UINT flags
)
3056 return IsInsideMessagePumpHook() ? gmph
.RealGetQueueStatus(flags
) : RealGetQueueStatus(flags
);
3060 * @name RealMsgWaitForMultipleObjectsEx
3062 * Wait either for either message arrival or for one of the passed events
3066 * Number of handles in the pHandles array.
3068 * Handles of events to wait for.
3069 * @param dwMilliseconds
3072 * Mask specifying on which message events we should wakeup.
3074 * Wait type (see MWMO_* constants).
3080 RealMsgWaitForMultipleObjectsEx(
3082 const HANDLE
*pHandles
,
3083 DWORD dwMilliseconds
,
3087 LPHANDLE RealHandles
;
3088 HANDLE MessageQueueHandle
;
3091 PCLIENTTHREADINFO pcti
;
3093 if (dwFlags
& ~(MWMO_WAITALL
| MWMO_ALERTABLE
| MWMO_INPUTAVAILABLE
))
3095 SetLastError(ERROR_INVALID_PARAMETER
);
3099 pci
= GetWin32ClientInfo();
3100 if (!pci
) return WAIT_FAILED
;
3102 pcti
= pci
->pClientThreadInfo
;
3103 if (pcti
&& ( !nCount
|| !(dwFlags
& MWMO_WAITALL
) ))
3105 if ( (pcti
->fsChangeBits
& LOWORD(dwWakeMask
)) ||
3106 ( (dwFlags
& MWMO_INPUTAVAILABLE
) && (pcti
->fsWakeBits
& LOWORD(dwWakeMask
)) ) )
3108 //FIXME("Chg 0x%x Wake 0x%x Mask 0x%x nCnt %d\n",pcti->fsChangeBits, pcti->fsWakeBits, dwWakeMask, nCount);
3113 MessageQueueHandle
= NtUserxMsqSetWakeMask(MAKELONG(dwWakeMask
, dwFlags
));
3114 if (MessageQueueHandle
== NULL
)
3116 SetLastError(0); /* ? */
3120 RealHandles
= HeapAlloc(GetProcessHeap(), 0, (nCount
+ 1) * sizeof(HANDLE
));
3121 if (RealHandles
== NULL
)
3123 NtUserxMsqClearWakeMask();
3124 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
3128 RtlCopyMemory(RealHandles
, pHandles
, nCount
* sizeof(HANDLE
));
3129 RealHandles
[nCount
] = MessageQueueHandle
;
3131 Result
= WaitForMultipleObjectsEx(nCount
+ 1, RealHandles
,
3132 dwFlags
& MWMO_WAITALL
,
3133 dwMilliseconds
, dwFlags
& MWMO_ALERTABLE
);
3135 HeapFree(GetProcessHeap(), 0, RealHandles
);
3136 NtUserxMsqClearWakeMask();
3137 //FIXME("Result 0X%x\n",Result);
3145 MsgWaitForMultipleObjectsEx(
3147 CONST HANDLE
*lpHandles
,
3148 DWORD dwMilliseconds
,
3152 return IsInsideMessagePumpHook() ? gmph
.RealMsgWaitForMultipleObjectsEx(nCount
, lpHandles
, dwMilliseconds
, dwWakeMask
, dwFlags
) : RealMsgWaitForMultipleObjectsEx(nCount
, lpHandles
,dwMilliseconds
, dwWakeMask
, dwFlags
);
3159 MsgWaitForMultipleObjects(
3161 CONST HANDLE
*lpHandles
,
3163 DWORD dwMilliseconds
,
3166 return MsgWaitForMultipleObjectsEx(nCount
, lpHandles
, dwMilliseconds
,
3167 dwWakeMask
, fWaitAll
? MWMO_WAITALL
: 0);
3171 BOOL FASTCALL
MessageInit(VOID
)
3173 InitializeCriticalSection(&DdeCrst
);
3174 InitializeCriticalSection(&gcsMPH
);
3179 VOID FASTCALL
MessageCleanup(VOID
)
3181 DeleteCriticalSection(&DdeCrst
);
3182 DeleteCriticalSection(&gcsMPH
);
3189 IsDialogMessageA( HWND hwndDlg
, LPMSG pmsg
)
3192 msg
.wParam
= map_wparam_AtoW( msg
.message
, msg
.wParam
);
3193 return IsDialogMessageW( hwndDlg
, &msg
);
3198 IntBroadcastSystemMessage(
3200 LPDWORD lpdwRecipients
,
3208 DWORD recips
= BSM_ALLCOMPONENTS
;
3209 BOOL ret
= -1; // Set to return fail
3210 static const DWORD all_flags
= ( BSF_QUERY
| BSF_IGNORECURRENTTASK
| BSF_FLUSHDISK
| BSF_NOHANG