dialogbox 的奇怪问题!!

qq_27711121 2015-04-25 09:41:19
弄了半天实在无法理解, 求解惑!

用vs2010创建了一个windows空项目, 里面有个about Dialog是用dialogbox创建的.
自带的代码如下:
INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
UNREFERENCED_PARAMETER(lParam);
switch (message)
{
case WM_INITDIALOG:
return (INT_PTR)TRUE;

case WM_COMMAND:
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
{
EndDialog(hDlg, LOWORD(wParam));
return (INT_PTR)TRUE;
}
break;
}
return (INT_PTR)FALSE;
}


本来出来的Dialogbox是可以按右上角的X关闭的, 但是只要我一修改代码,,这个dialogbox按X就无法关闭了!!!
比如我把
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)

改成
if (LOWORD(wParam) == IDOK)

除非自己处理WM_CLOSE消息. 才能响应按X关闭. 有时候即使写了WM_CLOSE也执行不到,导致无法关闭. 找了几天都摸不着头脑,求救!!
...全文
217 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
「已注销」 2015-06-04
  • 打赏
  • 举报
回复
如果你是用 CreateDialogXXX 系列的函数创建对话框,一般都是这样:

INT_PTR CALLBACK About(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message) {
    case WM_CLOSE:
        DestroyWindow(hwndDlg);
        break;
    case WM_DESTROY:
        PostQuitMessage(0);
        break;
    default:
        break;
    }
    return 0;
}
如果你是用 DialogBoxXXX 系列的函数创建对话框,一般都是这样:

INT_PTR CALLBACK About(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message) {
    case WM_CLOSE:
        EndDialog(hwndDlg, 0);
        break;
    default:
        break;
    }
    return 0;
}
赵4老师 2015-04-27
  • 打赏
  • 举报
回复
如果楼主嫌学Spy++太费劲的话,参考下面: Setting a Breakpoint on a Message Received by a Windows Function You can set message breakpoints to stop the debugger when a particular WndProc function message is received. Note Message breakpoints work only on x86- or Pentium-based systems. To set a breakpoint on a message From the Edit menu, click Breakpoints. The Breakpoints dialog box appears. Click the Messages tab. In the Break At WndProc text box, type the name of the Windows function. If you are setting a breakpoint during a debug session, the list contains the exported functions in your project. In the Set One Breakpoint For Each Message To Watch list box, select the message. To set another breakpoint, press ENTER, and then repeat steps 3 and 4. The Breakpoints list displays the currently active breakpoints. Click OK to set the breakpoints. Note If you interrupt execution while Windows or other system code is running, the results can be unpredictable.
赵4老师 2015-04-27
  • 打赏
  • 举报
回复
楼主学习使用Spy++软件正当时。
fly_dragon_fly 2015-04-27
  • 打赏
  • 举报
回复
那个叉就是IDCANCEL,dialog有自己的消息内循环,最好使用enddialog来关闭

33,319

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 新手乐园
社区管理员
  • 新手乐园社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧