-
Notifications
You must be signed in to change notification settings - Fork 0
/
AppWindow.h
81 lines (59 loc) · 2.62 KB
/
AppWindow.h
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
#pragma once
#ifndef _SCRIPT_PAD_APP_WINDOW_H
#define _SCRIPT_PAD_APP_WINDOW_H
#define WM_WEBVIEW (WM_USER + 100)
#include "Util.h"
#include <Windows.h>
#include <stdlib.h>
#include <string.h>
#include <tchar.h>
#include <wrl.h>
#include <wil/com.h>
#include "WebView2.h"
#include "resource.h"
using namespace Microsoft::WRL;
static constexpr size_t s_maxLoadString = 100;
namespace querier {
/*class Message;*/
static TCHAR szWindowClass[] = _T("DesktopApp");
static TCHAR szTitle[] = _T("Script pad desktop application");
static HINSTANCE g_appInstance;
class AppWindow {
public:
AppWindow(HINSTANCE hInstance, int nCmdShow);
~AppWindow();
void AddWebMessageReceivedHandler(HRESULT(*webMessage)(ICoreWebView2* webView, ICoreWebView2WebMessageReceivedEventArgs* args));
void AddWebMessageHandler(std::function<std::wstring(json)> function);
void AddOnWebViewCreatedHandler(void (*OnWebViewCreatedHandler)(ICoreWebView2* webview));
bool Show();
ICoreWebView2* get_WebView() {
return m_webView.get();
};
HWND get_MainWindow() {
return m_mainWindow;
};
/*static std::wstring GetResponse(Message msg);*/
private:
HINSTANCE m_hInst{ 0 };
HWND m_mainWindow{ 0 };
int m_nShow{ 0 };
HRESULT(*WebMessageReceivedHandler)(ICoreWebView2*, ICoreWebView2WebMessageReceivedEventArgs*);
std::function<HRESULT(ICoreWebView2*, ICoreWebView2WebMessageReceivedEventArgs*)> OnWebMessageReceived;
std::function<std::wstring(json)> HandleWebMessage;
void (*OnWebViewCreated)(ICoreWebView2* webview);
bool m_customWebMessageHandler{ 0 };
wil::com_ptr<ICoreWebView2Environment> m_webViewEnv;
wil::com_ptr<ICoreWebView2Controller> m_webViewCtrl;
wil::com_ptr<ICoreWebView2> m_webView;
bool InitializeWindow();
PCWSTR GetWindowClass();
void InitializeWebview();
void RegisterEventHandlers();
HRESULT OnCreateEnvironmentCompleted(HRESULT result, ICoreWebView2Environment* environment);
HRESULT OnCreateCoreWebView2ControllerCompleted(HRESULT result, ICoreWebView2Controller* controller);
bool HandleWindowMessage(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam, LRESULT* result);
static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
HRESULT WebMessageReceived(ICoreWebView2* webView, ICoreWebView2WebMessageReceivedEventArgs* args);
};
} //namespace scriptpad
#endif //_SCRIPT_PAD_APP_WINDOW_H