Solved

Showmodal in C++?

Posted on 2011-02-22
5
955 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

785 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