开发者

where are these duplicated GUI elements coming from?

开发者 https://www.devze.com 2023-03-01 17:46 出处:网络
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:

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:

where are these duplicated GUI elements coming from?

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;
} 


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消