对于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();