gpt4 book ai didi

c++ - 让 TAB 键在我的 win32 应用程序中工作

转载 作者:太空狗 更新时间:2023-10-29 20:13:26 25 4
gpt4 key购买 nike

我想让标签按钮在我的应用程序上工作,所以当我按下标签时,它会从一个编辑框变为另一个,这些是编辑框代码:

    case WM_CREATE:

TextBox = CreateWindow("EDIT",
"",
WS_BORDER|WS_CHILD|WS_VISIBLE|WS_EX_LAYERED|WS_TABSTOP|WS_GROUP,
60,50,200,20,
hwnd,NULL,NULL,NULL);
DataBox = CreateWindow("EDIT",
"",
WS_BORDER|WS_CHILD|WS_VISIBLE|WS_TABSTOP|WS_GROUP,
60,72,200,20,
hwnd,NULL,NULL,NULL);
MotivBox = CreateWindow("EDIT",
"",
WS_BORDER|WS_CHILD|WS_VISIBLE|WS_TABSTOP|WS_GROUP,
60,92,200,20,
hwnd,NULL,NULL,NULL);
PretBox = CreateWindow("EDIT",
"",
WS_BORDER|WS_CHILD|WS_VISIBLE|WS_TABSTOP|WS_GROUP,
60,112,200,20,
hwnd,NULL,NULL,NULL);

最佳答案

修复非常简单。考虑到您正在处理 WM_CREATE 消息而不是 WM_INITDIALOG 消息,可以安全地假设您正在将控件添加到“标准”窗口而不是“对话框”。

考虑到这一点,我希望您的 winmain 中有如下内容:

/* Run the message loop. It will run until GetMessage() returns 0 */
while (GetMessage (&messages, NULL, 0, 0))
{
/* Translate virtual-key messages into character messages */
TranslateMessage(&messages);
/* Send message to WindowProcedure */
DispatchMessage(&messages);
}

但是,IsDialogMessage 的文档指出:

"Although the IsDialogMessage function is intended for modeless dialog boxes, you can use it with any window that contains controls, enabling the windows to provide the same keyboard selection as is used in a dialog box. When IsDialogMessage processes a message, it checks for keyboard messages and converts them into selection commands for the corresponding dialog box. For example, the TAB key, when pressed, selects the next control or group of controls, and the DOWN ARROW key, when pressed, selects the next control in a group.

Because the IsDialogMessage function performs all necessary translating and dispatching of messages, a message processed by IsDialogMessage must not be passed to the TranslateMessage or DispatchMessage function."

因此,您可以将消息泵更改为如下所示:

/* Run the message loop. It will run until GetMessage() returns 0 */
while (GetMessage (&messages, NULL, 0, 0))
{
/* Translate virtual-key messages into character messages */
if (IsDialogMessage(hwnd, &messages) == 0)
{
TranslateMessage(&messages);
/* Send message to WindowProcedure */
DispatchMessage(&messages);
}
}

关于c++ - 让 TAB 键在我的 win32 应用程序中工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21509748/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com