about Dialog Box

Posted on 2003-02-25
Medium Priority
Last Modified: 2008-02-01
I had a "modal" Dialog Box that I displayed it like:

         CDialogDlg dialog;

and the dialog works perfectly.

But Now I want to change from "Modal" to "Modeless" then I did for displaying:

        CDialogDlg * dialog;
     dialog = new CDialogDlg();
     if(dialog != NULL)
          BOOL ret = dialog->Create(IDD_DIALOG1,this);
          if(!ret)   //Create failed.
          AfxMessageBox("Error creating Dialog");
            AfxMessageBox("Error Creating Dialog Object");     }

Then the dialog is created perfectly but when I press one button of this dialog that calls to the "CDC:MoveTo" function appears one assert error. To debug it, the error appear in the line:
VERIFY(::MoveToEx(m_hAttribDC, x, y, &point));
of CDC:MoveTo definition.

The question is: Why when the Dialog is Modal everything working perfectly, but when the dialog os Modeless appears this error?

Thanks in advance.
Question by:javieruco
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

Accepted Solution

vadik earned 400 total points
ID: 8018109
How are you getting DC? I did somehing like this:

void CTwoDlg::OnButton3()
     CDC * dc = this ->GetDC();    

     dc ->MoveTo(100, 100);
     dc ->LineTo(200, 200);

... end it is working fine.
LVL 46

Expert Comment

by:Kent Olsen
ID: 8019227
vadik's solution seems sound.

A couple of points:

If a DialogBox isn't modal, it isn't really a DialogBox.  Oh, it may LOOK like a DialogBox, but it's really just another open window (form).

The purpose of a DialogBox is to pause the task (thread) and receive interaction.  If you allow the task to continue executing by opening the form (intended to be a DialogBox) in a non-modal fashion, the originating task continues to execute and a fair amount of additional handshake is necessary to even detect that the pseudo-DiaglogBox has closed and left data lying around that is to be acted upon by the originating task.


Expert Comment

ID: 8019408
Thhis is code snippet from DLGCORE.CPP. I don't see here what a modeless DialogBox is not rallr DialogBox :(

Sorry for my English...

BOOL CDialog::Create(LPCTSTR lpszTemplateName, CWnd* pParentWnd)
     ASSERT(HIWORD(lpszTemplateName) == 0 ||

     m_lpszTemplateName = lpszTemplateName;  // used for help
     if (HIWORD(m_lpszTemplateName) == 0 && m_nIDHelp == 0)
          m_nIDHelp = LOWORD((DWORD)m_lpszTemplateName);

#ifdef _DEBUG
     if (!_AfxCheckDialogTemplate(lpszTemplateName, FALSE))
          ASSERT(FALSE);          // invalid dialog template name
          PostNcDestroy();        // cleanup if Create fails too soon
          return FALSE;
#endif //_DEBUG

     HINSTANCE hInst = AfxFindResourceHandle(lpszTemplateName, RT_DIALOG);
     HRSRC hResource = ::FindResource(hInst, lpszTemplateName, RT_DIALOG);
     HGLOBAL hTemplate = LoadResource(hInst, hResource);
     BOOL bResult = CreateIndirect(hTemplate, pParentWnd, hInst);

     return bResult;
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

LVL 46

Expert Comment

by:Kent Olsen
ID: 8020568

A DialogBox is a communication between the application and the user, just as the Experts Exchange board is a dialog between its members.

As the name dialog implies, there is a two-way communication, with each participant taking turns.

A DialogBox is a request for input.  It is the Windows application's equivalent to reading from stdin.

It is also the reason that a DialogBox normally executes as a modal object.  The application needs data to continue (a file name, a service name, etc) so it pauses waiting for input.  Once the input has been accepted the application continues.

While you can program your application to treat a DialogBox as an asyncronous object, there is a lot more coding that has to occur for it to interact meaningfully with your application.  It's much easier to use the mechanism that comes with the modal behavior.

If you really want an asyncronous object, you probably want a separate form (Window).  The coding is probably easier if you create an asyncronous form and let it create the modal dialog box.  This will allow you full GUI control over the application and the appearance of a non-modal DialogBox.


Expert Comment

ID: 8020822
You are right. Dialog box is "object" for communications between application's and user's...

Expert Comment

ID: 8023984

I'm not sure you are right. From technical point of view you are completelly not right - the only difference between modal and modeless dialog boxes is how they process messages.

From UI point - look at the modeless dialog box "Project Options" in Visual Studio .NET - it is the dialog box but you can change things in the main window as well. Try to tell to Microsoft that this is not a dialog box - they will have a lot of fun :)))

The last point - the question was technical, and there is a good answer on it by Vadik. All your "bla-bla-bla" are not related to the subj.

LVL 46

Expert Comment

by:Kent Olsen
ID: 8025330
Hi Andrew,

Please note that the very first line of my very first response was to credit Vadik on his technical response.  He offered a sound technical solution.

To me, the original question suggested that Javieruco is new to Windows (GUI) programming.  The very question, "why does this work when executed modally but not modelessly?" didn't ask anyone to "debug this code" -- it asked for an explanation.  Vadik told him how to solve the problem, I attempted to warn him of the issues that he could expect.

Yes, most DialogBoxes can be executed modally or modelessly by calling the appropriate method.  Yes, a modeless DialogBox can be made to "feel" like a Modal DialogBox by setting the StayOnTop property.  Yes.  Yes.  Yes.  There is very little difference in the DialogBox when displayed in either manner.

But I stand by my original statement.  The behavior of most DialogBoxes is such that their execution is syncronous -- modal.  Additional programming is required for the calling application to detect and process data received from a modeless execution.  Much of the behavior of a modeless DialogBox resembles a separate form/Window more than it does a modal DialogBox.

Language is a barrier in this kind of forum.  This is compounded by the very nature of the people in this business -- communication is often a problem even when English is a person's primary language.  Coming to the party late and shooting the place up isn't very productive.

Sorry if my answer offended you.  Take a Valium.

LVL 11

Expert Comment

ID: 9846014
No comment has been added lately, so it's time to clean up this TA. I will
leave a recommendation in the Cleanup topic area that this question is:

Answered: Points to vadik: Grade A
(honorable mention to Kdo for keeping his cool)

Please leave any comments here within the next seven days.

Experts: Silence means you don't care. Grading recommendations are made in light
of the posted grading guidlines (http://www.experts-exchange.com/help.jsp#hi73).


-bcl (bcladd)
EE Cleanup Volunteer

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

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…
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 goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
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.
Suggested Courses

765 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