本文介绍了Win32的:工具栏对话框似乎永远不会得到关注,并导致主窗口处理慢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在写下面的的应用程序。我知道,这个教程日期,正因为如此,我已经适应了code考虑到单向code。

I'm writing an application following this tutorial. I'm aware that this tutorial dates, and as such, I have adapted the code to take into consideration the unicode.

我有一个看起来像一个MDI主窗口。然后,我有一个查看菜单来回切换工具栏对话框,以显示和隐藏。

I have a main window which looks like an MDI. Then, I have a View menu which toggles a Toolbar dialog as to be shown and hidden.

当我显示对话框,它显示出来,但按钮式,则无法正确显示。当我再次点击我的主窗口,它们才会出现。

When I show the dialog, it is displayed, but the PUSHBUTTONs are not displayed correctly. They only appear when I click my main window again.

另外,我似乎不能够点击,无论是按钮式取值为我的工具栏对话框。

Plus, I don't seem to be able to click neither of the PUSHBUTTONs into my toolbar dialog.

RESOURCE.H )的定义如下资源(只显示什么是有关这个问题):

The resources (resource.h) are defined as follows (only showing what is relevant to this question):

#define IDD_TOOLBAR              102
#define IDC_PRESS               1000
#define IDC_OTHER               1001
#define ID_VIEW_SHOWTOOLBAR    40002
#define ID_VIEW_HIDETOOLBAR    40003

和对话作为我的 .RC 文件如下:

And the dialog as follows in my .rc file:

IDD_TOOLBAR DIALOGEX 0, 0, 85, 50
    STYLE    DS_FIXEDSYS | DS_MODALFRAME | WS_CAPTION | WS_POPUP
    EXSTYLE  WS_EX_TOOLWINDOW
    CAPTION  L"Toolbar"
    FONT     8, "MS Shell Dlg"
BEGIN
    PUSHBUTTON     L"&Press this button",     IDC_PRESS, 7,  7, 70, 14
    PUSHBUTTON     L"&Or this one",           IDC_OTHER, 7, 28, 70, 14
END

,并将其显示在我的的WndProc 功能如下:

// As a global variable I have my toolbar handler.
HWND g_hToolbar = NULL;

BOOL CALLBACK ToolbarDlgProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) {
    switch (Msg) {
        case IDC_OTHER:
            MessageBoxW(hWnd, L"You just clicked IDC_OTHER!", L"Information", MB_OK | MB_ICONINFORMATION);
            break;
        case IDC_PRESS:
            MessageBoxW(hWnd, L"You just clicked ODC_PRESS!", L"Information", MB_OK | MB_ICONINFORMATION);
            break;
        default:
            return FALSE;
    }

    return TRUE;
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) {
    switch (Msg) {
        case WM_COMMAND:
            switch (LOWORD(wParam)) {
                case ID_VIEW_HIDETOOLBAR:
                    ShowWindow(g_hToolbar, SW_HIDE);
                    break;
                case ID_VIEW_SHOWTOOLBAR:
                    if (NULL == g_hToolbar)
                        g_hToolbar = CreateDialogW(GetModuleHandle(NULL)
                                                    , MAKEINTRESOURCE(IDD_TOOLBAR)
                                                    , hWnd
                                                    , ToolbarDlgProc);

                    ShowWindow(g_hToolbar, SW_SHOW);
                    break;
            }
            break;
        default:
            return DefWindowProcW(hWnd, Msg, wParam, lParam);
    }
}

而这里的路上,我处理我的的WinMain 功能为我的主窗口中我的消息循环不同的消息和我的对话。

And here's the way I handle the different messages for my main window and my dialog in my message loop in my WinMain function.

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) {
    // Declaring, registring and creating my main window to hWnd here...
    MSG Msg;

    ShowWindow(hWnd, nShowCmd);
    UpdateWindow(hWnd);

    while (GetMessageW(&Msg, hWnd, 0, 0) > 0) {
        if (!IsDialogMessageW(g_hToolbar, &Msg)) {
            TranslateMessage(&Msg);
            DispatchMessageW(&Msg);
        }
    }
}

我的问题是:


  1. 我似乎不能够点击我的对话框的按钮。

当我尝试点击我的对话框上的按钮,我的主要窗口,成为对自己的消息作出反应很慢。

也就是说,当我想表明我的工具栏对话框,无模式对话框,因为当我表现出来模态的,它完美的作品!

That is, when I want to show my Toolbar dialog as a modeless dialog, because when I show it modal, it works perfectly!

任何线索来解决这个问题?

Any clue to solve this issue?

谢谢!

推荐答案

现在的问题是,作为DReJ在上面的评论说,在我的消息泵。

The problem is, as DReJ said in the above comment, in my message pump.

麻烦的是,我写的:

while (GetMessageW(&Msg, hWnd, 0, 0) > 0) {
    // Processing message here...
}

和我将写的:

while (GetMessageW(&Msg, NULL, 0, 0) > 0) {
    // Processing message here...
}

所以,因为我得到消息对于一个给定的窗口,在的hWnd 例如,我ToolbarDialog似乎没有时间彻底划清自身或类似的东西。更换的hWnd 对于 NULL 在该方案完全解决了这个问题。

So, because I was getting the messages for a given window, the hWnd instance, my ToolbarDialog seemed to lack of time to draw itself completely or something like it. Replacing hWnd for NULL in that scenario solved the problem entirely.

这篇关于Win32的:工具栏对话框似乎永远不会得到关注,并导致主窗口处理慢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 18:01
查看更多