用向导生成一个activex控件,在oncreate中生成了两个richedit。其中一个richedit使用了自己写的类并在里面重画形成一个按钮,当用户点击这个按钮的时候,弹出一个对话框。里面是一些图片,选择可以插入richedit中(就像qq的聊天表情),然后回车(就是发言),插入到另一个只读的richedit中。 在原先的程序中,这些都没有任何问题。但是现在我要封装到一个activex控件中就有了问题。当点击按钮弹出对话框后能把图片插入到对话框中,但是回车的时候没有响应任何消息。当我重新在点击一下那个只读的richedit的时候,在回来点击这个richedit的时候,回车就可以响应消息。 为什么,activex控件有什么特别的原因吗》???
解决方案 »
- 悲剧了...我的程序怎么只能在装了vs2010的系统上运行?
- vsto wordaddin 无法正常加载 LOADBEHAVIOR总是为2,开发机器可以运行而客户端机器却有问题?
- 在使用《计算机常用数值计算方法与程序(C++版)》时遇到了困难,请求帮助!!
- 写PING程序
- 100分紧急求助!!!各位高手请帮忙。
- 我的VC疯掉了,昨天的程序还好好的,我什么也没改,可是今天运行程序,在创建某个模态对话框时,总是出现错误!!!怎么办啊?我跟踪过,
- VC调试中异常中断到某个函数了,怎样知道调用它的位置在哪里?
- 如何实现被远程注入的程序启动便自动运行DLL
- 我用的XP系统,怎么找不到newdev.h文件的啊
- 菜单简单问题,如何获得/设置某菜单项为当前菜单?
- ODBC数据库
- SDK for opera 哪位有?
一个替代的解决方案是在对话框创建的时候安装一个本进程内的键盘钩子。
适用于
This article was previously published under Q233263
SYMPTOMS
When a modeless dialog box is launched from a dynamic-link library (DLL), the TAB key and the arrow keys do not move the focus from control to control as you would expect.
CAUSE
For a modeless dialog box to process a TAB key, the message pump needs to call the IsDialogMessage API. However, if you are writing a DLL and do not have access to the .exe's source code, you cannot modify the message pump to do this.
RESOLUTION
To work around this problem, you can use a WH_GETMESSAGE hook to capture the keystroke messages and call the IsDialogMessage API. If IsDialogMessage returns TRUE, then do not pass the message on to the message pump. Set the hook when handling WM_INITDIALOG and unset it when handling the WM_DESTROY message.
STATUS
This behavior is by design.
MORE INFORMATION
The following code illustrates how to set and unset the hook as well as how to use IsDialogMessage() to process TAB key messages:BOOL CALLBACK DllDlgProc( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
switch ( uMsg )
{
case WM_INITDIALOG:
hHook = SetWindowsHookEx( WH_GETMESSAGE, GetMsgProc,
NULL, GetCurrentThreadId() );
return TRUE; case WM_COMMAND:
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
{
DestroyWindow( hwndDlg );
hwndDllDlg = NULL;
}
return TRUE; case WM_DESTROY:
UnhookWindowsHookEx( hHook );
return FALSE;
}
return FALSE;
}
The hook procedure, GetMsgProc, should resemble the following:LRESULT FAR PASCAL GetMsgProc(int nCode, WPARAM wParam, LPARAM lParam)
{
LPMSG lpMsg = (LPMSG) lParam; if ( nCode >= 0 && PM_REMOVE == wParam )
{
// Don't translate non-input events.
if ( (lpMsg->message >= WM_KEYFIRST && lpMsg->message <= WM_KEYLAST) )
{
if ( IsDialogMessage(hwndDllDlg, lpMsg) )
{
// The value returned from this hookproc is ignored,
// and it cannot be used to tell Windows the message has been handled.
// To avoid further processing, convert the message to WM_NULL
// before returning.
lpMsg->message = WM_NULL;
lpMsg->lParam = 0;
lpMsg->wParam = 0;
}
}
} return CallNextHookEx(hHook, nCode, wParam, lParam);
}