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 // Ansi to Unicode -> callout
572 MsgiAnsiToUnicodeMessage(HWND hwnd
, LPMSG UnicodeMsg
, LPMSG AnsiMsg
)
574 UNICODE_STRING UnicodeString
;
576 *UnicodeMsg
= *AnsiMsg
;
578 switch (AnsiMsg
->message
)
581 case WM_ASKCBFORMATNAME
:
584 if (!AnsiMsg
->lParam
) break;
585 Buffer
= RtlAllocateHeap(GetProcessHeap(), HEAP_ZERO_MEMORY
, AnsiMsg
->wParam
* sizeof(WCHAR
));
586 //ERR("WM_GETTEXT A2U Size %d\n",AnsiMsg->wParam);
587 if (!Buffer
) return FALSE
;
588 UnicodeMsg
->lParam
= (LPARAM
)Buffer
;
594 DWORD Size
= 1024 * sizeof(WCHAR
);
595 if (!AnsiMsg
->lParam
|| !listbox_has_strings( AnsiMsg
->hwnd
)) break;
596 /*Size = SendMessageW( AnsiMsg->hwnd, LB_GETTEXTLEN, AnsiMsg->wParam, 0 );
599 ERR("LB_GETTEXT LB_ERR\n");
600 Size = sizeof(ULONG_PTR);
602 Size = (Size + 1) * sizeof(WCHAR);*/
603 UnicodeMsg
->lParam
= (LPARAM
) RtlAllocateHeap(GetProcessHeap(), HEAP_ZERO_MEMORY
, Size
);
604 if (!UnicodeMsg
->lParam
) return FALSE
;
610 DWORD Size
= 1024 * sizeof(WCHAR
);
611 if (!AnsiMsg
->lParam
|| !combobox_has_strings( AnsiMsg
->hwnd
)) break;
612 /*Size = SendMessageW( AnsiMsg->hwnd, CB_GETLBTEXTLEN, AnsiMsg->wParam, 0 );
615 ERR("CB_GETTEXT LB_ERR\n");
616 Size = sizeof(ULONG_PTR);
618 Size = (Size + 1) * sizeof(WCHAR);*/
619 UnicodeMsg
->lParam
= (LPARAM
) RtlAllocateHeap(GetProcessHeap(), HEAP_ZERO_MEMORY
, Size
);
620 if (!UnicodeMsg
->lParam
) return FALSE
;
624 /* AnsiMsg->lParam is string (0-terminated) */
626 case WM_WININICHANGE
:
627 case WM_DEVMODECHANGE
:
633 if (!AnsiMsg
->lParam
) break;
634 RtlCreateUnicodeStringFromAsciiz(&UnicodeString
, (LPSTR
)AnsiMsg
->lParam
);
635 UnicodeMsg
->lParam
= (LPARAM
)UnicodeString
.Buffer
;
640 case LB_ADDSTRING_LOWER
:
641 case LB_ADDSTRING_UPPER
:
642 case LB_INSERTSTRING
:
643 case LB_INSERTSTRING_UPPER
:
644 case LB_INSERTSTRING_LOWER
:
646 case LB_FINDSTRINGEXACT
:
647 case LB_SELECTSTRING
:
649 if (AnsiMsg
->lParam
&& listbox_has_strings(AnsiMsg
->hwnd
))
651 RtlCreateUnicodeStringFromAsciiz(&UnicodeString
, (LPSTR
)AnsiMsg
->lParam
);
652 UnicodeMsg
->lParam
= (LPARAM
)UnicodeString
.Buffer
;
658 case CB_INSERTSTRING
:
660 case CB_FINDSTRINGEXACT
:
661 case CB_SELECTSTRING
:
663 if (AnsiMsg
->lParam
&& combobox_has_strings(AnsiMsg
->hwnd
))
665 RtlCreateUnicodeStringFromAsciiz(&UnicodeString
, (LPSTR
)AnsiMsg
->lParam
);
666 UnicodeMsg
->lParam
= (LPARAM
)UnicodeString
.Buffer
;
674 MDICREATESTRUCTW mdi_cs
;
677 CREATESTRUCTW cs
; /* new structure */
678 LPCWSTR lpszName
; /* allocated Name */
679 LPCWSTR lpszClass
; /* allocated Class */
682 struct s
*xs
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(struct s
));
687 xs
->cs
= *(CREATESTRUCTW
*)AnsiMsg
->lParam
;
688 if (!IS_INTRESOURCE(xs
->cs
.lpszName
))
690 RtlCreateUnicodeStringFromAsciiz(&UnicodeString
, (LPSTR
)xs
->cs
.lpszName
);
691 xs
->lpszName
= xs
->cs
.lpszName
= UnicodeString
.Buffer
;
693 if (!IS_ATOM(xs
->cs
.lpszClass
))
695 RtlCreateUnicodeStringFromAsciiz(&UnicodeString
, (LPSTR
)xs
->cs
.lpszClass
);
696 xs
->lpszClass
= xs
->cs
.lpszClass
= UnicodeString
.Buffer
;
699 if (GetWindowLongW(hwnd
, GWL_EXSTYLE
) & WS_EX_MDICHILD
)
701 mdi_cs
= *(MDICREATESTRUCTW
*)xs
->cs
.lpCreateParams
;
702 mdi_cs
.szTitle
= xs
->cs
.lpszName
;
703 mdi_cs
.szClass
= xs
->cs
.lpszClass
;
704 xs
->cs
.lpCreateParams
= &mdi_cs
;
707 UnicodeMsg
->lParam
= (LPARAM
)xs
;
713 MDICREATESTRUCTW
*cs
=
714 (MDICREATESTRUCTW
*)HeapAlloc(GetProcessHeap(), 0, sizeof(*cs
));
721 *cs
= *(MDICREATESTRUCTW
*)AnsiMsg
->lParam
;
723 if (!IS_ATOM(cs
->szClass
))
725 RtlCreateUnicodeStringFromAsciiz(&UnicodeString
, (LPSTR
)cs
->szClass
);
726 cs
->szClass
= UnicodeString
.Buffer
;
729 RtlCreateUnicodeStringFromAsciiz(&UnicodeString
, (LPSTR
)cs
->szTitle
);
730 cs
->szTitle
= UnicodeString
.Buffer
;
732 UnicodeMsg
->lParam
= (LPARAM
)cs
;
737 if (UnicodeMsg
->lParam
)
739 MSG newmsg
= *(MSG
*)UnicodeMsg
->lParam
;
740 newmsg
.wParam
= map_wparam_AtoW( newmsg
.message
, newmsg
.wParam
);
750 case EM_SETPASSWORDCHAR
:
752 UnicodeMsg
->wParam
= map_wparam_AtoW( AnsiMsg
->message
, AnsiMsg
->wParam
);
755 ERR("FIXME EM_GETLINE A2U\n");
764 MsgiAnsiToUnicodeCleanup(LPMSG UnicodeMsg
, LPMSG AnsiMsg
)
766 UNICODE_STRING UnicodeString
;
768 switch (AnsiMsg
->message
)
771 if (!listbox_has_strings( UnicodeMsg
->hwnd
)) break;
773 if (UnicodeMsg
->message
== CB_GETLBTEXT
&& !combobox_has_strings( UnicodeMsg
->hwnd
)) break;
775 case WM_ASKCBFORMATNAME
:
777 if (!UnicodeMsg
->lParam
) break;
778 RtlFreeHeap(GetProcessHeap(), 0, (PVOID
) UnicodeMsg
->lParam
);
783 case WM_WININICHANGE
:
784 case WM_DEVMODECHANGE
:
790 if (!UnicodeMsg
->lParam
) break;
791 RtlInitUnicodeString(&UnicodeString
, (PCWSTR
)UnicodeMsg
->lParam
);
792 RtlFreeUnicodeString(&UnicodeString
);
797 case LB_ADDSTRING_LOWER
:
798 case LB_ADDSTRING_UPPER
:
799 case LB_INSERTSTRING
:
800 case LB_INSERTSTRING_UPPER
:
801 case LB_INSERTSTRING_LOWER
:
803 case LB_FINDSTRINGEXACT
:
804 case LB_SELECTSTRING
:
806 if (UnicodeMsg
->lParam
&& listbox_has_strings(AnsiMsg
->hwnd
))
808 RtlInitUnicodeString(&UnicodeString
, (PCWSTR
)UnicodeMsg
->lParam
);
809 RtlFreeUnicodeString(&UnicodeString
);
815 case CB_INSERTSTRING
:
817 case CB_FINDSTRINGEXACT
:
818 case CB_SELECTSTRING
:
820 if (UnicodeMsg
->lParam
&& combobox_has_strings(AnsiMsg
->hwnd
))
822 RtlInitUnicodeString(&UnicodeString
, (PCWSTR
)UnicodeMsg
->lParam
);
823 RtlFreeUnicodeString(&UnicodeString
);
833 CREATESTRUCTW cs
; /* new structure */
834 LPWSTR lpszName
; /* allocated Name */
835 LPWSTR lpszClass
; /* allocated Class */
838 struct s
*xs
= (struct s
*)UnicodeMsg
->lParam
;
841 RtlInitUnicodeString(&UnicodeString
, (PCWSTR
)xs
->lpszName
);
842 RtlFreeUnicodeString(&UnicodeString
);
846 RtlInitUnicodeString(&UnicodeString
, (PCWSTR
)xs
->lpszClass
);
847 RtlFreeUnicodeString(&UnicodeString
);
849 HeapFree(GetProcessHeap(), 0, xs
);
855 MDICREATESTRUCTW
*cs
= (MDICREATESTRUCTW
*)UnicodeMsg
->lParam
;
856 RtlInitUnicodeString(&UnicodeString
, (PCWSTR
)cs
->szTitle
);
857 RtlFreeUnicodeString(&UnicodeString
);
858 if (!IS_ATOM(cs
->szClass
))
860 RtlInitUnicodeString(&UnicodeString
, (PCWSTR
)cs
->szClass
);
861 RtlFreeUnicodeString(&UnicodeString
);
863 HeapFree(GetProcessHeap(), 0, cs
);
872 * callout return -> Unicode Result to Ansi Result
875 MsgiAnsiToUnicodeReply(LPMSG UnicodeMsg
, LPMSG AnsiMsg
, LRESULT
*Result
)
877 LPWSTR Buffer
= (LPWSTR
)UnicodeMsg
->lParam
;
878 LPSTR AnsiBuffer
= (LPSTR
)AnsiMsg
->lParam
;
880 switch (AnsiMsg
->message
)
883 case WM_ASKCBFORMATNAME
:
885 if (UnicodeMsg
->wParam
)
888 if (*Result
) RtlUnicodeToMultiByteN( AnsiBuffer
, UnicodeMsg
->wParam
- 1, &len
, Buffer
, strlenW(Buffer
) * sizeof(WCHAR
));
891 //ERR("WM_GETTEXT U2A Result %d Size %d\n",*Result,AnsiMsg->wParam);
897 if (!AnsiBuffer
|| !listbox_has_strings( UnicodeMsg
->hwnd
)) break;
901 RtlUnicodeToMultiByteN( AnsiBuffer
, ~0u, &len
, Buffer
, (strlenW(Buffer
) + 1) * sizeof(WCHAR
) );
908 if (!AnsiBuffer
|| !combobox_has_strings( UnicodeMsg
->hwnd
)) break;
912 RtlUnicodeToMultiByteN( AnsiBuffer
, ~0u, &len
, Buffer
, (strlenW(Buffer
) + 1) * sizeof(WCHAR
) );
919 MsgiAnsiToUnicodeCleanup(UnicodeMsg
, AnsiMsg
);
925 // Unicode to Ansi callout ->
928 MsgiUnicodeToAnsiMessage(HWND hwnd
, LPMSG AnsiMsg
, LPMSG UnicodeMsg
)
930 ANSI_STRING AnsiString
;
931 UNICODE_STRING UnicodeString
;
933 *AnsiMsg
= *UnicodeMsg
;
935 switch(UnicodeMsg
->message
)
940 MDICREATESTRUCTA
*pmdi_cs
;
945 CsW
= (CREATESTRUCTW
*)(UnicodeMsg
->lParam
);
946 CsA
= RtlAllocateHeap(GetProcessHeap(), 0, sizeof(CREATESTRUCTA
) + sizeof(MDICREATESTRUCTA
));
951 memcpy(CsA
, CsW
, sizeof(CREATESTRUCTW
));
953 /* pmdi_cs starts right after CsA */
954 pmdi_cs
= (MDICREATESTRUCTA
*)(CsA
+ 1);
956 RtlInitUnicodeString(&UnicodeString
, CsW
->lpszName
);
957 Status
= RtlUnicodeStringToAnsiString(&AnsiString
, &UnicodeString
, TRUE
);
958 if (! NT_SUCCESS(Status
))
960 RtlFreeHeap(GetProcessHeap(), 0, CsA
);
963 CsA
->lpszName
= AnsiString
.Buffer
;
964 if (HIWORD((ULONG_PTR
)CsW
->lpszClass
) != 0)
966 RtlInitUnicodeString(&UnicodeString
, CsW
->lpszClass
);
967 Status
= RtlUnicodeStringToAnsiString(&AnsiString
, &UnicodeString
, TRUE
);
968 if (! NT_SUCCESS(Status
))
970 RtlInitAnsiString(&AnsiString
, CsA
->lpszName
);
971 RtlFreeAnsiString(&AnsiString
);
972 RtlFreeHeap(GetProcessHeap(), 0, CsA
);
975 CsA
->lpszClass
= AnsiString
.Buffer
;
978 if (GetWindowLongW(hwnd
, GWL_EXSTYLE
) & WS_EX_MDICHILD
)
980 *pmdi_cs
= *(MDICREATESTRUCTA
*)CsW
->lpCreateParams
;
981 pmdi_cs
->szTitle
= CsA
->lpszName
;
982 pmdi_cs
->szClass
= CsA
->lpszClass
;
983 CsA
->lpCreateParams
= pmdi_cs
;
986 AnsiMsg
->lParam
= (LPARAM
)CsA
;
990 case WM_ASKCBFORMATNAME
:
992 if (!UnicodeMsg
->lParam
) break;
993 /* Ansi string might contain MBCS chars so we need 2 * the number of chars */
994 AnsiMsg
->lParam
= (LPARAM
) RtlAllocateHeap(GetProcessHeap(), HEAP_ZERO_MEMORY
, UnicodeMsg
->wParam
* 2);
995 //ERR("WM_GETTEXT U2A Size %d\n",AnsiMsg->wParam);
996 if (!AnsiMsg
->lParam
) return FALSE
;
1003 if (!UnicodeMsg
->lParam
|| !listbox_has_strings( UnicodeMsg
->hwnd
)) break;
1004 /*Size = SendMessageA( UnicodeMsg->hwnd, LB_GETTEXTLEN, UnicodeMsg->wParam, 0 );
1007 ERR("LB_GETTEXT LB_ERR\n");
1008 Size = sizeof(ULONG_PTR);
1010 Size = (Size + 1) * sizeof(WCHAR);*/
1011 AnsiMsg
->lParam
= (LPARAM
) RtlAllocateHeap(GetProcessHeap(), HEAP_ZERO_MEMORY
, Size
);
1012 if (!AnsiMsg
->lParam
) return FALSE
;
1019 if (!UnicodeMsg
->lParam
|| !combobox_has_strings( UnicodeMsg
->hwnd
)) break;
1020 /*Size = SendMessageA( UnicodeMsg->hwnd, CB_GETLBTEXTLEN, UnicodeMsg->wParam, 0 );
1023 ERR("CB_GETTEXT LB_ERR\n");
1024 Size = sizeof(ULONG_PTR);
1026 Size = (Size + 1) * sizeof(WCHAR);*/
1027 AnsiMsg
->lParam
= (LPARAM
) RtlAllocateHeap(GetProcessHeap(), HEAP_ZERO_MEMORY
, Size
);
1028 if (!AnsiMsg
->lParam
) return FALSE
;
1033 case WM_WININICHANGE
:
1034 case WM_DEVMODECHANGE
:
1040 if (!UnicodeMsg
->lParam
) break;
1041 RtlInitUnicodeString(&UnicodeString
, (PWSTR
) UnicodeMsg
->lParam
);
1042 if (! NT_SUCCESS(RtlUnicodeStringToAnsiString(&AnsiString
,
1048 AnsiMsg
->lParam
= (LPARAM
) AnsiString
.Buffer
;
1053 case LB_ADDSTRING_LOWER
:
1054 case LB_ADDSTRING_UPPER
:
1055 case LB_INSERTSTRING
:
1056 case LB_INSERTSTRING_UPPER
:
1057 case LB_INSERTSTRING_LOWER
:
1059 case LB_FINDSTRINGEXACT
:
1060 case LB_SELECTSTRING
:
1062 if (UnicodeMsg
->lParam
&& listbox_has_strings(AnsiMsg
->hwnd
))
1064 RtlInitUnicodeString(&UnicodeString
, (PWSTR
) UnicodeMsg
->lParam
);
1065 if (! NT_SUCCESS(RtlUnicodeStringToAnsiString(&AnsiString
,
1071 AnsiMsg
->lParam
= (LPARAM
) AnsiString
.Buffer
;
1077 case CB_INSERTSTRING
:
1079 case CB_FINDSTRINGEXACT
:
1080 case CB_SELECTSTRING
:
1082 if (UnicodeMsg
->lParam
&& combobox_has_strings(AnsiMsg
->hwnd
))
1084 RtlInitUnicodeString(&UnicodeString
, (PWSTR
) UnicodeMsg
->lParam
);
1085 if (! NT_SUCCESS(RtlUnicodeStringToAnsiString(&AnsiString
,
1091 AnsiMsg
->lParam
= (LPARAM
) AnsiString
.Buffer
;
1098 MDICREATESTRUCTA
*cs
=
1099 (MDICREATESTRUCTA
*)HeapAlloc(GetProcessHeap(), 0, sizeof(*cs
));
1106 *cs
= *(MDICREATESTRUCTA
*)UnicodeMsg
->lParam
;
1108 if (!IS_ATOM(cs
->szClass
))
1110 RtlInitUnicodeString(&UnicodeString
, (LPCWSTR
)cs
->szClass
);
1111 if (! NT_SUCCESS(RtlUnicodeStringToAnsiString(&AnsiString
,
1115 HeapFree(GetProcessHeap(), 0, cs
);
1118 cs
->szClass
= AnsiString
.Buffer
;
1121 RtlInitUnicodeString(&UnicodeString
, (LPCWSTR
)cs
->szTitle
);
1122 if (! NT_SUCCESS(RtlUnicodeStringToAnsiString(&AnsiString
,
1126 if (!IS_ATOM(cs
->szClass
))
1128 RtlInitAnsiString(&AnsiString
, cs
->szClass
);
1129 RtlFreeAnsiString(&AnsiString
);
1132 HeapFree(GetProcessHeap(), 0, cs
);
1135 cs
->szTitle
= AnsiString
.Buffer
;
1137 AnsiMsg
->lParam
= (LPARAM
)cs
;
1142 if (UnicodeMsg
->lParam
)
1144 MSG newmsg
= *(MSG
*)UnicodeMsg
->lParam
;
1145 switch(newmsg
.message
)
1150 case WM_SYSDEADCHAR
:
1151 newmsg
.wParam
= map_wparam_char_WtoA( newmsg
.wParam
, 1 );
1154 newmsg
.wParam
= map_wparam_char_WtoA( newmsg
.wParam
, 2 );
1162 WCHAR wch
= UnicodeMsg
->wParam
;
1164 DWORD cp
= get_input_codepage();
1165 DWORD len
= WideCharToMultiByte( cp
, 0, &wch
, 1, ch
, 2, NULL
, NULL
);
1166 AnsiMsg
->wParam
= (BYTE
)ch
[0];
1167 if (len
== 2) AnsiMsg
->wParam
= (BYTE
)ch
[1];
1175 case WM_SYSDEADCHAR
:
1176 case EM_SETPASSWORDCHAR
:
1177 AnsiMsg
->wParam
= map_wparam_char_WtoA(UnicodeMsg
->wParam
,1);
1181 AnsiMsg
->wParam
= map_wparam_char_WtoA(UnicodeMsg
->wParam
,2);
1184 ERR("FIXME EM_GETLINE U2A\n");
1190 static BOOL FASTCALL
1191 MsgiUnicodeToAnsiCleanup(LPMSG AnsiMsg
, LPMSG UnicodeMsg
)
1193 ANSI_STRING AnsiString
;
1195 switch(UnicodeMsg
->message
)
1198 if (!listbox_has_strings( AnsiMsg
->hwnd
)) break;
1200 if (AnsiMsg
->message
== CB_GETLBTEXT
&& !combobox_has_strings( AnsiMsg
->hwnd
)) break;
1202 case WM_ASKCBFORMATNAME
:
1204 if (!AnsiMsg
->lParam
) break;
1205 RtlFreeHeap(GetProcessHeap(), 0, (PVOID
) AnsiMsg
->lParam
);
1213 Cs
= (CREATESTRUCTA
*) AnsiMsg
->lParam
;
1214 RtlInitAnsiString(&AnsiString
, Cs
->lpszName
);
1215 RtlFreeAnsiString(&AnsiString
);
1216 if (HIWORD((ULONG_PTR
)Cs
->lpszClass
) != 0)
1218 RtlInitAnsiString(&AnsiString
, Cs
->lpszClass
);
1219 RtlFreeAnsiString(&AnsiString
);
1221 RtlFreeHeap(GetProcessHeap(), 0, Cs
);
1226 case WM_WININICHANGE
:
1227 case WM_DEVMODECHANGE
:
1233 if (!AnsiMsg
->lParam
) break;
1234 RtlInitAnsiString(&AnsiString
, (PSTR
) AnsiMsg
->lParam
);
1235 RtlFreeAnsiString(&AnsiString
);
1240 case LB_ADDSTRING_LOWER
:
1241 case LB_ADDSTRING_UPPER
:
1242 case LB_INSERTSTRING
:
1243 case LB_INSERTSTRING_UPPER
:
1244 case LB_INSERTSTRING_LOWER
:
1246 case LB_FINDSTRINGEXACT
:
1247 case LB_SELECTSTRING
:
1249 if (AnsiMsg
->lParam
&& listbox_has_strings(AnsiMsg
->hwnd
))
1251 RtlInitAnsiString(&AnsiString
, (PSTR
) AnsiMsg
->lParam
);
1252 RtlFreeAnsiString(&AnsiString
);
1258 case CB_INSERTSTRING
:
1260 case CB_FINDSTRINGEXACT
:
1261 case CB_SELECTSTRING
:
1263 if (AnsiMsg
->lParam
&& combobox_has_strings(AnsiMsg
->hwnd
))
1265 RtlInitAnsiString(&AnsiString
, (PSTR
) AnsiMsg
->lParam
);
1266 RtlFreeAnsiString(&AnsiString
);
1273 MDICREATESTRUCTA
*cs
= (MDICREATESTRUCTA
*)AnsiMsg
->lParam
;
1274 RtlInitAnsiString(&AnsiString
, (PCSTR
)cs
->szTitle
);
1275 RtlFreeAnsiString(&AnsiString
);
1276 if (!IS_ATOM(cs
->szClass
))
1278 RtlInitAnsiString(&AnsiString
, (PCSTR
)cs
->szClass
);
1279 RtlFreeAnsiString(&AnsiString
);
1281 HeapFree(GetProcessHeap(), 0, cs
);
1291 * callout return -> Ansi Result to Unicode Result
1293 static BOOL FASTCALL
1294 MsgiUnicodeToAnsiReply(LPMSG AnsiMsg
, LPMSG UnicodeMsg
, LRESULT
*Result
)
1296 LPSTR Buffer
= (LPSTR
) AnsiMsg
->lParam
;
1297 LPWSTR UBuffer
= (LPWSTR
) UnicodeMsg
->lParam
;
1299 switch (UnicodeMsg
->message
)
1302 case WM_ASKCBFORMATNAME
:
1304 DWORD len
= AnsiMsg
->wParam
;// * 2;
1309 RtlMultiByteToUnicodeN( UBuffer
, AnsiMsg
->wParam
*sizeof(WCHAR
), &len
, Buffer
, strlen(Buffer
)+1 );
1310 *Result
= len
/sizeof(WCHAR
) - 1; /* do not count terminating null */
1311 //ERR("WM_GETTEXT U2A Result %d Size %d\n",*Result,AnsiMsg->wParam);
1313 UBuffer
[*Result
] = 0;
1319 if (!UBuffer
|| !listbox_has_strings( UnicodeMsg
->hwnd
)) break;
1323 RtlMultiByteToUnicodeN( UBuffer
, ~0u, &len
, Buffer
, strlen(Buffer
) + 1 );
1324 *Result
= len
/ sizeof(WCHAR
) - 1;
1330 if (!UBuffer
|| !combobox_has_strings( UnicodeMsg
->hwnd
)) break;
1334 RtlMultiByteToUnicodeN( UBuffer
, ~0u, &len
, Buffer
, strlen(Buffer
) + 1 );
1335 *Result
= len
/ sizeof(WCHAR
) - 1;
1341 MsgiUnicodeToAnsiCleanup(AnsiMsg
, UnicodeMsg
);
1349 DesktopWndProcA( HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1354 TRACE("Desktop A Class Atom! hWnd 0x%x, Msg %d\n", hwnd
, message
);
1356 AnsiMsg
.hwnd
= hwnd
;
1357 AnsiMsg
.message
= message
;
1358 AnsiMsg
.wParam
= wParam
;
1359 AnsiMsg
.lParam
= lParam
;
1361 // Desktop is always Unicode so convert Ansi here.
1362 if (!MsgiAnsiToUnicodeMessage(hwnd
, &UcMsg
, &AnsiMsg
))
1367 Result
= DesktopWndProcW(hwnd
, message
, UcMsg
.wParam
, UcMsg
.lParam
);
1369 MsgiAnsiToUnicodeCleanup(&UcMsg
, &AnsiMsg
);
1379 GetMessageExtraInfo(VOID
)
1381 return NtUserxGetMessageExtraInfo();
1392 return NtUserxGetMessagePos();
1400 GetMessageTime(VOID
)
1402 return NtUserGetThreadState(THREADSTATE_GETMESSAGETIME
);
1413 PCLIENTTHREADINFO pcti
= GetWin32ClientInfo()->pClientThreadInfo
;
1416 if (pcti
->CTI_flags
& CTI_INSENDMESSAGE
)
1421 return(NtUserGetThreadState(THREADSTATE_INSENDMESSAGE
) != ISMEX_NOSEND
);
1433 PCLIENTTHREADINFO pcti
= GetWin32ClientInfo()->pClientThreadInfo
;
1434 if (pcti
&& !(pcti
->CTI_flags
& CTI_INSENDMESSAGE
))
1435 return ISMEX_NOSEND
;
1437 return NtUserGetThreadState(THREADSTATE_INSENDMESSAGE
);
1446 ReplyMessage(LRESULT lResult
)
1448 return NtUserxReplyMessage(lResult
);
1457 SetMessageExtraInfo(
1460 return NtUserxSetMessageExtraInfo(lParam
);
1464 IntCallWindowProcW(BOOL IsAnsiProc
,
1474 BOOL Hook
= FALSE
, MsgOverride
= FALSE
, Dialog
;
1475 LRESULT Result
= 0, PreResult
= 0;
1478 if (WndProc
== NULL
)
1480 WARN("IntCallWindowsProcW() called with WndProc = NULL!\n");
1485 Dialog
= (pWnd
->fnid
== FNID_DIALOG
);
1489 Hook
= BeginIfHookedUserApiHook();
1493 MsgOverride
= IsMsgOverride( Msg
, &guah
.WndProcArray
);
1495 MsgOverride
= IsMsgOverride( Msg
, &guah
.DlgProcArray
);
1500 UnicodeMsg
.hwnd
= hWnd
;
1501 UnicodeMsg
.message
= Msg
;
1502 UnicodeMsg
.wParam
= wParam
;
1503 UnicodeMsg
.lParam
= lParam
;
1504 if (! MsgiUnicodeToAnsiMessage(hWnd
, &AnsiMsg
, &UnicodeMsg
))
1509 if (Hook
&& MsgOverride
)
1514 PreResult
= guah
.PreWndProc(AnsiMsg
.hwnd
, AnsiMsg
.message
, AnsiMsg
.wParam
, AnsiMsg
.lParam
, (ULONG_PTR
)&Result
, &Data
);
1516 PreResult
= guah
.PreDefDlgProc(AnsiMsg
.hwnd
, AnsiMsg
.message
, AnsiMsg
.wParam
, AnsiMsg
.lParam
, (ULONG_PTR
)&Result
, &Data
);
1518 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1524 if (PreResult
) goto Exit
;
1526 _SEH2_TRY
// wine does this.
1528 Result
= WndProc(AnsiMsg
.hwnd
, AnsiMsg
.message
, AnsiMsg
.wParam
, AnsiMsg
.lParam
);
1530 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1532 ERR("Exception when calling Ansi WndProc %p Msg %d pti %p Wndpti %p\n",WndProc
,Msg
,GetW32ThreadInfo(),pWnd
->head
.pti
);
1536 if (Hook
&& MsgOverride
)
1541 guah
.PostWndProc(AnsiMsg
.hwnd
, AnsiMsg
.message
, AnsiMsg
.wParam
, AnsiMsg
.lParam
, (ULONG_PTR
)&Result
, &Data
);
1543 guah
.PostDefDlgProc(AnsiMsg
.hwnd
, AnsiMsg
.message
, AnsiMsg
.wParam
, AnsiMsg
.lParam
, (ULONG_PTR
)&Result
, &Data
);
1545 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1551 if (! MsgiUnicodeToAnsiReply(&AnsiMsg
, &UnicodeMsg
, &Result
))
1558 if (Hook
&& MsgOverride
)
1563 PreResult
= guah
.PreWndProc(hWnd
, Msg
, wParam
, lParam
, (ULONG_PTR
)&Result
, &Data
);
1565 PreResult
= guah
.PreDefDlgProc(hWnd
, Msg
, wParam
, lParam
, (ULONG_PTR
)&Result
, &Data
);
1567 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1573 if (PreResult
) goto Exit
;
1577 Result
= WndProc(hWnd
, Msg
, wParam
, lParam
);
1579 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1581 ERR("Exception when calling unicode WndProc %p Msg %d pti %p Wndpti %p\n",WndProc
, Msg
,GetW32ThreadInfo(),pWnd
->head
.pti
);
1585 if (Hook
&& MsgOverride
)
1590 guah
.PostWndProc(hWnd
, Msg
, wParam
, lParam
, (ULONG_PTR
)&Result
, &Data
);
1592 guah
.PostDefDlgProc(hWnd
, Msg
, wParam
, lParam
, (ULONG_PTR
)&Result
, &Data
);
1594 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1602 if (Hook
) EndUserApiHook();
1606 static LRESULT FASTCALL
1607 IntCallWindowProcA(BOOL IsAnsiProc
,
1617 //ULONG_PTR LowLimit;
1618 BOOL Hook
= FALSE
, MsgOverride
= FALSE
, Dialog
;
1619 LRESULT Result
= 0, PreResult
= 0;
1622 if (WndProc
== NULL
)
1624 WARN("IntCallWindowsProcA() called with WndProc = NULL!\n");
1628 LowLimit
= (ULONG_PTR
)NtCurrentTeb()->NtTib
.StackLimit
;
1629 if (((ULONG_PTR
)&lParam
- LowLimit
) < PAGE_SIZE
)
1631 ERR("IntCallWindowsProcA() Exceeded Stack!\n");
1636 Dialog
= (pWnd
->fnid
== FNID_DIALOG
);
1640 Hook
= BeginIfHookedUserApiHook();
1644 MsgOverride
= IsMsgOverride( Msg
, &guah
.WndProcArray
);
1646 MsgOverride
= IsMsgOverride( Msg
, &guah
.DlgProcArray
);
1651 if (Hook
&& MsgOverride
)
1656 PreResult
= guah
.PreWndProc(hWnd
, Msg
, wParam
, lParam
, (ULONG_PTR
)&Result
, &Data
);
1658 PreResult
= guah
.PreDefDlgProc(hWnd
, Msg
, wParam
, lParam
, (ULONG_PTR
)&Result
, &Data
);
1660 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1666 if (PreResult
) goto Exit
;
1670 Result
= WndProc(hWnd
, Msg
, wParam
, lParam
);
1672 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1674 ERR("Exception when calling Ansi WndProc %p Msg %d pti %p Wndpti %p\n",WndProc
,Msg
,GetW32ThreadInfo(),pWnd
->head
.pti
);
1678 if (Hook
&& MsgOverride
)
1683 guah
.PostWndProc(hWnd
, Msg
, wParam
, lParam
, (ULONG_PTR
)&Result
, &Data
);
1685 guah
.PostDefDlgProc(hWnd
, Msg
, wParam
, lParam
, (ULONG_PTR
)&Result
, &Data
);
1687 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1695 AnsiMsg
.hwnd
= hWnd
;
1696 AnsiMsg
.message
= Msg
;
1697 AnsiMsg
.wParam
= wParam
;
1698 AnsiMsg
.lParam
= lParam
;
1699 if (! MsgiAnsiToUnicodeMessage(hWnd
, &UnicodeMsg
, &AnsiMsg
))
1704 if (Hook
&& MsgOverride
)
1709 PreResult
= guah
.PreWndProc(UnicodeMsg
.hwnd
, UnicodeMsg
.message
, UnicodeMsg
.wParam
, UnicodeMsg
.lParam
, (ULONG_PTR
)&Result
, &Data
);
1711 PreResult
= guah
.PreDefDlgProc(UnicodeMsg
.hwnd
, UnicodeMsg
.message
, UnicodeMsg
.wParam
, UnicodeMsg
.lParam
, (ULONG_PTR
)&Result
, &Data
);
1713 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1719 if (PreResult
) goto Exit
;
1723 Result
= WndProc(UnicodeMsg
.hwnd
, UnicodeMsg
.message
,
1724 UnicodeMsg
.wParam
, UnicodeMsg
.lParam
);
1726 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1728 ERR("Exception when calling unicode WndProc %p Msg %d pti %p Wndpti %p\n",WndProc
, Msg
,GetW32ThreadInfo(),pWnd
->head
.pti
);
1732 if (Hook
&& MsgOverride
)
1737 guah
.PostWndProc(UnicodeMsg
.hwnd
, UnicodeMsg
.message
, UnicodeMsg
.wParam
, UnicodeMsg
.lParam
, (ULONG_PTR
)&Result
, &Data
);
1739 guah
.PostDefDlgProc(UnicodeMsg
.hwnd
, UnicodeMsg
.message
, UnicodeMsg
.wParam
, UnicodeMsg
.lParam
, (ULONG_PTR
)&Result
, &Data
);
1741 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1747 if (! MsgiAnsiToUnicodeReply(&UnicodeMsg
, &AnsiMsg
, &Result
))
1754 if (Hook
) EndUserApiHook();
1759 static LRESULT WINAPI
1760 IntCallMessageProc(IN PWND Wnd
, IN HWND hWnd
, IN UINT Msg
, IN WPARAM wParam
, IN LPARAM lParam
, IN BOOL Ansi
)
1766 Class
= DesktopPtrToUser(Wnd
->pcls
);
1769 if ( Wnd
->head
.pti
!= GetW32ThreadInfo())
1770 { // Must be inside the same thread!
1771 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
1775 This is the message exchange for user32. If there's a need to monitor messages,
1778 TRACE("HWND %p, MSG %u, WPARAM %p, LPARAM %p, Ansi %d\n", hWnd
, Msg
, wParam
, lParam
, Ansi
);
1779 // if (Class->fnid <= FNID_GHOST && Class->fnid >= FNID_BUTTON )
1780 if (Class
->fnid
<= FNID_GHOST
&& Class
->fnid
>= FNID_FIRST
)
1784 if (GETPFNCLIENTW(Class
->fnid
) == Wnd
->lpfnWndProc
)
1785 WndProc
= GETPFNCLIENTA(Class
->fnid
);
1789 if (GETPFNCLIENTA(Class
->fnid
) == Wnd
->lpfnWndProc
)
1790 WndProc
= GETPFNCLIENTW(Class
->fnid
);
1797 IsAnsi
= !Wnd
->Unicode
;
1798 WndProc
= Wnd
->lpfnWndProc
;
1803 IsAnsi
= !Wnd
->Unicode
;
1804 WndProc
= Wnd
->lpfnWndProc
;
1807 Message caller can be Ansi/Unicode and the receiver can be Unicode/Ansi or
1811 return IntCallWindowProcW(IsAnsi
, WndProc
, Wnd
, hWnd
, Msg
, wParam
, lParam
);
1813 return IntCallWindowProcA(IsAnsi
, WndProc
, Wnd
, hWnd
, Msg
, wParam
, lParam
);
1821 CallWindowProcA(WNDPROC lpPrevWndFunc
,
1828 PCALLPROCDATA CallProc
;
1830 if (lpPrevWndFunc
== NULL
)
1832 WARN("CallWindowProcA: lpPrevWndFunc == NULL!\n");
1836 pWnd
= ValidateHwnd(hWnd
);
1838 if (!IsCallProcHandle(lpPrevWndFunc
))
1839 return IntCallWindowProcA(TRUE
, lpPrevWndFunc
, pWnd
, hWnd
, Msg
, wParam
, lParam
);
1842 CallProc
= ValidateCallProc((HANDLE
)lpPrevWndFunc
);
1843 if (CallProc
!= NULL
)
1845 return IntCallWindowProcA(!(CallProc
->wType
& UserGetCPDA2U
),
1846 CallProc
->pfnClientPrevious
,
1855 WARN("CallWindowProcA: can not dereference WndProcHandle\n");
1866 CallWindowProcW(WNDPROC lpPrevWndFunc
,
1873 PCALLPROCDATA CallProc
;
1875 /* FIXME - can the first parameter be NULL? */
1876 if (lpPrevWndFunc
== NULL
)
1878 WARN("CallWindowProcA: lpPrevWndFunc == NULL!\n");
1882 pWnd
= ValidateHwnd(hWnd
);
1884 if (!IsCallProcHandle(lpPrevWndFunc
))
1885 return IntCallWindowProcW(FALSE
, lpPrevWndFunc
, pWnd
, hWnd
, Msg
, wParam
, lParam
);
1888 CallProc
= ValidateCallProc((HANDLE
)lpPrevWndFunc
);
1889 if (CallProc
!= NULL
)
1891 return IntCallWindowProcW(!(CallProc
->wType
& UserGetCPDA2U
),
1892 CallProc
->pfnClientPrevious
,
1901 WARN("CallWindowProcW: can not dereference WndProcHandle\n");
1914 DispatchMessageA(CONST MSG
*lpmsg
)
1921 if ( lpmsg
->message
& ~WM_MAXIMUM
)
1923 SetLastError( ERROR_INVALID_PARAMETER
);
1927 if (lpmsg
->hwnd
!= NULL
)
1929 Wnd
= ValidateHwnd(lpmsg
->hwnd
);
1935 if (is_pointer_message(lpmsg
->message
))
1937 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
1941 if ((lpmsg
->message
== WM_TIMER
|| lpmsg
->message
== WM_SYSTIMER
) && lpmsg
->lParam
!= 0)
1943 WNDPROC WndProc
= (WNDPROC
)lpmsg
->lParam
;
1945 if ( lpmsg
->message
== WM_SYSTIMER
)
1946 return NtUserDispatchMessage( (PMSG
)lpmsg
);
1948 if (!NtUserValidateTimerCallback(lpmsg
->hwnd
, lpmsg
->wParam
, lpmsg
->lParam
))
1950 WARN("Validating Timer Callback failed!\n");
1954 _SEH2_TRY
// wine does this. Hint: Prevents call to another thread....
1956 Ret
= WndProc(lpmsg
->hwnd
,
1961 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1967 else if (Wnd
!= NULL
)
1969 if ( (lpmsg
->message
!= WM_PAINT
) && !(Wnd
->state
& WNDS_SERVERSIDEWINDOWPROC
) )
1971 Ret
= IntCallMessageProc(Wnd
,
1980 if (!MsgiAnsiToUnicodeMessage(lpmsg
->hwnd
, &UnicodeMsg
, (LPMSG
)lpmsg
))
1985 Ret
= NtUserDispatchMessage(&UnicodeMsg
);
1987 if (!MsgiAnsiToUnicodeReply(&UnicodeMsg
, (LPMSG
)lpmsg
, &Ret
))
1996 WARN("Exception in Timer Callback WndProcA!\n");
2008 DispatchMessageW(CONST MSG
*lpmsg
)
2014 if ( lpmsg
->message
& ~WM_MAXIMUM
)
2016 SetLastError( ERROR_INVALID_PARAMETER
);
2020 if (lpmsg
->hwnd
!= NULL
)
2022 Wnd
= ValidateHwnd(lpmsg
->hwnd
);
2028 if (is_pointer_message(lpmsg
->message
))
2030 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
2034 if ((lpmsg
->message
== WM_TIMER
|| lpmsg
->message
== WM_SYSTIMER
) && lpmsg
->lParam
!= 0)
2036 WNDPROC WndProc
= (WNDPROC
)lpmsg
->lParam
;
2038 if ( lpmsg
->message
== WM_SYSTIMER
)
2039 return NtUserDispatchMessage( (PMSG
) lpmsg
);
2041 if (!NtUserValidateTimerCallback(lpmsg
->hwnd
, lpmsg
->wParam
, lpmsg
->lParam
))
2043 WARN("Validating Timer Callback failed!\n");
2049 Ret
= WndProc(lpmsg
->hwnd
,
2054 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2060 else if (Wnd
!= NULL
)
2062 if ( (lpmsg
->message
!= WM_PAINT
) && !(Wnd
->state
& WNDS_SERVERSIDEWINDOWPROC
) )
2064 Ret
= IntCallMessageProc(Wnd
,
2072 Ret
= NtUserDispatchMessage( (PMSG
) lpmsg
);
2077 WARN("Exception in Timer Callback WndProcW!\n");
2083 IntConvertMsgToAnsi(LPMSG lpMsg
)
2088 switch (lpMsg
->message
)
2093 case WM_SYSDEADCHAR
:
2095 wch
[0] = LOWORD(lpMsg
->wParam
);
2096 wch
[1] = HIWORD(lpMsg
->wParam
);
2098 WideCharToMultiByte(CP_THREAD_ACP
, 0, wch
, 2, ch
, 2, NULL
, NULL
);
2099 lpMsg
->wParam
= MAKEWPARAM(ch
[0] | (ch
[1] << 8), 0);
2110 GetMessageA(LPMSG lpMsg
,
2117 if ( (wMsgFilterMin
|wMsgFilterMax
) & ~WM_MAXIMUM
)
2119 SetLastError( ERROR_INVALID_PARAMETER
);
2123 Res
= NtUserGetMessage(lpMsg
, hWnd
, wMsgFilterMin
, wMsgFilterMax
);
2124 if (-1 == (int) Res
)
2129 IntConvertMsgToAnsi(lpMsg
);
2140 GetMessageW(LPMSG lpMsg
,
2147 if ( (wMsgFilterMin
|wMsgFilterMax
) & ~WM_MAXIMUM
)
2149 SetLastError( ERROR_INVALID_PARAMETER
);
2153 Res
= NtUserGetMessage(lpMsg
, hWnd
, wMsgFilterMin
, wMsgFilterMax
);
2154 if (-1 == (int) Res
)
2163 PeekMessageWorker( PMSG pMsg
,
2170 PCLIENTTHREADINFO pcti
;
2171 pci
= GetWin32ClientInfo();
2172 pcti
= pci
->pClientThreadInfo
;
2174 if (!hWnd
&& pci
&& pcti
)
2178 if ((pci
->cSpins
>= 100) && (pci
->dwTIFlags
& TIF_SPINNING
))
2179 { // Yield after 100 spin cycles and ready to swap vinyl.
2180 if (!(pci
->dwTIFlags
& TIF_WAITFORINPUTIDLE
))
2181 { // Not waiting for idle event.
2182 if (!pcti
->fsChangeBits
&& !pcti
->fsWakeBits
)
2183 { // No messages are available.
2184 if ((GetTickCount() - pcti
->tickLastMsgChecked
) > 1000)
2185 { // Up the msg read count if over 1 sec.
2186 NtUserGetThreadState(THREADSTATE_UPTIMELASTREAD
);
2190 FIXME("seeSpins!\n");
2196 return NtUserPeekMessage(pMsg
, hWnd
, wMsgFilterMin
, wMsgFilterMax
, wRemoveMsg
);
2205 PeekMessageA(LPMSG lpMsg
,
2213 Res
= PeekMessageWorker(lpMsg
, hWnd
, wMsgFilterMin
, wMsgFilterMax
, wRemoveMsg
);
2214 if (-1 == (int) Res
|| !Res
)
2219 IntConvertMsgToAnsi(lpMsg
);
2240 Res
= PeekMessageWorker(lpMsg
, hWnd
, wMsgFilterMin
, wMsgFilterMax
, wRemoveMsg
);
2241 if (-1 == (int) Res
|| !Res
)
2262 /* Check for combo box or a list box to send names. */
2263 if (Msg
== CB_DIR
|| Msg
== LB_DIR
)
2266 Set DDL_POSTMSGS, so use the PostMessage function to send messages to the
2267 combo/list box. Forces a call like DlgDirListComboBox.
2269 //wParam |= DDL_POSTMSGS;
2270 return NtUserPostMessage(hWnd
, Msg
, wParam
, lParam
);
2273 /* No drop files or current Process, just post message. */
2274 if ( (Msg
!= WM_DROPFILES
) ||
2275 ( NtUserQueryWindow( hWnd
, QUERY_WINDOW_UNIQUE_PROCESS_ID
) ==
2276 PtrToUint(NtCurrentTeb()->ClientId
.UniqueProcess
) ) )
2278 return NtUserPostMessage(hWnd
, Msg
, wParam
, lParam
);
2281 /* We have drop files and this is not the same process for this window. */
2283 /* Just incase, check wParam for Global memory handle and send size. */
2284 Ret
= SendMessageA( hWnd
,
2286 (WPARAM
)GlobalSize((HGLOBAL
)wParam
), // Zero if not a handle.
2287 (LPARAM
)wParam
); // Send wParam as lParam.
2289 if ( Ret
) return NtUserPostMessage(hWnd
, Msg
, (WPARAM
)Ret
, lParam
);
2307 /* Check for combo box or a list box to send names. */
2308 if (Msg
== CB_DIR
|| Msg
== LB_DIR
)
2311 Set DDL_POSTMSGS, so use the PostMessage function to send messages to the
2312 combo/list box. Forces a call like DlgDirListComboBox.
2314 //wParam |= DDL_POSTMSGS;
2315 return NtUserPostMessage(hWnd
, Msg
, wParam
, lParam
);
2318 /* No drop files or current Process, just post message. */
2319 if ( (Msg
!= WM_DROPFILES
) ||
2320 ( NtUserQueryWindow( hWnd
, QUERY_WINDOW_UNIQUE_PROCESS_ID
) ==
2321 PtrToUint(NtCurrentTeb()->ClientId
.UniqueProcess
) ) )
2323 return NtUserPostMessage(hWnd
, Msg
, wParam
, lParam
);
2326 /* We have drop files and this is not the same process for this window. */
2328 /* Just incase, check wParam for Global memory handle and send size. */
2329 Ret
= SendMessageW( hWnd
,
2331 (WPARAM
)GlobalSize((HGLOBAL
)wParam
), // Zero if not a handle.
2332 (LPARAM
)wParam
); // Send wParam as lParam.
2334 if ( Ret
) return NtUserPostMessage(hWnd
, Msg
, (WPARAM
)Ret
, lParam
);
2347 NtUserxPostQuitMessage(nExitCode
);
2362 return NtUserPostThreadMessage(idThread
, Msg
, wParam
, lParam
);
2377 return NtUserPostThreadMessage(idThread
, Msg
, wParam
, lParam
);
2385 SendMessageW(HWND Wnd
,
2393 PTHREADINFO ti
= GetW32ThreadInfo();
2395 if ( Msg
& ~WM_MAXIMUM
)
2397 SetLastError( ERROR_INVALID_PARAMETER
);
2401 if (Wnd
!= HWND_TOPMOST
&& Wnd
!= HWND_BROADCAST
&& (Msg
< WM_DDE_FIRST
|| Msg
> WM_DDE_LAST
))
2403 Window
= ValidateHwnd(Wnd
);
2405 if ( Window
!= NULL
&&
2406 Window
->head
.pti
== ti
&&
2407 !ISITHOOKED(WH_CALLWNDPROC
) &&
2408 !ISITHOOKED(WH_CALLWNDPROCRET
) &&
2409 !(Window
->state
& WNDS_SERVERSIDEWINDOWPROC
) )
2411 /* NOTE: We can directly send messages to the window procedure
2412 if *all* the following conditions are met:
2414 * Window belongs to calling thread
2415 * The calling thread is not being hooked for CallWndProc
2416 * Not calling a server side proc:
2417 Desktop, Switch, ScrollBar, Menu, IconTitle, or hWndMessage
2420 return IntCallMessageProc(Window
, Wnd
, Msg
, wParam
, lParam
, FALSE
);
2425 UMMsg
.message
= Msg
;
2426 UMMsg
.wParam
= wParam
;
2427 UMMsg
.lParam
= lParam
;
2429 if (! MsgiUMToKMMessage(&UMMsg
, &KMMsg
, FALSE
))
2434 Result
= NtUserMessageCall( Wnd
,
2442 MsgiUMToKMCleanup(&UMMsg
, &KMMsg
);
2452 SendMessageA(HWND Wnd
, UINT Msg
, WPARAM wParam
, LPARAM lParam
)
2454 MSG AnsiMsg
, UcMsg
, KMMsg
;
2457 PTHREADINFO ti
= GetW32ThreadInfo();
2459 if ( Msg
& ~WM_MAXIMUM
)
2461 SetLastError( ERROR_INVALID_PARAMETER
);
2465 if (Wnd
!= HWND_TOPMOST
&& Wnd
!= HWND_BROADCAST
&& (Msg
< WM_DDE_FIRST
|| Msg
> WM_DDE_LAST
))
2467 Window
= ValidateHwnd(Wnd
);
2469 if ( Window
!= NULL
&&
2470 Window
->head
.pti
== ti
&&
2471 !ISITHOOKED(WH_CALLWNDPROC
) &&
2472 !ISITHOOKED(WH_CALLWNDPROCRET
) &&
2473 !(Window
->state
& WNDS_SERVERSIDEWINDOWPROC
) )
2475 /* NOTE: We can directly send messages to the window procedure
2476 if *all* the following conditions are met:
2478 * Window belongs to calling thread
2479 * The calling thread is not being hooked for CallWndProc
2480 * Not calling a server side proc:
2481 Desktop, Switch, ScrollBar, Menu, IconTitle, or hWndMessage
2484 return IntCallMessageProc(Window
, Wnd
, Msg
, wParam
, lParam
, TRUE
);
2489 AnsiMsg
.message
= Msg
;
2490 AnsiMsg
.wParam
= wParam
;
2491 AnsiMsg
.lParam
= lParam
;
2493 if (!MsgiAnsiToUnicodeMessage(Wnd
, &UcMsg
, &AnsiMsg
))
2498 if (!MsgiUMToKMMessage(&UcMsg
, &KMMsg
, FALSE
))
2500 MsgiAnsiToUnicodeCleanup(&UcMsg
, &AnsiMsg
);
2504 Result
= NtUserMessageCall( Wnd
,
2512 MsgiUMToKMCleanup(&UcMsg
, &KMMsg
);
2513 MsgiAnsiToUnicodeReply(&UcMsg
, &AnsiMsg
, &Result
);
2523 SendMessageCallbackA(
2528 SENDASYNCPROC lpCallBack
,
2533 CALL_BACK_INFO CallBackInfo
;
2535 if (is_pointer_message(Msg
))
2537 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
2541 CallBackInfo
.CallBack
= lpCallBack
;
2542 CallBackInfo
.Context
= dwData
;
2544 AnsiMsg
.hwnd
= hWnd
;
2545 AnsiMsg
.message
= Msg
;
2546 AnsiMsg
.wParam
= wParam
;
2547 AnsiMsg
.lParam
= lParam
;
2549 if (!MsgiAnsiToUnicodeMessage(hWnd
, &UcMsg
, &AnsiMsg
))
2554 Result
= NtUserMessageCall( hWnd
,
2558 (ULONG_PTR
)&CallBackInfo
,
2559 FNID_SENDMESSAGECALLBACK
,
2562 MsgiAnsiToUnicodeCleanup(&UcMsg
, &AnsiMsg
);
2572 SendMessageCallbackW(
2577 SENDASYNCPROC lpCallBack
,
2580 CALL_BACK_INFO CallBackInfo
;
2582 if (is_pointer_message(Msg
))
2584 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
2588 CallBackInfo
.CallBack
= lpCallBack
;
2589 CallBackInfo
.Context
= dwData
;
2591 return NtUserMessageCall(hWnd
,
2595 (ULONG_PTR
)&CallBackInfo
,
2596 FNID_SENDMESSAGECALLBACK
,
2605 SendMessageTimeoutA(
2612 PDWORD_PTR lpdwResult
)
2618 if ( Msg
& ~WM_MAXIMUM
|| fuFlags
& ~(SMTO_NOTIMEOUTIFNOTHUNG
|SMTO_ABORTIFHUNG
|SMTO_BLOCK
))
2620 SetLastError( ERROR_INVALID_PARAMETER
);
2624 if (lpdwResult
) *lpdwResult
= 0;
2626 SPY_EnterMessage(SPY_SENDMESSAGE
, hWnd
, Msg
, wParam
, lParam
);
2628 dsm
.uFlags
= fuFlags
;
2629 dsm
.uTimeout
= uTimeout
;
2631 AnsiMsg
.hwnd
= hWnd
;
2632 AnsiMsg
.message
= Msg
;
2633 AnsiMsg
.wParam
= wParam
;
2634 AnsiMsg
.lParam
= lParam
;
2636 if (! MsgiAnsiToUnicodeMessage(hWnd
, &UcMsg
, &AnsiMsg
))
2641 Result
= NtUserMessageCall( hWnd
,
2646 FNID_SENDMESSAGEWTOOPTION
,
2649 MsgiAnsiToUnicodeReply(&UcMsg
, &AnsiMsg
, &Result
);
2651 if (lpdwResult
) *lpdwResult
= dsm
.Result
;
2653 SPY_ExitMessage(SPY_RESULT_OK
, hWnd
, Msg
, Result
, wParam
, lParam
);
2664 SendMessageTimeoutW(
2671 PDWORD_PTR lpdwResult
)
2676 if ( Msg
& ~WM_MAXIMUM
|| fuFlags
& ~(SMTO_NOTIMEOUTIFNOTHUNG
|SMTO_ABORTIFHUNG
|SMTO_BLOCK
))
2678 SetLastError( ERROR_INVALID_PARAMETER
);
2682 if (lpdwResult
) *lpdwResult
= 0;
2684 SPY_EnterMessage(SPY_SENDMESSAGE
, hWnd
, Msg
, wParam
, lParam
);
2686 dsm
.uFlags
= fuFlags
;
2687 dsm
.uTimeout
= uTimeout
;
2689 Result
= NtUserMessageCall( hWnd
,
2694 FNID_SENDMESSAGEWTOOPTION
,
2697 if (lpdwResult
) *lpdwResult
= dsm
.Result
;
2699 SPY_ExitMessage(SPY_RESULT_OK
, hWnd
, Msg
, Result
, wParam
, lParam
);
2718 if (is_pointer_message(Msg
))
2720 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
2724 AnsiMsg
.hwnd
= hWnd
;
2725 AnsiMsg
.message
= Msg
;
2726 AnsiMsg
.wParam
= wParam
;
2727 AnsiMsg
.lParam
= lParam
;
2728 if (! MsgiAnsiToUnicodeMessage(hWnd
, &UcMsg
, &AnsiMsg
))
2732 Ret
= SendNotifyMessageW(hWnd
, UcMsg
.message
, UcMsg
.wParam
, UcMsg
.lParam
);
2734 MsgiAnsiToUnicodeCleanup(&UcMsg
, &AnsiMsg
);
2753 if (is_pointer_message(Msg
))
2755 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
2760 UMMsg
.message
= Msg
;
2761 UMMsg
.wParam
= wParam
;
2762 UMMsg
.lParam
= lParam
;
2763 if (! MsgiUMToKMMessage(&UMMsg
, &KMMsg
, TRUE
))
2767 Result
= NtUserMessageCall( hWnd
,
2772 FNID_SENDNOTIFYMESSAGE
,
2775 MsgiUMToKMCleanup(&UMMsg
, &KMMsg
);
2784 TranslateMessageEx(CONST MSG
*lpMsg
, UINT Flags
)
2786 switch (lpMsg
->message
)
2792 return(NtUserTranslateMessage((LPMSG
)lpMsg
, Flags
));
2795 if ( lpMsg
->message
& ~WM_MAXIMUM
)
2796 SetLastError(ERROR_INVALID_PARAMETER
);
2806 TranslateMessage(CONST MSG
*lpMsg
)
2810 // Ref: msdn ImmGetVirtualKey:
2811 // http://msdn.microsoft.com/en-us/library/aa912145.aspx
2813 if ( (LOWORD(lpMsg->wParam) != VK_PROCESSKEY) ||
2814 !(Ret = IMM_ImmTranslateMessage( lpMsg->hwnd,
2819 Ret
= TranslateMessageEx((LPMSG
)lpMsg
, 0);
2829 RegisterWindowMessageA(LPCSTR lpString
)
2831 UNICODE_STRING String
;
2834 if (!RtlCreateUnicodeStringFromAsciiz(&String
, (PCSZ
)lpString
))
2838 Atom
= NtUserRegisterWindowMessage(&String
);
2839 RtlFreeUnicodeString(&String
);
2848 RegisterWindowMessageW(LPCWSTR lpString
)
2850 UNICODE_STRING String
;
2852 RtlInitUnicodeString(&String
, lpString
);
2853 return(NtUserRegisterWindowMessage(&String
));
2862 return (HWND
)NtUserGetThreadState(THREADSTATE_CAPTUREWINDOW
);
2869 ReleaseCapture(VOID
)
2871 return NtUserxReleaseCapture();
2880 RealGetQueueStatus(UINT flags
)
2882 #define QS_TEMPALLINPUT 255 // ATM, do not support QS_RAWINPUT
2883 if (flags
& ~(QS_SMRESULT
|QS_ALLPOSTMESSAGE
|QS_TEMPALLINPUT
))
2885 SetLastError( ERROR_INVALID_FLAGS
);
2888 return NtUserxGetQueueStatus(flags
);
2895 BOOL WINAPI
GetInputState(VOID
)
2897 PCLIENTTHREADINFO pcti
= GetWin32ClientInfo()->pClientThreadInfo
;
2899 if ((!pcti
) || (pcti
->fsChangeBits
& (QS_KEY
|QS_MOUSEBUTTON
)))
2900 return (BOOL
)NtUserGetThreadState(THREADSTATE_GETINPUTSTATE
);
2907 User32CallWindowProcFromKernel(PVOID Arguments
, ULONG ArgumentLength
)
2909 PWINDOWPROC_CALLBACK_ARGUMENTS CallbackArgs
;
2912 PCLIENTINFO pci
= GetWin32ClientInfo();
2914 /* Make sure we don't try to access mem beyond what we were given */
2915 if (ArgumentLength
< sizeof(WINDOWPROC_CALLBACK_ARGUMENTS
))
2917 return STATUS_INFO_LENGTH_MISMATCH
;
2920 CallbackArgs
= (PWINDOWPROC_CALLBACK_ARGUMENTS
) Arguments
;
2921 KMMsg
.hwnd
= CallbackArgs
->Wnd
;
2922 KMMsg
.message
= CallbackArgs
->Msg
;
2923 KMMsg
.wParam
= CallbackArgs
->wParam
;
2924 /* Check if lParam is really a pointer and adjust it if it is */
2925 if (0 <= CallbackArgs
->lParamBufferSize
)
2927 if (ArgumentLength
!= sizeof(WINDOWPROC_CALLBACK_ARGUMENTS
)
2928 + CallbackArgs
->lParamBufferSize
)
2930 return STATUS_INFO_LENGTH_MISMATCH
;
2932 KMMsg
.lParam
= (LPARAM
) ((char *) CallbackArgs
+ sizeof(WINDOWPROC_CALLBACK_ARGUMENTS
));
2933 switch(KMMsg
.message
)
2937 PRECT prect
= (PRECT
) KMMsg
.lParam
;
2938 ERR("WM_SIZING 1 t %d l %d r %d b %d\n",prect
->top
,prect
->left
,prect
->right
,prect
->bottom
);
2947 if (ArgumentLength
!= sizeof(WINDOWPROC_CALLBACK_ARGUMENTS
))
2949 return STATUS_INFO_LENGTH_MISMATCH
;
2951 KMMsg
.lParam
= CallbackArgs
->lParam
;
2954 if (WM_NCCALCSIZE
== CallbackArgs
->Msg
&& CallbackArgs
->wParam
)
2956 NCCALCSIZE_PARAMS
*Params
= (NCCALCSIZE_PARAMS
*) KMMsg
.lParam
;
2957 Params
->lppos
= (PWINDOWPOS
) (Params
+ 1);
2960 if (! MsgiKMToUMMessage(&KMMsg
, &UMMsg
))
2964 if (pci
->CallbackWnd
.hWnd
== UMMsg
.hwnd
)
2965 pWnd
= pci
->CallbackWnd
.pWnd
;
2967 CallbackArgs
->Result
= IntCallWindowProcW( CallbackArgs
->IsAnsiProc
,
2975 if (! MsgiKMToUMReply(&KMMsg
, &UMMsg
, &CallbackArgs
->Result
))
2979 if (0 <= CallbackArgs
->lParamBufferSize
)
2981 switch(KMMsg
.message
)
2985 PRECT prect
= (PRECT
) KMMsg
.lParam
;
2986 ERR("WM_SIZING 2 t %d l %d r %d b %d\n",prect
->top
,prect
->left
,prect
->right
,prect
->bottom
);
2993 return ZwCallbackReturn(CallbackArgs
, ArgumentLength
, STATUS_SUCCESS
);
2999 BOOL WINAPI
SetMessageQueue(int cMessagesMax
)
3001 /* Function does nothing on 32 bit windows */
3004 typedef DWORD (WINAPI
* RealGetQueueStatusProc
)(UINT flags
);
3005 typedef DWORD (WINAPI
* RealMsgWaitForMultipleObjectsExProc
)(DWORD nCount
, CONST HANDLE
*lpHandles
, DWORD dwMilliseconds
, DWORD dwWakeMask
, DWORD dwFlags
);
3006 typedef BOOL (WINAPI
* RealInternalGetMessageProc
)(LPMSG
,HWND
,UINT
,UINT
,UINT
,BOOL
);
3007 typedef BOOL (WINAPI
* RealWaitMessageExProc
)(DWORD
,UINT
);
3009 typedef struct _USER_MESSAGE_PUMP_ADDRESSES
{
3011 RealInternalGetMessageProc NtUserRealInternalGetMessage
;
3012 RealWaitMessageExProc NtUserRealWaitMessageEx
;
3013 RealGetQueueStatusProc RealGetQueueStatus
;
3014 RealMsgWaitForMultipleObjectsExProc RealMsgWaitForMultipleObjectsEx
;
3015 } USER_MESSAGE_PUMP_ADDRESSES
, * PUSER_MESSAGE_PUMP_ADDRESSES
;
3019 RealMsgWaitForMultipleObjectsEx(
3021 CONST HANDLE
*pHandles
,
3022 DWORD dwMilliseconds
,
3026 typedef BOOL (WINAPI
* MESSAGEPUMPHOOKPROC
)(BOOL Unregistering
,PUSER_MESSAGE_PUMP_ADDRESSES MessagePumpAddresses
);
3028 CRITICAL_SECTION gcsMPH
;
3029 MESSAGEPUMPHOOKPROC gpfnInitMPH
;
3030 DWORD gcLoadMPH
= 0;
3031 USER_MESSAGE_PUMP_ADDRESSES gmph
= {sizeof(USER_MESSAGE_PUMP_ADDRESSES
),
3032 NtUserRealInternalGetMessage
,
3033 NtUserRealWaitMessageEx
,
3035 RealMsgWaitForMultipleObjectsEx
3038 DWORD gfMessagePumpHook
= 0;
3040 BOOL WINAPI
IsInsideMessagePumpHook()
3041 { // FF uses this and polls it when Min/Max
3042 PCLIENTTHREADINFO pcti
= GetWin32ClientInfo()->pClientThreadInfo
;
3043 return (gfMessagePumpHook
&& pcti
&& (pcti
->dwcPumpHook
> 0));
3046 void WINAPI
ResetMessagePumpHook(PUSER_MESSAGE_PUMP_ADDRESSES Addresses
)
3048 Addresses
->cbSize
= sizeof(USER_MESSAGE_PUMP_ADDRESSES
);
3049 Addresses
->NtUserRealInternalGetMessage
= NtUserRealInternalGetMessage
;
3050 Addresses
->NtUserRealWaitMessageEx
= NtUserRealWaitMessageEx
;
3051 Addresses
->RealGetQueueStatus
= RealGetQueueStatus
;
3052 Addresses
->RealMsgWaitForMultipleObjectsEx
= RealMsgWaitForMultipleObjectsEx
;
3055 BOOL WINAPI
RegisterMessagePumpHook(MESSAGEPUMPHOOKPROC Hook
)
3057 EnterCriticalSection(&gcsMPH
);
3059 SetLastError(ERROR_INVALID_PARAMETER
);
3060 LeaveCriticalSection(&gcsMPH
);
3064 USER_MESSAGE_PUMP_ADDRESSES Addresses
;
3066 ResetMessagePumpHook(&Addresses
);
3067 if(!Hook(FALSE
, &Addresses
) || !Addresses
.cbSize
) {
3068 LeaveCriticalSection(&gcsMPH
);
3071 memcpy(&gmph
, &Addresses
, Addresses
.cbSize
);
3073 if(gpfnInitMPH
!= Hook
) {
3074 LeaveCriticalSection(&gcsMPH
);
3078 if(NtUserxInitMessagePump()) {
3079 LeaveCriticalSection(&gcsMPH
);
3083 InterlockedExchange((PLONG
)&gfMessagePumpHook
, 1);
3085 LeaveCriticalSection(&gcsMPH
);
3089 BOOL WINAPI
UnregisterMessagePumpHook(VOID
)
3091 EnterCriticalSection(&gcsMPH
);
3093 if(NtUserxUnInitMessagePump()) {
3096 InterlockedExchange((PLONG
)&gfMessagePumpHook
, 0);
3097 gpfnInitMPH(TRUE
, NULL
);
3098 ResetMessagePumpHook(&gmph
);
3101 LeaveCriticalSection(&gcsMPH
);
3105 LeaveCriticalSection(&gcsMPH
);
3109 DWORD WINAPI
GetQueueStatus(UINT flags
)
3111 return IsInsideMessagePumpHook() ? gmph
.RealGetQueueStatus(flags
) : RealGetQueueStatus(flags
);
3115 * @name RealMsgWaitForMultipleObjectsEx
3117 * Wait either for either message arrival or for one of the passed events
3121 * Number of handles in the pHandles array.
3123 * Handles of events to wait for.
3124 * @param dwMilliseconds
3127 * Mask specifying on which message events we should wakeup.
3129 * Wait type (see MWMO_* constants).
3135 RealMsgWaitForMultipleObjectsEx(
3137 const HANDLE
*pHandles
,
3138 DWORD dwMilliseconds
,
3142 LPHANDLE RealHandles
;
3143 HANDLE MessageQueueHandle
;
3146 PCLIENTTHREADINFO pcti
;
3148 if (dwFlags
& ~(MWMO_WAITALL
| MWMO_ALERTABLE
| MWMO_INPUTAVAILABLE
))
3150 SetLastError(ERROR_INVALID_PARAMETER
);
3154 pci
= GetWin32ClientInfo();
3155 if (!pci
) return WAIT_FAILED
;
3157 pcti
= pci
->pClientThreadInfo
;
3158 if (pcti
&& ( !nCount
|| !(dwFlags
& MWMO_WAITALL
) ))
3160 if ( (pcti
->fsChangeBits
& LOWORD(dwWakeMask
)) ||
3161 ( (dwFlags
& MWMO_INPUTAVAILABLE
) && (pcti
->fsWakeBits
& LOWORD(dwWakeMask
)) ) )
3163 //FIXME("Chg 0x%x Wake 0x%x Mask 0x%x nCnt %d\n",pcti->fsChangeBits, pcti->fsWakeBits, dwWakeMask, nCount);
3168 MessageQueueHandle
= NtUserxMsqSetWakeMask(MAKELONG(dwWakeMask
, dwFlags
));
3169 if (MessageQueueHandle
== NULL
)
3171 SetLastError(0); /* ? */
3175 RealHandles
= HeapAlloc(GetProcessHeap(), 0, (nCount
+ 1) * sizeof(HANDLE
));
3176 if (RealHandles
== NULL
)
3178 NtUserxMsqClearWakeMask();
3179 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
3183 RtlCopyMemory(RealHandles
, pHandles
, nCount
* sizeof(HANDLE
));
3184 RealHandles
[nCount
] = MessageQueueHandle
;
3186 Result
= WaitForMultipleObjectsEx(nCount
+ 1, RealHandles
,
3187 dwFlags
& MWMO_WAITALL
,
3188 dwMilliseconds
, dwFlags
& MWMO_ALERTABLE
);
3190 HeapFree(GetProcessHeap(), 0, RealHandles
);
3191 NtUserxMsqClearWakeMask();
3192 //FIXME("Result 0X%x\n",Result);
3200 MsgWaitForMultipleObjectsEx(
3202 CONST HANDLE
*lpHandles
,
3203 DWORD dwMilliseconds
,
3207 return IsInsideMessagePumpHook() ? gmph
.RealMsgWaitForMultipleObjectsEx(nCount
, lpHandles
, dwMilliseconds
, dwWakeMask
, dwFlags
) : RealMsgWaitForMultipleObjectsEx(nCount
, lpHandles
,dwMilliseconds
, dwWakeMask
, dwFlags
);
3214 MsgWaitForMultipleObjects(
3216 CONST HANDLE
*lpHandles
,
3218 DWORD dwMilliseconds
,
3221 return MsgWaitForMultipleObjectsEx(nCount
, lpHandles
, dwMilliseconds
,
3222 dwWakeMask
, fWaitAll
? MWMO_WAITALL
: 0);
3226 BOOL FASTCALL
MessageInit(VOID
)
3228 InitializeCriticalSection(&DdeCrst
);
3229 InitializeCriticalSection(&gcsMPH
);
3234 VOID FASTCALL
MessageCleanup(VOID
)
3236 DeleteCriticalSection(&DdeCrst
);
3237 DeleteCriticalSection(&gcsMPH
);
3244 IsDialogMessageA( HWND hwndDlg
, LPMSG pmsg
)
3247 msg
.wParam
= map_wparam_AtoW( msg
.message
, msg
.wParam
);
3248 return IsDialogMessageW( hwndDlg
, &msg
);
3253 IntBroadcastSystemMessage(
3255 LPDWORD lpdwRecipients
,
3263 DWORD recips
= BSM_ALLCOMPONENTS
;
3264 BOOL ret
= -1; // Set to return fail
3265 static const DWORD all_flags
= ( BSF_QUERY
| BSF_IGNORECURRENTTASK
| BSF_FLUSHDISK
| BSF_NOHANG
3266 | BSF_POSTMESSAGE
| BSF_FORCEIFHUNG
| BSF_NOTIMEOUTIFNOTHUNG
3267 | BSF_ALLOWSFW
| BSF_SENDNOTIFYMESSAGE
| BSF_RETURNHDESK
| BSF_LUID
);
3269 if ((dwflags
& ~all_flags
) ||
3270 (!pBSMInfo
&& (dwflags
& (BSF_RETURNHDESK
|BSF_LUID
))) )
3272 SetLastError(ERROR_INVALID_PARAMETER
);
3276 if(uiMessage
>= WM_USER
&& uiMessage
< 0xC000)
3278 SetLastError(ERROR_INVALID_PARAMETER
);
3282 if (dwflags
& BSF_FORCEIFHUNG
) dwflags
|= BSF_NOHANG
;
3284 if (dwflags
& BSF_QUERY
) dwflags
&= ~BSF_SENDNOTIFYMESSAGE
|BSF_POSTMESSAGE
;
3286 if (!lpdwRecipients
)
3287 lpdwRecipients
= &recips
;
3289 if (*lpdwRecipients
& ~(BSM_APPLICATIONS
|BSM_ALLDESKTOPS
|BSM_INSTALLABLEDRIVERS
|BSM_NETDRIVER
|BSM_VXDS
))
3291 SetLastError(ERROR_INVALID_PARAMETER
);
3295 if ( pBSMInfo
&& (dwflags
& BSF_QUERY
) )
3297 if (pBSMInfo
->cbSize
!= sizeof(BSMINFO
))
3299 SetLastError(ERROR_INVALID_PARAMETER
);
3306 parm
.flags
= dwflags
;
3307 parm
.recipients
= *lpdwRecipients
;
3309 if (dwflags
& BSF_LUID
) parm
.luid
= pBSMInfo
->luid
;
3311 ret
= NtUserMessageCall(GetDesktopWindow(),
3316 FNID_BROADCASTSYSTEMMESSAGE
,
3321 if ( pBSMInfo
&& (dwflags
& BSF_QUERY
) )
3323 pBSMInfo
->hdesk
= parm
.hDesk
;
3324 pBSMInfo
->hwnd
= parm
.hWnd
;
3335 BroadcastSystemMessageA(
3337 LPDWORD lpdwRecipients
,
3342 return IntBroadcastSystemMessage( dwFlags
, lpdwRecipients
, uiMessage
, wParam
, lParam
, NULL
, TRUE
);
3350 BroadcastSystemMessageW(
3352 LPDWORD lpdwRecipients
,
3357 return IntBroadcastSystemMessage( dwFlags
, lpdwRecipients
, uiMessage
, wParam
, lParam
, NULL
, FALSE
);
3365 BroadcastSystemMessageExA(
3367 LPDWORD lpdwRecipients
,
3373 return IntBroadcastSystemMessage( dwflags
, lpdwRecipients
, uiMessage
, wParam
, lParam
, pBSMInfo
, TRUE
);
3381 BroadcastSystemMessageExW(
3383 LPDWORD lpdwRecipients
,
3389 return IntBroadcastSystemMessage( dwflags
, lpdwRecipients
, uiMessage
, wParam
, lParam
, pBSMInfo
, FALSE
);