-
Notifications
You must be signed in to change notification settings - Fork 135
/
transparent_wnd.cpp
1610 lines (1548 loc) · 43 KB
/
transparent_wnd.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
#pragma comment ( lib, "imm32.lib" )
#include "transparent_wnd.h"
#include <sstream>
#include "cefclient/string_util.h"
#include <tchar.h>
#pragma comment( lib, "gdiplus.lib" )
#include <comdef.h>
#include <GdiPlus.h>
#include "network\MelodyProxy.h"
#include "base64.h"
#include "system.h"
using namespace Gdiplus;
#define WM_INIT WM_USER+2
#define ODS(msg) MessageBox(NULL, msg, msg, 0);
#define WM_NOTIFYICON WM_USER+5
#define IDI_ICON 0x0005
#define GUID_LEN 64
//#ifndef ULONG_PTR
//#define ULONG_PTR unsigned long*
//#endif
int TransparentWnd::count = 0;
CSFMServer* pServer=new CSFMServer(NULL, L"AlloyDesktop", 1);
extern HINSTANCE hInst;
ULONG_PTR m_gdiplusToken;
extern wstring modulePath;
GdiplusStartupInput gdiplusStartupInput;
void TransparentWnd::CreateBrowserWindow(CefString url, UINT ex_style, bool isTransparent){
RegisterClass(hInst);
this->url=url;
this->isTransparent=isTransparent;
UINT ex_style1=ex_style;
if(isTransparent){
ex_style1=WS_EX_TOOLWINDOW;
}
hWnd = CreateWindowEx(ex_style1, L"browser", L"透明浏览器",
WS_OVERLAPPED&~(WS_CAPTION|WS_BORDER), 0, 0, 0,
0, NULL, NULL, hInst, NULL);
g_handler=new MyHandler();
g_handler->win=(long)this;
InitCallback();
SetWindowLong(hWnd, GWL_USERDATA, (LONG)this);
if(isTransparent){
EnableTransparent(ex_style);
}
else{
SendMessage(hWnd, WM_INIT, NULL, NULL);
DWORD dwStyle = GetWindowLong(hWnd, GWL_STYLE);//获取旧样式
DWORD dwNewStyle = WS_OVERLAPPED | WS_VISIBLE| WS_SYSMENU |WS_MINIMIZEBOX|WS_MAXIMIZEBOX|WS_CLIPCHILDREN|WS_CLIPSIBLINGS;
dwNewStyle&=dwStyle;//按位与将旧样式去掉
SetWindowLong(hWnd,GWL_STYLE,dwNewStyle);//设置成新的样式
DWORD dwExStyle = GetWindowLong(hWnd, GWL_EXSTYLE);//获取旧样式
DWORD dwNewExStyle = WS_EX_TOOLWINDOW|WS_EX_LEFT |WS_EX_LTRREADING |WS_EX_RIGHTSCROLLBAR;
dwNewExStyle&=dwExStyle;//按位与将旧扩展样式去掉
SetWindowLong(hWnd,GWL_EXSTYLE,dwNewExStyle);//设置新的扩展样式
ShowWindow(hWnd, SW_SHOW);
UpdateWindow(hWnd);
}
}
CefString TransparentWnd::GetSaveName(CefString fileName){
TCHAR szFile[2048];
SaveFileDialog(hWnd, fileName.ToWString().data(), szFile);
wstring d(szFile);
CefString s(d);
return s;
}
CefString TransparentWnd::GetOpenNames(CefString fileName){
TCHAR szFiles[4096];
OpenMultiFilesDialog(hWnd, fileName.ToWString().data(), szFiles);
// Multi-Select
std::wstringstream ss;
ss<<"[\"";
wchar_t* p = szFiles;
ss<<p<<"\"";
p += lstrlen(p) + 1;
while(*p)
{
wstring s(p);
ss<<","<<"\""<<s<<"\"";
p += lstrlen(p) + 1;
// "p" - name of each files
}
ss<<"]";
return ss.str();
}
CefString TransparentWnd::GetOpenName(CefString fileName){
TCHAR szFile[4096];
OpenFileDialog(hWnd, fileName.ToWString().data(), szFile);
wstring d(szFile);
CefString s(d);
return s;
}
CefString TransparentWnd::GetFolder(){
TCHAR szFolder[4096];
::GetFolder(hWnd,szFolder);
wstring d(szFolder);
CefString s(d);
return s;
}
void TransparentWnd::EnableTransparent(UINT ex_style){
isTransparent=true;
SendMessage(hWnd, WM_INIT, NULL, NULL);
RegisterTransparentClass(hInst);
renderWindow=CreateWindowEx(WS_EX_LAYERED|ex_style, L"transparent", L"透明浏览器",
WS_POPUP&~(WS_CAPTION|WS_BORDER), 0, 0, 0,
0, NULL, NULL, hInst, NULL);
SetWindowLong(renderWindow, GWL_USERDATA, (LONG)this);
SendMessage(renderWindow, WM_INIT, NULL, NULL);
//MoveWindow(renderWindow, 0, 0, 1000, 650, false);
//MoveWindow(hWnd, -1000, -1000, 1000, 650, false);
ShowWindow(renderWindow, SW_SHOW);
UpdateWindow(renderWindow);
if(g_handler->GetBrowser()){
g_handler->GetBrowser()->GetMainFrame()->LoadURL(url);
}
ModifyStyle(renderWindow,0,WS_MINIMIZEBOX,0);
}
void TransparentWnd::CreateBrowserWindowBase(CefString path, UINT ex_style, bool isTransparent){
TCHAR szPath[1000];
GetModuleFileName(NULL,szPath,MAX_PATH);
wstring _path(szPath);
_path=_path.substr(0,_path.find_last_of('\\')+1);
replace_allW(_path, L"\\", L"/");
CefString pathC(_path);
std::stringstream ss;
ss<<pathC.ToString().c_str()<<path.ToString().c_str();
CefString s(ss.str());
CreateBrowserWindow(s, ex_style, isTransparent);
}
ATOM TransparentWnd::RegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = TransparentWnd::WndProc;
wcex.cbClsExtra = sizeof(HANDLE);
wcex.cbWndExtra = TRUE;
wcex.hInstance = hInstance;
wcex.hIcon = hIcon;//LoadIcon(hInstance, MAKEINTRESOURCE(IDI_CEFCLIENT));
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = NULL;
wcex.lpszClassName = L"browser";
wcex.hIconSm = hIcon;//LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
return RegisterClassEx(&wcex);
}
void TransparentWnd::RunApp(CefString appName, CefString param, CefString baseUrl){
wstring appNameW=appName.ToWString();
wstring path;
if(!baseUrl.length()){
path=modulePath;
}
else{
path=baseUrl.ToWString();
replace_allW(path, L"\\", L"/");
path=path.substr(0,path.find_last_of('/')+1);
}
if(appNameW.find(L":")==-1){
appNameW=path.append(appNameW);
}
CreateBrowser(appNameW,param);
}
CefString TransparentWnd::GetCurrentDirectory(){
return folder;
}
void TransparentWnd::RunAppIn(CefString appName, CefString param, CefString baseUrl){
wstring appNameW=appName.ToWString();
if(appNameW.find(L":")==-1){
wstring path;
if(!baseUrl.length()){
path=modulePath;//szPath;
}
else{
path=baseUrl.ToWString();
replace_allW(path, L"\\", L"/");
path=path.substr(0,path.find_last_of('/')+1);
}
appNameW=path.append(appNameW);
}
replace_allW(appNameW, L"\\", L"/");
int w,h,_x,_y;
int enableDrag=0,disableTransparent=0,exStyle=0,hasBorder=false,_max=false,_enableResize=false,disableRefresh=0,disableDevelop=0;
TCHAR url[1000],name[100],iconPath[1000];
wstring _folder=appNameW.substr(0,appNameW.find_last_of('/')+1);
folder=_folder;
GetPrivateProfileString(L"BASE",L"url",NULL,url,1000,appNameW.data());
GetPrivateProfileString(L"BASE",L"name",NULL,name,100,appNameW.data());
GetPrivateProfileString(L"BASE",L"icon",NULL,iconPath,1000,appNameW.data());
w=GetPrivateProfileInt(L"BASE",L"width",0,appNameW.data());
h=GetPrivateProfileInt(L"BASE",L"height",0,appNameW.data());
_x=GetPrivateProfileInt(L"BASE",L"x",0,appNameW.data());
_y=GetPrivateProfileInt(L"BASE",L"y",0,appNameW.data());
enableDrag=GetPrivateProfileInt(L"BASE",L"enableDrag",0,appNameW.data());
disableRefresh=GetPrivateProfileInt(L"BASE",L"disableRefresh",0,appNameW.data());
disableDevelop=GetPrivateProfileInt(L"BASE",L"disableDevelop",0,appNameW.data());
_enableResize=GetPrivateProfileInt(L"BASE",L"enableResize",0,appNameW.data());
disableTransparent=GetPrivateProfileInt(L"BASE",L"disableTransparent",0,appNameW.data());
hasBorder=GetPrivateProfileInt(L"BASE",L"hasBorder",0,appNameW.data());
_max=GetPrivateProfileInt(L"BASE",L"max",0,appNameW.data());
exStyle=GetPrivateProfileInt(L"BASE",L"exStyle",0,appNameW.data());
int l=wcslen(iconPath);
if(l>0){
hIcon=GetIcon(iconPath);
}
if(_enableResize>0){
enableResize=true;
}
enableRefresh=disableRefresh==0;
enableDevelop=disableDevelop==0;
CefString cefFile(url);
wstring file=cefFile.ToWString();
if(file.find(L":")==-1){
file=_folder.append(file);
}
bool isTransparent=disableTransparent==0;
if(hasBorder){
char t[10];
_itoa(isTransparent,t,10);
CefString ct(t);
wstring _name(name);
file=modulePath.append(L"window\\index.html?name=").append(_name).append(L"&url=").append(file).append(L"&transparent=").append(ct.ToWString().data()).append(L"&x=");
_itoa(_x,t,10);
ct=t;
file.append(ct.ToWString().data());
file.append(L"&y=");
_itoa(_y,t,10);
ct=t;
file.append(ct.ToWString().data());
file.append(L"&width=");
_itoa(w,t,10);
ct=t;
file.append(ct.ToWString().data());
file.append(L"&height=");
_itoa(h,t,10);
ct=t;
file.append(ct.ToWString().data());
file.append(L"&max=");
_itoa(_max,t,10);
ct=t;
file.append(ct.ToWString().data());
isTransparent=true;
if(param.length()){
file.append(L"¶m="+param.ToWString());
}
}
else {
if(param.length()){
file.append(L"?param="+param.ToWString());
}
}
CreateBrowserWindow(file, exStyle, isTransparent);
if(_max){
this->Max();
}
else{
SetSize(w,h);
Move(_x,_y);
}
this->SetTitle(name);
if(enableDrag>0){
EnableDrag();
}
}
ATOM TransparentWnd::RegisterTransparentClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = TransparentWnd::TransparentWndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = sizeof(HANDLE);
wcex.hInstance = hInstance;
wcex.hIcon = hIcon;
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = NULL;
wcex.lpszClassName = L"transparent";
wcex.hIconSm = hIcon;//LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
return RegisterClassEx(&wcex);
}
LRESULT CALLBACK TransparentWnd::TransparentWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
CefRefPtr<CefBrowser> browser = NULL;
HWND browserhWnd=NULL;
TransparentWnd* handler=NULL;
static int top=0,left=0;
static HWND editHWnd;
static BOOL _bMouseTrack=TRUE;
extern HINSTANCE hInst;
switch (message)
{
case WM_CREATE:
DragAcceptFiles(hWnd,TRUE);
break;
case WM_DROPFILES:
{
handler=(TransparentWnd*)GetWindowLong(hWnd, GWL_USERDATA);
CefRefPtr<ClientHandler> g_handler=handler->g_handler;
HWND browserHwnd = g_handler->GetBrowserHwnd();
//当文件拖进来时
HDROP hDrop=HDROP(wParam);
handler->DropHandler(hDrop);
SendMessage(handler->hWnd, message, wParam, lParam);
SendMessage(browserHwnd, message, wParam, lParam);
DragFinish(hDrop);
}
break;
case WM_INIT:
{
handler=(TransparentWnd*)GetWindowLong(hWnd, GWL_USERDATA);
CefRefPtr<ClientHandler> g_handler=handler->g_handler;
browser = g_handler->GetBrowser();
left=GetSystemMetrics(SM_CXFRAME);
top=GetSystemMetrics(SM_CYFRAME)+GetSystemMetrics(SM_CYCAPTION)-2;
DragAcceptFiles(g_handler->GetBrowserHwnd(),TRUE);
}
break;
case WM_NCHITTEST:
{
handler=(TransparentWnd*)GetWindowLong(hWnd, GWL_USERDATA);
if(!handler->enableResize){
if(handler->isTransparent){
return HTCLIENT;
}
else{
return HTCAPTION;
}
}
else{
int x,y,width=handler->width,height=handler->height;
x=LOWORD(lParam)-handler->x;
y=HIWORD(lParam)-handler->y;
TCHAR w[100];
wsprintf(w,L"%d,%d",x,y);
if(x<10&&y<10){
return HTTOPLEFT;
}
else if(x+10>width&&y+10>height){
return HTBOTTOMRIGHT;
}
else if(x+10>width&&y<10){
return HTTOPRIGHT;
}
else if(x<10&&y+10>height){
return HTBOTTOMLEFT;
}
else if(x<5){
return HTLEFT;
}
else if(y<5){
return HTTOP;
}
else if(x+5>width){
return HTRIGHT;
}
else if(y+5>height){
return HTBOTTOM;
}
}
}
break;
case WM_NCLBUTTONUP:
{
handler=(TransparentWnd*)GetWindowLong(hWnd, GWL_USERDATA);
RECT rect;
GetWindowRect(hWnd, &rect);
handler->Move(rect.left, rect.top);
POINT pt;
GetCursorPos(&pt);
handler->SetSize(rect.right-rect.left,rect.bottom-rect.top);
}
break;
case WM_LBUTTONDOWN:
case WM_RBUTTONDOWN:
{
handler=(TransparentWnd*)GetWindowLong(hWnd, GWL_USERDATA);
CefRefPtr<ClientHandler> g_handler=handler->g_handler;
browser = g_handler->GetBrowser();
SetCapture(hWnd);
SetFocus(hWnd);
browser->SendMouseClickEvent(LOWORD(lParam), HIWORD(lParam),
(message==WM_LBUTTONDOWN?MBT_LEFT:MBT_RIGHT), false, 1);
if(handler->isEnableDrag){
handler->dragX=LOWORD(lParam);
handler->dragY=HIWORD(lParam);
handler->isDrag=true;
}
}
break;
case WM_LBUTTONUP:
case WM_RBUTTONUP:
{
handler=(TransparentWnd*)GetWindowLong(hWnd, GWL_USERDATA);
CefRefPtr<ClientHandler> g_handler=handler->g_handler;
browser = g_handler->GetBrowser();
if (GetCapture() == hWnd)
ReleaseCapture();
browser->SendMouseClickEvent(LOWORD(lParam), HIWORD(lParam),
(message==WM_LBUTTONUP?MBT_LEFT:MBT_RIGHT), true, 1);
handler->isDrag=false;
}
break;
case WM_MOUSEMOVE:
{
handler=(TransparentWnd*)GetWindowLong(hWnd, GWL_USERDATA);
if(handler->isDrag){
POINT pt;
GetCursorPos(&pt);
handler->Move(pt.x-handler->dragX, pt.y-handler->dragY);
handler->MoveHandler(handler->x,handler->y);
}
else{
CefRefPtr<ClientHandler> g_handler=handler->g_handler;
browser = g_handler->GetBrowser();
browser->SendMouseMoveEvent(LOWORD(lParam), HIWORD(lParam), false);
}
if (_bMouseTrack) //若允许追踪,则。
{
TRACKMOUSEEVENT csTME;
csTME.cbSize = sizeof(csTME);
csTME.dwFlags = TME_LEAVE|TME_HOVER;
csTME.hwndTrack = hWnd;//指定要追踪的窗口
csTME.dwHoverTime = 10; //鼠标在按钮上停留超过10ms,才认为状态为HOVER
::TrackMouseEvent(&csTME); //开启Windows的WM_MOUSELEAVE,WM_MOUSEHOVER事件支持
_bMouseTrack=FALSE; //若已经追踪,则停止追踪
}
}
break;
case WM_MOUSELEAVE:
{
handler=(TransparentWnd*)GetWindowLong(hWnd, GWL_USERDATA);
CefRefPtr<ClientHandler> g_handler=handler->g_handler;
browser = g_handler->GetBrowser();
browser->SendMouseMoveEvent(LOWORD(lParam)-handler->x, HIWORD(lParam)-handler->y, true);
handler->LeaveHandler();
_bMouseTrack=TRUE;
}
break;
case WM_MOUSEWHEEL:
{
handler=(TransparentWnd*)GetWindowLong(hWnd, GWL_USERDATA);
CefRefPtr<ClientHandler> g_handler=handler->g_handler;
browser = g_handler->GetBrowser();
browser->SendMouseWheelEvent(LOWORD(lParam)-handler->x, HIWORD(lParam)-handler->y, GET_WHEEL_DELTA_WPARAM(wParam), GET_WHEEL_DELTA_WPARAM(wParam));
}
break;
case WM_SETFOCUS:
{
handler=(TransparentWnd*)GetWindowLong(hWnd, GWL_USERDATA);
CefRefPtr<ClientHandler> g_handler=handler->g_handler;
browser = g_handler->GetBrowser();
handler->FocusHandler();
browser->SendFocusEvent(message==WM_SETFOCUS);
//handler->isMini=false;
//GetCapture();
}
break;
case WM_KILLFOCUS:
{
handler=(TransparentWnd*)GetWindowLong(hWnd, GWL_USERDATA);
CefRefPtr<ClientHandler> g_handler=handler->g_handler;
browser = g_handler->GetBrowser();
browser->SendFocusEvent(message==WM_SETFOCUS);
if (GetCapture() == hWnd)
ReleaseCapture();
//handler->isMini=true;
}
break;
case WM_CAPTURECHANGED:
case WM_CANCELMODE:
{
handler=(TransparentWnd*)GetWindowLong(hWnd, GWL_USERDATA);
CefRefPtr<ClientHandler> g_handler=handler->g_handler;
browser = g_handler->GetBrowser();
browser->SendCaptureLostEvent();
}
break;
case WM_INPUTLANGCHANGE:
case WM_INPUTLANGCHANGEREQUEST:
break;
case WM_KEYDOWN:
case WM_KEYUP:
case WM_SYSKEYDOWN:
case WM_SYSKEYUP:
case WM_CHAR:
case WM_SYSCHAR:
case WM_IME_CHAR:
{
CefBrowser::KeyType type = KT_CHAR;
CefKeyInfo cki;
bool sysChar = false, imeChar = false;
if (message == WM_KEYDOWN || message == WM_SYSKEYDOWN)
type = KT_KEYDOWN;
else if (message == WM_KEYUP || message == WM_SYSKEYUP)
type = KT_KEYUP;
if (message == WM_SYSKEYDOWN || message == WM_SYSKEYUP ||
message == WM_SYSCHAR)
sysChar = true;
if (message == WM_IME_CHAR)
imeChar = true;
cki.imeChar=imeChar;
cki.sysChar=sysChar;
cki.key=wParam;
handler=(TransparentWnd*)GetWindowLong(hWnd, GWL_USERDATA);
CefRefPtr<ClientHandler> g_handler=handler->g_handler;
browser = g_handler->GetBrowser();
browser->SendKeyEvent(type, cki, lParam);
return 0;
}
break;
case WM_CLOSE:
{
handler=(TransparentWnd*)GetWindowLong(hWnd, GWL_USERDATA);
if(handler->g_handler->win){
handler->CloseHandler();
return 0;
};
}
break;
case WM_SIZING:
{
handler=(TransparentWnd*)GetWindowLong(hWnd, GWL_USERDATA);
LPRECT lpRect=(LPRECT)lParam;
int m_nWidth = lpRect->right-lpRect->left;
int m_nHeight = lpRect->bottom-lpRect->top;
handler->Move(lpRect->left,lpRect->top);
handler->SetSize(m_nWidth,m_nHeight);
}
break;
case WM_NCMOUSEMOVE:
{
RECT rect;
handler=(TransparentWnd*)GetWindowLong(hWnd, GWL_USERDATA);
if(handler){
int x = (int)LOWORD(lParam);
int y = (int)HIWORD(lParam);
GetWindowRect(hWnd, &rect);
}
}
break;
case WM_MOVE:
{
RECT rect;
handler=(TransparentWnd*)GetWindowLong(hWnd, GWL_USERDATA);
if(handler){
int x = (int)LOWORD(lParam);
int y = (int)HIWORD(lParam);
GetWindowRect(hWnd, &rect);
}
}
break;
case WM_PAINT:
{
PAINTSTRUCT ps;
BeginPaint(hWnd, &ps);
EndPaint(hWnd, &ps);
}
return 0;
case WM_ERASEBKGND:
return 0;
default:
break;
}
return DefWindowProc(hWnd, message, wParam, lParam);
}
HICON TransparentWnd::GetIcon(CefString path){
if(path.ToWString().find(L":")==-1){
wstring _path;
_path=url.ToWString();
replace_allW(_path, L"\\", L"/");
_path=_path.substr(0,_path.find_last_of('/')+1);
path=_path.append(path);
}
return (HICON)::LoadImage(NULL,path.ToWString().data(),IMAGE_ICON,0,0,LR_DEFAULTSIZE|LR_LOADFROMFILE);
//Bitmap bm(path.ToWString().data());
//HICON hIcon;
//bm.GetHICON(&hIcon);
//return hIcon;
}
void TransparentWnd::SetTaskIcon(int id, CefString iconPath, CefString title){
// 将图标放入系统托盘
NOTIFYICONDATA nd;
nd.cbSize = sizeof (NOTIFYICONDATA);
nd.hWnd = hWnd;
nd.uID = id;
nd.uFlags = NIF_ICON|NIF_MESSAGE|NIF_TIP;
nd.uCallbackMessage = WM_NOTIFYICON;
nd.hIcon = GetIcon(iconPath);
wcscpy(nd.szTip, title.ToWString().data());
Shell_NotifyIcon(NIM_ADD, &nd);
}
void TransparentWnd::TaskMouseHandler(UINT type){
std::stringstream ss;
ss<<"var e = new CustomEvent('AlloyDesktopTaskMouse',{"
<<" detail:{"
<<" type:"<<type
<<" }"
<<"});"
<<"dispatchEvent(e);";
ExecJS(ss.str());
}
void TransparentWnd::DelTaskIcon(int id){
// 将图标放入系统托盘
NOTIFYICONDATA nd;
nd.cbSize = sizeof (NOTIFYICONDATA);
nd.hWnd = hWnd;
nd.uID = id;
nd.uFlags = NIF_ICON|NIF_MESSAGE|NIF_TIP;
nd.uCallbackMessage = WM_NOTIFYICON;
nd.hIcon = NULL;//m_hIcon;
Shell_NotifyIcon(NIM_DELETE, &nd);
}
VOID CALLBACK TransparentWnd::OnTimerProc(HWND hWnd,UINT uMsg,UINT_PTR idEvent,DWORD dwTime)
{
TransparentWnd *handler=(TransparentWnd*)GetWindowLong(hWnd, GWL_USERDATA);
handler->Render();
}
void TransparentWnd::SaveImageFromStream(CefString path,AmfStream* pStream,int width,int height){
Bitmap bm(width,height);
Rect r(0,0,width,height);
BitmapData bmData;
bm.LockBits(&r, ImageLockModeWrite, PixelFormat32bppARGB, &bmData);
int l=width*height*4;
byte* p = (byte*)bmData.Scan0;
BYTE* pb2=pStream->GetStream();
for(int i=0;i<l;i+=4){
p[i+2]=pb2[i];
p[i]=pb2[i+2];
p[i+1]=pb2[i+1];
p[i+3]=pb2[i+3];
}
bm.UnlockBits(&bmData);
CLSID tiffClsid;
wstring type=wstring(L"image/")+GetExtW(path.ToWString());
GetEncoderClsid(type.data(), &tiffClsid);
bm.Save(TranslatePath(path).ToWString().data(), &tiffClsid);
}
LRESULT CALLBACK TransparentWnd::WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static CefRefPtr<CefBrowser> browser = NULL;
static HWND browserhWnd=NULL;
static RECT rect;
static TransparentWnd* handler;
static int top=GetSystemMetrics(SM_CYFRAME)+GetSystemMetrics(SM_CYCAPTION)-2,left=GetSystemMetrics(SM_CXFRAME);
switch (message)
{
case WM_INIT:
{
// Create the single static handler class instance
handler=(TransparentWnd*)GetWindowLong(hWnd, GWL_USERDATA);
CefRefPtr<MyHandler> g_handler=handler->g_handler;
g_handler->SetMainHwnd(hWnd);
GetClientRect(hWnd, &rect);
CefWindowInfo info;
CefBrowserSettings settings;
// Populate the settings based on command line arguments.
AppGetBrowserSettings(settings);
// Initialize window info to the defaults for a child window
info.SetAsChild(hWnd, rect);
if(handler->isTransparent){
info.m_bWindowRenderingDisabled = TRUE;
info.SetTransparentPainting(TRUE);
}
// Creat the new child browser window
CefBrowser::CreateBrowserSync(info,
static_cast<CefRefPtr<CefClient> >(g_handler),
handler->GetUrl(), settings);
DragAcceptFiles(hWnd,TRUE);
}
break;
case WM_NOTIFYICON:
{
handler=(TransparentWnd*)GetWindowLong(hWnd, GWL_USERDATA);
handler->TaskMouseHandler(lParam);
}
break;
case WM_ACTIVATE:
{
handler=(TransparentWnd*)GetWindowLong(hWnd, GWL_USERDATA);
handler->FocusHandler();
}
break;
case WM_CLOSE:
{
handler=(TransparentWnd*)GetWindowLong(hWnd, GWL_USERDATA);
if(handler->g_handler->win){
handler->CloseHandler();
return 0;
};
}
break;
case WM_LBUTTONDOWN:
case WM_RBUTTONDOWN:
{
handler=(TransparentWnd*)GetWindowLong(hWnd, GWL_USERDATA);
if(handler->isEnableDrag){
SetCapture(hWnd);
handler->dragX=LOWORD(lParam);
handler->dragY=HIWORD(lParam);
handler->isDrag=true;
}
}
break;
case WM_LBUTTONUP:
case WM_RBUTTONUP:
{
handler=(TransparentWnd*)GetWindowLong(hWnd, GWL_USERDATA);
if (GetCapture() == hWnd)
ReleaseCapture();
handler->isDrag=false;
}
break;
case WM_MOUSEMOVE:
{
handler=(TransparentWnd*)GetWindowLong(hWnd, GWL_USERDATA);
if(handler->isDrag){
POINT pt;
GetCursorPos(&pt);
handler->Move(pt.x-handler->dragX, pt.y-handler->dragY);
handler->MoveHandler(handler->x,handler->y);
}
}
break;
case WM_SIZE:
{
handler=(TransparentWnd*)GetWindowLong(hWnd, GWL_USERDATA);
switch(wParam){
case SIZE_MINIMIZED:
ShowWindow(handler->hWnd, SW_MINIMIZE);
break;
case SIZE_RESTORED:
break;
default:
handler=(TransparentWnd*)GetWindowLong(hWnd, GWL_USERDATA);
GetWindowRect(hWnd, &rect);
int m_x = rect.left;
int m_y = rect.top;
int m_nWidth = rect.right - rect.left;
int m_nHeight = rect.bottom - rect.top;
if(rect.right-rect.left>0){
handler->SetSize(m_nWidth,m_nHeight);
}
}
if(!handler->isTransparent){
RECT rect;
GetClientRect(hWnd, &rect);
MoveWindow(handler->g_handler->GetBrowserHwnd(), rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top, false);
}
}
break;
case WM_SIZING:
{
handler=(TransparentWnd*)GetWindowLong(hWnd, GWL_USERDATA);
LPRECT lpRect=(LPRECT)lParam;
int m_nWidth = lpRect->right-lpRect->left;
int m_nHeight = lpRect->bottom-lpRect->top;
handler->Move(lpRect->left,lpRect->top);
handler->SetSize(m_nWidth,m_nHeight);
}
break;
default:
break;
}
return DefWindowProc(hWnd, message, wParam, lParam);
}
CSFMServer* TransparentWnd::CreateMemory(CefString name, CefString fileName, int size){
if(fileName.length()>0){
return new CSFMServer(TranslatePath(fileName).ToWString().data(), name.ToWString().data(), size);
}
else{
return new CSFMServer(NULL, name.ToWString().data(), size);
}
}
void TransparentWnd::DeleteMemory(CSFMServer* mem){
delete mem;
}
AmfStream* TransparentWnd::CreateStream(CSFMServer* mem){
PBYTE p=(PBYTE)mem->GetBuffer();
return new AmfStream(p);
}
void TransparentWnd::DeleteStream(AmfStream* pStream){
delete pStream;
}
void TransparentWnd::ShowTip(CefString& text){
return;
TransparentWnd* pWin;
if(!pTipWin){
if(text.length()){
pWin=new TransparentWnd();
pTipWin=(void *)pWin;
std::stringstream ss;
POINT pt;
GetCursorPos(&pt);
ss<<"{\"text\":\""<<text.ToString()<<"\",\"x\":"<<pt.x<<",\"y\":"<<pt.y<<"}";
pWin->RunAppIn("tip/index.app",ss.str());
}
}
else{
pWin=(TransparentWnd *)pTipWin;
if(text.length()){
std::wstringstream ss;
POINT pt;
GetCursorPos(&pt);
wstring t=text.ToWString();
replace_allW(t,L"'",L"\'");
ss<<"var e = new CustomEvent('AlloyDesktopShowTip', {"
"detail: {"
" 'text':'"<<t<<"',"<<
" 'x':"<<pt.x<<","
" 'y':"<<pt.y<<
"}"
"});"
"dispatchEvent(e);";
pWin->ExecJS(ss.str());
ExecJS(ss.str());
if(pWin->isHide){
pWin->Restore();
}
}
else{
pWin->Hide();
}
}
}
TransparentWnd::TransparentWnd(void)
{
x=0;
y=0;
width=0;
height=0;
isDrag=false;
isEnableDrag=false;
m_buffer=NULL;
readyHandler="";
isMini=false;
downloadHandler=NULL;
url="";
hIcon=LoadIcon(hInst, MAKEINTRESOURCE(IDI_CEFCLIENT));
enableResize=false;
++count;
if(count==1){
GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL);
}
p2p.winHandler=(LPVOID)this;
pClient=new CSFMClient(FILE_MAP_READ|FILE_MAP_WRITE, L"AlloyDesktop");
PBYTE p=(PBYTE)pClient->GetBuffer();
pStream = new AmfStream(p);
hBitMap=NULL;
pTipWin=NULL;
InitializeCriticalSection(&cs);
}
TransparentWnd::~TransparentWnd(void)
{
if(m_buffer){
delete m_buffer;
}
g_handler->win=NULL;
SendMessage(hWnd, WM_CLOSE, 0, 0);
SendMessage(renderWindow, WM_CLOSE, 0, 0);
--count;
if (g_handler.get()) {
CefRefPtr<CefBrowser> browser = g_handler->GetBrowser();
if (browser.get()) {
// Let the browser window know we are about to destroy it.
browser->ParentWindowWillClose();
}
}
delete pClient;
delete pStream;
if(hBitMap){
DeleteObject(hBitMap);
}
if(pTipWin){
delete (TransparentWnd*)pTipWin;
}
DeleteCriticalSection(&cs);
if(count==0){
delete pServer;
GdiplusShutdown(m_gdiplusToken);
PostQuitMessage(0);
}
}
void TransparentWnd::SetUrl(CefString url){
this->url=url;
g_handler->GetBrowser()->GetMainFrame()->LoadURL(url);
}
void TransparentWnd::ReloadIgnoreCache(){
//g_handler->GetBrowser()->Release();
g_handler->GetBrowser()->ReloadIgnoreCache();
}
void TransparentWnd::SetWindowStyle(UINT dwNewExStyle){
HWND hWndTemp=isTransparent?renderWindow:hWnd;
DWORD dwExStyle = GetWindowLong(hWndTemp, GWL_EXSTYLE);//获取旧样式
dwNewExStyle|=dwExStyle;//按位与将旧扩展样式去掉
SetWindowLong(hWndTemp,GWL_EXSTYLE,dwNewExStyle);//设置新的扩展样式
}
void TransparentWnd::SetToolWindow(){
}
void TransparentWnd::SetTopMost(){
DWORD dwExStyle = GetWindowLong(hWnd, GWL_EXSTYLE);//获取旧样式
DWORD dwNewExStyle = WS_EX_TOPMOST;
dwNewExStyle|=dwExStyle;//按位与将旧扩展样式去掉
SetWindowLong(hWnd,GWL_EXSTYLE,dwNewExStyle);//设置新的扩展样式
SetWindowPos(hWnd,HWND_TOPMOST,0,0,0,0,SWP_NOMOVE | SWP_NOSIZE);
if(isTransparent){
SetWindowPos(renderWindow,HWND_TOPMOST,0,0,0,0,SWP_NOMOVE | SWP_NOSIZE);
}
}
void TransparentWnd::Reload(){
g_handler->GetBrowser()->Reload();
}
HWND TransparentWnd::GetHwnd(){
return hWnd;
}
HWND TransparentWnd::GetRenderHwnd(){
return renderWindow;
}
CefString TransparentWnd::GetUrl(){
return url;
}
void TransparentWnd::SetHinst(HINSTANCE hinst){
this->hinst=hinst;
}
void TransparentWnd::Browse(CefString& url){
RunApp("browser/index.app",url);
}
void TransparentWnd::DropHandler(HDROP hDrop){
CefRefPtr<CefFrame> frame=g_handler->GetBrowser()->GetMainFrame();
TCHAR szFilePathName[MAX_PATH+1] = {0};
UINT nNumOfFiles = DragQueryFile(hDrop, 0xFFFFFFFF, NULL, 0); //得到文件个数
std::stringstream ss;
ss<<"var e = new CustomEvent('AlloyDesktopDragDrop',{"
<<" detail:{"
<<" list:[\"";
for (UINT nIndex=0 ; nIndex< nNumOfFiles-1; ++nIndex)
{
DragQueryFile(hDrop, nIndex, szFilePathName, MAX_PATH); //得到文件名
wstring path(szFilePathName);
replace_allW(path, L"\\", L"/");
CefString url(path);
ss<<url.ToString().c_str()<<"\",\"";
}
DragQueryFile(hDrop, nNumOfFiles-1, szFilePathName, MAX_PATH);
wstring path(szFilePathName);
replace_allW(path, L"\\", L"/");
CefString url(path);
ss<<url.ToString().c_str()<<"\"]"
<<" }"
<<"});"
<<"dispatchEvent(e);";
ExecJS(ss.str());
}
void TransparentWnd::MoveHandler(int x, int y){
std::stringstream ss;
ss<<"var e = new CustomEvent('AlloyDesktopWindowMove',{"
<<" detail:{"
<<" x:"<<x<<","
<<" y:"<<y
<<" }"