Click here to Skip to main content
Licence 
First Posted 9 Nov 2000
Views 230,720
Bookmarked 34 times

Create a modeless dialog box as child window

By | 9 Nov 2000 | Article
Simple step by step article explaining how to create a modeless dialog box as child window.

This article is part of the drag and drop interface samples.

  1. Serializing ASCII Data
  2. Modeless child dialog
  3. Modeless sibling dialog
  4. The drag source
  5. The MFC drop target
  6. The TBTextTarget class

  • Download source files - 44 Kb

    To create the modeless dialog as sibling, follow this link.

    Follow these steps:

    1. Create a new dialog resource and use the Class Wizard for making a new CDialog based class for it; let's call it CDropDialog
    2. In your CFormView-derived class, add a (private) member variable of type CDropDialog* as a container for the modeless dialog class, let's call it m_pModeless. In the constructor of your view, make sure you initialize m_pModeless to NULL
    3. In your appropriate message handler, let's call it OnModeless, do the following:
      void CInterfaceView::OnModeless() 
      {
          // Display the modal dialog box
          <FONT color=#000080>if</FONT> (!m_pModeless)
              m_pModeless = new CDropDialog;
      
          <FONT color=#000080>if</FONT> (!::IsWindow(m_pModeless->GetSafeHwnd()))
              m_pModeless->
    In the destructor of the parent window, proof if the dialog has been closed and release the memory:
    CInterfaceView::~CInterfaceView()
    {
        <FONT color=#000080>if</FONT> (m_pModeless)
        {
            <FONT color=#000080>if </FONT>(::IsWindow(m_pModeless->GetSafeHwnd()))
                m_pModeless->EndDialog(IDCANCEL);
            <FONT color=#000080>delete</FONT> m_pModeless;
        }
    }
  • License

    This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

    A list of licenses authors might use can be found here

    About the Author

    Thomas Blenkers

    Web Developer

    Germany Germany

    Member

    PhD Chemist,
    programming with MSVC & MFC since 1996

    Sign Up to vote   Poor Excellent
    Add a reason or comment to your vote: x
    Votes of 3 or less require a comment

    Comments and Discussions

     
    You must Sign In to use this message board. (secure sign-in)
     
    Search this forum  
     FAQ
        Noise  Layout  Per page   
      Refresh
    QuestionModeless Dialog boxes Pinmemberksrikant8319:42 2 Jul '08  
    AnswerRe: Modeless Dialog boxes PinmemberPandele Florin3:01 18 Jan '11  
    Questionare you suppose to be able to type data in text box?? Pinmemberdoctorrie8:30 23 May '05  
    AnswerRe: are you suppose to be able to type data in text box?? Pinmembercristitomi4:32 22 Mar '07  
    GeneralControls on child dialog are not enabled - Solution! PinmemberStephen_Hosking16:15 29 Mar '05  
    GeneralIf this doesn't work for you... PinmemberSteve (Stephen Hosking)16:24 29 Mar '05  
    Generaldialog style as Child but always disabled Pinsusswondermind12:20 13 Oct '04  
    GeneralSee "Solution", 30 March 2005. nt PinmemberSteve (Stephen Hosking)16:19 29 Mar '05  
    GeneralRe: dialog style as Child but always disabled Pinmembercristitomi4:33 22 Mar '07  
    GeneralModeless dialoge Pinmembersohcher@harandiha.com10:20 26 Feb '04  
    Generalusing database Pinmembervishalbhatara23:49 4 May '03  
    QuestionHow 2 call a dialog using a button PinmemberBiswakalyan23:05 16 Jun '02  
    AnswerRe: How 2 call a dialog using a button PinsussAnonymous5:07 2 Nov '02  
    Generalfront window Pinmembertammari21:20 8 May '02  
    GeneralRe: front window Pinmemberwalker23:19 12 May '02  
    GeneralRe: front window PinmemberDarkCloud1411:39 9 Dec '03  
    GeneralDetected memory leaks!! PinmemberAnonymous22:11 8 Apr '02  
    GeneralJumping between several dialogs PinmemberMIG2912:57 29 Jul '01  
    GeneralHEELLLPPPPP PinmemberAnonymous9:14 10 Jul '01  
    GeneralRe: HEELLLPPPPP PinmemberAnonymous9:44 10 Jul '01  
    GeneralHELP!! SAME PROBLEM HERE TOO Pinsusswondermind9:32 13 Oct '04  
    GeneralIf I set the dialog style to Child, it is not enabled PinmemberDavid Fleming22:15 14 Jun '01  
    GeneralRe: If I set the dialog style to Child, it is not enabled PinmemberNice Özgürce12:09 18 Jan '05  
    GeneralOnModeless PinmemberJulien11:35 4 Jan '01  
    In the message handler OnModeless there are compilcations.
     
    I had a CListControl taking up all the space on the 2nd dialog and
    in the method OnKillfocusList(NMHDR* pNMHDR, LRESULT* pResult) I
    added this->DestroyWindow(); (Which produced the PostNcDestory etc etc)
     
    However when I tried to Create(ID_2ND_DIALOG, this) the 2nd time I got a
    DebugBreak which I could not locate in the source. I went down the whole
    path of just re-using the first instance of the Dialog (so Create is only
    called once) but I didn't like it.
     
    So, I added this :
    const int WM_CUSTOM_DESTROY = WM_USER+100;
     
    void C2ndDlg::OnKillfocusList(NMHDR* pNMHDR, LRESULT* pResult)
    {
    *pResult = 0;
    // this->DestroyWindow(); We don't want to call this any more.
    this->PostMessage(WM_CUSTOM_DESTROY);
    }
     
    void C2ndDlg::OnCustomDestroy(UINT, UINT)
    {
    this->DestroyWindow();
    }
     
    and to the MessageMap
    ON_MESSAGE(WM_CUSTOM_DESTROY, OnCustomDestroy)
     
    Suddenly it works!
    Which allows me to NOT maintain all the pointer to the C2ndDlg objects
    and instead add 'delete this' to the OnPostNcDestory() as in MSDN.
     
    FYI:
    What this means is that stuff is happening After the OnKillfocusList
    which needs to happen before we can call DestroyWindow, its just really
    hard to find out what.
    If anyone know can they please reply.
     
    Thanks
    Jules
    GeneralRe: OnModeless PinmemberJulien11:46 4 Jan '01  

    General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

    Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

    Permalink | Advertise | Privacy | Mobile
    Web02 | 2.5.120529.1 | Last Updated 10 Nov 2000
    Article Copyright 2000 by Thomas Blenkers
    Everything else Copyright © CodeProject, 1999-2012
    Terms of Use
    Layout: fixed | fluid