这些重复的 GUI 元素从何而来?

发布于 2024-11-04 22:05:11 字数 896 浏览 1 评论 0原文

我最近尝试使用 .rc 文件在 DLL 中编写 GUI,但不幸的是遇到了

一些问题。下面是 GUI 的屏幕截图:

在此处输入图像描述

如您所见,文本“找到主窗口?否”已被复制(我没有这样做),

该框也已被复制(我也没有这样做。)

这是我用来生成对话框的代码:

DWORD WINAPI MainWin (HMODULE hMod)
{
    DialogBox (hMod, MAKEINTRESOURCE (IDD_DIALOG1), NULL, (DLGPROC)EventHandler); 
    ExitThread (0);
    return 0;
}

BOOL CALLBACK EventHandler (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    switch (uMsg)
    {
        case WM_INITDIALOG:
        ControlHwnd = hDlg;

        case WM_COMMAND:
        switch(LOWORD(wParam))
        {
            case IDC_CHECKBOX1:
                Test = !Test;
                CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)&TestFunc,NULL,0,NULL);
                Beep (500,500); 
                break;
        }
        break; 
    }

    return 0;
} 

I recently attempted to code a GUI in a DLL using .rc files, but unfortunately have ran into

a few problems. Here is a screenshot of the GUI:

enter image description here

As you can see, the text "Main Window Found? No" has been duplicated (which I did not do),

also the box has also been duplicated (which I also did not do.)

This is the code I use to generate the Dialog:

DWORD WINAPI MainWin (HMODULE hMod)
{
    DialogBox (hMod, MAKEINTRESOURCE (IDD_DIALOG1), NULL, (DLGPROC)EventHandler); 
    ExitThread (0);
    return 0;
}

BOOL CALLBACK EventHandler (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    switch (uMsg)
    {
        case WM_INITDIALOG:
        ControlHwnd = hDlg;

        case WM_COMMAND:
        switch(LOWORD(wParam))
        {
            case IDC_CHECKBOX1:
                Test = !Test;
                CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)&TestFunc,NULL,0,NULL);
                Beep (500,500); 
                break;
        }
        break; 
    }

    return 0;
} 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不知所踪 2024-11-11 22:05:11
DialogBox (..., (DLGPROC)EventHandler); 

好吧,你让编译器关闭并告诉你你做错了什么。你用那个演员调用了“上帝模式”。即使上帝也在 switch 语句中使用了 break 。并注意对话框回调过程的规则,在 MSDN 的预言

有很多类库可以帮助您避免陷入此类陷阱。 Qt、MFC、Winforms、WPF 等。当你阅读了佩措尔德并理解了一切之后,你就可以调用上帝模式了。

DialogBox (..., (DLGPROC)EventHandler); 

Well, you got the compiler to shut-up and tell you that you are doing something wrong. You invoked "god-mode" with that cast. Even God uses break in a switch statement though. And pays attention to the rules of the dialog callback procedure, well explained in the oracle of MSDN.

There are lots of class libraries around that help you avoid falling into these kind of traps. Qt, MFC, Winforms, WPF, etcetera. You can invoke god-mode after you read Petzold and understood everything.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文