-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.cpp
2164 lines (2008 loc) · 80.6 KB
/
main.cpp
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
#include <windows.h>
#include "ncbind.hpp"
// ウィンドウクラス名取得用のバッファサイズ
#define CLASSNAME_MAX 1024
// イベント名一覧
#define EXEV_MINIMIZE TJS_W("onMinimize")
#define EXEV_MAXIMIZE TJS_W("onMaximize")
#define EXEV_QUERYMAX TJS_W("onMaximizeQuery")
#define EXEV_SHOW TJS_W("onShow")
#define EXEV_HIDE TJS_W("onHide")
#define EXEV_RESIZING TJS_W("onResizing")
#define EXEV_MOVING TJS_W("onMoving")
#define EXEV_MOVE TJS_W("onMove")
#define EXEV_MVSZBEGIN TJS_W("onMoveSizeBegin")
#define EXEV_MVSZEND TJS_W("onMoveSizeEnd")
#define EXEV_DISPCHG TJS_W("onDisplayChanged")
#define EXEV_ENTERMENU TJS_W("onEnterMenuLoop")
#define EXEV_EXITMENU TJS_W("onExitMenuLoop")
#define EXEV_ACTIVATE TJS_W("onActivateChanged")
#define EXEV_SCREENSV TJS_W("onScreenSave")
#define EXEV_MONITORPW TJS_W("onMonitorPower")
#define EXEV_NCMSMOVE TJS_W("onNcMouseMove")
#define EXEV_NCMSLEAVE TJS_W("onNcMouseLeave")
#define EXEV_NCMSDOWN TJS_W("onNcMouseDown")
#define EXEV_NCMSUP TJS_W("onNcMouseUp")
#define EXEV_SYSMENU TJS_W("onExSystemMenuSelected")
#define EXEV_KEYMENU TJS_W("onStartKeyMenu")
#define EXEV_ACCELKEY TJS_W("onAccelKeyMenu")
#define EXEV_NCMSEV TJS_W("onNonCapMouseEvent")
#define EXEV_MSGHOOK TJS_W("onWindowsMessageHook")
////////////////////////////////////////////////////////////////
struct WindowEx
{
//--------------------------------------------------------------
// ユーティリティ
// ネイティブインスタンスポインタを取得
static inline WindowEx * GetInstance(iTJSDispatch2 *obj) {
return ncbInstanceAdaptor<WindowEx>::GetNativeInstance(obj);
}
// ウィンドウハンドルを取得
static HWND GetHWND(iTJSDispatch2 *obj) {
tTJSVariant val;
obj->PropGet(0, TJS_W("HWND"), 0, &val, obj);
return (HWND)(tjs_int)(val);
}
// RECTを辞書に保存
static bool SetRect(ncbDictionaryAccessor &rdic, LPCRECT lprect) {
bool r;
if ((r = rdic.IsValid())) {
rdic.SetValue(TJS_W("x"), lprect->left);
rdic.SetValue(TJS_W("y"), lprect->top);
rdic.SetValue(TJS_W("w"), lprect->right - lprect->left);
rdic.SetValue(TJS_W("h"), lprect->bottom - lprect->top );
}
return r;
}
// 辞書からRECTに保存
static void GetRect(LPRECT rect, ncbPropAccessor &dict) {
ncbTypedefs::Tag<LONG> LongTypeTag;
rect->left = dict.GetValue(TJS_W("x"), LongTypeTag);
rect->top = dict.GetValue(TJS_W("y"), LongTypeTag);
rect->right = dict.GetValue(TJS_W("w"), LongTypeTag);
rect->bottom = dict.GetValue(TJS_W("h"), LongTypeTag);
rect->right += rect->left;
rect->bottom += rect->top;
}
// SYSCOMMANDを送る
static tjs_error postSysCommand(iTJSDispatch2 *objthis, WPARAM wp, LPARAM lp = 0) {
::PostMessage(GetHWND(objthis), WM_SYSCOMMAND, wp, lp);
return TJS_S_OK;
}
//--------------------------------------------------------------
// クラス追加メソッド(RawCallback形式)
// minimize, maximize, showRestore
static tjs_error TJS_INTF_METHOD minimize( tTJSVariant *r, tjs_int n, tTJSVariant **p, iTJSDispatch2 *obj) { return postSysCommand(obj, SC_MINIMIZE); }
static tjs_error TJS_INTF_METHOD maximize( tTJSVariant *r, tjs_int n, tTJSVariant **p, iTJSDispatch2 *obj) { return postSysCommand(obj, SC_MAXIMIZE); }
static tjs_error TJS_INTF_METHOD showRestore(tTJSVariant *r, tjs_int n, tTJSVariant **p, iTJSDispatch2 *obj) { return postSysCommand(obj, SC_RESTORE); }
static tjs_error TJS_INTF_METHOD focusMenuByKey(tTJSVariant *r,tjs_int n,tTJSVariant **p,iTJSDispatch2 *obj) { return postSysCommand(obj, SC_KEYMENU, n >= 0 ? (LPARAM)p[0]->AsInteger() : 0); }
// resetWindowIcon
static tjs_error TJS_INTF_METHOD resetWindowIcon(tTJSVariant *r, tjs_int n, tTJSVariant **p, iTJSDispatch2 *obj) {
WindowEx *self = GetInstance(obj);
return (self != NULL) ? self->_resetWindowIcon() : TJS_E_ACCESSDENYED;
}
// setWindowIcon
static tjs_error TJS_INTF_METHOD setWindowIcon(tTJSVariant *r, tjs_int n, tTJSVariant **p, iTJSDispatch2 *obj) {
WindowEx *self = GetInstance(obj);
return (self != NULL) ? self->_setWindowIcon(n > 0 ? p[0] : NULL, n > 1 ? p[1]->operator bool() : false) : TJS_E_ACCESSDENYED;
}
static HICON _loadExternalIcon(const ttstr &file) {
HICON ret = NULL;
if (file.length() > 0) {
ttstr placed = TVPGetPlacedPath(file);
if (!placed.length()) TVPThrowExceptionMessage(TJS_W("file not found."));
ttstr local = TVPGetLocallyAccessibleName(placed);
if (!local.length()) TVPThrowExceptionMessage(TJS_W("cannot get in archive icon."));
ret = ::ExtractIconW(GetModuleHandle(0), local.c_str(), 0);
if (ret == NULL) TVPThrowExceptionMessage(TJS_W("icon not found."));
}
return ret;
}
static void _setApplicationIcon(HICON icon);
tjs_error _setWindowIcon(tTJSVariant *ptr, bool withapp) {
if (externalIcon) {
::DestroyIcon(externalIcon);
externalIcon = NULL;
}
if (ptr && ptr->Type() == tvtString) {
externalIcon = _loadExternalIcon(ptr->AsStringNoAddRef());
}
if (withapp) _setApplicationIcon(externalIcon);
return _resetWindowIcon();
}
tjs_error _resetWindowIcon() const {
HWND hwnd = GetHWND(self);
if (hwnd != NULL) {
HICON icon = getCurrentIcon();
::PostMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)icon);
}
return TJS_S_OK;
}
HICON getCurrentIcon() const {
return externalIcon ? externalIcon : (::LoadIcon(GetModuleHandle(0), IDI_APPLICATION));
}
// getWindowRect
static tjs_error TJS_INTF_METHOD getWindowRect(tTJSVariant *r, tjs_int n, tTJSVariant **p, iTJSDispatch2 *obj) {
RECT rect;
HWND hwnd = GetHWND(obj);
if (r) r->Clear();
if (hwnd != NULL && ::GetWindowRect(hwnd, &rect)) {
ncbDictionaryAccessor dict;
if (SetRect(dict, &rect) && r) *r = tTJSVariant(dict, dict);
}
return TJS_S_OK;
}
// getClientRect
static tjs_error TJS_INTF_METHOD getClientRect(tTJSVariant *r, tjs_int n, tTJSVariant **p, iTJSDispatch2 *obj) {
RECT rect;
POINT zero = { 0, 0 };
HWND hwnd = GetHWND(obj);
if (r) r->Clear();
if (hwnd != NULL && ::GetClientRect(hwnd, &rect)) {
::ClientToScreen(hwnd, &zero);
rect.left += zero.x; rect.top += zero.y;
rect.right += zero.x; rect.bottom += zero.y;
ncbDictionaryAccessor dict;
if (SetRect(dict, &rect) && r) *r = tTJSVariant(dict, dict);
}
return TJS_S_OK;
}
// getNormalRect
static tjs_error TJS_INTF_METHOD getNormalRect(tTJSVariant *r, tjs_int n, tTJSVariant **p, iTJSDispatch2 *obj) {
HWND hwnd = GetHWND(obj);
WINDOWPLACEMENT place;
ZeroMemory(&place, sizeof(place));
place.length = sizeof(place);
MONITORINFOEXW mi;
ZeroMemory(&mi, sizeof(mi));
mi.cbSize = sizeof(mi);
if (r) r->Clear();
if (hwnd != NULL && ::GetWindowPlacement(hwnd, &place)) {
RECT *rc = &place.rcNormalPosition;
ncbDictionaryAccessor dict;
ncbPropAccessor prop(obj);
bool nofix = (n > 0 && !!p[0]->AsInteger());
if (!nofix && ::GetMonitorInfoW(::MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST), &mi)) {
LONG ox = mi.rcWork.left - mi.rcMonitor.left;
LONG oy = mi.rcWork.top - mi.rcMonitor.top;
rc->left += ox, rc->right += ox;
rc->top += oy, rc->bottom += oy;
}
if (SetRect(dict, rc) && r) *r = tTJSVariant(dict, dict);
}
return TJS_S_OK;
}
// property maximized box
static tjs_error TJS_INTF_METHOD getMaximizeBox(tTJSVariant *r, tjs_int n, tTJSVariant **p, iTJSDispatch2 *obj) {
HWND hwnd = GetHWND(obj);
if (r) *r = (GetWindowLong(hwnd, GWL_STYLE) & WS_MAXIMIZEBOX) != 0;
return TJS_S_OK;
}
static tjs_error TJS_INTF_METHOD setMaximizeBox(tTJSVariant *r, tjs_int n, tTJSVariant **p, iTJSDispatch2 *obj) {
bool m = !!p[0]->AsInteger();
HWND hwnd = GetHWND(obj);
LONG style = GetWindowLong(hwnd, GWL_STYLE);
style &= ~WS_MAXIMIZEBOX;
if (m) style |= WS_MAXIMIZEBOX;
SetWindowLong(hwnd, GWL_STYLE, style);
return TJS_S_OK;
}
// property minimized box
static tjs_error TJS_INTF_METHOD getMinimizeBox(tTJSVariant *r, tjs_int n, tTJSVariant **p, iTJSDispatch2 *obj) {
HWND hwnd = GetHWND(obj);
if (r) *r = (GetWindowLong(hwnd, GWL_STYLE) & WS_MINIMIZEBOX) != 0;
return TJS_S_OK;
}
static tjs_error TJS_INTF_METHOD setMinimizeBox(tTJSVariant *r, tjs_int n, tTJSVariant **p, iTJSDispatch2 *obj) {
bool m = !!p[0]->AsInteger();
HWND hwnd = GetHWND(obj);
LONG style = GetWindowLong(hwnd, GWL_STYLE);
style &= ~WS_MINIMIZEBOX;
if (m) style |= WS_MINIMIZEBOX;
SetWindowLong(hwnd, GWL_STYLE, style);
return TJS_S_OK;
}
// property maximized
static bool isMaximized(iTJSDispatch2 *obj) {
HWND hwnd = GetHWND(obj);
return (hwnd != NULL && ::IsZoomed(hwnd));
}
static tjs_error TJS_INTF_METHOD getMaximized(tTJSVariant *r, tjs_int n, tTJSVariant **p, iTJSDispatch2 *obj) {
if (r) *r = isMaximized(obj);
return TJS_S_OK;
}
static tjs_error TJS_INTF_METHOD setMaximized(tTJSVariant *r, tjs_int n, tTJSVariant **p, iTJSDispatch2 *obj) {
bool m = !!p[0]->AsInteger();
if (m != isMaximized(obj)) postSysCommand(obj, m ? SC_MAXIMIZE : SC_RESTORE);
return TJS_S_OK;
}
// property minimized
static bool isMinimized(iTJSDispatch2 *obj) {
HWND hwnd = GetHWND(obj);
return (hwnd != NULL && ::IsIconic(hwnd));
}
static tjs_error TJS_INTF_METHOD getMinimized(tTJSVariant *r, tjs_int n, tTJSVariant **p, iTJSDispatch2 *obj) {
if (r) *r = isMinimized(obj);
return TJS_S_OK;
}
static tjs_error TJS_INTF_METHOD setMinimized(tTJSVariant *r, tjs_int n, tTJSVariant **p, iTJSDispatch2 *obj) {
bool m = !!p[0]->AsInteger();
if (m != isMinimized(obj)) postSysCommand(obj, m ? SC_MINIMIZE : SC_RESTORE);
return TJS_S_OK;
}
// property disableResize
static tjs_error TJS_INTF_METHOD getDisableResize(tTJSVariant *r, tjs_int n, tTJSVariant **p, iTJSDispatch2 *obj) {
WindowEx *self = GetInstance(obj);
if (r) *r = (self != NULL && self->disableResize);
return TJS_S_OK;
}
static tjs_error TJS_INTF_METHOD setDisableResize(tTJSVariant *r, tjs_int n, tTJSVariant **p, iTJSDispatch2 *obj) {
WindowEx *self = GetInstance(obj);
if (self == NULL) return TJS_E_ACCESSDENYED;
self->disableResize = !!p[0]->AsInteger();
return TJS_S_OK;
}
// property disableMove
static tjs_error TJS_INTF_METHOD getDisableMove(tTJSVariant *r, tjs_int n, tTJSVariant **p, iTJSDispatch2 *obj) {
WindowEx *self = GetInstance(obj);
if (r) *r = (self != NULL && self->disableMove);
return TJS_S_OK;
}
static tjs_error TJS_INTF_METHOD setDisableMove(tTJSVariant *r, tjs_int n, tTJSVariant **p, iTJSDispatch2 *obj) {
WindowEx *self = GetInstance(obj);
if (self == NULL) return TJS_E_ACCESSDENYED;
self->disableMove = !!p[0]->AsInteger();
//_resetExSystemMenu(self);
return TJS_S_OK;
}
// setOverlayBitmap
static tjs_error TJS_INTF_METHOD setOverlayBitmap(tTJSVariant *r, tjs_int n, tTJSVariant **p, iTJSDispatch2 *obj) {
WindowEx *self = GetInstance(obj);
return (self != NULL) ? self->_setOverlayBitmap(n, p) : TJS_E_ACCESSDENYED;
}
// property exSystemMenu
static tjs_error TJS_INTF_METHOD getExSystemMenu(tTJSVariant *r, tjs_int n, tTJSVariant **p, iTJSDispatch2 *obj) {
WindowEx *self = GetInstance(obj);
if (r && self != NULL) *r = tTJSVariant(self->sysMenuModified, self->sysMenuModified);
return TJS_S_OK;
}
static tjs_error TJS_INTF_METHOD setExSystemMenu(tTJSVariant *r, tjs_int n, tTJSVariant **p, iTJSDispatch2 *obj) {
WindowEx *self = GetInstance(obj);
if (self == NULL) return TJS_E_ACCESSDENYED;
if (self->sysMenuModified != NULL) {
self->resetSystemMenu();
self->sysMenuModified->Release();
}
/**/self->sysMenuModified = p[0]->AsObject();
/**/self->modifySystemMenu();
return TJS_S_OK;
}
// resetExSystemMenu
static tjs_error TJS_INTF_METHOD resetExSystemMenu(tTJSVariant *r, tjs_int n, tTJSVariant **p, iTJSDispatch2 *obj) {
_resetExSystemMenu(GetInstance(obj));
return TJS_S_OK;
}
static void _resetExSystemMenu(WindowEx *self) {
if (self != NULL && self->sysMenu != NULL) {
::DestroyMenu(self->sysMenu);
self->sysMenu = NULL;
if (self->cachedHWND != NULL) ::GetSystemMenu(self->cachedHWND, TRUE);
if (self->sysMenuModified != NULL) self->modifySystemMenu();
}
}
// property enableNCMouseEvent
static tjs_error TJS_INTF_METHOD getEnNCMEvent(tTJSVariant *r, tjs_int n, tTJSVariant **p, iTJSDispatch2 *obj) {
WindowEx *self = GetInstance(obj);
if (r) *r = (self != NULL && self->enableNCMEvent);
return TJS_S_OK;
}
static tjs_error TJS_INTF_METHOD setEnNCMEvent(tTJSVariant *r, tjs_int n, tTJSVariant **p, iTJSDispatch2 *obj) {
WindowEx *self = GetInstance(obj);
if (self == NULL) return TJS_E_ACCESSDENYED;
self->enableNCMEvent = !!p[0]->AsInteger();
return TJS_S_OK;
}
// ncHitTest
static tjs_error TJS_INTF_METHOD nonClientHitTest(tTJSVariant *r, tjs_int n, tTJSVariant **p, iTJSDispatch2 *obj) {
if (n < 2) return TJS_E_BADPARAMCOUNT;
tjs_int x = (p[0]->AsInteger()) & 0xFFFF;
tjs_int y = (p[1]->AsInteger()) & 0xFFFF;
if (r) *r = (tjs_int)::SendMessage(GetHWND(obj), WM_NCHITTEST, 0, (LPARAM)(x | y << 16));
return TJS_S_OK;
}
// setMessageHook
static tjs_error TJS_INTF_METHOD setMessageHook(tTJSVariant *r, tjs_int n, tTJSVariant **p, iTJSDispatch2 *obj) {
WindowEx *self = GetInstance(obj);
if (self == NULL) return TJS_E_ACCESSDENYED;
bool on = (n >= 1) ? !!p[0]->AsInteger() : false;
bool ret = false;
if (n >= 2) {
tjs_int num = -1;
if (p[1]->Type() == tvtString) {
ttstr key(*p[1]);
num = getWindowNotificationNum(key);
} else {
num = (tjs_int)*p[1];
}
if (num < 0 || num >= 0x400) return TJS_E_FAIL;
ret = self->setMessageHookOnel(on, num);
} else {
ret = self->setMessageHookAll(on);
}
if (r) *r = ret;
return TJS_S_OK;
}
// bringTo
static tjs_error TJS_INTF_METHOD bringTo(tTJSVariant *r, tjs_int n, tTJSVariant **p, iTJSDispatch2 *obj) {
HWND hwnd = GetHWND(obj);
if (hwnd != NULL) {
HWND ins = NULL;
if (n >= 1) {
switch (p[0]->Type()) {
case tvtInteger:
ins = (HWND)(tTVInteger)p[0];
break;
case tvtString:
{
ttstr str(*p[0]);
str.ToLowerCase();
if (str == TJS_W("bottom" )) ins = HWND_BOTTOM;
else if (str == TJS_W("notopmost")) ins = HWND_NOTOPMOST;
else if (str == TJS_W("top" )) ins = HWND_TOP;
else if (str == TJS_W("topmost" )) ins = HWND_TOPMOST;
}
break;
case tvtObject:
{
iTJSDispatch2 *win = p[0]->AsObjectNoAddRef();
if (win && win->IsInstanceOf(0, 0, 0, TJS_W("Window"), win))
ins = GetHWND(win);
}
break;
}
}
::SetWindowPos(hwnd, ins, 0, 0, 0, 0, ((n >= 2 && !!p[1]->AsInteger()) ? 0 : SWP_NOACTIVATE) |
SWP_NOMOVE | SWP_NOSIZE | SWP_NOOWNERZORDER);
}
return TJS_S_OK;
}
static tjs_error TJS_INTF_METHOD sendToBack(tTJSVariant *r, tjs_int n, tTJSVariant **p, iTJSDispatch2 *obj) {
HWND hwnd = GetHWND(obj);
if (hwnd != NULL) {
::SetWindowPos(hwnd, HWND_BOTTOM, 0, 0, 0, 0,
SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_NOOWNERZORDER);
}
return TJS_S_OK;
}
//--------------------------------------------------------------
// 拡張イベント用
// メンバが存在するか
bool hasMember(tjs_char const *name) const {
tTJSVariant func;
return TJS_SUCCEEDED(self->PropGet(TJS_MEMBERMUSTEXIST, name, 0, &func, self));
}
// TJSメソッド呼び出し
tjs_error funcCall(tjs_char const *name, tTJSVariant *result, tjs_int numparams = 0, tTJSVariant **params = 0) const {
return Try_iTJSDispatch2_FuncCall(self, 0, name, 0, result, numparams, params, self);
// return self->FuncCall(0, name, 0, result, numparams, params, self);
}
// 引数なしコールバック
bool callback(tjs_char const *name) const {
if (!hasMember(name)) return false;
tTJSVariant rslt;
funcCall(name, &rslt, 0, 0);
return !!rslt.AsInteger();
}
// variant渡しコールバック
bool callback(tjs_char const *name, tTJSVariant *v) const {
if (!hasMember(name)) return false;
tTJSVariant rslt;
funcCall(name, &rslt, 1, &v);
return !!rslt.AsInteger();
}
// 座標渡しコールバック
bool callback(tjs_char const *name, int x, int y) const {
tTJSVariant vx(x), vy(y);
tTJSVariant rslt, *params[] = { &vx, &vy };
funcCall(name, &rslt, 2, params);
return !!rslt.AsInteger();
}
// 4個渡しコールバック
bool callback(tjs_char const *name, int a, int b, int c, int d) const {
tTJSVariant va(a), vb(b), vc(c), vd(d);
tTJSVariant rslt, *params[] = { &va, &vb, &vc, &vd };
funcCall(name, &rslt, 4, params);
return !!rslt.AsInteger();
}
// 矩形渡しコールバック
bool callback(tjs_char const *name, RECT *rect, int type = 0) const {
ncbDictionaryAccessor dict;
if (SetRect(dict, rect)) {
if (type != 0) dict.SetValue(TJS_W("type"), type);
tTJSVariant pdic(dict, dict);
tTJSVariant rslt, *params[] = { &pdic };
funcCall(name, &rslt, 1, params);
if (rslt.AsInteger()) {
GetRect(rect, dict);
return true;
}
}
return false;
}
// メッセージ処理
bool onMessage(tTVPWindowMessage *mes) {
switch (mes->Msg) {
case TVP_WM_ATTACH:
cachedHWND = (HWND)mes->LParam;
if (sysMenuModified != NULL) modifySystemMenu();
break;
case TVP_WM_DETACH:
resetSystemMenu();
if (sysMenu != NULL) {
::DestroyMenu(sysMenu);
sysMenu = NULL;
if (cachedHWND != NULL) ::GetSystemMenu(cachedHWND, TRUE);
}
cachedHWND = NULL;
deleteOverlayBitmap();
break;
}
HWND hwnd = cachedHWND;
if (hwnd == NULL) return false;
if (enableWinMsgHook && mes->Msg < 0x400 && (bitHooks[mes->Msg>>5] & (1<<(mes->Msg&31)))) {
if (callback(EXEV_MSGHOOK, mes->Msg, mes->WParam, mes->LParam, 0)) return true;
}
switch (mes->Msg) {
case WM_SETCURSOR:
if (enableNCMEvent)
return callback(EXEV_NCMSEV, (int)LOWORD(mes->LParam), (int)HIWORD(mes->LParam));
break;
case WM_MENUCHAR:
if (callback(EXEV_ACCELKEY, (int)LOWORD(mes->WParam), (int)HIWORD(mes->WParam))) {
LRESULT res = mes->Result = ::DefWindowProc(hwnd, mes->Msg, mes->WParam, mes->LParam);
if (!HIWORD(res)) mes->Result |= (1 << 16);
return true;
}
break;
case WM_SYSCOMMAND:
if (sysMenuModMap != NULL && (mes->WParam & 0xFFFF) < 0xF000) {
tTJSVariant var;
if (TJS_SUCCEEDED(sysMenuModMap->PropGetByNum(0, (tjs_int)(mes->WParam & 0xFFFF), &var, sysMenuModMap))) {
return callback(EXEV_SYSMENU, &var);
}
}
switch (mes->WParam & 0xFFF0) {
case SC_MAXIMIZE: return callback(EXEV_QUERYMAX);
case SC_SCREENSAVE: return callback(EXEV_SCREENSV);
case SC_MONITORPOWER: return callback(EXEV_MONITORPW, (int)mes->LParam, 0);
case SC_KEYMENU: return callback(EXEV_KEYMENU, (int)mes->LParam, 0);
case SC_MOVE: if (disableMove) { mes->Result = 0; return true; } break;
}
break;
case WM_SIZE:
switch (mes->WParam) {
case SIZE_MINIMIZED: callback(EXEV_MINIMIZE); break;
case SIZE_MAXIMIZED: callback(EXEV_MAXIMIZE); break;
}
break;
case WM_SHOWWINDOW:
switch (mes->LParam) {
case SW_PARENTOPENING: callback(EXEV_SHOW); break;
case SW_PARENTCLOSING: callback(EXEV_HIDE); break;
}
break;
case WM_QUERYOPEN:
callback(EXEV_SHOW);
break;
case WM_ENTERSIZEMOVE: callback(EXEV_MVSZBEGIN); break;
case WM_EXITSIZEMOVE: callback(EXEV_MVSZEND); break;
case WM_SIZING: if (hasResizing) callback(EXEV_RESIZING, (RECT*)mes->LParam, mes->WParam); break;
case WM_MOVING: if (hasMoving) callback(EXEV_MOVING, (RECT*)mes->LParam); break;
case WM_MOVE: if (hasMove) callback(EXEV_MOVE, (int)LOWORD(mes->LParam), (int)HIWORD(mes->LParam)); break;
// サイズ変更カーソルを抑制
case WM_NCHITTEST:
if (disableResize) {
LRESULT res = ::DefWindowProc(hwnd, mes->Msg, mes->WParam, mes->LParam);
switch (res) {
/**/ case HTLEFT: case HTRIGHT:
case HTTOP: case HTTOPLEFT: case HTTOPRIGHT:
case HTBOTTOM: case HTBOTTOMLEFT: case HTBOTTOMRIGHT:
res = HTBORDER;
break;
}
mes->Result = res;
return true;
}
break;
case WM_NCLBUTTONDOWN: callback(EXEV_NCMSDOWN, (int)LOWORD(mes->LParam), (int)HIWORD(mes->LParam), 0/*mbLeft*/, (int)mes->WParam); break;
case WM_NCRBUTTONDOWN: callback(EXEV_NCMSDOWN, (int)LOWORD(mes->LParam), (int)HIWORD(mes->LParam), 1/*mbRight*/, (int)mes->WParam); break;
case WM_NCMBUTTONDOWN: callback(EXEV_NCMSDOWN, (int)LOWORD(mes->LParam), (int)HIWORD(mes->LParam), 2/*mbMiddle*/, (int)mes->WParam); break;
case WM_NCLBUTTONUP: callback(EXEV_NCMSUP, (int)LOWORD(mes->LParam), (int)HIWORD(mes->LParam), 0/*mbLeft*/, (int)mes->WParam); break;
case WM_NCRBUTTONUP: callback(EXEV_NCMSUP, (int)LOWORD(mes->LParam), (int)HIWORD(mes->LParam), 1/*mbRight*/, (int)mes->WParam); break;
case WM_NCMBUTTONUP: callback(EXEV_NCMSUP, (int)LOWORD(mes->LParam), (int)HIWORD(mes->LParam), 2/*mbMiddle*/, (int)mes->WParam); break;
case WM_NCMOUSELEAVE: callback(EXEV_NCMSLEAVE); break;
case WM_NCMOUSEMOVE:
if (hasNcMsMove) callback(EXEV_NCMSMOVE, (int)LOWORD(mes->LParam), (int)HIWORD(mes->LParam), (int)mes->WParam, 0);
break;
case WM_INITMENUPOPUP:
if (HIWORD(mes->LParam)) {
if (sysMenu != NULL && sysMenu == (HMENU)mes->WParam) modifySystemMenu();
if (disableResize || disableMove) {
// システムメニューサイズ変更抑制
mes->Result = ::DefWindowProc(hwnd, mes->Msg, mes->WParam, mes->LParam);
if (disableResize) ::EnableMenuItem((HMENU)mes->WParam, SC_SIZE, MF_GRAYED | MF_BYCOMMAND);
if (disableMove) ::EnableMenuItem((HMENU)mes->WParam, SC_MOVE, MF_GRAYED | MF_BYCOMMAND);
return true;
}
} else if (menuex) {
// メニューアイコン強制差し替え
mes->Result = ::DefWindowProc(hwnd, mes->Msg, mes->WParam, mes->LParam);
HMENU menu = (HMENU)mes->WParam;
checkUpdateMenuItem(menu);
return true;
}
break;
case WM_NCPAINT:
if (menuex) checkUpdateMenuItem(::GetMenu(hwnd));
break;
// メニュー開始終了
case WM_ENTERMENULOOP:
callback(EXEV_ENTERMENU);
break;
case WM_EXITMENULOOP:
callback(EXEV_EXITMENU);
break;
// ディスプレイモード変更通知
case WM_DISPLAYCHANGE:
callback(EXEV_DISPCHG);
break;
case WM_ACTIVATE:
return callback(EXEV_ACTIVATE, (int)(mes->WParam & 0xFFFF), (int)((mes->WParam >> 16) & 0xFFFF));
}
return false;
}
// メニュー更新処理(MenuItemEx用)
void setMenuItemID(iTJSDispatch2*, UINT, bool);
void checkUpdateMenuItem(HMENU, int, UINT);
void checkUpdateMenuItem(HMENU menu) {
int cnt = menu ? ::GetMenuItemCount(menu) : 0;
for (int i = 0; i < cnt; i++) checkUpdateMenuItem(menu, i, ::GetMenuItemID(menu, i));
}
// メッセージレシーバ
static bool __stdcall receiver(void *userdata, tTVPWindowMessage *mes) {
WindowEx *inst = GetInstance((iTJSDispatch2*)userdata);
return inst ? inst->onMessage(mes) : false;
}
// Message Receiver 登録・解除
void regist(bool en) {
tTJSVariant mode(en ? wrmRegister : wrmUnregister);
tTJSVariant func((tTVInteger)(&receiver));
tTJSVariant data((tTVInteger)(self));
tTJSVariant rslt, *params[] = { &mode, &func, &data };
self->FuncCall(0, TJS_W("registerMessageReceiver"), 0, &rslt, 3, params, self);
}
// ネイティブインスタンスの生成・破棄にあわせてレシーバを登録・解除する
WindowEx(iTJSDispatch2 *obj)
: self(obj), menuex(0),
sysMenuModified(0), sysMenuModMap(0),
cachedHWND(0),
sysMenu(0),
externalIcon(0),
hasResizing(false),
hasMoving(false),
hasMove(false),
disableResize(false),
disableMove(false),
enableNCMEvent(false),
enableWinMsgHook(false),
ovbmp(NULL)
{
cachedHWND = GetHWND(self);
regist(true);
setMessageHookAll(false);
}
~WindowEx() {
if (menuex) menuex ->Release();
if (sysMenuModified) sysMenuModified->Release();
if (externalIcon) ::DestroyIcon(externalIcon);
resetSystemMenu();
deleteOverlayBitmap();
regist(false);
}
void checkExEvents() {
hasResizing = hasMember(EXEV_RESIZING);
hasMoving = hasMember(EXEV_MOVING);
hasMove = hasMember(EXEV_MOVE);
hasNcMsMove = hasMember(EXEV_NCMSMOVE);
}
void deleteOverlayBitmap() {
if (ovbmp) delete ovbmp;
ovbmp = NULL;
}
void resetSystemMenu();
void modifySystemMenu();
bool setMessageHookOnel(bool on, tjs_int num) {
if (num >= 0 && num < 0x400) {
if (on) {
bitHooks[num>>5] |= 1L<<(num&31);
enableWinMsgHook = true;
} else {
enableWinMsgHook = false;
bitHooks[num>>5] &= ~(1L<<(num&31));
for (int i = 0; i < 0x0400/32; i++)
if (bitHooks[i]) { enableWinMsgHook = true; break; }
}
}
return enableWinMsgHook;
}
bool setMessageHookAll(bool on) {
DWORD v = on ? ~0L : 0;
for (int i = 0; i < 0x0400/32; i++) bitHooks[i] = v;
return (enableWinMsgHook = on);
}
static tjs_int getWindowNotificationNum(ttstr key) {
tTJSVariant tmp;
if (!_getNotificationVariant(tmp))
TVPThrowExceptionMessage(TJS_W("cache setup failed."));
ncbPropAccessor nf(tmp);
return nf.getIntValue(key.c_str(), -1);
}
static ttstr getWindowNotificationName(tjs_int num) {
tTJSVariant tmp;
if (!_getNotificationVariant(tmp))
TVPThrowExceptionMessage(TJS_W("cache setup failed."));
ncbPropAccessor nf(tmp);
return nf.getStrValue(num);
}
protected:
tjs_error _setOverlayBitmap(tjs_int n, tTJSVariant **p) {
if (ovbmp) ovbmp->hide();
if (n > 0 && p[0]->Type() == tvtObject) {
if (!ovbmp) {
ovbmp = new OverlayBitmap();
if (!ovbmp) return TJS_E_FAIL;
}
if (!ovbmp->setBitmap(self, p[0]->AsObjectNoAddRef())) {
deleteOverlayBitmap();
return TJS_E_FAIL;
}
}
return TJS_S_OK;
}
static bool _getNotificationVariant(tTJSVariant &tmp) {
iTJSDispatch2 *obj = TVPGetScriptDispatch();
tmp.Clear();
bool hasval = TJS_SUCCEEDED(obj->PropGet(TJS_MEMBERMUSTEXIST, TJS_W("Window"), 0, &tmp, obj));
obj->Release();
if (!hasval) return false;
obj = tmp.AsObjectNoAddRef();
tmp.Clear();
if (TJS_FAILED(obj->PropGet(TJS_MEMBERMUSTEXIST, TJS_W("_Notifications"), 0, &tmp, obj))) {
ncbDictionaryAccessor dict;
#ifndef WM_CTLCOLOR
#define WM_CTLCOLOR 0x0019
#endif
#define WM(key) dict.SetValue(TJS_W(# key), WM_ ## key), dict.SetValue(WM_ ## key, ttstr(TJS_W(# key)))
WM(NULL), WM(CREATE), WM(DESTROY), WM(MOVE),
WM(SIZE), WM(ACTIVATE), WM(SETFOCUS), WM(KILLFOCUS),
WM(ENABLE), WM(SETREDRAW), WM(SETTEXT), WM(GETTEXT),
WM(GETTEXTLENGTH), WM(PAINT), WM(CLOSE), WM(QUERYENDSESSION),
WM(QUERYOPEN), WM(ENDSESSION), WM(QUIT), WM(ERASEBKGND),
WM(SYSCOLORCHANGE), WM(SHOWWINDOW), WM(CTLCOLOR), WM(WININICHANGE),
WM(SETTINGCHANGE), WM(DEVMODECHANGE), WM(ACTIVATEAPP), WM(FONTCHANGE),
WM(TIMECHANGE), WM(CANCELMODE), WM(SETCURSOR), WM(MOUSEACTIVATE),
WM(CHILDACTIVATE), WM(QUEUESYNC), WM(GETMINMAXINFO), WM(PAINTICON),
WM(ICONERASEBKGND), WM(NEXTDLGCTL), WM(SPOOLERSTATUS), WM(DRAWITEM),
WM(MEASUREITEM), WM(DELETEITEM), WM(VKEYTOITEM), WM(CHARTOITEM),
WM(SETFONT), WM(GETFONT), WM(SETHOTKEY), WM(GETHOTKEY),
WM(QUERYDRAGICON), WM(COMPAREITEM), WM(GETOBJECT), WM(COMPACTING),
WM(COMMNOTIFY), WM(WINDOWPOSCHANGING), WM(WINDOWPOSCHANGED), WM(POWER),
WM(COPYDATA), WM(CANCELJOURNAL), WM(NOTIFY), WM(INPUTLANGCHANGEREQUEST),
WM(INPUTLANGCHANGE), WM(TCARD), WM(HELP), WM(USERCHANGED),
WM(NOTIFYFORMAT), WM(CONTEXTMENU), WM(STYLECHANGING), WM(STYLECHANGED),
WM(DISPLAYCHANGE), WM(GETICON), WM(SETICON), WM(NCCREATE),
WM(NCDESTROY), WM(NCCALCSIZE), WM(NCHITTEST), WM(NCPAINT),
WM(NCACTIVATE), WM(GETDLGCODE), WM(SYNCPAINT), WM(NCMOUSEMOVE),
WM(NCLBUTTONDOWN), WM(NCLBUTTONUP), WM(NCLBUTTONDBLCLK), WM(NCRBUTTONDOWN),
WM(NCRBUTTONUP), WM(NCRBUTTONDBLCLK), WM(NCMBUTTONDOWN), WM(NCMBUTTONUP),
WM(NCMBUTTONDBLCLK), WM(NCXBUTTONDOWN), WM(NCXBUTTONUP), WM(NCXBUTTONDBLCLK),
WM(INPUT_DEVICE_CHANGE), WM(INPUT), WM(KEYFIRST), WM(KEYDOWN),
WM(KEYUP), WM(CHAR), WM(DEADCHAR), WM(SYSKEYDOWN),
WM(SYSKEYUP), WM(SYSCHAR), WM(SYSDEADCHAR), WM(UNICHAR),
WM(KEYLAST), WM(KEYLAST), WM(IME_STARTCOMPOSITION), WM(IME_ENDCOMPOSITION),
WM(IME_COMPOSITION), WM(IME_KEYLAST), WM(INITDIALOG), WM(COMMAND),
WM(SYSCOMMAND), WM(TIMER), WM(HSCROLL), WM(VSCROLL),
WM(INITMENU), WM(INITMENUPOPUP), WM(MENUSELECT), WM(MENUCHAR),
WM(ENTERIDLE), WM(MENURBUTTONUP), WM(MENUDRAG), WM(MENUGETOBJECT),
WM(UNINITMENUPOPUP), WM(MENUCOMMAND), WM(CHANGEUISTATE), WM(UPDATEUISTATE),
WM(QUERYUISTATE), WM(CTLCOLORMSGBOX), WM(CTLCOLOREDIT), WM(CTLCOLORLISTBOX),
WM(CTLCOLORBTN), WM(CTLCOLORDLG), WM(CTLCOLORSCROLLBAR), WM(CTLCOLORSTATIC),
WM(MOUSEFIRST), WM(MOUSEMOVE), WM(LBUTTONDOWN), WM(LBUTTONUP),
WM(LBUTTONDBLCLK), WM(RBUTTONDOWN), WM(RBUTTONUP), WM(RBUTTONDBLCLK),
WM(MBUTTONDOWN), WM(MBUTTONUP), WM(MBUTTONDBLCLK), WM(MOUSEWHEEL),
WM(XBUTTONDOWN), WM(XBUTTONUP), WM(XBUTTONDBLCLK), WM(MOUSEHWHEEL),
WM(MOUSELAST), WM(MOUSELAST), WM(MOUSELAST), WM(MOUSELAST),
WM(PARENTNOTIFY), WM(ENTERMENULOOP), WM(EXITMENULOOP), WM(NEXTMENU),
WM(SIZING), WM(CAPTURECHANGED), WM(MOVING), WM(POWERBROADCAST),
WM(DEVICECHANGE), WM(MDICREATE), WM(MDIDESTROY), WM(MDIACTIVATE),
WM(MDIRESTORE), WM(MDINEXT), WM(MDIMAXIMIZE), WM(MDITILE),
WM(MDICASCADE), WM(MDIICONARRANGE), WM(MDIGETACTIVE), WM(MDISETMENU),
WM(ENTERSIZEMOVE), WM(EXITSIZEMOVE), WM(DROPFILES), WM(MDIREFRESHMENU),
WM(IME_SETCONTEXT), WM(IME_NOTIFY), WM(IME_CONTROL), WM(IME_COMPOSITIONFULL),
WM(IME_SELECT), WM(IME_CHAR), WM(IME_REQUEST), WM(IME_KEYDOWN),
WM(IME_KEYUP), WM(MOUSEHOVER), WM(MOUSELEAVE), WM(NCMOUSEHOVER),
WM(NCMOUSELEAVE), WM(WTSSESSION_CHANGE), WM(TABLET_FIRST), WM(TABLET_LAST),
WM(CUT), WM(COPY), WM(PASTE), WM(CLEAR),
WM(UNDO), WM(RENDERFORMAT), WM(RENDERALLFORMATS), WM(DESTROYCLIPBOARD),
WM(DRAWCLIPBOARD), WM(PAINTCLIPBOARD), WM(VSCROLLCLIPBOARD), WM(SIZECLIPBOARD),
WM(ASKCBFORMATNAME), WM(CHANGECBCHAIN), WM(HSCROLLCLIPBOARD), WM(QUERYNEWPALETTE),
WM(PALETTEISCHANGING), WM(PALETTECHANGED), WM(HOTKEY), WM(PRINT),
WM(PRINTCLIENT), WM(APPCOMMAND), WM(THEMECHANGED), WM(CLIPBOARDUPDATE),
WM(DWMCOMPOSITIONCHANGED), WM(DWMNCRENDERINGCHANGED), WM(DWMCOLORIZATIONCOLORCHANGED),WM(DWMWINDOWMAXIMIZEDCHANGE),
WM(GETTITLEBARINFOEX), WM(HANDHELDFIRST), WM(HANDHELDLAST), WM(AFXFIRST),
WM(AFXLAST), WM(PENWINFIRST), WM(PENWINLAST),
#undef WM
tmp = dict;
if (TJS_FAILED(obj->PropSet(TJS_MEMBERENSURE, TJS_W("_Notifications"), 0, &tmp, obj)))
return false;
}
return true;
}
private:
iTJSDispatch2 *self, *menuex;
iTJSDispatch2 *sysMenuModified, *sysMenuModMap; //< システムメニュー改変用
HWND cachedHWND;
HMENU sysMenu;
HICON externalIcon;
bool hasResizing, hasMoving, hasMove, hasNcMsMove; //< メソッドが存在するかフラグ
bool disableResize; //< サイズ変更禁止
bool disableMove; //< ウィンドウ移動禁止
bool enableNCMEvent; //< WM_SETCURSORコールバック
bool enableWinMsgHook; //< メッセージフック有効
DWORD bitHooks[0x0400/32];
public:
//----------------------------------------------------------
// オーバーレイビットマップ用サブクラス
//----------------------------------------------------------
struct OverlayBitmap {
OverlayBitmap() : overlay(0), bitmap(0), bmpdc(0) {}
~OverlayBitmap() {
if (overlay) ::DestroyWindow(overlay);
removeBitmap();
}
static BOOL CALLBACK SearchScrollBox(HWND hwnd, LPARAM lp) {
HWND *result = (HWND*)lp;
tjs_char name[CLASSNAME_MAX];
::GetClassNameW(hwnd, name, CLASSNAME_MAX);
if (ttstr(name) == TJS_W("TScrollBox")) {
*result = hwnd;
return FALSE;
}
return TRUE;
}
static LRESULT WINAPI WndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) {
OverlayBitmap *self = reinterpret_cast<OverlayBitmap*>(::GetWindowLongPtr(hwnd, GWLP_USERDATA));
if (self != NULL && msg == WM_PAINT) {
self->onPaint(hwnd);
return 0;
}
return DefWindowProc(hwnd, msg, wp, lp);
}
void drawBitmap(HDC dc) {
if (bitmap) ::BitBlt(dc, bmpx, bmpy, bmpw, bmph, bmpdc, 0, 0, SRCCOPY);
}
void removeBitmap() {
if (bmpdc) ::DeleteDC(bmpdc);
if (bitmap) ::DeleteObject(bitmap);
bmpdc = NULL;
bitmap = NULL;
}
void onPaint(HWND hwnd) {
PAINTSTRUCT ps;
drawBitmap(::BeginPaint(hwnd, &ps));
::EndPaint(hwnd, &ps);
}
static HBITMAP CopyLayerToBitmap(HDC dc, int ts, iTJSDispatch2 *lay, tjs_int &w, tjs_int &h, tjs_int *x=0, tjs_int *y=0) {
typedef unsigned char PIX;
ncbPropAccessor obj(lay);
if (x) *x = obj.getIntValue(TJS_W("left"));
if (y) *y = obj.getIntValue(TJS_W("top"));
w = obj.getIntValue(TJS_W("imageWidth"));
h = obj.getIntValue(TJS_W("imageHeight"));
tjs_int ln = obj.getIntValue(TJS_W("mainImageBufferPitch"));
PIX *pw, *pr = reinterpret_cast<unsigned char *>(obj.getIntPtrValue(TJS_W("mainImageBuffer")));
BITMAPINFO info;
ZeroMemory(&info, sizeof(info));
info.bmiHeader.biSize = sizeof(BITMAPINFO);
info.bmiHeader.biWidth = w;
info.bmiHeader.biHeight = h;
info.bmiHeader.biPlanes = 1;
info.bmiHeader.biBitCount = (ts > 0) ? 32 : 24;
HBITMAP bmp = ::CreateDIBSection(dc, (LPBITMAPINFO)&info, DIB_RGB_COLORS, (LPVOID*)&pw, NULL, 0);
if (bmp && pw) {
if (ts > 0) {
PIX pts = (PIX)ts;
for (int y = h-1; y >= 0; y--) {
PIX *src = pr + (y * ln);
PIX *dst = pw + ((h-1 - y) * ((w*4+3) & ~3L));
for (int n = w-1; n >= 0; n--, src+=4, dst+=4) {
dst[0] = src[0];
dst[1] = src[1];
dst[2] = src[2];
dst[3] =(src[3] >= pts) ? 255: 0;
}
}
} else {
for (int y = h-1; y >= 0; y--) {
PIX *src = pr + (y * ln);
PIX *dst = pw + ((h-1 - y) * ((w*3+3) & ~3L));
for (int n = w-1; n >= 0; n--, src+=4, dst+=3) {
dst[0] = src[0];
dst[1] = src[1];
dst[2] = src[2];
}
}
}
}
return bmp;
}
bool setBitmap(iTJSDispatch2 *win, iTJSDispatch2 *lay) {
if (!lay || !lay->IsInstanceOf(0, 0, 0, TJS_W("Layer"), lay)) return false;
if (!initOverlay()) return false;
HWND base = GetHWND(win);
HWND hwnd = NULL;
::EnumChildWindows(base, SearchScrollBox, (LPARAM)&hwnd);
if (!hwnd) hwnd = base; // return false; // for krkrZ
removeBitmap();
HDC dc = ::GetDC(overlay);
bmpdc = ::CreateCompatibleDC(dc);
bitmap = CopyLayerToBitmap(dc, 0, lay, bmpw, bmph, &bmpx, &bmpy);
if (bitmap) ::SelectObject(bmpdc, bitmap);
if (!bitmap || !bmpdc) {
removeBitmap();
::ReleaseDC(overlay, dc);
return false;
}
RECT rect;
::GetWindowRect(hwnd, &rect);
::SetParent( overlay, hwnd);
::SetWindowPos( overlay, HWND_TOP, 0, 0, (rect.right-rect.left), (rect.bottom-rect.top), 0); //SWP_HIDEWINDOW);
::InvalidateRect(overlay, NULL, TRUE);
::UpdateWindow( overlay);
::ShowWindow( overlay, SW_SHOWNORMAL);
drawBitmap(dc);
::ReleaseDC(overlay, dc);
return true;
}
bool initOverlay() {
HINSTANCE hinst = ::GetModuleHandle(NULL);
if (!hinst) return false;
if (!WindowClass) {
WNDCLASSEXW wcex = {
/*size*/sizeof(WNDCLASSEX), /*style*/CS_PARENTDC|CS_VREDRAW|CS_HREDRAW, /*proc*/WndProc, /*extra*/0L,0L, /*hinst*/hinst,
/*icon*/NULL, /*cursor*/::LoadCursor(NULL, IDC_ARROW), /*brush*/(HBRUSH)::GetStockObject(BLACK_BRUSH), /*menu*/NULL,
/*class*/TJS_W("WindowEx OverlayBitmap Window Class"), /*smicon*/NULL };
WindowClass = ::RegisterClassExW(&wcex);
if (!WindowClass) return false;
}
if (!overlay) {
overlay = ::CreateWindowExW(WS_EX_TOPMOST, (LPCWSTR)MAKELONG(WindowClass, 0), TJS_W("WindowExOverlayBitmap"),
WS_CHILDWINDOW, 0, 0, 1, 1, TVPGetApplicationWindowHandle(), NULL, hinst, NULL);
if (!overlay) return false;
::SetWindowLongPtr(overlay, GWLP_USERDATA, (LONG_PTR)this);
}
return true;
}
void show() const { if (overlay) ::ShowWindow(overlay, SW_SHOWNORMAL); }
void hide() const { if (overlay) ::ShowWindow(overlay, SW_HIDE); }
private:
HWND overlay;
HBITMAP bitmap;
HDC bmpdc;
tjs_int bmpx, bmpy, bmpw, bmph;
static ATOM WindowClass;
} *ovbmp;
};
ATOM WindowEx::OverlayBitmap::WindowClass = 0;
// 拡張イベント用ネイティブインスタンスゲッタ
NCB_GET_INSTANCE_HOOK(WindowEx)
{
/**/ NCB_GET_INSTANCE_HOOK_CLASS () {}
/**/ ~NCB_GET_INSTANCE_HOOK_CLASS () {}
NCB_INSTANCE_GETTER(objthis) {
ClassT* obj = GetNativeInstance(objthis);
if (!obj) SetNativeInstance(objthis, (obj = new ClassT(objthis)));
return obj;
}
};
// メソッド追加
NCB_ATTACH_CLASS_WITH_HOOK(WindowEx, Window)
{
Variant(TJS_W("nchtError"), (tjs_int)(HTERROR & 0xFFFF));
Variant(TJS_W("nchtTransparent"), (tjs_int)(HTTRANSPARENT & 0xFFFF));
Variant(TJS_W("nchtNoWhere"), (tjs_int)HTNOWHERE);
Variant(TJS_W("nchtClient"), (tjs_int)HTCLIENT);
Variant(TJS_W("nchtCaption"), (tjs_int)HTCAPTION);
Variant(TJS_W("nchtSysMenu"), (tjs_int)HTSYSMENU);
Variant(TJS_W("nchtSize"), (tjs_int)HTSIZE);
Variant(TJS_W("nchtGrowBox"), (tjs_int)HTGROWBOX);
Variant(TJS_W("nchtMenu"), (tjs_int)HTMENU);
Variant(TJS_W("nchtHScroll"), (tjs_int)HTHSCROLL);
Variant(TJS_W("nchtVScroll"), (tjs_int)HTVSCROLL);
Variant(TJS_W("nchtMinButton"), (tjs_int)HTMINBUTTON);
Variant(TJS_W("nchtReduce"), (tjs_int)HTREDUCE);
Variant(TJS_W("nchtMaxButton"), (tjs_int)HTMAXBUTTON);
Variant(TJS_W("nchtZoom"), (tjs_int)HTZOOM);