Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ MFC dialog
Hello,
 
I want to make a dialog that get opened only if a condition occurs.
in the dialog, I will have ok button and cancel button, and I want to continue only if user presses OK.
 
for example:
 
if (condition)
{
 open dialog.
 if user clicked OK, do something
 else do something else
}
 
How can I do it using MFC?
 
Thanks
Posted 17-Jan-12 1:55am
Edited 17-Jan-12 2:18am
CPallini319.6K
v2
Comments
SAKryukov at 17-Jan-12 23:41pm
   
OK, this is a pseudo-code. Now write some code out of it. You did not explain main thing -- what's the problem?
--SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

In a glance, you need a modal dialog. I think there's a plethora of tutorials[^] on the web.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

This is usually done calling DoModal() of your dialog and using the return value:
if (condition)
{
    CMyDialog Dlg;
    if (Dlg.DoModal() == IDOK)
    {
        // OK pressed
    }
    else
    {
        // Dialog cancelled
    }
}
  Permalink  
Comments
Schehaider_Aymen at 17-Jan-12 8:55am
   
only extra information, you have to include the .h too

#include "CMyDialog.h"
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

This is trivial...
 
If you only need to display information, use a AfxMessageBox() (it's easy to use), if you need a dialog, then make a dialog derived from the CDialog MFC class and use the CDialog::DoModal() method to bring up the dialog (this is if you want to make it modal, to make it modeless, create it first then bring it up using ShowWindow()).
 
Override CDialog::OnInitDialog() to update any controls you may be using within the dialog (DO NOT do this in the constructor! This is a common mistake, the controls have not been created at this point).
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

ha,Maybe you will like the API:GetOpenFileName,It is suiteable to you~~
http://msdn.microsoft.com/en-us/library/windows/desktop/ms646927(v=vs.85).aspx[^]
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

Hi,
 
I think you don't need a dialog, instead you only need a MessageBox()
 
you can use the MessageBox like this;
 
if(IDOK== MessageBox(""))
{
 
}
else
{
 
}
 
Cheers
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 6,725
1 OriginalGriff 6,696
2 CPallini 5,315
3 George Jonsson 3,589
4 Gihan Liyanage 2,650


Advertise | Privacy | Mobile
Web01 | 2.8.140922.1 | Last Updated 17 Jan 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100