forked from otya128/winevdm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmessage.c
5343 lines (5023 loc) · 178 KB
/
message.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 messaging support
*
* 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 "config.h"
#include "wine/port.h"
#include <assert.h>
#include <stdarg.h>
#include <string.h>
#include "wine/winuser16.h"
#include "wownt32.h"
#include "winerror.h"
#include "dde.h"
#include "user_private.h"
#include "wine/debug.h"
#include "message_table.h"
#include "../krnl386/kernel16_private.h"
#include "commctrl.h"
#include "wine/exception.h"
#include <shellapi.h>
#include <shlobj.h>
/*
unknwon combobox message
When EDIT received WM_KILLFOCUS, EDIT sent this message to COMBOBOX.
*/
#define CB_UNKNOWN_167 0x167
#define CB_UNKNOWN_167_16 (WM_USER + 27)
/* undocumented messages */
//reactos sdk/include/reactos/undocuser.h
#define WM_QUERYPARKICON 0x00000036
#define WM_CLIENTSHUTDOWN 0x0000003B
#define WM_COPYGLOBALDATA 0x00000049
#define WM_LOGONNOTIFY 0x0000004C
#define WM_KLUDGEMINRECT 0x0000008B
#define WM_UAHDRAWMENU 0x00000091
#define WM_UAHDRAWITEM 0x00000092 // WM_DRAWITEM
#define WM_UAHINITMENU 0x00000093
#define WM_UAHMEASUREITEM 0x00000094 // WM_MEASUREITEM
#define WM_UAHDRAWMENUNC 0x00000095
#define WM_NCUAHDRAWCAPTION 0x000000AE
#define WM_NCUAHDRAWFRAME 0x000000AF
#define WM_CBLOSTTEXTFOCUS 0x00000167
#define MN_SETHMENU 0x000001e0
#define WM_POPUPSYSTEMMENU 0x00000313
#define WM_UAHINIT 0x0000031b
#ifndef EM_ENABLEFEATURE /* WINVER < 0x0604 */
#define EM_ENABLEFEATURE 0x00DA
#endif
WINE_DEFAULT_DEBUG_CHANNEL(msg);
WINE_DECLARE_DEBUG_CHANNEL(message);
BOOL is_win_menu_disallowed(DWORD style);
DWORD USER16_AlertableWait = 0;
static UINT aviwnd_msg = 0;
static void *aviwnd_cwp;
static ATOM dialogmsgthunk;
struct wow_handlers32 wow_handlers32;
#define TIMER32_LPARAM 0x42137460
struct timer32_wrapper
{
WPARAM wParam;
LPARAM lParam;
BOOL ref;
};
#define TIMER32_WRAP_SIZE 400
static int timer32_count;
static struct timer32_wrapper timer32[TIMER32_WRAP_SIZE];
typedef enum
{
WINDOW_TYPE_WINDOW,
WINDOW_TYPE_STATIC,
WINDOW_TYPE_BUTTON,
WINDOW_TYPE_LISTBOX,
WINDOW_TYPE_EDIT,
WINDOW_TYPE_SCROLLBAR,
WINDOW_TYPE_COMBOBOX,
WINDOW_TYPE_MDICLIENT,
WINDOW_TYPE_AVIWND,
} WINDOW_TYPE;
LPBYTE window_type_table;
#include <pshpack1.h>
typedef struct
{
UINT16 uNotification;
HWND16 hWnd;
POINT16 ptCursor;
} DRAGLISTINFO16;
#include <poppack.h>
UINT drag_list_message;
static void dump_hmenu(HMENU menu)
{
int count = GetMenuItemCount(menu);
for (int i = 0; i < count; i++)
{
MENUITEMINFOA item = { sizeof(MENUITEMINFOA) };
item.fMask = MIIM_BITMAP | MIIM_ID | MIIM_STRING;
char buf[1000];
buf[0] = 0;
item.dwTypeData = buf;
item.cch = 1000;
if (!GetMenuItemInfoA(menu, i, TRUE, &item))
{
}
MESSAGE("%s bmp:%p id:%04x\n", buf, item.hbmpItem, item.wID);
if (item.hSubMenu)
{
MESSAGE("====BEGIN SUB MENU %p/%p ====\n", menu, item.hSubMenu);
dump_hmenu(item.hSubMenu);
MESSAGE("====END SUB MENU %p/%p ====\n", menu, item.hSubMenu);
}
}
}
static void dump_menu(HWND hwnd)
{
HMENU menu = GetMenu(hwnd);
dump_hmenu(menu);
}
static LRESULT send_message_callback( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp,
LRESULT *result, void *arg )
{
*result = SendMessageA( hwnd, msg, wp, lp );
return *result;
}
static LRESULT post_message_callback( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp,
LRESULT *result, void *arg )
{
*result = 0;
return PostMessageA( hwnd, msg, wp, lp );
}
static LRESULT post_thread_message_callback( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp,
LRESULT *result, void *arg )
{
DWORD_PTR tid = (DWORD_PTR)arg;
*result = 0;
return PostThreadMessageA( tid, msg, wp, lp );
}
/*static */LRESULT get_message_callback( HWND16 hwnd, UINT16 msg, WPARAM16 wp, LPARAM lp,
LRESULT *result, void *arg )
{
MSG16 *msg16 = arg;
msg16->hwnd = hwnd;
msg16->message = msg;
msg16->wParam = wp;
msg16->lParam = lp;
*result = 0;
return 0;
}
static LRESULT defdlg_proc_callback( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp,
LRESULT *result, void *arg )
{
*result = DefDlgProcA( hwnd, msg, wp, lp );
return *result;
}
static LRESULT call_window_proc_callback( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp,
LRESULT *result, void *arg )
{
WNDPROC proc = arg;
DWORD count;
ReleaseThunkLock(&count);
*result = CallWindowProcA( proc, hwnd, msg, wp, lp );
RestoreThunkLock(count);
return *result;
}
/**********************************************************************
* Support for window procedure thunks
*/
#include "pshpack1.h"
typedef struct
{
BYTE popl_eax; /* popl %eax (return address) */
BYTE pushl_func; /* pushl $proc */
WNDPROC proc;
BYTE pushl_eax; /* pushl %eax */
BYTE ljmp; /* ljmp relay*/
DWORD relay_offset; /* __wine_call_wndproc */
WORD relay_sel;
} WINPROC_THUNK;
#include "poppack.h"
/* 0xffffxxxx is already used by WOW64. */
#define WINPROC_HANDLE 0xfffe
#define MAX_WINPROCS32 4096
#define MAX_WINPROCS16 1024
static WNDPROC16 winproc16_array[MAX_WINPROCS16];
static unsigned int winproc16_used;
static WINPROC_THUNK *thunk_array;
static UINT thunk_selector;
/* return the window proc index for a given handle, or -1 for an invalid handle
* indices 0 .. MAX_WINPROCS32-1 are for 32-bit procs,
* indices MAX_WINPROCS32 .. MAX_WINPROCS32+MAX_WINPROCS16-1 for 16-bit procs */
static int winproc_to_index( WNDPROC16 handle )
{
unsigned int index;
if (HIWORD(handle) == thunk_selector)
{
index = LOWORD(handle) / sizeof(WINPROC_THUNK);
/* check alignment */
if (index * sizeof(WINPROC_THUNK) != LOWORD(handle)) return -1;
/* check array limits */
if (index >= MAX_WINPROCS32) return -1;
}
else
{
index = LOWORD(handle);
if ((ULONG_PTR)handle >> 16 != WINPROC_HANDLE) return -1;
/* check array limits */
if (index >= winproc16_used + MAX_WINPROCS32) return -1;
}
return index;
}
/* allocate a 16-bit thunk for an existing window proc */
static WNDPROC16 alloc_win16_thunk( WNDPROC handle )
{
static FARPROC16 relay;
WINPROC_THUNK *thunk;
#if 0
UINT index = LOWORD( handle );
if (index >= MAX_WINPROCS32) /* already a 16-bit proc */
return winproc16_array[index - MAX_WINPROCS32];
#else
UINT index;
index = LOWORD(wow_handlers32.alloc_winproc(handle, FALSE));
#endif
if (!thunk_array) /* allocate the array and its selector */
{
LDT_ENTRY entry;
assert( MAX_WINPROCS16 * sizeof(WINPROC_THUNK) <= 0x10000 );
if (!(thunk_selector = wine_ldt_alloc_entries(1))) return NULL;
if (!(thunk_array = VirtualAlloc( NULL, MAX_WINPROCS16 * sizeof(WINPROC_THUNK), MEM_COMMIT,
PAGE_EXECUTE_READWRITE ))) return NULL;
wine_ldt_set_base( &entry, thunk_array );
wine_ldt_set_limit( &entry, MAX_WINPROCS16 * sizeof(WINPROC_THUNK) - 1 );
wine_ldt_set_flags( &entry, WINE_LDT_FLAGS_CODE | WINE_LDT_FLAGS_32BIT );
wine_ldt_set_entry( thunk_selector, &entry );
relay = GetProcAddress16( GetModuleHandle16("user"), "__wine_call_wndproc" );
}
thunk = &thunk_array[index];
thunk->popl_eax = 0x58; /* popl %eax */
thunk->pushl_func = 0x68; /* pushl $proc */
thunk->proc = handle;
thunk->pushl_eax = 0x50; /* pushl %eax */
thunk->ljmp = 0xea; /* ljmp relay*/
thunk->relay_offset = OFFSETOF(relay);
thunk->relay_sel = SELECTOROF(relay);
return (WNDPROC16)MAKESEGPTR( thunk_selector, index * sizeof(WINPROC_THUNK) );
}
LRESULT CALLBACK WindowProc16(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam);
LRESULT CALLBACK edit_wndproc16(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
/**********************************************************************
* WINPROC_GetProc16
*
* Get a window procedure pointer that can be passed to the Windows program.
*/
WNDPROC16 WINPROC_GetProc16( WNDPROC proc, BOOL unicode )
{
#if 0
WNDPROC winproc = wow_handlers32.alloc_winproc( proc, unicode );
if ((ULONG_PTR)winproc >> 16 != WINPROC_HANDLE) return (WNDPROC16)winproc;
return alloc_win16_thunk( winproc );
#else
if (!proc)
return NULL;
if (proc == WindowProc16)
proc = DefWindowProcA;
return alloc_win16_thunk(proc);
#endif
}
/* call a 16-bit window procedure */
/*static*/ LRESULT call_window_proc16( HWND16 hwnd, UINT16 msg, WPARAM16 wParam, LPARAM lParam,
LRESULT *result, void *arg )
{
WNDPROC16 func = arg;
int index = winproc_to_index( func );
CONTEXT context;
size_t size = 0;
#include <pshpack1.h>
struct
{
WORD params[5];
union
{
CREATESTRUCT16 cs16;
DRAWITEMSTRUCT16 dis16;
COMPAREITEMSTRUCT16 cis16;
} u;
} args;
#include <poppack.h>
if (index >= MAX_WINPROCS32) func = winproc16_array[index - MAX_WINPROCS32];
/* Window procedures want ax = hInstance, ds = es = ss */
memset(&context, 0, sizeof(context));
context.SegDs = context.SegEs = SELECTOROF(getWOW32Reserved());
context.SegFs = wine_get_fs();
context.SegGs = wine_get_gs();
context.Eax = !hwnd ? 0 : GetWindowWord16(hwnd, GWLP_HINSTANCE) | 1; /* Handle To Sel */
if (!context.Eax || (func == GetDlgProc16(hwnd))) context.Eax = context.SegDs;
context.Ebx = 6;
context.Esi = hwnd;
context.SegCs = SELECTOROF(func);
context.Eip = OFFSETOF(func);
context.Ebp = OFFSETOF(getWOW32Reserved()) + FIELD_OFFSET(STACK16FRAME, bp);
if (lParam)
{
/* Some programs (eg. the "Undocumented Windows" examples, JWP) only
work if structures passed in lParam are placed in the stack/data
segment. Programmers easily make the mistake of converting lParam
to a near rather than a far pointer, since Windows apparently
allows this. We copy the structures to the 16 bit stack; this is
ugly but makes these programs work. */
switch (msg)
{
case WM_CREATE:
case WM_NCCREATE:
size = sizeof(CREATESTRUCT16); break;
case WM_DRAWITEM:
size = sizeof(DRAWITEMSTRUCT16); break;
case WM_COMPAREITEM:
size = sizeof(COMPAREITEMSTRUCT16); break;
}
if (size)
{
memcpy( &args.u, MapSL(lParam), size );
lParam = PtrToUlong(getWOW32Reserved()) - size;
}
}
PVOID old = getWOW32Reserved();
args.params[4] = hwnd;
args.params[3] = msg;
args.params[2] = wParam;
args.params[1] = HIWORD(lParam);
args.params[0] = LOWORD(lParam);
WOWCallback16Ex( 0, WCB16_REGS, sizeof(args.params) + size, &args, (DWORD *)&context );
//restore stack
setWOW32Reserved(old);
*result = MAKELONG( LOWORD(context.Eax), LOWORD(context.Edx) );
return *result;
}
static LRESULT call_dialog_proc16( HWND16 hwnd, UINT16 msg, WPARAM16 wp, LPARAM lp,
LRESULT *result, void *arg )
{
LRESULT ret = call_window_proc16( hwnd, msg, wp, lp, result, arg );
*result = GetWindowLongPtrW( WIN_Handle32(hwnd), DWLP_MSGRESULT );
return LOWORD(ret);
}
static LRESULT call_window_proc_Ato16( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp,
LRESULT *result, void *arg )
{
return WINPROC_CallProc32ATo16( call_window_proc16, hwnd, msg, wp, lp, result, arg );
}
static LRESULT call_dialog_proc_Ato16( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp,
LRESULT *result, void *arg )
{
return WINPROC_CallProc32ATo16( call_dialog_proc16, hwnd, msg, wp, lp, result, arg );
}
/**********************************************************************
* Support for Edit word break proc thunks
*/
#define MAX_THUNKS 32
#include <pshpack1.h>
static struct word_break_thunk
{
BYTE popl_eax; /* popl %eax (return address) */
BYTE pushl_proc16; /* pushl proc16 */
EDITWORDBREAKPROC16 proc16;
BYTE pushl_eax; /* pushl %eax */
BYTE jmp; /* ljmp call_word_break_proc16 */
DWORD callback;
} *word_break_thunks;
#include <poppack.h>
/**********************************************************************
* call_word_break_proc16
*/
static INT16 CALLBACK call_word_break_proc16( SEGPTR proc16, LPSTR text, INT index, INT count, INT action )
{
SEGPTR segptr;
WORD args[5];
DWORD result;
segptr = MapLS( text );
args[4] = SELECTOROF(segptr);
args[3] = OFFSETOF(segptr);
args[2] = index;
args[1] = count;
args[0] = action;
WOWCallback16Ex( proc16, WCB16_PASCAL, sizeof(args), args, &result );
UnMapLS( segptr );
return LOWORD(result);
}
/******************************************************************
* add_word_break_thunk
*/
static struct word_break_thunk *add_word_break_thunk( EDITWORDBREAKPROC16 proc16 )
{
struct word_break_thunk *thunk;
if (!word_break_thunks)
{
word_break_thunks = VirtualAlloc( NULL, MAX_THUNKS * sizeof(*thunk),
MEM_COMMIT, PAGE_EXECUTE_READWRITE );
if (!word_break_thunks) return NULL;
for (thunk = word_break_thunks; thunk < &word_break_thunks[MAX_THUNKS]; thunk++)
{
thunk->popl_eax = 0x58; /* popl %eax */
thunk->pushl_proc16 = 0x68; /* pushl proc16 */
thunk->pushl_eax = 0x50; /* pushl %eax */
thunk->jmp = 0xe9; /* jmp call_word_break_proc16 */
thunk->callback = (char *)call_word_break_proc16 - (char *)(&thunk->callback + 1);
}
}
for (thunk = word_break_thunks; thunk < &word_break_thunks[MAX_THUNKS]; thunk++)
if (thunk->proc16 == proc16) return thunk;
for (thunk = word_break_thunks; thunk < &word_break_thunks[MAX_THUNKS]; thunk++)
{
if (thunk->proc16) continue;
thunk->proc16 = proc16;
return thunk;
}
FIXME("Out of word break thunks\n");
return NULL;
}
/******************************************************************
* get_word_break_thunk
*/
static EDITWORDBREAKPROC16 get_word_break_thunk( EDITWORDBREAKPROCA proc )
{
struct word_break_thunk *thunk = (struct word_break_thunk *)proc;
if (word_break_thunks && thunk >= word_break_thunks && thunk < &word_break_thunks[MAX_THUNKS])
return thunk->proc16;
return NULL;
}
/***********************************************************************
* Support for 16<->32 message mapping
*/
static inline void *get_buffer( void *static_buffer, size_t size, size_t need )
{
if (size >= need) return static_buffer;
return HeapAlloc( GetProcessHeap(), 0, need );
}
static inline void free_buffer( void *static_buffer, void *buffer )
{
if (buffer != static_buffer) HeapFree( GetProcessHeap(), 0, buffer );
}
static void RECT16to32( const RECT16 *from, RECT *to )
{
to->left = from->left;
to->top = from->top;
to->right = from->right;
to->bottom = from->bottom;
}
static void RECT32to16( const RECT *from, RECT16 *to )
{
to->left = from->left;
to->top = from->top;
to->right = from->right;
to->bottom = from->bottom;
}
static void MINMAXINFO32to16( const MINMAXINFO *from, MINMAXINFO16 *to )
{
to->ptReserved.x = from->ptReserved.x;
to->ptReserved.y = from->ptReserved.y;
to->ptMaxSize.x = from->ptMaxSize.x;
to->ptMaxSize.y = from->ptMaxSize.y;
to->ptMaxPosition.x = from->ptMaxPosition.x;
to->ptMaxPosition.y = from->ptMaxPosition.y;
to->ptMinTrackSize.x = from->ptMinTrackSize.x;
to->ptMinTrackSize.y = from->ptMinTrackSize.y;
to->ptMaxTrackSize.x = from->ptMaxTrackSize.x;
to->ptMaxTrackSize.y = from->ptMaxTrackSize.y;
}
static void MINMAXINFO16to32( const MINMAXINFO16 *from, MINMAXINFO *to )
{
to->ptReserved.x = from->ptReserved.x;
to->ptReserved.y = from->ptReserved.y;
to->ptMaxSize.x = from->ptMaxSize.x;
to->ptMaxSize.y = from->ptMaxSize.y;
to->ptMaxPosition.x = from->ptMaxPosition.x;
to->ptMaxPosition.y = from->ptMaxPosition.y;
to->ptMinTrackSize.x = from->ptMinTrackSize.x;
to->ptMinTrackSize.y = from->ptMinTrackSize.y;
to->ptMaxTrackSize.x = from->ptMaxTrackSize.x;
to->ptMaxTrackSize.y = from->ptMaxTrackSize.y;
}
static void WINDOWPOS32to16( const WINDOWPOS* from, WINDOWPOS16* to )
{
to->hwnd = HWND_16(from->hwnd);
to->hwndInsertAfter = HWND_16(from->hwndInsertAfter);
to->x = from->x;
to->y = from->y;
to->cx = from->cx;
to->cy = from->cy;
to->flags = from->flags;
}
static void WINDOWPOS16to32( const WINDOWPOS16* from, WINDOWPOS* to )
{
to->hwnd = WIN_Handle32(from->hwnd);
to->hwndInsertAfter = (from->hwndInsertAfter == (HWND16)-1) ?
HWND_TOPMOST : WIN_Handle32(from->hwndInsertAfter);
to->x = from->x;
to->y = from->y;
to->cx = from->cx;
to->cy = from->cy;
to->flags = from->flags;
}
/* The strings are not copied */
static void CREATESTRUCT32Ato16( HWND hwnd32, const CREATESTRUCTA* from, CREATESTRUCT16* to )
{
to->lpCreateParams = (SEGPTR)from->lpCreateParams;
to->hInstance = HINSTANCE_16(from->hInstance);
if (!is_win_menu_disallowed(GetWindowLongA(hwnd32, GWL_STYLE)))
{
to->hMenu = HMENU_16(from->hMenu);
}
else
{
to->hMenu = (HMENU16)from->hMenu;
}
to->hwndParent = HWND_16(from->hwndParent);
to->cy = from->cy == CW_USEDEFAULT ? CW_USEDEFAULT16 : from->cy;
to->cx = from->cx == CW_USEDEFAULT ? CW_USEDEFAULT16 : from->cx;
to->y = from->y == CW_USEDEFAULT ? CW_USEDEFAULT16 : from->y;
to->x = from->x == CW_USEDEFAULT ? CW_USEDEFAULT16 : from->x;
to->style = from->style;
to->dwExStyle = from->dwExStyle;
}
static void CREATESTRUCT16to32A( HWND hwnd32, const CREATESTRUCT16* from, CREATESTRUCTA *to )
{
to->lpCreateParams = (LPVOID)from->lpCreateParams;
to->hInstance = HINSTANCE_32(from->hInstance);
if (!is_win_menu_disallowed(GetWindowLongA(hwnd32, GWL_STYLE)))
{
to->hMenu = HMENU_32(from->hMenu);
}
else
{
to->hMenu = (HMENU)from->hMenu;
}
to->hwndParent = WIN_Handle32(from->hwndParent);
to->cy = from->cy == CW_USEDEFAULT16 ? CW_USEDEFAULT : from->cy;
to->cx = from->cx == CW_USEDEFAULT16 ? CW_USEDEFAULT : from->cx;
to->y = from->y == CW_USEDEFAULT16 ? CW_USEDEFAULT : from->y;
to->x = from->x == CW_USEDEFAULT16 ? CW_USEDEFAULT : from->x;
to->style = from->style;
to->dwExStyle = from->dwExStyle;
to->lpszName = MapSL(from->lpszName);
to->lpszClass = win32classname(from->hInstance, MapSL(from->lpszClass));
}
/* The strings are not copied */
static void MDICREATESTRUCT32Ato16( const MDICREATESTRUCTA* from, MDICREATESTRUCT16* to )
{
to->hOwner = HINSTANCE_16(from->hOwner);
to->x = from->x;
to->y = from->y;
to->cx = from->cx;
to->cy = from->cy;
to->style = from->style;
to->lParam = from->lParam;
}
static void MDICREATESTRUCT16to32A( const MDICREATESTRUCT16* from, MDICREATESTRUCTA *to )
{
to->hOwner = HINSTANCE_32(from->hOwner);
to->x = (from->x == CW_USEDEFAULT16) ? CW_USEDEFAULT : (INT)from->x;
to->y = (from->y == CW_USEDEFAULT16) ? CW_USEDEFAULT : (INT)from->y;
to->cx = (from->cx == CW_USEDEFAULT16) ? CW_USEDEFAULT : (INT)from->cx;
to->cy = (from->cy == CW_USEDEFAULT16) ? CW_USEDEFAULT : (INT)from->cy;
to->style = from->style;
to->lParam = from->lParam;
to->szTitle = MapSL(from->szTitle);
to->szClass = win32classname(from->hOwner, MapSL(from->szClass));
}
HGLOBAL GLOBAL_GetLink(HGLOBAL16 hg);
void GLOBAL_SetLink(HGLOBAL16 hg16, HGLOBAL hg);
HGLOBAL16 GLOBAL_FindLink(HGLOBAL hg);
static UINT_PTR convert_handle_16_to_32(HANDLE16 src, unsigned int flags)
{
HANDLE dst;
UINT sz = GlobalSize16(src);
LPSTR ptr16, ptr32;
if (dst = GLOBAL_GetLink(src))
{
if (GlobalSize(dst) != sz)
dst = GlobalReAlloc(dst, sz, 0);
}
else if (!(dst = GlobalAlloc(flags, sz)))
return 0;
ptr16 = GlobalLock16(src);
ptr32 = GlobalLock(dst);
if (ptr16 != NULL && ptr32 != NULL) memcpy(ptr32, ptr16, sz);
GlobalUnlock16(src);
GlobalUnlock(dst);
GLOBAL_SetLink(src, dst);
return (UINT_PTR)dst;
}
static HANDLE16 convert_handle_32_to_16(UINT_PTR src, unsigned int flags)
{
HANDLE16 dst;
UINT sz = GlobalSize((HANDLE)src);
LPSTR ptr16, ptr32;
if (dst = GLOBAL_FindLink(src))
{
if (GlobalSize16(dst) != sz)
dst = GlobalReAlloc16(dst, sz, 0);
}
else if (!(dst = GlobalAlloc16(flags, sz)))
return 0;
ptr32 = GlobalLock((HANDLE)src);
ptr16 = GlobalLock16(dst);
if (ptr16 != NULL && ptr32 != NULL) memcpy(ptr16, ptr32, sz);
GlobalUnlock((HANDLE)src);
GlobalUnlock16(dst);
GLOBAL_SetLink(dst, (HANDLE)src);
return dst;
}
static BOOL is_old_app( HWND hwnd )
{
HINSTANCE inst = (HINSTANCE)GetWindowLongPtrW( hwnd, GWLP_HINSTANCE );
return inst && !((ULONG_PTR)inst >> 16) && (GetExpWinVer16(LOWORD(inst)) & 0xFF00) == 0x0300;
}
static int find_sub_menu( HMENU *hmenu, HMENU16 target )
{
int i, pos, count = GetMenuItemCount( *hmenu );
for (i = 0; i < count; i++)
{
HMENU sub = GetSubMenu( *hmenu, i );
if (!sub) continue;
if (HMENU_16(sub) == target) return i;
if ((pos = find_sub_menu( &sub, target )) != -1)
{
*hmenu = sub;
return pos;
}
}
return -1;
}
WNDPROC get_classinfo_wndproc(const char *class)
{
WNDCLASSA wc;
GetClassInfoA(NULL, class, &wc);
return wc.lpfnWndProc;
}
WNDPROC get_window_wndproc(const char *class)
{
WNDPROC lpfnWndProc2 = NULL;
HWND hWnd = CreateWindowExA(0, class, "", 0, 0, 0, 1, 1, 0, 0, GetModuleHandleA(NULL), 0);
if (hWnd)
{
lpfnWndProc2 = (WNDPROC)GetWindowLongPtrA(hWnd, GWLP_WNDPROC);
DestroyWindow(hWnd);
}
return lpfnWndProc2;
}
BOOL is_listbox_wndproc(WNDPROC lpfnWndProc)
{
static WNDPROC lpfnWndProc1 = 0;
static WNDPROC lpfnWndProc2 = 0;
if (!lpfnWndProc1)
lpfnWndProc1 = get_classinfo_wndproc("LISTBOX");
if (!lpfnWndProc2)
lpfnWndProc2 = get_window_wndproc("LISTBOX");
return lpfnWndProc ? (lpfnWndProc == lpfnWndProc1 || lpfnWndProc == lpfnWndProc2) : FALSE;
}
BOOL isListBox(HWND16 hWnd16, HWND hWnd)
{
if (window_type_table[hWnd16] == WINDOW_TYPE_LISTBOX)
return TRUE;
WNDPROC lpfnWndProc = (WNDPROC)GetWindowLongPtrA(hWnd, GWLP_WNDPROC);
return is_listbox_wndproc(lpfnWndProc);
}
BOOL is_edit_wndproc(WNDPROC lpfnWndProc)
{
static WNDPROC lpfnWndProc1 = 0;
static WNDPROC lpfnWndProc2 = 0;
if (!lpfnWndProc1)
lpfnWndProc1 = get_classinfo_wndproc("EDIT");
if (!lpfnWndProc2)
lpfnWndProc2 = get_window_wndproc("EDIT");
return lpfnWndProc ? (lpfnWndProc == lpfnWndProc1 || lpfnWndProc == lpfnWndProc2) : FALSE;
}
BOOL isEdit(HWND16 hWnd16, HWND hWnd)
{
if (window_type_table[hWnd16] == WINDOW_TYPE_EDIT)
return TRUE;
WNDPROC lpfnWndProc = (WNDPROC)GetWindowLongPtrA(hWnd, GWLP_WNDPROC);
return is_edit_wndproc(lpfnWndProc);
}
BOOL is_scrollbar_wndproc(WNDPROC lpfnWndProc)
{
static WNDPROC lpfnWndProc1 = 0;
static WNDPROC lpfnWndProc2 = 0;
if (!lpfnWndProc1)
lpfnWndProc1 = get_classinfo_wndproc("SCROLLBAR");
if (!lpfnWndProc2)
lpfnWndProc2 = get_window_wndproc("SCROLLBAR");
return lpfnWndProc ? (lpfnWndProc == lpfnWndProc1 || lpfnWndProc == lpfnWndProc2) : FALSE;
}
BOOL isScrollBar(HWND16 hWnd16, HWND hWnd)
{
if (window_type_table[hWnd16] == WINDOW_TYPE_SCROLLBAR)
return TRUE;
WNDPROC lpfnWndProc = (WNDPROC)GetWindowLongPtrA(hWnd, GWLP_WNDPROC);
return is_scrollbar_wndproc(lpfnWndProc);
}
BOOL is_combobox_wndproc(WNDPROC lpfnWndProc)
{
static WNDPROC lpfnWndProc1 = 0;
static WNDPROC lpfnWndProc2 = 0;
if (!lpfnWndProc1)
lpfnWndProc1 = get_classinfo_wndproc("COMBOBOX");
if (!lpfnWndProc2)
lpfnWndProc2 = get_window_wndproc("COMBOBOX");
return lpfnWndProc ? (lpfnWndProc == lpfnWndProc1 || lpfnWndProc == lpfnWndProc2) : FALSE;
}
BOOL isComboBox(HWND16 hWnd16, HWND hWnd)
{
if (window_type_table[hWnd16] == WINDOW_TYPE_COMBOBOX)
return TRUE;
WNDPROC lpfnWndProc = (WNDPROC)GetWindowLongPtrA(hWnd, GWLP_WNDPROC);
return is_combobox_wndproc(lpfnWndProc);
}
BOOL is_static_wndproc(WNDPROC lpfnWndProc)
{
static WNDPROC lpfnWndProc1 = 0;
static WNDPROC lpfnWndProc2 = 0;
if (!lpfnWndProc1)
lpfnWndProc1 = get_classinfo_wndproc("STATIC");
if (!lpfnWndProc2)
lpfnWndProc2 = get_window_wndproc("STATIC");
return lpfnWndProc ? (lpfnWndProc == lpfnWndProc1 || lpfnWndProc == lpfnWndProc2) : FALSE;
}
BOOL isStatic(HWND16 hWnd16, HWND hWnd)
{
if (window_type_table[hWnd16] == WINDOW_TYPE_STATIC)
return TRUE;
WNDPROC lpfnWndProc = (WNDPROC)GetWindowLongPtrA(hWnd, GWLP_WNDPROC);
return is_static_wndproc(lpfnWndProc);
}
BOOL is_button_wndproc(WNDPROC lpfnWndProc)
{
static WNDPROC lpfnWndProc1 = 0;
static WNDPROC lpfnWndProc2 = 0;
if (!lpfnWndProc1)
lpfnWndProc1 = get_classinfo_wndproc("BUTTON");
if (!lpfnWndProc2)
lpfnWndProc2 = get_window_wndproc("BUTTON");
return lpfnWndProc ? (lpfnWndProc == lpfnWndProc1 || lpfnWndProc == lpfnWndProc2) : FALSE;
}
BOOL isButton(HWND16 hWnd16, HWND hWnd)
{
if (window_type_table[hWnd16] == WINDOW_TYPE_BUTTON)
return TRUE;
WNDPROC lpfnWndProc = (WNDPROC)GetWindowLongPtrA(hWnd, GWLP_WNDPROC);
return is_button_wndproc(lpfnWndProc);
}
BOOL is_mdiclient_wndproc(WNDPROC lpfnWndProc)
{
static WNDPROC lpfnWndProc1 = 0;
static WNDPROC lpfnWndProc2 = 0;
if (!lpfnWndProc1)
lpfnWndProc1 = get_classinfo_wndproc("MDICLIENT");
if (!lpfnWndProc2)
{
CLIENTCREATESTRUCT ccs = { 0 };
HWND hwnd = CreateWindowExA(0, "MDICLIENT", "", 0, 0, 0, 1, 1, 0, 0, GetModuleHandleA(NULL), &ccs);
lpfnWndProc2 = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_WNDPROC);
DestroyWindow(hwnd);
}
return lpfnWndProc ? (lpfnWndProc == lpfnWndProc1 || lpfnWndProc == lpfnWndProc2) : FALSE;
}
BOOL is_mdiclient(HWND16 hWnd16, HWND hWnd)
{
if (window_type_table[hWnd16] == WINDOW_TYPE_MDICLIENT)
return TRUE;
WNDPROC lpfnWndProc = (WNDPROC)GetWindowLongPtrA(hWnd, GWLP_WNDPROC);
return is_mdiclient_wndproc(lpfnWndProc);
}
BOOL is_aviwnd(HWND16 hWnd16, HWND hWnd)
{
if (window_type_table[hWnd16] == WINDOW_TYPE_AVIWND)
return TRUE;
char name[10];
if (GetClassNameA(hWnd, &name, 10))
{
if (!strcmp(name, "AVIWnd32"))
{
window_type_table[hWnd16] = WINDOW_TYPE_AVIWND;
return TRUE;
}
}
return FALSE;
}
/***********************************************************************
* LISTBOX_FindFileStrPos
*
* Find the nearest string located before a given string in directory
* sort order (i.e. first files, then directories, then drives).
*/
static INT LISTBOX_FindFileStrPos( HWND lbhwnd, LPCSTR str )
{
INT min, max, res;
CHAR p[MAX_PATH];
if (!(GetWindowLongA(lbhwnd, GWL_STYLE) & LBS_HASSTRINGS))
return SendMessageA(lbhwnd, LB_FINDSTRING, -1, str);
min = 0;
max = SendMessageA(lbhwnd, LB_GETCOUNT, 0, 0);
while (min != max)
{
INT index = (min + max) / 2;
SendMessageA(lbhwnd, LB_GETTEXT, index, p);
if (*p == '[') /* drive or directory */
{
if (*str != '[') res = -1;
else if (p[1] == '-') /* drive */
{
if (str[1] == '-') res = str[2] - p[2];
else res = -1;
}
else /* directory */
{
if (str[1] == '-') res = 1;
else res = lstrcmpiA( str, p );
}
}
else /* filename */
{
if (*str == '[') res = 1;
else res = lstrcmpiA( str, p );
}
if (!res) return index;
if (res < 0) max = index;
else min = index + 1;
}
return max;
}
/***********************************************************************
* LISTBOX_Directory
*/
static LRESULT LISTBOX_Directory( HWND lbhwnd, UINT attrib, LPCWSTR filespec )
{
HANDLE handle;
LRESULT ret = LB_OKAY;
WIN32_FIND_DATAA entry;
int pos;
LRESULT maxinsert = LB_ERR;
/* don't scan directory if we just want drives exclusively */
if (attrib != (DDL_DRIVES | DDL_EXCLUSIVE)) {
/* scan directory */
if ((handle = FindFirstFileA(filespec, &entry)) == INVALID_HANDLE_VALUE)
{
int le = GetLastError();
if ((le != ERROR_NO_MORE_FILES) && (le != ERROR_FILE_NOT_FOUND)) return LB_ERR;
}
else
{
do
{
CHAR buffer[270];
if (entry.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
if (!(attrib & DDL_DIRECTORY) ||
!strcmp( entry.cFileName, "." )) continue;
buffer[0] = '[';
if (entry.cAlternateFileName[0])
lstrcpyA( buffer + 1, entry.cAlternateFileName );
else
lstrcpyA( buffer + 1, entry.cFileName );
lstrcatA(buffer, "]");
}
else /* not a directory */
{
#define ATTRIBS (FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_HIDDEN | \
FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_DIRECTORY)
if ((attrib & DDL_EXCLUSIVE) &&
((attrib & ATTRIBS) != (entry.dwFileAttributes & ATTRIBS)))
continue;
#undef ATTRIBS
if (entry.cAlternateFileName[0])
lstrcpyA( buffer, entry.cAlternateFileName );
else
lstrcpyA( buffer, entry.cFileName );
}
CharLowerA( buffer );
pos = LISTBOX_FindFileStrPos( lbhwnd, buffer );
if ((ret = SendMessageA(lbhwnd, LB_INSERTSTRING, pos, buffer)) < 0)
break;
if (ret <= maxinsert) maxinsert++; else maxinsert = ret;
} while (FindNextFileA( handle, &entry ));
FindClose( handle );
}
}
if (ret >= 0)
{
ret = maxinsert;
/* scan drives */
if (attrib & DDL_DRIVES)
{
CHAR buffer[] = "[-a-]";
CHAR root[] = "A:\\";