这些重复的 GUI 元素从何而来?
我最近尝试使用 .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:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,你让编译器关闭并告诉你你做错了什么。你用那个演员调用了“上帝模式”。即使上帝也在 switch 语句中使用了 break 。并注意对话框回调过程的规则,在 MSDN 的预言。
有很多类库可以帮助您避免陷入此类陷阱。 Qt、MFC、Winforms、WPF 等。当你阅读了佩措尔德并理解了一切之后,你就可以调用上帝模式了。
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.