122 lines
3.0 KiB
C++
122 lines
3.0 KiB
C++
#define _CRT_SECURE_NO_WARNINGS
|
|
|
|
#include "WkeWindow.h"
|
|
#include "UtilHelper.h"
|
|
#include <Imm.h>
|
|
#include <assert.h>
|
|
|
|
#pragma comment(lib, "shell32.lib")
|
|
#pragma comment(lib, "shlwapi.lib")
|
|
#pragma comment(lib, "user32.lib")
|
|
#pragma comment(lib, "comctl32.lib")
|
|
#pragma comment(lib, "imm32.lib")
|
|
|
|
CWkeWindow::CWkeWindow(void)
|
|
{
|
|
|
|
}
|
|
|
|
CWkeWindow::~CWkeWindow(void)
|
|
{
|
|
|
|
}
|
|
|
|
static void WKE_CALL_TYPE onDidCreateScriptContextCallback(wkeWebView webView, void* param, wkeWebFrameHandle frameId, void* context, int extensionGroup, int worldId)
|
|
{
|
|
|
|
}
|
|
|
|
static void handleWindowDestroy(wkeWebView webWindow, void* param)
|
|
{
|
|
|
|
}
|
|
|
|
static void handleDocumentReady(wkeWebView webWindow, void* param)
|
|
{
|
|
wkeShowWindow(webWindow, true);
|
|
}
|
|
|
|
static void handleTitleChanged(wkeWebView webWindow, void* param, const wkeString title)
|
|
{
|
|
wkeSetWindowTitleW(webWindow, wkeGetStringW(title));
|
|
}
|
|
|
|
static wkeWebView onCreateView(wkeWebView webWindow, void* param, wkeNavigationType navType, const wkeString url, const wkeWindowFeatures* features)
|
|
{
|
|
wkeWebView newWindow = wkeCreateWebWindow(WKE_WINDOW_TYPE_POPUP, NULL, features->x, features->y, features->width, features->height);
|
|
wkeShowWindow(newWindow, true);
|
|
return newWindow;
|
|
}
|
|
|
|
static bool onLoadUrlBegin(wkeWebView webView, void* param, const char* url, void* job)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
static void onLoadUrlEnd(wkeWebView webView, void* param, const char* url, void* job, void* buf, int len)
|
|
{
|
|
|
|
}
|
|
|
|
wchar_t buf1[16 * 1024] = { 0 }, buf2[16 * 1024] = { 0 };
|
|
jsValue JsToNative(jsExecState es, void* param)
|
|
{
|
|
CWkeWindow* pThis = (CWkeWindow*)param;
|
|
|
|
int nArg = jsArgCount(es);
|
|
if (nArg == 2)
|
|
{
|
|
jsValue arg1 = jsArg(es, 0);
|
|
jsValue arg2 = jsArg(es, 1);
|
|
if (jsIsString(arg1) && jsIsString(arg2))
|
|
{
|
|
memset(buf1, 0, sizeof(wchar_t) * 16 * 1024);
|
|
memset(buf2, 0, sizeof(wchar_t) * 16 * 1024);
|
|
wcsncpy_s(buf1, jsToTempStringW(es, arg1), 16 * 1024 - 1);
|
|
wcsncpy_s(buf2, jsToTempStringW(es, arg2), 16 * 1024 - 1);
|
|
|
|
LPCTSTR lpArg1 = buf1;
|
|
LPCTSTR lpArg2 = buf2;
|
|
|
|
if (wcscmp(lpArg1, L"SetTokenAndZoneId") == 0)
|
|
{
|
|
//前端获取token和zoneId
|
|
return jsStringW(es, pThis->m_tokenAndZoneId.c_str());
|
|
}
|
|
|
|
return jsUndefined();
|
|
}
|
|
}
|
|
|
|
return jsUndefined();
|
|
}
|
|
|
|
void CWkeWindow::InitWindow()
|
|
{
|
|
RECT rc;
|
|
::GetClientRect(this->GetHWND(), &rc);
|
|
window = wkeCreateWebWindow(WKE_WINDOW_TYPE_CONTROL, GetHWND(), 0, 0, rc.right - rc.left, rc.bottom - rc.top);
|
|
wkeOnDidCreateScriptContext(window, onDidCreateScriptContextCallback, this);
|
|
wkeOnWindowDestroy(window, handleWindowDestroy, this);
|
|
|
|
wkeOnDocumentReady(window, handleDocumentReady, this);
|
|
wkeOnTitleChanged(window, handleTitleChanged, this);
|
|
wkeOnCreateView(window, onCreateView, this);
|
|
wkeOnLoadUrlBegin(window, onLoadUrlBegin, this);
|
|
wkeOnLoadUrlEnd(window, onLoadUrlEnd, this);
|
|
wkeSetDebugConfig(window, "decodeUrlRequest", nullptr);
|
|
wkeJsBindFunction("jsToNative", &JsToNative, this, 2);
|
|
}
|
|
|
|
void CWkeWindow::LoadUrl(std::wstring url)
|
|
{
|
|
wkeLoadURLW(window, url.c_str());
|
|
wkeShowWindow(window, true);
|
|
}
|
|
|
|
void CWkeWindow::Runjs(const char * js)
|
|
{
|
|
wkeRunJS(window, js);
|
|
}
|
|
|