Solved

Showmodal in C++?

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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Getting IP address 8 104
Best book to learn C++ 4 87
Precision Problem in C++ 7 52
Need some help with mailto 16 34
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
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 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…

730 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