mirrored from https://gitlab.winehq.org/wine/wine.git
-
Notifications
You must be signed in to change notification settings - Fork 1k
/
win.c
1814 lines (1538 loc) · 53 KB
/
win.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Window related functions
*
* Copyright 1993, 1994 Alexandre Julliard
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include "user_private.h"
#include "controls.h"
#include "winver.h"
#include "wine/server.h"
#include "wine/asm.h"
#include "wine/exception.h"
#include "wine/debug.h"
WINE_DEFAULT_DEBUG_CHANNEL(win);
/*******************************************************************
* list_window_children
*
* Build an array of the children of a given window. The array must be
* freed with HeapFree. Returns NULL when no windows are found.
*/
static HWND *list_window_children( HDESK desktop, HWND hwnd, UNICODE_STRING *class, DWORD tid )
{
HWND *list;
int i, size = 128;
ATOM atom = class ? get_int_atom_value( class ) : 0;
/* empty class is not the same as NULL class */
if (!atom && class && !class->Length) return NULL;
for (;;)
{
int count = 0;
if (!(list = HeapAlloc( GetProcessHeap(), 0, size * sizeof(HWND) ))) break;
SERVER_START_REQ( get_window_children )
{
req->desktop = wine_server_obj_handle( desktop );
req->parent = wine_server_user_handle( hwnd );
req->tid = tid;
req->atom = atom;
if (!atom && class) wine_server_add_data( req, class->Buffer, class->Length );
wine_server_set_reply( req, list, (size-1) * sizeof(user_handle_t) );
if (!wine_server_call( req )) count = reply->count;
}
SERVER_END_REQ;
if (count && count < size)
{
/* start from the end since HWND is potentially larger than user_handle_t */
for (i = count - 1; i >= 0; i--)
list[i] = wine_server_ptr_handle( ((user_handle_t *)list)[i] );
list[count] = 0;
return list;
}
HeapFree( GetProcessHeap(), 0, list );
if (!count) break;
size = count + 1; /* restart with a large enough buffer */
}
return NULL;
}
/*******************************************************************
* is_desktop_window
*
* Check if window is the desktop or the HWND_MESSAGE top parent.
*/
BOOL is_desktop_window( HWND hwnd )
{
struct ntuser_thread_info *thread_info = NtUserGetThreadInfo();
if (!hwnd) return FALSE;
if (hwnd == UlongToHandle( thread_info->top_window )) return TRUE;
if (hwnd == UlongToHandle( thread_info->msg_window )) return TRUE;
if (!HIWORD(hwnd) || HIWORD(hwnd) == 0xffff)
{
if (LOWORD(thread_info->top_window) == LOWORD(hwnd)) return TRUE;
if (LOWORD(thread_info->msg_window) == LOWORD(hwnd)) return TRUE;
}
return FALSE;
}
/* check if hwnd is a broadcast magic handle */
static inline BOOL is_broadcast( HWND hwnd )
{
return hwnd == HWND_BROADCAST || hwnd == HWND_TOPMOST;
}
/***********************************************************************
* WIN_IsCurrentProcess
*
* Check whether a given window belongs to the current process (and return the full handle).
*/
HWND WIN_IsCurrentProcess( HWND hwnd )
{
return UlongToHandle( NtUserCallHwnd( hwnd, NtUserIsCurrentProcessWindow ));
}
/***********************************************************************
* WIN_IsCurrentThread
*
* Check whether a given window belongs to the current thread (and return the full handle).
*/
HWND WIN_IsCurrentThread( HWND hwnd )
{
return UlongToHandle( NtUserCallHwnd( hwnd, NtUserIsCurrentThreadWindow ));
}
/***********************************************************************
* WIN_GetFullHandle
*
* Convert a possibly truncated window handle to a full 32-bit handle.
*/
HWND WIN_GetFullHandle( HWND hwnd )
{
return UlongToHandle( NtUserCallHwnd( hwnd, NtUserGetFullWindowHandle ));
}
/***********************************************************************
* WIN_SetStyle
*
* Change the style of a window.
*/
ULONG WIN_SetStyle( HWND hwnd, ULONG set_bits, ULONG clear_bits )
{
/* FIXME: Use SetWindowLong or move callers to win32u instead.
* We use STYLESTRUCT to pass params, but meaning of its field does not match our usage. */
STYLESTRUCT style = { .styleNew = set_bits, .styleOld = clear_bits };
return NtUserCallHwndParam( hwnd, (UINT_PTR)&style, NtUserSetWindowStyle );
}
/***********************************************************************
* dump_window_styles
*/
static void dump_window_styles( DWORD style, DWORD exstyle )
{
TRACE( "style:" );
if(style & WS_POPUP) TRACE(" WS_POPUP");
if(style & WS_CHILD) TRACE(" WS_CHILD");
if(style & WS_MINIMIZE) TRACE(" WS_MINIMIZE");
if(style & WS_VISIBLE) TRACE(" WS_VISIBLE");
if(style & WS_DISABLED) TRACE(" WS_DISABLED");
if(style & WS_CLIPSIBLINGS) TRACE(" WS_CLIPSIBLINGS");
if(style & WS_CLIPCHILDREN) TRACE(" WS_CLIPCHILDREN");
if(style & WS_MAXIMIZE) TRACE(" WS_MAXIMIZE");
if((style & WS_CAPTION) == WS_CAPTION) TRACE(" WS_CAPTION");
else
{
if(style & WS_BORDER) TRACE(" WS_BORDER");
if(style & WS_DLGFRAME) TRACE(" WS_DLGFRAME");
}
if(style & WS_VSCROLL) TRACE(" WS_VSCROLL");
if(style & WS_HSCROLL) TRACE(" WS_HSCROLL");
if(style & WS_SYSMENU) TRACE(" WS_SYSMENU");
if(style & WS_THICKFRAME) TRACE(" WS_THICKFRAME");
if (style & WS_CHILD)
{
if(style & WS_GROUP) TRACE(" WS_GROUP");
if(style & WS_TABSTOP) TRACE(" WS_TABSTOP");
}
else
{
if(style & WS_MINIMIZEBOX) TRACE(" WS_MINIMIZEBOX");
if(style & WS_MAXIMIZEBOX) TRACE(" WS_MAXIMIZEBOX");
}
/* FIXME: Add dumping of BS_/ES_/SBS_/LBS_/CBS_/DS_/etc. styles */
#define DUMPED_STYLES \
((DWORD)(WS_POPUP | \
WS_CHILD | \
WS_MINIMIZE | \
WS_VISIBLE | \
WS_DISABLED | \
WS_CLIPSIBLINGS | \
WS_CLIPCHILDREN | \
WS_MAXIMIZE | \
WS_BORDER | \
WS_DLGFRAME | \
WS_VSCROLL | \
WS_HSCROLL | \
WS_SYSMENU | \
WS_THICKFRAME | \
WS_GROUP | \
WS_TABSTOP | \
WS_MINIMIZEBOX | \
WS_MAXIMIZEBOX))
if(style & ~DUMPED_STYLES) TRACE(" %08lx", style & ~DUMPED_STYLES);
TRACE("\n");
#undef DUMPED_STYLES
TRACE( "exstyle:" );
if(exstyle & WS_EX_DLGMODALFRAME) TRACE(" WS_EX_DLGMODALFRAME");
if(exstyle & WS_EX_DRAGDETECT) TRACE(" WS_EX_DRAGDETECT");
if(exstyle & WS_EX_NOPARENTNOTIFY) TRACE(" WS_EX_NOPARENTNOTIFY");
if(exstyle & WS_EX_TOPMOST) TRACE(" WS_EX_TOPMOST");
if(exstyle & WS_EX_ACCEPTFILES) TRACE(" WS_EX_ACCEPTFILES");
if(exstyle & WS_EX_TRANSPARENT) TRACE(" WS_EX_TRANSPARENT");
if(exstyle & WS_EX_MDICHILD) TRACE(" WS_EX_MDICHILD");
if(exstyle & WS_EX_TOOLWINDOW) TRACE(" WS_EX_TOOLWINDOW");
if(exstyle & WS_EX_WINDOWEDGE) TRACE(" WS_EX_WINDOWEDGE");
if(exstyle & WS_EX_CLIENTEDGE) TRACE(" WS_EX_CLIENTEDGE");
if(exstyle & WS_EX_CONTEXTHELP) TRACE(" WS_EX_CONTEXTHELP");
if(exstyle & WS_EX_RIGHT) TRACE(" WS_EX_RIGHT");
if(exstyle & WS_EX_RTLREADING) TRACE(" WS_EX_RTLREADING");
if(exstyle & WS_EX_LEFTSCROLLBAR) TRACE(" WS_EX_LEFTSCROLLBAR");
if(exstyle & WS_EX_CONTROLPARENT) TRACE(" WS_EX_CONTROLPARENT");
if(exstyle & WS_EX_STATICEDGE) TRACE(" WS_EX_STATICEDGE");
if(exstyle & WS_EX_APPWINDOW) TRACE(" WS_EX_APPWINDOW");
if(exstyle & WS_EX_LAYERED) TRACE(" WS_EX_LAYERED");
if(exstyle & WS_EX_NOINHERITLAYOUT) TRACE(" WS_EX_NOINHERITLAYOUT");
if(exstyle & WS_EX_LAYOUTRTL) TRACE(" WS_EX_LAYOUTRTL");
if(exstyle & WS_EX_COMPOSITED) TRACE(" WS_EX_COMPOSITED");
if(exstyle & WS_EX_NOACTIVATE) TRACE(" WS_EX_NOACTIVATE");
#define DUMPED_EX_STYLES \
((DWORD)(WS_EX_DLGMODALFRAME | \
WS_EX_DRAGDETECT | \
WS_EX_NOPARENTNOTIFY | \
WS_EX_TOPMOST | \
WS_EX_ACCEPTFILES | \
WS_EX_TRANSPARENT | \
WS_EX_MDICHILD | \
WS_EX_TOOLWINDOW | \
WS_EX_WINDOWEDGE | \
WS_EX_CLIENTEDGE | \
WS_EX_CONTEXTHELP | \
WS_EX_RIGHT | \
WS_EX_RTLREADING | \
WS_EX_LEFTSCROLLBAR | \
WS_EX_CONTROLPARENT | \
WS_EX_STATICEDGE | \
WS_EX_APPWINDOW | \
WS_EX_LAYERED | \
WS_EX_NOINHERITLAYOUT | \
WS_EX_LAYOUTRTL | \
WS_EX_COMPOSITED |\
WS_EX_NOACTIVATE))
if(exstyle & ~DUMPED_EX_STYLES) TRACE(" %08lx", exstyle & ~DUMPED_EX_STYLES);
TRACE("\n");
#undef DUMPED_EX_STYLES
}
static BOOL is_default_coord( int x )
{
return x == CW_USEDEFAULT || x == 0x8000;
}
/***********************************************************************
* WIN_CreateWindowEx
*
* Implementation of CreateWindowEx().
*/
HWND WIN_CreateWindowEx( CREATESTRUCTW *cs, LPCWSTR className, HINSTANCE module, BOOL unicode )
{
UNICODE_STRING class, window_name = {0};
HWND hwnd, top_child = 0;
MDICREATESTRUCTW mdi_cs;
WNDCLASSEXW info;
WCHAR name_buf[8];
HMENU menu;
if (!get_class_info( module, className, &info, &class, FALSE )) return FALSE;
TRACE("%s %s%s%s ex=%08lx style=%08lx %d,%d %dx%d parent=%p menu=%p inst=%p params=%p\n",
unicode ? debugstr_w(cs->lpszName) : debugstr_a((LPCSTR)cs->lpszName),
debugstr_w(className), class.Buffer != className ? "->" : "",
class.Buffer != className ? debugstr_wn(class.Buffer, class.Length / sizeof(WCHAR)) : "",
cs->dwExStyle, cs->style, cs->x, cs->y, cs->cx, cs->cy,
cs->hwndParent, cs->hMenu, cs->hInstance, cs->lpCreateParams );
if(TRACE_ON(win)) dump_window_styles( cs->style, cs->dwExStyle );
/* Fix the styles for MDI children */
if (cs->dwExStyle & WS_EX_MDICHILD)
{
POINT pos[2];
UINT id = 0;
if (!NtUserGetMDIClientInfo( cs->hwndParent ))
{
WARN("WS_EX_MDICHILD, but parent %p is not MDIClient\n", cs->hwndParent);
return 0;
}
/* cs->lpCreateParams of WM_[NC]CREATE is different for MDI children.
* MDICREATESTRUCT members have the originally passed values.
*
* Note: we rely on the fact that MDICREATESTRUCTA and MDICREATESTRUCTW
* have the same layout.
*/
mdi_cs.szClass = cs->lpszClass;
mdi_cs.szTitle = cs->lpszName;
mdi_cs.hOwner = cs->hInstance;
mdi_cs.x = cs->x;
mdi_cs.y = cs->y;
mdi_cs.cx = cs->cx;
mdi_cs.cy = cs->cy;
mdi_cs.style = cs->style;
mdi_cs.lParam = (LPARAM)cs->lpCreateParams;
cs->lpCreateParams = &mdi_cs;
if (GetWindowLongW(cs->hwndParent, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
{
if (cs->style & WS_POPUP)
{
TRACE("WS_POPUP with MDIS_ALLCHILDSTYLES is not allowed\n");
return 0;
}
cs->style |= WS_CHILD | WS_CLIPSIBLINGS;
}
else
{
cs->style &= ~WS_POPUP;
cs->style |= WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CAPTION |
WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX;
}
top_child = GetWindow(cs->hwndParent, GW_CHILD);
if (top_child)
{
/* Restore current maximized child */
if((cs->style & WS_VISIBLE) && IsZoomed(top_child))
{
TRACE("Restoring current maximized child %p\n", top_child);
if (cs->style & WS_MAXIMIZE)
{
/* if the new window is maximized don't bother repainting */
SendMessageW( top_child, WM_SETREDRAW, FALSE, 0 );
NtUserShowWindow( top_child, SW_SHOWNORMAL );
SendMessageW( top_child, WM_SETREDRAW, TRUE, 0 );
}
else NtUserShowWindow( top_child, SW_SHOWNORMAL );
}
}
MDI_CalcDefaultChildPos( cs->hwndParent, -1, pos, 0, &id );
if (!(cs->style & WS_POPUP)) cs->hMenu = ULongToHandle(id);
TRACE( "MDI child id %04x\n", id );
if (cs->style & (WS_CHILD | WS_POPUP))
{
if (is_default_coord( cs->x ))
{
cs->x = pos[0].x;
cs->y = pos[0].y;
}
if (is_default_coord( cs->cx ) || !cs->cx) cs->cx = pos[1].x;
if (is_default_coord( cs->cy ) || !cs->cy) cs->cy = pos[1].y;
}
}
if (!unicode && cs->lpszName)
{
const char *nameA = (const char *)cs->lpszName;
/* resource ID string is a special case */
if (nameA[0] == '\xff')
{
name_buf[0] = 0xffff;
name_buf[1] = MAKEWORD( nameA[1], nameA[2] );
name_buf[2] = 0;
RtlInitUnicodeString( &window_name, name_buf );
}
else if (!RtlCreateUnicodeStringFromAsciiz( &window_name, (const char *)cs->lpszName ))
return 0;
}
else RtlInitUnicodeString( &window_name, cs->lpszName );
menu = cs->hMenu;
if (!menu && info.lpszMenuName && (cs->style & (WS_CHILD | WS_POPUP)) != WS_CHILD)
menu = LoadMenuW( cs->hInstance, info.lpszMenuName );
hwnd = NtUserCreateWindowEx( cs->dwExStyle, &class, NULL, &window_name, cs->style,
cs->x, cs->y, cs->cx, cs->cy, cs->hwndParent, menu, module,
cs->lpCreateParams, 0, cs->hInstance, 0, !unicode );
if (!hwnd && menu && menu != cs->hMenu) NtUserDestroyMenu( menu );
if (!unicode && window_name.Buffer != name_buf) RtlFreeUnicodeString( &window_name );
return hwnd;
}
/***********************************************************************
* CreateWindowExA (USER32.@)
*/
HWND WINAPI DECLSPEC_HOTPATCH CreateWindowExA( DWORD exStyle, LPCSTR className,
LPCSTR windowName, DWORD style, INT x,
INT y, INT width, INT height,
HWND parent, HMENU menu,
HINSTANCE instance, LPVOID data )
{
CREATESTRUCTA cs;
cs.lpCreateParams = data;
cs.hInstance = instance;
cs.hMenu = menu;
cs.hwndParent = parent;
cs.x = x;
cs.y = y;
cs.cx = width;
cs.cy = height;
cs.style = style;
cs.lpszName = windowName;
cs.lpszClass = className;
cs.dwExStyle = exStyle;
if (!IS_INTRESOURCE(className))
{
WCHAR bufferW[256];
if (!MultiByteToWideChar( CP_ACP, 0, className, -1, bufferW, ARRAY_SIZE( bufferW )))
return 0;
return wow_handlers.create_window( (CREATESTRUCTW *)&cs, bufferW, instance, FALSE );
}
/* Note: we rely on the fact that CREATESTRUCTA and */
/* CREATESTRUCTW have the same layout. */
return wow_handlers.create_window( (CREATESTRUCTW *)&cs, (LPCWSTR)className, instance, FALSE );
}
/***********************************************************************
* CreateWindowExW (USER32.@)
*/
HWND WINAPI DECLSPEC_HOTPATCH CreateWindowExW( DWORD exStyle, LPCWSTR className,
LPCWSTR windowName, DWORD style, INT x,
INT y, INT width, INT height,
HWND parent, HMENU menu,
HINSTANCE instance, LPVOID data )
{
CREATESTRUCTW cs;
cs.lpCreateParams = data;
cs.hInstance = instance;
cs.hMenu = menu;
cs.hwndParent = parent;
cs.x = x;
cs.y = y;
cs.cx = width;
cs.cy = height;
cs.style = style;
cs.lpszName = windowName;
cs.lpszClass = className;
cs.dwExStyle = exStyle;
return wow_handlers.create_window( &cs, className, instance, TRUE );
}
/***********************************************************************
* CloseWindow (USER32.@)
*/
BOOL WINAPI CloseWindow( HWND hwnd )
{
if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD) return FALSE;
NtUserShowWindow( hwnd, SW_MINIMIZE );
return TRUE;
}
/***********************************************************************
* OpenIcon (USER32.@)
*/
BOOL WINAPI OpenIcon( HWND hwnd )
{
if (!IsIconic( hwnd )) return FALSE;
NtUserShowWindow( hwnd, SW_SHOWNORMAL );
return TRUE;
}
/***********************************************************************
* FindWindowExW (USER32.@)
*/
HWND WINAPI FindWindowExW( HWND parent, HWND child, const WCHAR *class, const WCHAR *title )
{
UNICODE_STRING class_str, title_str;
if (title) RtlInitUnicodeString( &title_str, title );
if (class)
{
if (IS_INTRESOURCE(class))
{
class_str.Buffer = (WCHAR *)class;
class_str.Length = class_str.MaximumLength = 0;
}
else RtlInitUnicodeString( &class_str, class );
}
return NtUserFindWindowEx( parent, child, class ? &class_str : NULL,
title ? &title_str : NULL, 0 );
}
/***********************************************************************
* FindWindowA (USER32.@)
*/
HWND WINAPI FindWindowA( LPCSTR className, LPCSTR title )
{
HWND ret = FindWindowExA( 0, 0, className, title );
if (!ret) SetLastError (ERROR_CANNOT_FIND_WND_CLASS);
return ret;
}
/***********************************************************************
* FindWindowExA (USER32.@)
*/
HWND WINAPI FindWindowExA( HWND parent, HWND child, LPCSTR className, LPCSTR title )
{
LPWSTR titleW = NULL;
HWND hwnd = 0;
if (title)
{
DWORD len = MultiByteToWideChar( CP_ACP, 0, title, -1, NULL, 0 );
if (!(titleW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) ))) return 0;
MultiByteToWideChar( CP_ACP, 0, title, -1, titleW, len );
}
if (!IS_INTRESOURCE(className))
{
WCHAR classW[256];
if (MultiByteToWideChar( CP_ACP, 0, className, -1, classW, ARRAY_SIZE( classW )))
hwnd = FindWindowExW( parent, child, classW, titleW );
}
else
{
hwnd = FindWindowExW( parent, child, (LPCWSTR)className, titleW );
}
HeapFree( GetProcessHeap(), 0, titleW );
return hwnd;
}
/***********************************************************************
* FindWindowW (USER32.@)
*/
HWND WINAPI FindWindowW( LPCWSTR className, LPCWSTR title )
{
return FindWindowExW( 0, 0, className, title );
}
/**********************************************************************
* GetDesktopWindow (USER32.@)
*/
HWND WINAPI GetDesktopWindow(void)
{
struct ntuser_thread_info *thread_info = NtUserGetThreadInfo();
if (thread_info->top_window) return UlongToHandle( thread_info->top_window );
return NtUserGetDesktopWindow();
}
/*******************************************************************
* EnableWindow (USER32.@)
*/
BOOL WINAPI EnableWindow( HWND hwnd, BOOL enable )
{
return NtUserEnableWindow( hwnd, enable );
}
/***********************************************************************
* IsWindowEnabled (USER32.@)
*/
BOOL WINAPI IsWindowEnabled( HWND hwnd )
{
return NtUserIsWindowEnabled( hwnd );
}
/***********************************************************************
* IsWindowUnicode (USER32.@)
*/
BOOL WINAPI IsWindowUnicode( HWND hwnd )
{
return NtUserIsWindowUnicode( hwnd );
}
/***********************************************************************
* GetWindowDpiAwarenessContext (USER32.@)
*/
DPI_AWARENESS_CONTEXT WINAPI GetWindowDpiAwarenessContext( HWND hwnd )
{
return LongToHandle( NtUserGetWindowDpiAwarenessContext( hwnd ) );
}
/***********************************************************************
* GetWindowDpiHostingBehavior (USER32.@)
*/
DPI_HOSTING_BEHAVIOR WINAPI GetWindowDpiHostingBehavior( HWND hwnd )
{
FIXME("(%p): stub\n", hwnd);
return DPI_HOSTING_BEHAVIOR_DEFAULT;
}
static LONG_PTR get_window_long_ptr( HWND hwnd, int offset, LONG_PTR ret, BOOL ansi )
{
if (offset == DWLP_DLGPROC && NtUserGetDialogInfo( hwnd ))
{
DLGPROC proc = NtUserGetDialogProc( (DLGPROC)ret, ansi );
if (proc && proc != WINPROC_PROC16) return (LONG_PTR)proc;
}
return ret;
}
static LONG_PTR set_dialog_proc( HWND hwnd, LONG_PTR newval, BOOL ansi )
{
DLGPROC proc;
LONG_PTR ret;
newval = NtUserCallTwoParam( newval, ansi, NtUserAllocWinProc );
ret = NtUserSetWindowLongPtr( hwnd, DWLP_DLGPROC, newval, ansi );
proc = NtUserGetDialogProc( (DLGPROC)ret, ansi );
if (proc) ret = (UINT_PTR)proc;
return ret;
}
/***********************************************************************
* GetDpiForWindow (USER32.@)
*/
UINT WINAPI GetDpiForWindow( HWND hwnd )
{
return NtUserGetDpiForWindow( hwnd );
}
/***********************************************************************
* SwitchToThisWindow (USER32.@)
*/
void WINAPI SwitchToThisWindow( HWND hwnd, BOOL alt_tab )
{
if (IsIconic( hwnd )) NtUserShowWindow( hwnd, SW_RESTORE );
else BringWindowToTop( hwnd );
}
/***********************************************************************
* GetWindowRect (USER32.@)
*/
BOOL WINAPI GetWindowRect( HWND hwnd, RECT *rect )
{
UINT dpi = NTUSER_DPI_CONTEXT_GET_DPI( (UINT_PTR)GetThreadDpiAwarenessContext() );
BOOL ret = NtUserGetWindowRect( hwnd, rect, dpi );
if (ret) TRACE( "hwnd %p %s\n", hwnd, wine_dbgstr_rect(rect) );
return ret;
}
/***********************************************************************
* GetWindowRgn (USER32.@)
*/
int WINAPI GetWindowRgn( HWND hwnd, HRGN hrgn )
{
return NtUserGetWindowRgnEx( hwnd, hrgn, 0 );
}
/***********************************************************************
* GetWindowRgnBox (USER32.@)
*/
int WINAPI GetWindowRgnBox( HWND hwnd, RECT *rect )
{
int ret = ERROR;
HRGN hrgn;
if (!rect)
return ERROR;
if ((hrgn = CreateRectRgn( 0, 0, 0, 0 )))
{
if ((ret = GetWindowRgn( hwnd, hrgn )) != ERROR )
ret = GetRgnBox( hrgn, rect );
DeleteObject( hrgn );
}
return ret;
}
/***********************************************************************
* GetClientRect (USER32.@)
*/
BOOL WINAPI GetClientRect( HWND hwnd, RECT *rect )
{
UINT dpi = NTUSER_DPI_CONTEXT_GET_DPI( (UINT_PTR)GetThreadDpiAwarenessContext() );
return NtUserGetClientRect( hwnd, rect, dpi );
}
/*******************************************************************
* WindowFromPoint (USER32.@)
*/
HWND WINAPI WindowFromPoint( POINT pt )
{
return NtUserWindowFromPoint( pt.x, pt.y );
}
/*******************************************************************
* ChildWindowFromPoint (USER32.@)
*/
HWND WINAPI ChildWindowFromPoint( HWND parent, POINT pt )
{
return NtUserChildWindowFromPointEx( parent, pt.x, pt.y, CWP_ALL );
}
/*******************************************************************
* RealChildWindowFromPoint (USER32.@)
*/
HWND WINAPI RealChildWindowFromPoint( HWND parent, POINT pt )
{
return NtUserRealChildWindowFromPoint( parent, pt.x, pt.y );
}
/*******************************************************************
* ChildWindowFromPointEx (USER32.@)
*/
HWND WINAPI ChildWindowFromPointEx( HWND parent, POINT pt, UINT flags )
{
return NtUserChildWindowFromPointEx( parent, pt.x, pt.y, flags );
}
/*******************************************************************
* MapWindowPoints (USER32.@)
*/
INT WINAPI MapWindowPoints( HWND hwnd_from, HWND hwnd_to, POINT *points, UINT count )
{
UINT dpi = NTUSER_DPI_CONTEXT_GET_DPI( (UINT_PTR)GetThreadDpiAwarenessContext() );
return NtUserMapWindowPoints( hwnd_from, hwnd_to, points, count, dpi );
}
/*******************************************************************
* ClientToScreen (USER32.@)
*/
BOOL WINAPI ClientToScreen( HWND hwnd, POINT *pt )
{
return NtUserClientToScreen( hwnd, pt );
}
/*******************************************************************
* ScreenToClient (USER32.@)
*/
BOOL WINAPI ScreenToClient( HWND hwnd, POINT *pt )
{
return NtUserScreenToClient( hwnd, pt );
}
/***********************************************************************
* IsIconic (USER32.@)
*/
BOOL WINAPI IsIconic( HWND hwnd )
{
return (GetWindowLongW( hwnd, GWL_STYLE ) & WS_MINIMIZE) != 0;
}
/***********************************************************************
* IsZoomed (USER32.@)
*/
BOOL WINAPI IsZoomed( HWND hwnd )
{
return (GetWindowLongW( hwnd, GWL_STYLE ) & WS_MAXIMIZE) != 0;
}
/*******************************************************************
* AllowSetForegroundWindow (USER32.@)
*/
BOOL WINAPI AllowSetForegroundWindow( DWORD procid )
{
/* FIXME: If Win98/2000 style SetForegroundWindow behavior is
* implemented, then fix this function. */
return TRUE;
}
/*******************************************************************
* LockSetForegroundWindow (USER32.@)
*/
BOOL WINAPI LockSetForegroundWindow( UINT lockcode )
{
/* FIXME: If Win98/2000 style SetForegroundWindow behavior is
* implemented, then fix this function. */
return TRUE;
}
/***********************************************************************
* BringWindowToTop (USER32.@)
*/
BOOL WINAPI BringWindowToTop( HWND hwnd )
{
return NtUserSetWindowPos( hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE );
}
/***********************************************************************
* AnimateWindow (USER32.@)
*/
BOOL WINAPI AnimateWindow( HWND hwnd, DWORD time, DWORD flags )
{
FIXME( "partial stub\n" );
/* If trying to show/hide and it's already shown/hidden or invalid window,
* fail with invalid parameter. */
if (!IsWindow( hwnd ) || (!(flags & AW_HIDE)) == IsWindowVisible( hwnd ))
{
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
NtUserShowWindow( hwnd, (flags & AW_HIDE) ? SW_HIDE : ((flags & AW_ACTIVATE) ? SW_SHOW : SW_SHOWNA) );
return TRUE;
}
/***********************************************************************
* BeginDeferWindowPos (USER32.@)
*/
HDWP WINAPI BeginDeferWindowPos( INT count )
{
return NtUserBeginDeferWindowPos( count );
}
/***********************************************************************
* DeferWindowPos (USER32.@)
*/
HDWP WINAPI DeferWindowPos( HDWP hdwp, HWND hwnd, HWND after, INT x, INT y,
INT cx, INT cy, UINT flags )
{
return NtUserDeferWindowPosAndBand( hdwp, hwnd, after, x, y, cx, cy, flags, 0, 0 );
}
/***********************************************************************
* EndDeferWindowPos (USER32.@)
*/
BOOL WINAPI EndDeferWindowPos( HDWP hdwp )
{
return NtUserEndDeferWindowPosEx( hdwp, FALSE );
}
/***********************************************************************
* ArrangeIconicWindows (USER32.@)
*/
UINT WINAPI ArrangeIconicWindows( HWND parent )
{
return NtUserArrangeIconicWindows( parent );
}
/**********************************************************************
* GetWindowWord (USER32.@)
*/
WORD WINAPI GetWindowWord( HWND hwnd, INT offset )
{
return NtUserGetWindowWord( hwnd, offset );
}
/**********************************************************************
* GetWindowLongA (USER32.@)
*/
#ifdef __i386__
/* This wrapper is here to workaround a ntlea quirk. First of all, ntlea
* checks whether GetWindowLongA starts with the Win32 hotpatchable prologue,
* if it can find that, it will use a hooking strategy more difficult for us
* to deal with. Secondly, it assumes what follows the prologue is a `pushl $-2`,
* and will try to skip over this instruction when calling `GetWindowLongA`,
* (i.e. it tries to jump to `GetWindowLongA + 7`, 5 bytes for the prologue, 2
* bytes for the `pushl`.). We have to anticipate that and make sure the result
* of doing this won't be a messed up stack, or a desynced PC.
*/
__ASM_STDCALL_FUNC( GetWindowLongA, 8,
".byte 0x8b, 0xff, 0x55, 0x8b, 0xec\n" /* Win32 hotpatchable prologue. */
"pushl $-2\n"
"addl $4, %esp\n"
"popl %ebp\n"
"jmp " __ASM_STDCALL("get_window_longA", 8) )
LONG WINAPI get_window_longA( HWND hwnd, INT offset )
#else
LONG WINAPI DECLSPEC_HOTPATCH GetWindowLongA( HWND hwnd, INT offset )
#endif
{
switch (offset)
{
#ifdef _WIN64
case GWLP_WNDPROC:
case GWLP_HINSTANCE:
case GWLP_HWNDPARENT:
WARN( "Invalid offset %d\n", offset );
SetLastError( ERROR_INVALID_INDEX );
return 0;
#endif
default:
if (sizeof(void *) == sizeof(LONG))
{
LONG_PTR ret = NtUserGetWindowLongA( hwnd, offset );
return get_window_long_ptr( hwnd, offset, ret, TRUE );
}
return NtUserGetWindowLongA( hwnd, offset );
}
}
/**********************************************************************
* GetWindowLongW (USER32.@)
*/
LONG WINAPI GetWindowLongW( HWND hwnd, INT offset )
{
switch (offset)
{
#ifdef _WIN64
case GWLP_WNDPROC:
case GWLP_HINSTANCE:
case GWLP_HWNDPARENT:
WARN( "Invalid offset %d\n", offset );
SetLastError( ERROR_INVALID_INDEX );
return 0;
#endif
default:
if (sizeof(void *) == sizeof(LONG))
{
LONG_PTR ret = NtUserGetWindowLongW( hwnd, offset );
return get_window_long_ptr( hwnd, offset, ret, FALSE );
}
return NtUserGetWindowLongW( hwnd, offset );
}
}
/**********************************************************************
* SetWindowLongA (USER32.@)
*
* See SetWindowLongW.
*/
LONG WINAPI DECLSPEC_HOTPATCH SetWindowLongA( HWND hwnd, INT offset, LONG newval )
{
switch (offset)
{
#ifdef _WIN64
case GWLP_WNDPROC:
case GWLP_HINSTANCE:
case GWLP_HWNDPARENT:
WARN( "Invalid offset %d\n", offset );
SetLastError( ERROR_INVALID_INDEX );
return 0;
#else
case DWLP_DLGPROC:
if (NtUserGetDialogInfo( hwnd )) return set_dialog_proc( hwnd, newval, TRUE );
/* fall through */
#endif
default:
return NtUserSetWindowLong( hwnd, offset, newval, TRUE );
}
}