OfficeAssistant_Win10/OfficeAssistant_msvc/qminiblink.cpp

65 lines
1.9 KiB
C++
Raw Normal View History

2023-07-30 18:57:41 +08:00
#include "qminiblink.h"
2023-07-31 19:06:37 +08:00
#include <QThread>
#include <QDebug>
2023-07-30 18:57:41 +08:00
#pragma comment (lib,"Comctl32.lib")
2023-07-31 19:06:37 +08:00
QMiniBlink::QMiniBlink(QWidget *parent)
2023-07-30 18:57:41 +08:00
: QWidget(parent){
2023-07-31 19:06:37 +08:00
this->parent = parent;
wkeView = nullptr;
2023-07-30 18:57:41 +08:00
//QSizePolicy sizePolicy(QSizePolicy::Policy::Expanding, QSizePolicy::QSizePolicy::Expanding);
//setSizePolicy(sizePolicy);
}
void QMiniBlink::init() {
ui.setupUi(this);
wkeInit();
2023-07-31 19:06:37 +08:00
RECT rect;
2023-08-01 23:51:40 +08:00
GetWindowRect((HWND)parent->winId(), &rect);
2023-07-31 19:06:37 +08:00
resize(rect.right - rect.left, rect.bottom - rect.top);
this->wkeView = wkeCreateWebWindow(WKE_WINDOW_TYPE_CONTROL, (HWND)this->winId(), 0, 0, rect.right - rect.left, rect.bottom - rect.top);
wkeSetNavigationToNewWindowEnable(this->wkeView, false);
wkeShowWindow(this->wkeView, TRUE);
SetParent(wkeGetWindowHandle(this->wkeView), (HWND)this->winId());
wkeMoveWindow(this->wkeView, 0, 0, rect.right - rect.left, rect.bottom - rect.top);
//while(this->firstUrl.isEmpty()){}
//wkeLoadURL(this->wkeView, this->firstUrl.toStdString().c_str());
2023-07-30 18:57:41 +08:00
SetWindowSubclass((HWND)this->winId(), subClassProc, 0, (DWORD_PTR)this);
2023-07-31 19:06:37 +08:00
//wkeRunMessageLoop();
2023-07-30 18:57:41 +08:00
}
2023-07-31 19:06:37 +08:00
QMiniBlink::~QMiniBlink(){
qDebug() << "Destroyed";
}
void QMiniBlink::ondestroy() {
if (this->wkeView != nullptr) {
wkeDestroyWebView(wkeView);
qDebug() << "Destroyed";
}
wkeShutdown();
2023-07-30 18:57:41 +08:00
}
void QMiniBlink::switchUrl(QString url) {
wkeLoadURL(wkeView, url.toStdString().c_str());
}
LRESULT CALLBACK QMiniBlink::subClassProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData)
{
QMiniBlink *obj = (QMiniBlink *)dwRefData;
if (obj == nullptr)
return DefSubclassProc(hWnd, uMsg, wParam, lParam);
switch (uMsg) {
case WM_SIZE:
obj->autojustWebViewSize();
break;
default:
break;
}
return DefSubclassProc(hWnd, uMsg, wParam, lParam);
}
void QMiniBlink::autojustWebViewSize()
{
RECT rect;
GetWindowRect((HWND)this->winId(), &rect);
wkeMoveWindow(wkeView, 0, 0, rect.right - rect.left, rect.bottom - rect.top);
}