无法在 MFC Windowless Activex 中获取 Cwnd 类的句柄?
Can't get the handle of a Cwnd Class in MFC Windowless Activex?
我之前问过两个问题,每个帖子都有一些解决方案,但问题仍然存在。
我的第一个问题是:为什么没有窗口的Activex不返回句柄。建议是"更改创建设置并使无窗口激活关闭,我已经尝试过了,但m_hWnd
属性仍然返回零,因为GetSafeHwnd()
方法已经完成了。
第二个问题是同样的问题,这个问题关注的是COleControl类和它的祖先CWnd。解决方案如下"在控件初始化代码的某个地方创建不可见窗口。处理发送到此窗口的消息,并直接调用控件方法"。所以我这样做了,但创建的类仍然返回零句柄。
这是我新的不可见类源:
// moWind.cpp : implementation file
//
#include "stdafx.h"
#include "PINActive.h"
#include "moWind.h"
#include "includexfspin.h"
#include <math.h>
// moWind
IMPLEMENT_DYNAMIC(moWind, CWnd)
moWind::moWind(){}
moWind::~moWind(){}
//=============================================================
LRESULT moWind::OnExecuteEvent (WPARAM wParam, LPARAM lParam)
{
WFSRESULT *pResult = (WFSRESULT *)lParam;
CString EK=_T("");
CString str;
int reskey=0;
if (pResult->u.dwEventID=WFS_EXEE_PIN_KEY)
{
LPWFSPINKEY pressedkey;
pressedkey=(LPWFSPINKEY)pResult->lpBuffer;
reskey = log10((double)pressedkey->ulDigit) / log10((double)2);
EK.Format("%d",reskey);
xfsOnKeyEvent->OnKeyRecieved(reskey);
}
else
{
str.Format("ExecuteEvent: ID = %drn", pResult->u.dwEventID);
}
MessageBox("a Execute message Recieved");
return 0;
}
BEGIN_MESSAGE_MAP(moWind, CWnd)
ON_MESSAGE(WFS_EXECUTE_EVENT,OnExecuteEvent)
END_MESSAGE_MAP()
这是类的。h文件:
// moWind.h
class IXFSEvents
{
protected:
IXFSEvents(){};
virtual ~IXFSEvents(){};
public:
virtual void OnKeyRecieved(int key)=0;
};
class moWind : public CWnd
{
DECLARE_DYNAMIC(moWind)
public:
moWind();
virtual ~moWind();
void Register(IXFSEvents* obj)
{
xfsOnKeyEvent= obj;
}
protected:
IXFSEvents* xfsOnKeyEvent;
LRESULT OnExecuteEvent (WPARAM wParam, LPARAM lParam);
DECLARE_MESSAGE_MAP()
};
在这里结束,这是我在我的Activex中使用这个类的方式:在myActivex.h文件中:
<标题>包括"moWind.h"h1> 后在myActivex的创建方法中,我已经初始化了组件回调方法,并希望获得它的句柄如下:CmyActivexCtrl::CmyActivexCtrl()
{
InitializeIIDs(&IID_DmyActivex, &IID_DmyActivexEvents);
tmpWind.Register(this);
myOtherComponent.WindowsHandle=tmpWind.GetSafeHwnd(); //here my Cwnd derived class returns zero
//my other component gets the handle and call an API with it to register
//the given handle and force the API to send the messages to that handle.
}
标题>正如您所提到的,您需要一个窗口句柄来通过它接收用户消息,您总是可以选择创建一个帮助窗口,例如消息窗口,请参阅使用CreateWindowEx来创建一个消息窗口。
对于你的无窗口控件,没有任何窗口句柄是可以的,所以你不能真正依赖句柄的可用性,除非你自己拥有一个窗口。
相关文章:
- 外壳包装器句柄/执行交互式命令管道C++ UNIX
- 如何获取边缘窗口句柄 (HWND)?
- 枚举进程模块在有效句柄上返回无效句柄
- 在 c/c++ 中打开 PhysicalDrive 的句柄并写入 MBR 的 linux 等效是什么?
- 从运行服务的应用程序代码中提取窗口句柄
- 在读取文件后重置句柄
- 是否有像地图这样的C++结构,但我得到的不是值的键,而是值的句柄?
- Microsoft ODBC 无法创建有效的句柄
- 我是否可以使用 win32 句柄以编程方式记录发送到/接收到 USB/COM 的内容
- 获取特定进程的句柄数
- C++ 创建 NdisProt 驱动程序的句柄
- 是否需要关闭来自 WinHTTP 异步的句柄?
- 句柄OK全部崩溃
- 我需要通过窗口句柄(HWND)获取文件,我该怎么办?
- 什么是 C# 等同于C++句柄
- 未知C++错误:致命错误:glibc检测到无效的stdio句柄
- 获取现有进程句柄
- GetModuleHandle() 无法检索由 "notepad.exe" 加载的"advapi32.dll"的句柄
- 更正GLSL无绑定纹理句柄中的结构布局
- 无法在 MFC Windowless Activex 中获取 Cwnd 类的句柄?