Firebreath生成的Windows插件窗口对象与JS交互对象

对于Windows平台框架,Firebreath生成两个主要对象:

1.FB::PluginCore派生对象,主要与浏览器交互

2.FB::JSAPIAuto派生对象,主要与JS交互


对于FB::PluginCore派生对象,可以通过下面方法得到插件窗口句柄:

[cpp]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. FB::PluginWindowWin *pwnd = getWindow()->get_as<FB::PluginWindowWin>();  
  2. HWND hwnd = pwnd->getHWND();  

注意,FB::PluginWindowWin的定义需要引用头文件:#include "Win/PluginWindowWin.h"

对于FB::PluginCore派生对象,其头文件中可以用下面的宏进行Windows消息事件映射:

[cpp]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. BEGIN_PLUGIN_EVENT_MAP()  
  2.         EVENTTYPE_CASE(FB::MouseDownEvent, onMouseDown, FB::PluginWindow)  
  3.         EVENTTYPE_CASE(FB::MouseUpEvent, onMouseUp, FB::PluginWindow)  
  4.         EVENTTYPE_CASE(FB::MouseMoveEvent, onMouseMove, FB::PluginWindow)  
  5.         EVENTTYPE_CASE(FB::MouseMoveEvent, onMouseMove, FB::PluginWindow)  
  6.         EVENTTYPE_CASE(FB::AttachedEvent, onWindowAttached, FB::PluginWindow)  
  7.         EVENTTYPE_CASE(FB::DetachedEvent, onWindowDetached, FB::PluginWindow)  
  8.     EVENTTYPE_CASE(FB::RefreshEvent, onWindowRefresh, FB::PluginWindow)  
  9.     EVENTTYPE_CASE(FB::WindowsEvent, onWindowEvent, FB::PluginWindow)  
  10. END_PLUGIN_EVENT_MAP()  


最后一个映射可以处理所有的Windows消息:


EVENTTYPE_CASE(FB::WindowsEvent, onWindowEvent, FB::PluginWindow)

[cpp]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. //处理代码可能如下  
[cpp]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. bool onWindowEvent(FB::WindowsEvent *evt, FB::PluginWindow *wnd)  
  2. {  
  3.     switch (evt->uMsg)  
  4.     {  
  5.     case WM_SETFOCUS:  
  6.         ...  
  7.         break;  
  8.     case WM_KILLFOCUS:  
  9.         ...  
  10.         break;  
  11.     case WM_PAINT:  
  12.         ...  
  13.         break;  
  14.     }  
  15.     ...  
  16. }  


对于FB::JSAPIAuto派生对象,可以通过getPlugin()方法得到对应的FB::PluginCore派生对象,你可以用下面方法得到插件的窗口句柄:

[cpp]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. FB::PluginWindowWin *pwnd = getPlugin()->GetWindow()->get_as<FB::PluginWindowWin>();  
  2. HWND hwnd = pwnd->getHWND();  

猜你喜欢

转载自blog.csdn.net/shangbolei/article/details/52461446