2011-12-17 62 views
0

我正在使用firebreath开发一个NPAPI插件。我正在使用第三方dll集成到游戏设备。设备上的输入通过仅向设备打开通道时注册的消息窗口(HWND)传播到插件。使用CustomWndProc回复消息窗口句柄

最初,与设备驱动程序握手, 握手(HWND,...),并且在用户输入之后,在CustomWinProc()上进行回调以进行通知。

我做了以下内容,

-Created的WIN-CustomCallbackHandler.h下头& CPP文件,

#include "Win\PluginWindowWin.h" 
    #include "Win\WindowContextWin.h" 

    class CustomCallbackHandler : public FB::PluginWindowWin 
    { 
     public: 
    CustomCallbackHandler (const FB::WindowContextWin& ctx); 

     protected: 
    virtual bool CustomWinProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM 
     lParamm,LRESULT & lRes); 
    }; 

-CustomCallbackHandler.cpp

[code] 
    #include "CustomCallbackHandler.h" 
    #include "PluginWindowForwardDecl.h" 
    #include "Win\WindowContextWin.h" 
    #include "Win\PluginWindowWin.h" 

    CustomCallbackHandler::CustomCallbackHandler(const FB::WindowContextWin& ctx) :  
    FB::PluginWindowWin(ctx){ 
    } 

    bool CustomCallbackHandler::CustomWinProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM 
    lParamm,LRESULT & lRes){ 
    //if WPARAM is something some operation has to be performed. 
return false; 
    } 
    [/code] 

-Factory.cpp - 增加了以下方法来覆盖PluginWindowWin

FB::PluginWindowWin* createPluginWindowWin(const FB::WindowContextWin& ctx) 
{ 
    return new CustomCallbackHandler(ctx); 

} 

-MyFirstPluginAPI.cpp-(自动生成的JSAPIAuto子类) - JS方法。

bool MyFirstPluginAPI::handshake(FB::JSObjectPtr &callback) 
    { 
     FB::WinMessageWindow window; 
     thirdpartymethod(window.getHWND()); 
    } 

现在,当我调试,我可以看到customcallbackhandler被调用几次为常规插件事件,而是由设备生成的事件并不available.I相信消息窗口的不同实例被传递到dll。

- 我该如何获得PluginWindowWin的句柄?
- 我在CustomCallbackHandler上收到回调,如何生成自定义sendEvent()?

非常感谢您的帮助。

我是一名Java开发人员,在C++编程方面经验不足。我相信我缺少一些根本性的东西。

+0

-Am我在正确的方向试图子类的PluginWindowWin? - 或 - 我应该创建一个全新的消息类窗口为此通过调用RegisterClass和CreateWindow? – Yeshvanthni

+0

最初,我创建了另一组消息窗口,在阅读了一些博客之后,我认为最好是通过扩展它来利用插件窗口。有什么建议么? – Yeshvanthni

回答

1

你想要的是使用WinMessageWindow:

https://github.com/firebreath/FireBreath/blob/master/src/PluginCore/Win/WinMessageWindow.h

你不想使用PluginWindowWin;这对于其他事情来说太具体了。 WinMessageWindow是专门为你要做的事情创建的类型,它允许你在包含的类上创建一个winproc处理程序。

我最近发布了an example of using WinMessageWindow为了接收WM_DEVICENOTIFY消息;我相信你可以用它作为课程如何帮助你入门的例子。

+0

谢谢。这工作! – Yeshvanthni