2011-12-17 51 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