• 关于Win32 DialogBox的一些收获


    最近项目组让新来的小MM开发一个PC端的串口模拟器,我正好也一起学习一下win32编程。

    懒得用CreateWindow建立窗口,所以就用VC自带的资源编辑器画Dialog了。

    话说这个Dialog和window的编程思想差不多,都是create,show,update,消息队列循环这样一个流程。所以也就习惯了。

    但是今天晚上还是碰到了一些麻烦,我的Dialog程序关闭后窗口消失了,但是进程管理器显示进程并未被杀死。

    原来是在消息处理函数里少了如下语句:

    case WM_DESTROY:
            PostQuitMessage(
    0);

            return TRUE;  

    另外还有一个小小的收获:

    发生上述错误是因为codeblocks自动生成的代码在创建DialogBox使用的是:

    int DialogBox(
      HINSTANCE hInstance,  
    // handle to application instance
      LPCTSTR lpTemplate,   // identifies dialog box template
      HWND hWndParent,      // handle to owner window
      DLGPROC lpDialogFunc  // pointer to dialog box procedure

    );  

    而之后我把代码改成了CreateDialog,ShowDialog,UpdateDialog模式的代码。

    而关于DialogBox函数和CreateDialog,ShowDialog,UpdateDialog的区别,MSDN解释如下:

    The DialogBox macro uses the CreateWindowEx function to create the dialog box. DialogBox then sends a WM_INITDIALOG message (and a WM_SETFONT message if the template specifies the DS_SETFONT style) to the dialog box procedure. The function displays the dialog box (regardless of whether the template specifies the WS_VISIBLE style), disables the owner window, and starts its own message loop to retrieve and dispatch messages for the dialog box.

    When the dialog box procedure calls the EndDialog function, DialogBox destroys the dialog box, ends the message loop, enables the owner window (if previously enabled), and returns the nResult parameter specified by the dialog box procedure when it called EndDialog

     翻译如下:

    DialogBox宏使用CreateWindowEx函数创建对话框。然后DialogBox发送WM_INITDIALOG消息(如果对话框模板设置字体,则也发送WS_VISIBLE消息),使父窗体失效,启动自身的消息循环获取和处理消息。

    当对话框调用 EndDialog 函数,DialogBox 销毁对话框,结束消息循环,使父窗体有效,返回被对话框过程调用EndDialog时指定的nResult参数。

    (山寨翻译,敬请批评指正) 

  • 相关阅读:
    操作系统:进程同步
    操作系统:线程的概念
    操作系统:进程的概念与控制
    操作系统:操作系统概述
    CTF-WEB:攻防世界 ics-05(preg_replace() 函数 /e 漏洞)
    《剑指 Offer》学习记录:题 11:旋转数组的最小数字
    《剑指 Offer》学习记录:题 28:对称二叉树
    Linux为什么不是硬实时
    普通线程和内核线程
    linux内核栈和用户栈
  • 原文地址:https://www.cnblogs.com/Leon5/p/2004105.html
Copyright © 2020-2023  润新知