Solved

Showmodal in C++?

Posted on 2011-02-22
5
963 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 34

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
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.

729 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