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

本文介绍Firebreath框架下Windows平台插件开发的核心内容,包括FB::PluginCore派生对象与浏览器交互的方法,以及FB::JSAPIAuto派生对象与JS交互的方式。详细讲述了如何获取插件窗口句柄及处理Windows消息事件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

对于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();  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值