Click here to Skip to main content
15,354,574 members
Articles / Desktop Programming / MFC
Article
Posted 9 Nov 2000

Stats

287.5K views
3.3K downloads
32 bookmarked

Create a Modeless Dialog Box as Child Window

Rate me:
Please Sign up or sign in to vote.
4.00/5 (9 votes)
9 Nov 2000
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

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:
    C++
    void CInterfaceView::OnModeless() 
    {
        // Display the modal dialog box
        if (!m_pModeless)
            m_pModeless = new CDropDialog;
    
        if (!::IsWindow(m_pModeless->GetSafeHwnd()))
            m_pModeless->Create(IDD_DIALOG1, this);
    
        m_pModeless->ShowWindow(SW_SHOW); 
    }

In the destructor of the parent window, proof if the dialog has been closed and release the memory:

C++
CInterfaceView::~CInterfaceView()
{
    if (m_pModeless)
    {
        if (::IsWindow(m_pModeless->GetSafeHwnd()))
            m_pModeless->EndDialog(IDCANCEL);
        delete 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.

Share

About the Author

Thomas Blenkers
Web Developer
Germany Germany
PhD Chemist,
programming with MSVC & MFC since 1996

Comments and Discussions

 
QuestionModeless Dialog boxes Pin
ksrikant832-Jul-08 19:42
Memberksrikant832-Jul-08 19:42 
AnswerRe: Modeless Dialog boxes Pin
Pandele Florin18-Jan-11 3:01
MemberPandele Florin18-Jan-11 3:01 
Questionare you suppose to be able to type data in text box?? Pin
doctorrie23-May-05 8:30
Memberdoctorrie23-May-05 8:30 
AnswerRe: are you suppose to be able to type data in text box?? Pin
cristitomi22-Mar-07 4:32
Membercristitomi22-Mar-07 4:32 
GeneralControls on child dialog are not enabled - Solution! Pin
Member 121663229-Mar-05 16:15
MemberMember 121663229-Mar-05 16:15 
GeneralIf this doesn't work for you... Pin
Member 121663229-Mar-05 16:24
MemberMember 121663229-Mar-05 16:24 
Generaldialog style as Child but always disabled Pin
wondermind13-Oct-04 12:20
Memberwondermind13-Oct-04 12:20 
GeneralSee "Solution", 30 March 2005. nt Pin
Member 121663229-Mar-05 16:19
MemberMember 121663229-Mar-05 16:19 
GeneralRe: dialog style as Child but always disabled Pin
cristitomi22-Mar-07 4:33
Membercristitomi22-Mar-07 4:33 
GeneralModeless dialoge Pin
sohcher26-Feb-04 10:20
Membersohcher26-Feb-04 10:20 
Generalusing database Pin
vishalbhatara4-May-03 23:49
Membervishalbhatara4-May-03 23:49 
QuestionHow 2 call a dialog using a button Pin
Biswakalyan16-Jun-02 23:05
MemberBiswakalyan16-Jun-02 23:05 
AnswerRe: How 2 call a dialog using a button Pin
Anonymous2-Nov-02 5:07
MemberAnonymous2-Nov-02 5:07 
Generalfront window Pin
tammari8-May-02 21:20
Membertammari8-May-02 21:20 
GeneralRe: front window Pin
WalkerLan12-May-02 23:19
MemberWalkerLan12-May-02 23:19 
GeneralRe: front window Pin
DarkCloud149-Dec-03 11:39
MemberDarkCloud149-Dec-03 11:39 
GeneralDetected memory leaks!! Pin
8-Apr-02 22:11
suss8-Apr-02 22:11 
GeneralJumping between several dialogs Pin
29-Jul-01 12:57
suss29-Jul-01 12:57 
GeneralHEELLLPPPPP Pin
10-Jul-01 9:14
suss10-Jul-01 9:14 
GeneralRe: HEELLLPPPPP Pin
10-Jul-01 9:44
suss10-Jul-01 9:44 
GeneralHELP!! SAME PROBLEM HERE TOO Pin
wondermind13-Oct-04 9:32
Memberwondermind13-Oct-04 9:32 
GeneralIf I set the dialog style to Child, it is not enabled Pin
David Fleming14-Jun-01 22:15
MemberDavid Fleming14-Jun-01 22:15 
GeneralRe: If I set the dialog style to Child, it is not enabled Pin
Close Network18-Jan-05 12:09
MemberClose Network18-Jan-05 12:09 
GeneralRe: If I set the dialog style to Child, it is not enabled Pin
ZendLion31-Aug-17 20:02
MemberZendLion31-Aug-17 20:02 
GeneralOnModeless Pin
Julien4-Jan-01 11:35
MemberJulien4-Jan-01 11:35 

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

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