Firebreath生成的Windows外掛視窗物件與JS互動物件
阿新 • • 發佈:2019-01-06
對於Windows平臺框架,Firebreath生成兩個主要物件:
1.FB::PluginCore派生物件,主要與瀏覽器互動
2.FB::JSAPIAuto派生物件,主要與JS互動
對於FB::PluginCore派生物件,可以通過下面方法得到外掛視窗控制代碼:
- FB::PluginWindowWin *pwnd = getWindow()->get_as<FB::PluginWindowWin>();
- HWND hwnd = pwnd->getHWND();
注意,FB::PluginWindowWin的定義需要引用標頭檔案:#include "Win/PluginWindowWin.h"
對於FB::PluginCore派生物件,其標頭檔案中可以用下面的巨集進行Windows訊息事件對映:
- BEGIN_PLUGIN_EVENT_MAP()
- EVENTTYPE_CASE(FB::MouseDownEvent, onMouseDown, FB::PluginWindow)
- EVENTTYPE_CASE(FB::MouseUpEvent, onMouseUp, FB::PluginWindow)
-
EVENTTYPE_CASE(FB::MouseMoveEvent, onMouseMove, FB::PluginWindow)
- EVENTTYPE_CASE(FB::MouseMoveEvent, onMouseMove, FB::PluginWindow)
- EVENTTYPE_CASE(FB::AttachedEvent, onWindowAttached, FB::PluginWindow)
- EVENTTYPE_CASE(FB::DetachedEvent, onWindowDetached, FB::PluginWindow)
-
EVENTTYPE_CASE(FB::RefreshEvent, onWindowRefresh, FB::PluginWindow)
- EVENTTYPE_CASE(FB::WindowsEvent, onWindowEvent, FB::PluginWindow)
- END_PLUGIN_EVENT_MAP()
最後一個對映可以處理所有的Windows訊息:
EVENTTYPE_CASE(FB::WindowsEvent, onWindowEvent, FB::PluginWindow)
- //處理程式碼可能如下
- bool onWindowEvent(FB::WindowsEvent *evt, FB::PluginWindow *wnd)
- {
- switch (evt->uMsg)
- {
- case WM_SETFOCUS:
- ...
- break;
- case WM_KILLFOCUS:
- ...
- break;
- case WM_PAINT:
- ...
- break;
- }
- ...
- }
對於FB::JSAPIAuto派生物件,可以通過getPlugin()方法得到對應的FB::PluginCore派生物件,你可以用下面方法得到外掛的視窗控制代碼:
- FB::PluginWindowWin *pwnd = getPlugin()->GetWindow()->get_as<FB::PluginWindowWin>();
- HWND hwnd = pwnd->getHWND();