• 添加无模式对话框


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

    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 }
  • 相关阅读:
    10 个十分难得的 javascript 开发经验
    牛人推荐的跨浏览器兼容性总结
    不可不看!CSS3中三十一种选择器用法
    jQuery制作鼠标经过显示图片大图,生成图片tips效果
    解决IE6中 PNG图片透明的终极方案-八种方案!
    关于JavaScript代码的执行效率总结
    【我们开发有力量之二】利用javascript制作批量网络投票机器人(自动改IP)
    网页制作中最有用的免费Ajax和JavaScript代码库
    纯javascript代码实现浏览器图片选择预览、旋转、批量上传
    悲催的IE6 七宗罪大吐槽(带解决方法)第二部分
  • 原文地址:https://www.cnblogs.com/LouMengzhao/p/6041527.html
Copyright © 2020-2023  润新知