-
Notifications
You must be signed in to change notification settings - Fork 152
/
window.c
3472 lines (3066 loc) · 100 KB
/
window.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
/*
* 16-bit windowing functions
*
* Copyright 2001 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 "wine/winuser16.h"
#include "wownt32.h"
#include "user_private.h"
#include "wine/debug.h"
#include "wine/exception.h"
#include "../krnl386/kernel16_private.h"
WINE_DEFAULT_DEBUG_CHANNEL(win);
struct {
int next;
HDC16 dcs[5];
HWND16 wnds[5];
} dcc = {0};
/* Workaround for ReactOS */
BOOL is_reactos()
{
static BOOL detected;
static BOOL is;
HKEY hKey;
CHAR name[100];
DWORD dwType, dwSize = sizeof(name);
if (detected)
return is;
detected = TRUE;
if (ERROR_SUCCESS != RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", 0, KEY_QUERY_VALUE, &hKey))
return FALSE;
if (ERROR_SUCCESS != RegQueryValueExA(hKey, "ProductName", NULL, &dwType, (LPBYTE)name, &dwSize))
{
RegCloseKey(hKey);
return FALSE;
}
RegCloseKey(hKey);
if (dwType != REG_SZ)
return FALSE;
is = strstr(name, "ReactOS") != NULL;
return is;
}
void WINAPI K32WOWHandle16Destroy(HANDLE handle, WOW_HANDLE_TYPE type);
void WINAPI K32WOWHandle16DestroyHint(HANDLE handle, WOW_HANDLE_TYPE type);
BOOL16 WINAPI IsOldWindowsTask(HINSTANCE16 hInst);
BYTE get_aflags(HMODULE16 hModule);
/* size of buffer needed to store an atom string */
#define ATOM_BUFFER_SIZE 256
/* handle <--> handle16 conversions */
#define HANDLE_16(h32) (LOWORD(h32))
#define HANDLE_32(h16) ((HANDLE)(ULONG_PTR)(h16))
/* wine(25cc380b8ed41652b135657ef7651beef2f20ae4) dlls/user32/menu.c */
BOOL is_win_menu_disallowed(DWORD style)
{
return (style & (WS_CHILD | WS_POPUP)) == WS_CHILD;
}
static HWND16 hwndSysModal;
static struct list class_list = LIST_INIT( class_list );
struct wnd_enum_info
{
WNDENUMPROC16 proc;
LPARAM param;
};
/* callback for 16-bit window enumeration functions */
static BOOL CALLBACK wnd_enum_callback( HWND hwnd, LPARAM param )
{
const struct wnd_enum_info *info = (struct wnd_enum_info *)param;
WORD args[3];
DWORD ret;
args[2] = HWND_16(hwnd);
args[1] = HIWORD(info->param);
args[0] = LOWORD(info->param);
WOWCallback16Ex( (DWORD)info->proc, WCB16_PASCAL, sizeof(args), args, &ret );
return LOWORD(ret);
}
/* convert insert after window handle to 32-bit */
static inline HWND full_insert_after_hwnd( HWND16 hwnd )
{
if (hwnd == (HWND)0xffff)
return HWND_TOPMOST;
if (hwnd == (HWND)0xfffe)
return HWND_NOTOPMOST;
if (hwnd == (HWND)HWND_TOP)
return HWND_TOP;
if (hwnd == (HWND)HWND_BOTTOM)
return HWND_BOTTOM;
HWND ret = WIN_Handle32( hwnd );
return ret;
}
BOOL CALLBACK remove_wndproc(HWND hwnd, LPARAM lparam)
{
if (GetExePtr(GetWindowWord16(HWND_16(hwnd), GWL_HINSTANCE)) == lparam)
{
TRACE("HWND %x WNDPROC removed\n", hwnd);
EnumChildWindows(hwnd, remove_wndproc, lparam);
SetWindowLongPtrA(hwnd, GWLP_WNDPROC, DefWindowProcA);
}
return TRUE;
}
BOOL CALLBACK enum_thread_window(HWND hwnd, LPARAM lparam)
{
struct class_entry *clazz = (struct class_entry*)lparam;
if (GetClassWord(hwnd, GCW_ATOM) == clazz->atom)
{
if (GetWindowLongPtrA(hwnd, GWLP_WNDPROC) != DefWindowProcA)
{
TRACE("HWND %x WNDPROC removed\n", hwnd);
SetWindowLongPtrA(hwnd, GWLP_WNDPROC, DefWindowProcA);
}
TRACE("HWND %x destroyed\n", hwnd);
DestroyWindow(hwnd);
}
return TRUE;
}
void free_module_classes( HINSTANCE16 inst )
{
struct class_entry *class, *next;
EnumThreadWindows(GetCurrentThreadId(), remove_wndproc, (LPARAM)inst);
LIST_FOR_EACH_ENTRY_SAFE( class, next, &class_list, struct class_entry, entry )
{
if (class->inst != inst) continue;
list_remove( &class->entry );
if (!UnregisterClassA( (LPCSTR)MAKEINTATOM(class->atom), HINSTANCE_32(class->inst) ))
{
if (GetLastError() == ERROR_CLASS_HAS_WINDOWS)
{
EnumThreadWindows( GetCurrentThreadId(), enum_thread_window, (LPARAM)class );
UnregisterClassA( (LPCSTR)MAKEINTATOM(class->atom), HINSTANCE_32(class->inst) );
}
}
WNDCLASS16Info[class->atom].allocated = FALSE;
TRACE("Class %s unregistered\n", debugstr_a(class->win32_classname));
HeapFree( GetProcessHeap(), 0, class );
}
}
BOOL is_dialog(HWND hwnd)
{
struct WW
{
union
{
DWORD state;
struct
{
int WFMPRESENT : 1;
int WFVPRESENT : 1;
int WFHPRESENT : 1;
int WFCPRESENT : 1;
int WFSENDSIZEMOVE : 1;
int WFMSGBOX : 1;
int WFFRAMEON : 1;
int WFHASSPB : 1;
int WFNONCPAINT : 1;
int WFSENDERASEBKGND : 1;
int WFERASEBKGND : 1;
int WFSENDNCPAINT : 1;
int WFINTERNALPAINT : 1;
int WFUPDATEDIRTY : 1;
int WFHIDDENPOPUP : 1;
int WFMENUDRAW : 1;
int WFDIALOGWINDOW : 1;
/*...*/
} stateFlags;
};
DWORD state2;
DWORD exstyle;
DWORD style;
/*...*/
};
BOOL ret = FALSE;
if (is_reactos())
{
/* see dialog.c DIALOG_CreateIndirect16 */
return HIWORD(GetWindowLongPtrW(hwnd, GWLP_HINSTANCE)) == 0xfefe;
}
/* undocumented, GetWindowLongW(hwnd, -1) returns a pointer to the internal window structure */
struct WW *ww = GetWindowLongW(hwnd, -1);
if (!ww)
return FALSE;
__TRY
{
if (ww->stateFlags.WFDIALOGWINDOW)
ret = TRUE;
}
__EXCEPT_ALL
{
}
__ENDTRY
return ret;
}
struct ThreadWindows
{
UINT numHandles;
UINT numAllocs;
HWND *handles;
};
static BOOL CALLBACK MSGBOX_EnumProc(HWND hwnd, LPARAM lParam)
{
struct ThreadWindows *threadWindows = (struct ThreadWindows *)lParam;
if (!EnableWindow(hwnd, FALSE))
{
if(threadWindows->numHandles >= threadWindows->numAllocs)
{
threadWindows->handles = HeapReAlloc(GetProcessHeap(), 0, threadWindows->handles,
(threadWindows->numAllocs*2)*sizeof(HWND));
threadWindows->numAllocs *= 2;
}
threadWindows->handles[threadWindows->numHandles++]=hwnd;
}
return TRUE;
}
/**************************************************************************
* MessageBox (USER.1)
*/
INT16 WINAPI MessageBox16( HWND16 hwnd, LPCSTR text, LPCSTR title, UINT16 type )
{
DWORD count;
struct ThreadWindows threadWindows;
ReleaseThunkLock(&count);
#ifdef ATTACH_THREAD_INPUT
//Force to set window to foreground.
DWORD foregroundID = GetWindowThreadProcessId(GetForegroundWindow(), NULL);
AttachThreadInput(GetCurrentThreadId(), foregroundID, TRUE);
#endif
if ((type & MB_TASKMODAL) && (hwnd == NULL))
{
threadWindows.numHandles = 0;
threadWindows.numAllocs = 10;
threadWindows.handles = HeapAlloc(GetProcessHeap(), 0, 10*sizeof(HWND));
EnumThreadWindows(GetCurrentThreadId(), MSGBOX_EnumProc, (LPARAM)&threadWindows);
}
int ret = MessageBoxA( WIN_Handle32(hwnd), text, title, type & ~MB_TASKMODAL );
if ((type & MB_TASKMODAL) && (hwnd == NULL))
{
for (int i = 0; i < threadWindows.numHandles; i++)
EnableWindow(threadWindows.handles[i], TRUE);
HeapFree(GetProcessHeap(), 0, threadWindows.handles);
}
#ifdef ATTACH_THREAD_INPUT
AttachThreadInput(GetCurrentThreadId(), foregroundID, FALSE);
#endif
RestoreThunkLock(count);
return ret;
}
#include <pshpack1.h>
typedef struct
{
BYTE pop_eax; /* 58 */
BYTE push_imm; /* 68 */
LPVOID this_;
BYTE push_eax; /* 50 */
BYTE jmp; /* E9 */
UINT_PTR func;
BOOL used;
LPVOID param;
} TIMERTHUNK;
#include <poppack.h>
static TIMERTHUNK *timer_thunk_array;
static int MAX_TIMER_THUNK;
static void init_timer_thunk()
{
if (timer_thunk_array)
return;
MAX_TIMER_THUNK = 4096 / sizeof(TIMERTHUNK);
timer_thunk_array = VirtualAlloc(NULL, MAX_TIMER_THUNK * sizeof(TIMERTHUNK), MEM_COMMIT, PAGE_EXECUTE_READWRITE);
}
static TIMERTHUNK *init_timer_thunk_data(LPVOID param, int i, LPVOID func)
{
timer_thunk_array[i].pop_eax = 0x58;
timer_thunk_array[i].push_imm = 0x68;
timer_thunk_array[i].this_ = timer_thunk_array + i;
timer_thunk_array[i].push_eax = 0x50;
timer_thunk_array[i].jmp = 0xE9;
timer_thunk_array[i].func = (UINT_PTR)func - (UINT_PTR)(&timer_thunk_array[i].func + 1);
timer_thunk_array[i].used = TRUE;
timer_thunk_array[i].param = param;
return timer_thunk_array + i;
}
static TIMERPROC allocate_timer_thunk(LPVOID param, LPVOID func, BOOL re)
{
init_timer_thunk();
if (re)
{
for (int i = 0; i < MAX_TIMER_THUNK; i++)
{
if (timer_thunk_array[i].used && timer_thunk_array[i].param == param)
{
return (TIMERPROC)(timer_thunk_array + i);
}
}
}
for (int i = 0; i < MAX_TIMER_THUNK; i++)
{
if (!timer_thunk_array[i].used)
{
return (TIMERPROC)init_timer_thunk_data(param, i, func);
}
}
ERR("could not allocate timer thunk!\n");
return NULL;
}
VOID CALLBACK TimerProc_Thunk(TIMERTHUNK *data, HWND hWnd, UINT msg, UINT_PTR wp, DWORD lp)
{
CallWindowProc16(data->param, HWND_16(hWnd), msg, wp, lp);
return;
}
BOOL is_timer_thunk(TIMERPROC proc)
{
return timer_thunk_array <= proc && proc < timer_thunk_array + MAX_TIMER_THUNK;
}
/***********************************************************************
* SetTimer (USER.10)
*/
UINT16 WINAPI SetTimer16( HWND16 hwnd, UINT16 id, UINT16 timeout, TIMERPROC16 proc )
{
TIMERPROC proc32;
UINT ret;
if (proc == NULL)
{
return SetTimer(WIN_Handle32(hwnd), id, timeout, NULL);
}
proc32 = allocate_timer_thunk(proc, TimerProc_Thunk, TRUE);
ret = SetTimer( WIN_Handle32(hwnd), id, timeout, proc32 );
return ret;
}
/***********************************************************************
* SetSystemTimer (USER.11)
*/
UINT16 WINAPI SetSystemTimer16( HWND16 hwnd, UINT16 id, UINT16 timeout, TIMERPROC16 proc )
{
TIMERPROC proc32 = proc == NULL ? NULL : allocate_timer_thunk(proc, TimerProc_Thunk, TRUE);
if (!SetSystemTimer)
{
ERR("SetSystemTimer NULL\n");
return 0;
}
return SetSystemTimer( WIN_Handle32(hwnd), id, timeout, proc32 );
}
/**************************************************************************
* KillTimer (USER.12)
*/
BOOL16 WINAPI KillTimer16( HWND16 hwnd, UINT16 id )
{
return KillTimer( WIN_Handle32(hwnd), id );
}
/**************************************************************************
* SetCapture (USER.18)
*/
HWND16 WINAPI SetCapture16( HWND16 hwnd )
{
return HWND_16( SetCapture( WIN_Handle32(hwnd) ));
}
/**************************************************************************
* ReleaseCapture (USER.19)
*/
BOOL16 WINAPI ReleaseCapture16(void)
{
BOOL result = ReleaseCapture();
static BOOL checked_is_windows_10;
static BOOL is_windows_10_or_later;
if (!checked_is_windows_10)
{
checked_is_windows_10 = TRUE;
is_windows_10_or_later = GetProcAddress(GetModuleHandleA("KERNEL32"), "InitializeEnclave") != NULL;
}
if (is_windows_10_or_later)
{
/* Windows 10 doesn't send WM_MOUSEMOVE */
#if 0
POINT point;
if (GetCursorPos(&point))
{
HWND hwnd = GetCapture();
if (!hwnd)
hwnd = WindowFromPoint(point);
if (hwnd)
PostMessageA(hwnd, WM_MOUSEMOVE, 0, MAKELPARAM(point.x, point.y));
}
#endif
INPUT input;
input.type = INPUT_MOUSE;
input.mi.mouseData = 0;
input.mi.dwFlags = MOUSEEVENTF_MOVE;
input.mi.time = 0;
input.mi.dwExtraInfo = 0;
input.mi.dx = 1;
input.mi.dy = 0;
SendInput(1, &input, sizeof(input));
input.mi.dx = -1;
input.mi.dy = 0;
SendInput(1, &input, sizeof(input));
}
return result;
}
/**************************************************************************
* SetFocus (USER.22)
*/
HWND16 WINAPI SetFocus16( HWND16 hwnd )
{
DWORD count;
HWND16 result;
ReleaseThunkLock(&count);
result = HWND_16(SetFocus(WIN_Handle32(hwnd)));
RestoreThunkLock(count);
return result;
}
/**************************************************************************
* GetFocus (USER.23)
*/
HWND16 WINAPI GetFocus16(void)
{
return HWND_16( GetFocus() );
}
/**************************************************************************
* RemoveProp (USER.24)
*/
HANDLE16 WINAPI RemoveProp16( HWND16 hwnd, LPCSTR str )
{
return HANDLE_16(RemovePropA( WIN_Handle32(hwnd), str ));
}
/**************************************************************************
* GetProp (USER.25)
*/
HANDLE16 WINAPI GetProp16( HWND16 hwnd, LPCSTR str )
{
return HANDLE_16(GetPropA( WIN_Handle32(hwnd), str ));
}
/**************************************************************************
* SetProp (USER.26)
*/
BOOL16 WINAPI SetProp16( HWND16 hwnd, LPCSTR str, HANDLE16 handle )
{
return SetPropA( WIN_Handle32(hwnd), str, HANDLE_32(handle) );
}
/***********************************************************************
* EnumProps (USER.27)
*/
INT16 WINAPI EnumProps16( HWND16 hwnd, PROPENUMPROC16 func )
{
ERR("(%04x,%08x)\n", hwnd, func);
return 0;
#if 0
int ret = -1, i, count, total = 32;
property_data_t *list;
while (total)
{
if (!(list = HeapAlloc( GetProcessHeap(), 0, total * sizeof(*list) ))) break;
count = 0;
SERVER_START_REQ( get_window_properties )
{
req->window = wine_server_user_handle( HWND_32(hwnd) );
wine_server_set_reply( req, list, total * sizeof(*list) );
if (!wine_server_call( req )) count = reply->total;
}
SERVER_END_REQ;
if (count && count <= total)
{
char string[ATOM_BUFFER_SIZE];
SEGPTR segptr = MapLS( string );
WORD args[4];
DWORD result;
for (i = 0; i < count; i++)
{
if (list[i].string) /* it was a string originally */
{
if (!GlobalGetAtomNameA( list[i].atom, string, ATOM_BUFFER_SIZE )) continue;
args[3] = hwnd;
args[2] = SELECTOROF(segptr);
args[1] = OFFSETOF(segptr);
args[0] = LOWORD(list[i].data);
}
else
{
args[3] = hwnd;
args[2] = 0;
args[1] = list[i].atom;
args[0] = LOWORD(list[i].data);
}
WOWCallback16Ex( (DWORD)func, WCB16_PASCAL, sizeof(args), args, &result );
if (!(ret = LOWORD(result))) break;
}
UnMapLS( segptr );
HeapFree( GetProcessHeap(), 0, list );
break;
}
HeapFree( GetProcessHeap(), 0, list );
total = count; /* restart with larger buffer */
}
return ret;
#endif
}
/**************************************************************************
* ClientToScreen (USER.28)
*/
void WINAPI ClientToScreen16( HWND16 hwnd, LPPOINT16 lppnt )
{
MapWindowPoints16( hwnd, 0, lppnt, 1 );
}
/**************************************************************************
* ScreenToClient (USER.29)
*/
void WINAPI ScreenToClient16( HWND16 hwnd, LPPOINT16 lppnt )
{
MapWindowPoints16( 0, hwnd, lppnt, 1 );
}
/**************************************************************************
* WindowFromPoint (USER.30)
*/
HWND16 WINAPI WindowFromPoint16( POINT16 pt )
{
POINT pt32;
pt32.x = pt.x;
pt32.y = pt.y;
return HWND_16( WindowFromPoint( pt32 ) );
}
/**************************************************************************
* IsIconic (USER.31)
*/
BOOL16 WINAPI IsIconic16(HWND16 hwnd)
{
return IsIconic( WIN_Handle32(hwnd) );
}
/**************************************************************************
* GetWindowRect (USER.32)
*/
void WINAPI GetWindowRect16( HWND16 hwnd, LPRECT16 rect )
{
RECT rect32;
if (GetWindowRect( WIN_Handle32(hwnd), &rect32 ))
{
rect->left = rect32.left;
rect->top = rect32.top;
rect->right = rect32.right;
rect->bottom = rect32.bottom;
}
}
/**************************************************************************
* GetClientRect (USER.33)
*/
void WINAPI GetClientRect16( HWND16 hwnd, LPRECT16 rect )
{
RECT rect32;
if (GetClientRect( WIN_Handle32(hwnd), &rect32 ))
{
rect->left = rect32.left;
rect->top = rect32.top;
rect->right = rect32.right;
rect->bottom = rect32.bottom;
}
}
/**************************************************************************
* EnableWindow (USER.34)
*/
BOOL16 WINAPI EnableWindow16( HWND16 hwnd, BOOL16 enable )
{
DWORD count;
ReleaseThunkLock(&count);
BOOL16 result = EnableWindow( WIN_Handle32(hwnd), enable );
RestoreThunkLock(count);
return result;
}
/**************************************************************************
* IsWindowEnabled (USER.35)
*/
BOOL16 WINAPI IsWindowEnabled16(HWND16 hwnd)
{
return IsWindowEnabled( WIN_Handle32(hwnd) );
}
/**************************************************************************
* GetWindowText (USER.36)
*/
INT16 WINAPI GetWindowText16( HWND16 hwnd, SEGPTR lpString, INT16 nMaxCount )
{
return SendMessage16( hwnd, WM_GETTEXT, nMaxCount, lpString );
}
/**************************************************************************
* SetWindowText (USER.37)
*/
BOOL16 WINAPI SetWindowText16( HWND16 hwnd, SEGPTR lpString )
{
if (IsBadReadPtr16(lpString, 1)) return FALSE;
return SendMessage16( hwnd, WM_SETTEXT, 0, lpString );
}
/**************************************************************************
* GetWindowTextLength (USER.38)
*/
INT16 WINAPI GetWindowTextLength16( HWND16 hwnd )
{
return SendMessage16( hwnd, WM_GETTEXTLENGTH, 0, 0 );
}
/***********************************************************************
* BeginPaint (USER.39)
*/
HDC16 WINAPI BeginPaint16( HWND16 hwnd, LPPAINTSTRUCT16 lps )
{
PAINTSTRUCT ps = { 0 };
BeginPaint( WIN_Handle32(hwnd), &ps );
lps->hdc = HDC_16(ps.hdc);
lps->fErase = ps.fErase;
lps->rcPaint.top = ps.rcPaint.top;
lps->rcPaint.left = ps.rcPaint.left;
lps->rcPaint.right = ps.rcPaint.right;
lps->rcPaint.bottom = ps.rcPaint.bottom;
lps->fRestore = ps.fRestore;
lps->fIncUpdate = ps.fIncUpdate;
if (IsOldWindowsTask(GetCurrentTask()) && !(get_aflags(GetExePtr(GetCurrentTask())) & NE_AFLAGS_WIN2_PROTMODE) && (GetCurrentObject(ps.hdc, OBJ_FONT) == GetStockObject(SYSTEM_FONT)))
SelectObject(ps.hdc, GetStockObject(SYSTEM_FIXED_FONT));
return lps->hdc;
}
/***********************************************************************
* EndPaint (USER.40)
*/
BOOL16 WINAPI EndPaint16( HWND16 hwnd, const PAINTSTRUCT16* lps )
{
PAINTSTRUCT ps = { 0 };
ps.hdc = HDC_32(lps->hdc);
ps.fErase = lps->fErase;
ps.rcPaint.top = lps->rcPaint.top;
ps.rcPaint.left = lps->rcPaint.left;
ps.rcPaint.right = lps->rcPaint.right;
ps.rcPaint.bottom = lps->rcPaint.bottom;
ps.fRestore = lps->fRestore;
ps.fIncUpdate = lps->fIncUpdate;
BOOL result = EndPaint( WIN_Handle32(hwnd), &ps );
if (result)
{
for (int i = 0; i < 5; i++)
{
if (dcc.dcs[i] == lps->hdc)
{
dcc.dcs[i] = 0;
dcc.wnds[i] = 0;
}
}
K32WOWHandle16DestroyHint(ps.hdc, WOW_TYPE_HDC);
}
return result;
}
/***********************************************************************
* CreateWindow (USER.41)
*/
HWND16 WINAPI CreateWindow16( LPCSTR className, LPCSTR windowName,
DWORD style, INT16 x, INT16 y, INT16 width,
INT16 height, HWND16 parent, HMENU16 menu,
HINSTANCE16 instance, LPVOID data )
{
return CreateWindowEx16( 0, className, windowName, style,
x, y, width, height, parent, menu, instance, data );
}
/**************************************************************************
* ShowWindow (USER.42)
*/
BOOL16 WINAPI ShowWindow16( HWND16 hwnd, INT16 cmd )
{
DWORD count;
ReleaseThunkLock(&count);
#ifdef ATTACH_THREAD_INPUT
DWORD foregroundID = GetWindowThreadProcessId(GetForegroundWindow(), NULL);
//Attach
AttachThreadInput(GetCurrentThreadId(), foregroundID, TRUE);
#endif
BOOL ret = ShowWindow( WIN_Handle32(hwnd), cmd );
#ifdef ATTACH_THREAD_INPUT
//Dettach
AttachThreadInput(GetCurrentThreadId(), foregroundID, FALSE);
#endif
RestoreThunkLock(count);
return ret;
}
/**************************************************************************
* CloseWindow (USER.43)
*/
BOOL16 WINAPI CloseWindow16( HWND16 hwnd )
{
DWORD count;
ReleaseThunkLock(&count);
BOOL16 result = CloseWindow( WIN_Handle32(hwnd) );
RestoreThunkLock(count);
return result;
}
/**************************************************************************
* OpenIcon (USER.44)
*/
BOOL16 WINAPI OpenIcon16( HWND16 hwnd )
{
return OpenIcon( WIN_Handle32(hwnd) );
}
/**************************************************************************
* BringWindowToTop (USER.45)
*/
BOOL16 WINAPI BringWindowToTop16( HWND16 hwnd )
{
DWORD count;
BOOL16 result;
ReleaseThunkLock(&count);
#ifdef ATTACH_THREAD_INPUT
//Force to set window to foreground.
DWORD foregroundID = GetWindowThreadProcessId(GetForegroundWindow(), NULL);
AttachThreadInput(GetCurrentThreadId(), foregroundID, TRUE);
#endif
result = (BOOL16)BringWindowToTop( WIN_Handle32(hwnd) );
#ifdef ATTACH_THREAD_INPUT
AttachThreadInput(GetCurrentThreadId(), foregroundID, FALSE);
#endif
RestoreThunkLock(count);
return result;
}
/**************************************************************************
* GetParent (USER.46)
*/
HWND16 WINAPI GetParent16( HWND16 hwnd )
{
return HWND_16( GetParent( WIN_Handle32(hwnd) ));
}
/**************************************************************************
* IsWindow (USER.47)
*/
BOOL16 WINAPI IsWindow16( HWND16 hwnd )
{
STACK16FRAME *frame = MapSL( (SEGPTR)getWOW32Reserved() );
frame->es = USER_HeapSel;
HWND hwnd32 = HWND_32(hwnd);
if (!HIWORD(hwnd32))
{
/* invalid handle */
return FALSE;
}
/* don't use WIN_Handle32 here, we don't care about the full handle */
return IsWindow( hwnd32 );
}
/**************************************************************************
* IsChild (USER.48)
*/
BOOL16 WINAPI IsChild16( HWND16 parent, HWND16 child )
{
return IsChild( WIN_Handle32(parent), WIN_Handle32(child) );
}
/**************************************************************************
* IsWindowVisible (USER.49)
*/
BOOL16 WINAPI IsWindowVisible16( HWND16 hwnd )
{
return IsWindowVisible( WIN_Handle32(hwnd) );
}
HWND16 WINAPI FindWindowEx16(HWND16 parent, HWND16 child, LPCSTR className, LPCSTR title);
/**************************************************************************
* FindWindow (USER.50)
*/
HWND16 WINAPI FindWindow16( LPCSTR className, LPCSTR title )
{
return FindWindowEx16( (HWND16)NULL, (HWND16)NULL, className, title );
}
/**************************************************************************
* DestroyWindow (USER.53)
*/
BOOL16 WINAPI DestroyWindow16( HWND16 hwnd )
{
DWORD count;
BOOL result;
HMENU16 hmenu16 = GetMenu16(hwnd);
ReleaseThunkLock(&count);
result = DestroyWindow(WIN_Handle32(hwnd));
RestoreThunkLock(count);
if (result && IsMenu16(hmenu16))
DestroyMenu16(hmenu16);
return result;
}
/*******************************************************************
* EnumWindows (USER.54)
*/
BOOL16 WINAPI EnumWindows16( WNDENUMPROC16 func, LPARAM lParam )
{
struct wnd_enum_info info;
info.proc = func;
info.param = lParam;
return EnumWindows( wnd_enum_callback, (LPARAM)&info );
}
/**********************************************************************
* EnumChildWindows (USER.55)
*/
BOOL16 WINAPI EnumChildWindows16( HWND16 parent, WNDENUMPROC16 func, LPARAM lParam )
{
struct wnd_enum_info info;
info.proc = func;
info.param = lParam;
return EnumChildWindows( WIN_Handle32(parent), wnd_enum_callback, (LPARAM)&info );
}
/**************************************************************************
* MoveWindow (USER.56)
*/
BOOL16 WINAPI MoveWindow16( HWND16 hwnd, INT16 x, INT16 y, INT16 cx, INT16 cy, BOOL16 repaint )
{
return SetWindowPos16(hwnd, 0, x, y, cx, cy, SWP_NOZORDER | SWP_NOACTIVATE | (repaint ? 0 : SWP_NOREDRAW));
}
/***********************************************************************
* RegisterClass (USER.57)
*/
BOOL16 WINAPI RegisterClass16( const WNDCLASS16 *wc )
{
WNDCLASSEX16 wcex;
wcex.cbSize = sizeof(wcex);
wcex.style = wc->style;
wcex.lpfnWndProc = wc->lpfnWndProc;
wcex.cbClsExtra = wc->cbClsExtra;
wcex.cbWndExtra = wc->cbWndExtra;
wcex.hInstance = wc->hInstance;
wcex.hIcon = wc->hIcon;
wcex.hCursor = wc->hCursor;
wcex.hbrBackground = wc->hbrBackground;
wcex.lpszMenuName = wc->lpszMenuName;
wcex.lpszClassName = wc->lpszClassName;
wcex.hIconSm = 0;
return RegisterClassEx16( &wcex ) != 0;
}
/**************************************************************************
* GetClassName (USER.58)
*/
INT16 WINAPI GetClassName16( HWND16 hwnd, LPSTR buffer, INT16 count )
{
char sclassName[200];
SIZE_T len = sizeof(sclassName) / sizeof(sclassName[0]);
LPSTR className = sclassName;
SIZE_T clen;
if (count == 0)
return 0;
if (count == 1)
{
buffer[0] = '\0';
return 0;
}
while (TRUE)
{
clen = GetClassNameA(WIN_Handle32(hwnd), className, len);
//className is truncated
if (len - 1 == clen)
{
LPVOID heap;
if (className != sclassName)
{
heap = HeapReAlloc(GetProcessHeap(), 0, className, len * 2);
}
else
{
heap = HeapAlloc(GetProcessHeap(), 0, len * 2);
}
if (!heap)
break;
className = (LPSTR)heap;
len *= 2;
continue;
}
break;
}
if (clen > 32767)
{
clen = 32767;
}
if (clen != 0)
{
struct class_entry *entry = find_win32_class(className);
if (!entry)
{
clen = min(clen, (SIZE_T)(count - 1));
memcpy(buffer, className, clen);
buffer[clen] = 0;
}
else
{
clen = min(strlen(entry->classInfo.lpszClassName), (SIZE_T)(count - 1));