C ++对话框TAB键不起作用 [英] C++ Dialog Box TAB key not working
问题描述
我已经尝试了所有方法,但是无法使TAB键起作用,从而无法将焦点从资源对话框中的一个控件移至另一个控件.这是代码:
I have tried everything but couldn't get the TAB key working to move the focus from one control to another control in a resource dialog. Here is the code:
IDD_DLG_DIALOG DIALOGEX 0, 0, 219, 198
STYLE DS_SETFONT | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU | WS_EX_CONTROLPARENT
EXSTYLE WS_EX_APPWINDOW
CAPTION "Caption"
FONT 8, "Tw Cen MT", 400, 0, 0x0
BEGIN
DEFPUSHBUTTON "Done",IDOK,162,175,50,16
EDITTEXT IDC_EDIT1,27,13,185,12,ES_AUTOHSCROLL | WS_TABSTOP | WS_VISIBLE | WS_CHILD
PUSHBUTTON "Add",IDC_Add,109,30,33,13,WS_TABSTOP | WS_VISIBLE | WS_CHILD
LISTBOX IDC_LIST1,7,49,205,121,LBS_SORT | LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP | WS_VISIBLE | WS_CHILD
EDITTEXT IDC_EDIT2,27,31,81,12,ES_AUTOHSCROLL | WS_TABSTOP | WS_VISIBLE | WS_CHILD
LTEXT "Name",IDC_STATIC,7,33,18,11
LTEXT "Link",IDC_STATIC,7,15,15,11
PUSHBUTTON "Delete",IDC_DEL,144,30,33,13 | WS_TABSTOP | WS_VISIBLE | WS_CHILD
CONTROL "Autorun at startup",IDC_CHECK1,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,174,70,10
PUSHBUTTON "Edit",IDC_EDIT,179,30,33,13,WS_TABSTOP | WS_VISIBLE | WS_CHILD
END
主要While循环:
int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine,int nCmdShow)
{
MSG msg;
HACCEL hAccelTable;
// Perform application initialization:
if (!InitInstance (hInstance, nCmdShow)) return FALSE;
hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_STEALTHDIALOG);
while (GetMessage(&msg, NULL, 0, 0))
{
if((!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))||(!IsDialogMessage(msg.hwnd,&msg)))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
}
请在此处确定问题.谢谢.
Please identify the problem here. Thanks.
推荐答案
将您的 ||
更改为&&
.目前,如果 TranslateAccelerator
返回 0
(除非按下了加速键,否则它将被调用),则将永远不会调用 IsDialogMessage
-Tab键的处理内容.
Change your ||
to a &&
. At the moment, if TranslateAccelerator
returns 0
(which it will unless an accelerator key has been pressed), IsDialogMessage
will never be called - and that's what handles the tab key.
(此外,正如Marco A.在其答案中所暗示的那样,您应该传递对话框的 HWND
,而不是 msg.hwnd
作为 IsDialogMessage
调用,但这并不重要,除非实际上调用了 IsDialogMessage
,而在您使用 ||
而不是时,这几乎总是不会&&
).
(Additionally, as Marco A. implies in his answer, you should pass the HWND
of your dialog, and not msg.hwnd
as the first parameter of the IsDialogMessage
call. But this is immaterial unless IsDialogMessage
actually gets called, which it almost always won't while you have ||
instead of &&
).
这篇关于C ++对话框TAB键不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!