CDialog::DoModal() == -1

Hi,

I write a SDI Applikation wich use 2 nonmodal Dialogs as Controls created
with ::Create
now I will use a modal Dialog in a Function called by a menue message

 CObjectDialog od;
 int ret = od.DoModal();

ret is always -1

I tryed to create the same Dialog ressource nonmodal with create, but its
also not possible,
::Create returns 0

Is it possible to get a Information why DoModal does not work ? GetLastError
?

Does anyone have a idea whats the Problem.

Thx Peter



0
P.Dunker (3)
2/18/2004 3:56:51 PM
vc.mfc 33608 articles. 0 followers. Follow

3 Replies
1605 Views

Similar Articles

[PageSpeed] 3

DoModal nomally returns -1, whenever an error occurs and dialog cannot be
created.
I had a similar problem, when I tried used a dialog inside a DLL.


"Peter Dunker" <P.Dunker@gmx.de> wrote in message
news:c101nb$6bl$1@piggy.rz.tu-ilmenau.de...
> Hi,
>
> I write a SDI Applikation wich use 2 nonmodal Dialogs as Controls created
> with ::Create
> now I will use a modal Dialog in a Function called by a menue message
>
>  CObjectDialog od;
>  int ret = od.DoModal();
>
> ret is always -1
>
> I tryed to create the same Dialog ressource nonmodal with create, but its
> also not possible,
> ::Create returns 0
>
> Is it possible to get a Information why DoModal does not work ?
GetLastError
> ?
>
> Does anyone have a idea whats the Problem.
>
> Thx Peter
>
>
>


0
jagadeeshvn (256)
2/18/2004 6:24:35 PM
     Hi
          
            I have faced simillar problem. Are you using any custom control? DoModal() function returns -1 becoz not able to create all controls displayed on DialogBox.  
           You can try this by removing custom control (if you are using)

     Regards
     Vikas Mishr
     mishravik@yahoo.co.i



     ----- Jagadeesh wrote: ----
    
     DoModal nomally returns -1, whenever an error occurs and dialog cannot b
     created
     I had a similar problem, when I tried used a dialog inside a DLL
    
    
     "Peter Dunker" <P.Dunker@gmx.de> wrote in messag
     news:c101nb$6bl$1@piggy.rz.tu-ilmenau.de..
     > Hi
     >> I write a SDI Applikation wich use 2 nonmodal Dialogs as Controls create
     > with ::Creat
     > now I will use a modal Dialog in a Function called by a menue messag
     >>  CObjectDialog od
     >  int ret = od.DoModal()
     >> ret is always -
     >> I tryed to create the same Dialog ressource nonmodal with create, but it
     > also not possible
     > ::Create returns 
     >> Is it possible to get a Information why DoModal does not work 
     GetLastErro
     > 
     >> Does anyone have a idea whats the Problem
     >> Thx Pete
     >>>
0
2/19/2004 7:01:05 AM
It is possible that  it can't find the dialog template. If it uses any ActiveX control, it
means the control is probably not properly registered. If it uses a rich edit control, you
failed to initialize the rich edit library. Those are my first guesses.  Are you using any
unusual controls in the dialog?   

There are several possible ways to diagnose what is happening, but using GetLastError will
sometimes  help a lot in diagnosing what has gone wrong. In desperation, two other options
are available. THe simplest one is to check the option that tells the dialog to come up
even if there is a problem with a control. Then, by seeing which control is missing, you
know what went wrong. The other is more tedious, but single-stepping throught the MFC
source code watching DoModal do its thing is often useful.
				joe

On Wed, 18 Feb 2004 16:56:51 +0100, "Peter Dunker" <P.Dunker@gmx.de> wrote:

>Hi,
>
>I write a SDI Applikation wich use 2 nonmodal Dialogs as Controls created
>with ::Create
>now I will use a modal Dialog in a Function called by a menue message
>
> CObjectDialog od;
> int ret = od.DoModal();
>
>ret is always -1
>
>I tryed to create the same Dialog ressource nonmodal with create, but its
>also not possible,
>::Create returns 0
>
>Is it possible to get a Information why DoModal does not work ? GetLastError
>?
>
>Does anyone have a idea whats the Problem.
>
>Thx Peter
>
>

Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15975)
2/19/2004 8:39:23 AM
Reply:

Similar Artilces:

Changing layout to a CDialog
Hi to all. I'm trying to develop a CDialog subclass with to possible associated resource IDs, is it possible? I tried this code: CMyDialog dlg; dlg.Create(IDD_LAYOUT1); //create the dialog with first layout //... dlg.SetDlgCtrlID(IDD_LAYOUT2); //I want to change the layout, without to destroy the window and recreate it! dlg.UpdateData(FALSE); but nothing happens. What is wrong? Thanks in advance Bye Andrea Perhaps the CDialogTemplate class might be useful for what you are trying to do? -- Regards, Nish [VC++ MVP] "Acaccia" <andrea.cacciarru@~NOSPAM~email.it> w...

Array bounds read (ABR) and CDialog::Create
Hello, We have a an application that has some strange behaviour (crash) so that we have decided to perform some memory profiling unsing Rational Purify. We have this error: [E] ABR: Array bounds read in CreateDialogIndirectParamA {1 occurrence} Reading 2322 bytes from 0x001a2e18 (2238 bytes at 0x001a2e6c illegal) Address 0x001a2e18 is argument #2 of CreateDialogIndirectParamA Address 0x001a2e18 is at the beginning of a 84 byte block Address 0x001a2e18 points to a Global/LocalAlloc'd block Thread ID: 0x4c Error location CreateD...

RichEdit control (RichEdit20A) problems when creating dialog dynamically via CDialog::Create()
If I statically declare my dialog box and show it via ::DoModal(), the richedit text control works fine and I can set the text in it. Example: MyDialog l_oDialog( this ); l_oDialog.DoModal(); If I create the dialog dynamically it fails in the call to CDialog::Create(); Example: MyDialog* l_pDialog = NULL; l_pDialog = (MyDialog*)new MyDialog( this ); ASSERT( l_pDialog ); l_pDialog->Create( IDD_MYDIALOG_DIALOG, this ); Now, if the dialog does NOT contain the richedit text control, the dialog is created fine and works exactly as expected. Drop a rich edit t...

How to modify CDialog resize frame
I'm skinning my application, a CDialog based app. In order to make the dialog resizeable I set the dialog Border to Resizing with the resource editor. This gives me the desired behavior. But doing so puts the stock 3 pixel frame border around my dialog which is outside the client area. I need to draw that frame myself rather than use the stock frame. But since it's outside the client area I can't draw it myself. How does one accomplish this? Thanks, Mike Correction: It's not that the resize border is outside the client area, it is, but I am able to draw on the resize borde...

Z-Order and modeless CDialogs
Hey there, I'm creating an dialog-based application in MFC that utilized many (or at least some) modeless dialogs. I generally display the dialogs via calls to Create and the ShowWindow(SW_SHOW). This all works fine, except in the following circumstance. If I launch the initial dialog for the application and then subsequently launch 2 more modeless dialogs (for now all the dialogs are based on the same resource, if that matters), everything works fine - I can change focus from one dialog to another. The problem is that he window ordering does not change. If I click on the 2nd dialo...

CDialog background color in CTabCtrl
Hi, I have a dialog box that is child of a CTabCtrl control. When I select a tab, a new dialog box is displayed similar to what property sheets are doing. However when I display the dialog the background color of the dialog is not the one of the tab control (the parent). How can I change the background color of the dialog to be the same as the one of the tab control? I tried OnCtlColor(...) but this allows me to change the background color to a fixed predefined color. In other words I want that my dialog is not visible in the tab control, only the dialog's controls should be visi...

CDialog as panel
Hello, I want to create a "panel". So I insert new dialog, delete the titlebar and add to this dialog new class (that derive from CDialog). Now, on the OnInitDialog of the main dialog I am writing: CNetManDialog *diag= new CNetManDialog(); diag->Create(IDD_NETMAN, this); return TRUE; Here the problems begin. First, the dialog is not "inside" my dialog. This is mean that his positions are absolute and not dependant to my window. So i add the line: diag->SetParent(this); and this problem is solve. But now, I have problems with focus. First, I must return FALSE ...

CStatic in a CDialog
I'm dynamically creating a CStatic for a dialog with this code. I have overridden the WM_ON_PAINT message in the CStatic override to do custom drawing. The problem is I only get 1 paint message; when the dialog is initially displayed. When the dialog is covered by another window and then redisplayed, I don't get the paint message (ie static doesn't redraw). Can someone help? Thanks CStatic * staticptr = new CStatic; if ( !staticptr->Create( _T("Text"), WS_CHILD | WS_VISIBLE | SS_SIMPLE | SS_WHITEFRAME | SS_NOPREFIX, m_ViewArea, this, m_iNextId++ ) ) { ...

Invisible dialogue with DoModal() ?
I have a dialogue based MFC application and (for complicated reasons) I would like to run it (optionally) from a command line with the possibility of having the whole thing run invisibly and close itself. Is there any obvious way that a dialogue box run with DoModal() could be run hidden? [Making it do its job and then post itself a WM_CLOSE according to what command line flags are present is easy enough.] Dave -- David Webber Author MOZART the music processor for Windows - http://www.mozart.co.uk For discussion/support see http://www.mozart.co.uk/mzusers/mailinglist.htm You've ...

Cdialog question #2
Hi to all, I have a mfc dll, and there is a Cdilog function exported working properly. my exported funtion like below; DllExport SMessage(void) { ShowMsg MyMessage; MyMessage.DoModal(); } As you see I don't send a parameter like hWnd, because I call this dll function from a third party application, and I can not control hWnd for send to function parameter. My function working but not as a modal dialog, its working like non-modal dilogbox. My question, is there any more control, or more parameter for modal dialogbox whitout send hWnd parameter.? Thanks Sefer >As you s...

QueryCancelAutoPlay in CDialog
Hello, I am trying to disable Autorun while one of the dialog of my app is shown. I have registered the window message QueryCancelAutoPlay and tried to catch it in several different places (ON_REGISTERED_MESSAGE, DefWindowProc, WindowProc) but I never get such message when I insert a CD. Anyone has ever succeeded in doing this? Regards, Nicolas ...

CDialogs not working ????
HI, I am using the following code as CQChatDlg dlg; m_pMainWnd = &dlg; dlg.initMembers(); int nResponse = dlg.DoModal(); if (nResponse == IDOK) { // TODO: Place code here to handle when the dialog is // dismissed with OK } else if (nResponse == IDCANCEL) { // TODO: Place code here to handle when the dialog is // dismissed with Cancel } AfxMessageBox("Created"); qPub.Create(IDD_DIALOG_PUB); qPub.SetFocus(); qPub.EnableWindow(); AfxMessageBox("Created"); ******** The problem is that qPub dialog is not created and on debug I found ...

Trouble with CDialog DoModal()
I created a new dialog with two buttons and a richedit area. I used the wizard to create a new class and the code. Now, I got: ///////////////////////////////////////////////////////////////////////////// // CStatDialog dialog CStatDialog::CStatDialog(CWnd* pParent /*=NULL*/) : CDialog(CStatDialog::IDD, pParent) { //{{AFX_DATA_INIT(CStatDialog) m_StatisticText = _T(""); //}}AFX_DATA_INIT } void CStatDialog::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CStatDialog) DDX_Text(pDX, IDC_RICHEDIT1, m_StatisticText); //}}AFX_DATA_MAP } ...

CDialog::OnCopyData, what does it do?
I am using VC6. I have a dialog box application. I used Class Wizard and added OnCopyData. The wizard added [code] return CDialog::OnCopyData(pWnd, pCopyDataStruct); [/code] I have read the MSDN, http://msdn2.microsoft.com/en-us/library/5hcat2sc(VS.80).aspx I wanted to know the details of what this function does. Does it send a message back to the sending app saying that it received the message or just tells windows that it can free the memory? What happens if pWnd is NULL? The function does nothing at all. You have to write something IN the function to have it do something! There ...

Embed a CFrameWnd into a CDialog
I would like to embed a CFrameWnd into a CDialog. That is, when the CDialog is moved or minimized, the CFrameWnd will also be moved and minimized. I can use the OnMove and OnMinimize of CDialog, but is there any better way of doing so? Thanks. you can just create a Child Dialog inside another dialog. remember to set style of child dialog to Child(default is popup). And you may also want to set its border to none. "Leesei" <someone@microsoft.com> wrote in message news:uamo$RwjEHA.1800@TK2MSFTNGP15.phx.gbl... > I would like to embed a CFrameWnd into a CDialog. > That i...

Start a CDialog from a CToolbarCtrl
Hi, I am trying to start a CDialog from a CToolbarCtrl when the user clicks a button. It seems that the assertion at AfxGetResourceHandle inside CDialog fails. Why? How can I start a dialog from a CToolbarCtrl? Thanks, JOhn Hi, I believe this would be a problem with the Dialog. Try launching the Dialog in some other place. Break and look at what it is breaking on and the line before. Adding and removing stuff from a dialog causes a lot of problems. You should be assured of 2 things. 1. The Toolbar button works. 2. The Dialog works. If the Toolbar works and the dialog both work, then it i...

Question on CTabCtrl and CDialog
Hi there, I created a tab-control with two tabs on a CDialog. Each of the two tabs is a dialog with an edit box. Now the tab-control works well and I can see the two dialogs when I click the tabs. My trouble is how to get the two dialogs really work for me. I mean how to activate one of the dialogs and make it take my input in the edit box. DoModal() doesn't seem work. I appreciated your help and suggestions. Rich Sounds like your focus needs to be set to the edit control. When the dialog that contains the tabs is displayed, the other dialogs (tab pages) are already created, this...

CDialog background
Is there a way to show a .jpg file (from resource) as CDialog background image? I'm currently using following code in OnPaint() to load an .bmp image resource as my CDialog background image but I would like to know how to achieve the same with .jpg (because of the size and speed advantage over ..bmp)? I've searched everywhere but couldn't find anything. Thanks for replying and suggesting! CPaintDC dc(this); // device context for painting CBitmap bmp, *pOldBitmap; bmp.LoadBitmap(IDB_BACKGROUND); CDC bmpDC; bmpDC.CreateCompatibleDC(&dc); pOldBitmap = bmpDC.SelectObject...

SDI CFormView
I have an SDI with a CFormView. That CFormView has an derived edit control lets call it MyEditCntrl. I have used MyEditCntrl inside a dialog before and in the OnInitDialog I call a MyEditCntrl.SetMaxLength(4) to limit the number of char to 4 in length and this is also where I change the font of certain controls. Where in the FormView should I do this I have tried Create, and OnInitUpdate. Is there an equivalent function for a CFormView that corresponds to CDialog::OnInitDialog? Thanks for the time. barcio, OnCreate (message mapping to WM_CREATE) Johan Rosengren Abstrakt Mekanik AB "b...

DoModal() in Separate Process
Hi, I have written a MFC application that displays a dialog box. From this dialog box I would like to open up another dialog box in modal mode. Usually I would do something like this: CMyDialog dlg; Dlg.DoModal(); This works great. But what I would like to do now is to open up a modal dialog box that runs as a separate process. In order to do this I have created a new application. This application is a dialog based application that displays the dialog box. This second application creates the file ModalDialog.exe. To open this dialog box I do this instead of the previous code: She...

What happened to scroll message handler for CDialog
We have updated to C.Net at work and in adding a slider to a CDialog I went to handle the event from the dialog box as ususal and I couldn't find it. I also noticed that many of the layout tools are no longer working. What's going on. As far as I know everything still works the same. As for the layout problem I can't help you. But the scroll messages of the slider go to your CDialog class. capture the WM_HSCROLL message. Don't forget to compare the hwnd that is passed to you with your slider control to make sure the slider is the one who sent the message to you. Ali R....

How to DoModal a CDialog initially invisible
Hi all, Under specific circunstances, I need to start my dialog-based app invisible. Unfortunately, as expected, when I call DoModal, the window is always visible, whatever I do (uncheck the visible box on dialog properties in the resources, ModifyStyle in OnInitDialog, ...) Is there a clean way to do that ? If not, what could be the cleanest dirty way ? ;) Thanks. -- Dansk Just don't call DoModal(). Place the code that you need to execute into a separate function in the same dialog class and call that function. class MyDialog : public CDialog { public: MyDialog() : CDia...

CDialog #5
Hi, I have a method calling to my dialog. I'm calling to this method to show mt dialog is in the start ( InitInstance()) and in the OnCheckNow() option from the menu. I want to display only one performance of this dialog. I set CListViewDlg dlg as global var, then in the method that create my dialog: dlg.DestroyWindow();//????? int nResponse = dlg.DoModal(); It's correct to DestroyWindow anyway?? it's working to me..but is it a correct way to do this? Thanking you in anticipation!!! "Yael" <Yael@discussions.microsoft.com> wrote in message news:CBC2018F-1C48...

Re: Exporting/Importing CDialog DLL
Also, I tried adding AFX_MANAGE_STATE(AfxGetStaticModuleState( )); before CSampleDialog oTemp; oTemp.DoModal(); and the program throws a "Debug Assertion Failed!" error at: HINSTANCE hInst = AfxGetResourceHandle(); in DLGCORE.CPP. -Lei. --- lei@wam.umd.edu Lei Gong wrote: >Thanks! It's finally compiling now but now when I try to instantiate the >dialog class I wrote in a seperate project by calling: > >CSampleDialog oDialog; >hr = oDialog.DoModal(); > >hr is returned as -1. > >In the test container project, I imported the LIB and SampleDialog.h and...

CDialog cannot be seen
Hi! I have problems opening a modal dialog, when i open it it cannot be seen until i press Alt+Tab, then i can see it in the windows list and the it is shown directly Why this happend? how can i resolve it? This is the code is use to open the dialog: AgregarPosicion ap; char nombre[30]; if(ap.DoModal()==IDOK) { _tcscpy(nombre,ap.nombre); ptz->SetPreset(nombre); presetPosition.AddString(ap.nombre); And this is the code of the dialog: #include "stdafx.h" #include "4player.h" #include "AgregarPosicion.h" // Cuadro de diálogo de Agrega...