在我的win32应用程序中使TAB键工作 [英] Making TAB key work in my win32 app

查看:272
本文介绍了在我的win32应用程序中使TAB键工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使Tab按钮在我的应用程序上正常工作,因此当我按Tab时,它将从一个编辑框变为另一个编辑框,这些是编辑框代码:

I want to make the tab button work on my app , so when I press tab, it will change from one edit box to another, these are the edit box codes:

    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消息,因此可以安全地假设您将控件添加到标准窗口而不是对话框中。

The fix is quite simple. Given the fact you're handling the WM_CREATE message, rather than the WM_INITDIALOG message, it seems safe to assume that you're adding the controls to a 'standard' window, rather than a 'dialog'.

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

With that in mind, I expect you've got something like the following in your 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 指出:


尽管IsDialogMessage函数用于无模式对话框,但是您可以将其与包含控件的任何窗口一起使用,
IsDialogMessage处理一条消息时,它将检查键盘消息并将其转换为相应对话框的选择命令,例如TAB键,从而使窗口能够提供与对话框中使用的相同的键盘选择。

"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.

因为IsDialogMessage函数执行,所以当按下时,选择下一个控件或一组控件,然后按下向下键,选择组中的下一控件。所有必需的消息翻译和分发,都不能将IsDialogMessage处理的消息传递给TranslateMessage或DispatchMessage函数。

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."

您可以将消息泵更改为类似于以下内容:

So, you can change your message pump to resemble the following:

/* 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);
    }
}

这篇关于在我的win32应用程序中使TAB键工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆