dll创建的非模态对话框Tab键不起作用,如何解决

ljh 2004-12-21 08:46:34
如题
...全文
174 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
kingzai 2004-12-21
  • 打赏
  • 举报
回复
PRB: Modeless Dialog Box in a DLL Does Not Process TAB Key (233263)
http://support.microsoft.com/default.aspx?kbid=233263
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);
}

EnochShen 2004-12-21
  • 打赏
  • 举报
回复
Tab Stop属性点了?

16,473

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧