Solved

Showmodal in C++?

Posted on 2011-02-22
5
949 Views
Last Modified: 2012-05-11
Hello,

Stuppid question but... in Delphi, calling a form with .ShowModal it will freeze the entire application until the form is closed...

code example in Delphi

Form2 := TForm2.Create(Self);
try
  Form2.ShowModal; //app freeze here
finally
  Form2.Free;
  Application.Terminate;
end;

Application will only Terminate when the Form2 was closed by the user...

How to do the same in C++ and what's the name for this? example: in Delphi its call ShowModal

Haha sorry but i really need to know and my skills with C++ is -1 uhahuauha

Regards!
0
Comment
Question by:cebasso
5 Comments
 
LVL 19

Assisted Solution

by:mrwad99
mrwad99 earned 100 total points
ID: 34952266
If you are talking about an MFC modal CDialog, you call DoModal().  For example,

CDialog dlg ( ... );
dlg.DoModal();

// Any code here won't be executed until DoModal() returns, which will be when the dialog is closed.

HTH
0
 
LVL 86

Assisted Solution

by:jkr
jkr earned 100 total points
ID: 34953126
Without  any framework, the equivalent would be 'DialogBox()' (http://msdn.microsoft.com/en-us/library/ms645452(VS.85).aspx - see also http://msdn.microsoft.com/en-us/library/aa511268.aspx , "Dialog Boxes")
#include <windows.h>

LRESULT CALLBACK MyDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);

int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPTSTR    lpCmdLine,
                     int       nCmdShow)
{
    UNREFERENCED_PARAMETER(hPrevInstance);
    UNREFERENCED_PARAMETER(lpCmdLine);

    hInst = hInstance;

    int nRet = (int)DialogBox(hInst,MAKEINTRESOURCE(IDD_MY_DIALOG),0,(DLGPROC) MyDlgProc);

    if (-1 == nRet)
    {
      
      return -1;
    }

    return 0;
}

LRESULT CALLBACK MyDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) {

    switch (uMsg) {  // fill in the gaps here

                case    WM_INITDIALOG:  break;
                case    WM_COMMAND:     break;


            };

    return FALSE;
}

Open in new window

0
 
LVL 33

Expert Comment

by:sarabande
ID: 34953229
what os and compiler you were using?

you should know that c++ itself has no gui programming included.

so you need an additional library what can be MFC (microsoft foundation classes) when using visual c++ compiler or native WINAPI (a C library for programming in windows) or QT (a portable class library for many os' and compilers).

Sara
0
 
LVL 11

Accepted Solution

by:
DeepuAbrahamK earned 300 total points
ID: 34954986
0
 
LVL 4

Author Closing Comment

by:cebasso
ID: 34988831
Thanks you!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Visual c++ and text files 7 60
IdTelnet1DataAvailable handler freezes the Application 4 68
best sources to up-to-date in C++? 8 72
Add values of each row in an array 3 50
When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now