Solved

Showmodal in C++?

Posted on 2011-02-22
5
946 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
Comment Utility
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
Comment Utility
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 32

Expert Comment

by:sarabande
Comment Utility
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
Comment Utility
0
 
LVL 4

Author Closing Comment

by:cebasso
Comment Utility
Thanks you!
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

744 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

15 Experts available now in Live!

Get 1:1 Help Now