Problem with Dialog Box

This is a discussion on Problem with Dialog Box within the Windows Programming forums, part of the Platform Specific Boards category; I'm making a DialogBox using DialogBoxIndirect() and when I close the dialog window the entire application closes. Is there a ...

  1. #1
    Registered User KonArtis's Avatar
    Join Date
    Mar 2003
    Posts
    34

    Question Problem with Dialog Box

    I'm making a DialogBox using DialogBoxIndirect() and when I close the dialog window the entire application closes.

    Is there a reason why EndDialog() would close the entire application? If there is what would cause it? If not what could be the problem?

    Thanks,
    Joe

  2. #2
    Registered User
    Join Date
    May 2002
    Posts
    132
    I haven't tried it before, but it might be possible that EndDialog() is being passed the HWND to your main window? I could be wrong but it might be able to destroy normal window. Correct me please if I am.

    Thats the only guess I could come up with based on info provided.

    Why not post some code so we can take a look and try to actually see whats going on?

    Tyouk

  3. #3
    Registered User KonArtis's Avatar
    Join Date
    Mar 2003
    Posts
    34
    I have checked if EndDialog() is getting the handle of the main window and it is not. I even tried forcing the handle of the main window in EndDialog() and it didn't do anything

    For the complete source go to http://members.rogers.com/deacon12/windex.zip

    I didn't include this code because I thought it might complicate things. Any variables that are not defined are defined in the cWINDOWS class.

    Code:
    class cDIALOG: public cWINDOW
    {
    private:
    	static cDIALOG	*Me;
    	static cSTRING	*sCaption;	
    
    	static BOOL CALLBACK DlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
    public:
    	~cDIALOG()
    	{ Close(); }
    
    	int Create(HWND hParent, cSTRING sCaption,
    				int cx, int cy, int x=0, int y=0, 
    				DWORD dwStyle=0, DWORD dwExStyle=0);
    
    	void Close(int nResult=0)
    	{ ChildWindow.ForEach(del_all); ChildWindow.Clear(); EndDialog(hwnd, nResult); }
    //ChildWindow is a linked list structure. This structure has been tested and it work correctly
    
    	void OnCreate(void (*Function)())
    	{ WindowEvents[0].unEvent=WM_INITDIALOG; WindowEvents[0].Function=Function; }
    };

    Code:
    int cDIALOG::Create(HWND hParent, cSTRING sCaption,
    					int cx, int cy, int x, int y,
    					DWORD dwStyle, DWORD dwExStyle)
    {
    	HGLOBAL			hGlobal;
    	LPDLGTEMPLATE	Dlg;
    	cDIALOG			*PrevDlg=Me;
    	cWINDOW			*PrevObj=Objects;
    
    	if ( !(hGlobal=GlobalAlloc(GMEM_ZEROINIT, 1024)) )
    		return -1;
    
    	Dlg=LPDLGTEMPLATE(GlobalLock(hGlobal));
    
    	Dlg->cdit=0;
    	Dlg->cx=cx;
    	Dlg->cy=cy;
    	Dlg->dwExtendedStyle=dwExStyle;
    	Dlg->style=dwStyle;
    	Dlg->x=x;
    	Dlg->y=y;
    
    	GlobalUnlock(hGlobal);
    	Me=this; //Incase there are more than one dialog box created
    	Objects=this; //The objects on the window that can be create are subclassed and the sub-class function needs to be static
    	this->sCaption=&sCaption;
    	int nReturn=DialogBoxIndirect(AppInstance, Dlg, hParent, DlgProc);
    	Me=PrevDlg; //restore old window's handle
    	Objects=PrevObj; //restore old object's address
    	GlobalFree(hGlobal);
    
    	return  nReturn;
    }
    Code:
    BOOL CALLBACK cDIALOG::DlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
    	if ( message==WM_INITDIALOG )
    		Me->SetText(*sCaption);
    	
    	cCHILDWINDOW **TempChild;
    	cLINKEDLIST<cCHILDWINDOW*> *ChildWindow=&Me->ChildWindow;
    
    	ChildWindow->StepReset();
    	while ( (TempChild=ChildWindow->GetNode()) )
    	{
    		if ( (*TempChild)->ProcessParent(hwnd, message, wParam, lParam) )
    			return 0;
    		
    		ChildWindow->StepNext();
    	}
    
    	if ( Me->ProcessEvents(hwnd, message, wParam, lParam) )
    		return 1;
    	
    	else if ( message==WM_CLOSE )
    		Me->Close();
    
    	return 0;
    }
    Any help would be greatly appreciated
    -Joe

  4. #4
    Registered User
    Join Date
    May 2002
    Posts
    132
    Sorry, I can't. I've never bothered to learn C++ yet. Waiting till I master C before I move on.

    Tyouk

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Dialog Box error
    By JJFMJR in forum Windows Programming
    Replies: 4
    Last Post: 09-04-2007, 07:51 AM
  2. Parent of a BrowseForFolder dialog box
    By @nthony in forum Windows Programming
    Replies: 4
    Last Post: 01-08-2007, 01:54 PM
  3. Dialog Box Problems
    By Morgul in forum Windows Programming
    Replies: 21
    Last Post: 05-31-2005, 05:48 PM
  4. How to program a "back" button with MFC
    By 99atlantic in forum Windows Programming
    Replies: 3
    Last Post: 04-26-2005, 08:34 PM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21