-
Notifications
You must be signed in to change notification settings - Fork 2
/
BrowserUI.cpp
190 lines (166 loc) · 3.57 KB
/
BrowserUI.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
#include <windows.h>
#include <shlwapi.h>
#include "BrowserUI.h"
HWND hBrowser;
LRESULT WINAPI testWindowProc(
__in HWND hWnd,
__in UINT msg,
__in WPARAM wParam,
__in LPARAM lParam)
{
LRESULT result = 0;
//mbWebView view = (mbWebView)::GetProp(hWnd, L"mb");
//if (!view)
// return ::DefWindowProc(hWnd, msg, wParam, lParam);
switch (msg) {
case WM_ERASEBKGND:
return TRUE;
case WM_SIZE:
{
if(hBrowser)
{
RECT rc;
GetClientRect(hWnd, &rc);
::MoveWindow(hBrowser, rc.left, rc.top, rc.right, rc.bottom,1);
}
return 0;
}
case WM_KEYDOWN:
{
break;
}
case WM_KEYUP:
{
break;
}
case WM_CHAR:
{
break;
}
case WM_LBUTTONDOWN:
case WM_MBUTTONDOWN:
case WM_RBUTTONDOWN:
case WM_LBUTTONDBLCLK:
case WM_MBUTTONDBLCLK:
case WM_RBUTTONDBLCLK:
case WM_LBUTTONUP:
case WM_MBUTTONUP:
case WM_RBUTTONUP:
case WM_MOUSEMOVE:
{
break;
}
case WM_CONTEXTMENU:
{
break;
}
case WM_MOUSEWHEEL:
{
break;
}
case WM_SETFOCUS:
return 0;
case WM_KILLFOCUS:
return 0;
case WM_SETCURSOR:
break;
case WM_IME_STARTCOMPOSITION: {
break;
}
case WM_CLOSE: {
break;
}
case WM_DESTROY: {
PostQuitMessage( 0 );
break;
}
}
return ::DefWindowProc(hWnd, msg, wParam, lParam);
}
BOOL regWndClass(LPCTSTR lpcsClassName, DWORD dwStyle)
{
WNDCLASS wndclass = { 0 };
wndclass.style = dwStyle;
wndclass.lpfnWndProc = testWindowProc;
wndclass.cbClsExtra = 200;
wndclass.cbWndExtra = 200;
wndclass.hInstance = ::GetModuleHandle(NULL);
wndclass.hIcon = NULL;
//wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = lpcsClassName;
::RegisterClass(&wndclass);
return TRUE;
}
BJSCV* JSHAPPY(LONG_PTR funcName, int argc, LONG_PTR argv, int sizeofBJSCV)
{
if(argc<0 && argv==sizeofBJSCV==0)
{
delete (BJSCV*)funcName;
return 0;
}
int structSize=0;
char* args = bwParseCefV8Args(argv, structSize, false);
if(structSize)
{
BJSCV* val = (BJSCV*)(args+0*structSize);
if(val->value_type==typeString)
{
::MessageBox(NULL, (TCHAR*)val->charVal, TEXT(""), MB_OK);
}
// testJs('Hah')
}
return new BJSCV{typeString, 0, "HAPPY!"};
}
void onBrowserPrepared(bwWebView browserPtr)
{
hBrowser = bwGetHWNDForBrowser(browserPtr);
bwInstallJsNativeToWidget(browserPtr, "testJs", JSHAPPY);
}
url_intercept_result* InterceptBaidu(const char* url, const url_intercept_result* ret)
{
if(!url&&ret)
{
delete ret;
return 0;
}
if(url==std::string("https://www.baidu.com/")) {
return new url_intercept_result{(CHAR*)"哈哈", 6, 200, (CHAR*)"OK"};
}
return nullptr;
}
int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) {
HWND hwnd=0;
if(1)
{
regWndClass(L"ASDASD", CS_HREDRAW | CS_VREDRAW);
hwnd = ::CreateWindowEx(WS_EX_APPWINDOW , L"ASDASD" , NULL
, WS_OVERLAPPEDWINDOW | WS_VISIBLE , 0 , 0 , 840 , 680 , NULL , NULL , ::GetModuleHandle(NULL), NULL);
ShowWindow(hwnd, true);
}
TCHAR buffer[MAX_PATH];
GetModuleFileName(NULL, buffer, MAX_PATH);
PathRemoveFileSpec(buffer);
PathAppend(buffer, L"cefclient.dll");
TCHAR LibBwgtPath[MAX_PATH];
PathCanonicalize(LibBwgtPath, buffer);
if(bwInit(LibBwgtPath))
{
bwCreateBrowser({hwnd, "www.baidu.com", onBrowserPrepared, InterceptBaidu});
}
//if(pWIdGETINVOKER)
//{
// pWIdGETINVOKER((HINSTANCE)hLibBwgt, nCmdShow);
//}
MSG msg;
{
while (GetMessage(&msg, NULL, 0, 0)) {
//if ((looper->dialog_hwnd_ && IsDialogMessage(looper->dialog_hwnd_ , &msg)))
// continue;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return 0;
}