zoukankan      html  css  js  c++  java
  • 添加无模式对话框

    本文只描述了一种添加无模式对话框的方法,不涉及所有方法的讨论,有好的方法,欢迎大家讨论。关于模式和无模式的对话框的区别,在上篇文章中已有,不再赘述,直接捞干的。

    1、创建的是基于对话框的工程。(我的是wince下的);

    2、有一个父窗口,插入新的窗口如newDlg,并将其属性设置为child;

    3、给newDlg 添加类,如newDlg.cpp , newDlg.h

    4、在父窗口文件中添加以下代码:

            某个按钮操作函数{           //创建

            newDlg  NewDlg;

           NewDlg.Create(NewDlg.IDD,this);

           NewDlg.ShowWindow(SW_SHOW);

            }

           某个按钮操作函数{               //销毁

                NewDlg.ShowWindow(SW_HIDE);
                NewDlg.SendMessage(WM_DESTROY);
             }

    5、别忘了包含头文件。

    6、关于create函数:

    1 virtual BOOL Create(
    2    LPCTSTR lpszTemplateName,
    3    CWnd* pParentWnd = NULL 
    4 );
    5 virtual BOOL Create(
    6    UINT nIDTemplate,
    7    CWnd* pParentWnd = NULL 
    8 );
    9  
    lpszTemplateName

    Contains a null-terminated string that is the name of a dialog-box template resource.

    pParentWnd

    Points to the parent window object (of type CWnd) to which the dialog object belongs. If it is NULL, the dialog object's parent window is set to the main application window.

    nIDTemplate

    Contains the ID number of a dialog-box template resource.

    You can put the call to Create inside the constructor or call it after the constructor is invoked.

    Two forms of the Create member function are provided for access to the dialog-box template resource by either template name or template ID number (for example, IDD_DIALOG1).

    For either form, pass a pointer to the parent window object. If pParentWnd is NULL, the dialog box will be created with its parent or owner window set to the main application window.

    The Create member function returns immediately after it creates the dialog box.

    Use the WS_VISIBLE style in the dialog-box template if the dialog box should appear when the parent window is created. Otherwise, you must call ShowWindow. For further dialog-box styles and their application, see the DLGTEMPLATE structure in the Windows SDK and Window Styles in the MFC Reference.

    Use the CWnd::DestroyWindow function to destroy a dialog box created by the Create function.

    例子:

     1 void CMyDialog::OnMenuShowSimpleDialog()
     2 {
     3    //m_pSimpleDialog initialized to NULL in the constructor of CMyDialog class
     4    m_pSimpleDlg = new CSimpleDlg();
     5    //Check if new succeeded and we got a valid pointer to a dialog object
     6    if(m_pSimpleDlg != NULL)
     7    {
     8       BOOL ret = m_pSimpleDlg->Create(IDD_SIMPLEDIALOG, this);
     9 
    10       if(!ret)   //Create failed.
    11          AfxMessageBox(_T("Error creating Dialog"));
    12 
    13       m_pSimpleDlg->ShowWindow(SW_SHOW);
    14    }
    15    else
    16    {
    17       AfxMessageBox(_T("Error Creating Dialog Object"));
    18    }
    19 }
  • 相关阅读:
    华为全联接大会2019,共创智能新高度
    CTDC2019首席技术官领袖峰会,AI赋能 智享5G
    2019全球体验设计峰会:体验赋能商业,创造更好体验
    全球闪存峰会旨在深化技术创新,增进闪存产业链上下游
    PyCon 2019火热来袭,与大数据、人工智能等专家一起探讨Python语言
    PHPConChina 2019 PHP开发者大会将于8月在上海举办!
    2019腾讯Live开发者大会(TLC),引领技术新趋势
    2019 HTML5深度应用开发实践
    2019年5G物联网关键技术与应用培训,了解5G网络发展现状及进展
    2019第二届企业云服务大会 -- 企业智变,云化未来
  • 原文地址:https://www.cnblogs.com/LouMengzhao/p/6041527.html
Copyright © 2011-2022 走看看