CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 19
  1. #1
    Join Date
    Apr 2008
    Posts
    62

    [RESOLVED] calling dialogs

    hi
    what is the possible ways to call a dialog from another dialog except the
    DoModal() function...

  2. #2
    Join Date
    Sep 2004
    Location
    Holland (land of the dope)
    Posts
    4,123

    Re: calling dialogs

    You can use CWnd::ShowWindow (). You need to create the dialog yourself before showing.

  3. #3
    Join Date
    Apr 2008
    Posts
    62

    Re: calling dialogs

    thank u for ur fast reply
    this works if the dialog is based on CDialog
    but if the dialog is based on CBitmapDialog...it wont work(show)PROPERly...
    what do u think i should do about it
    ????
    it is reealy frustrating
    so pleease can u help me with this?

  4. #4
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: calling dialogs

    What's wrong with DoModal()

    There really are only two ways that I know of. DoModal and Create and ShowWindow(). What problem are you trying to overcome?

  5. #5
    Join Date
    Apr 2008
    Posts
    62

    Re: calling dialogs

    here is the situation:
    i have a dialog based application where the main dialog is not based on CDialog class ....it is based on a class called CBitmapDialog.
    it works fine ....
    now i inserted a new dialog (also based on CBitmapDialog)..
    when i try to call the second dialog from the first (using a button)
    the second dialog doesnt appear properly (alittile of the bitmap +alittle graybackgound)... it appears in a really BAD way and shape...
    i tried to use the OnModal()....and showwindow()....but they led me to the same result....disfigured dialog
    i hope u understand my problem
    now
    what can i do about that??

  6. #6
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: calling dialogs

    A dialog displayed with DoModal( ) shouldn't care what kind of parent dialog or window has displayed it.

    So to determine if the problem is in the child dialog, try to start up the dialog from somewhare else. As good as place as any is CWinApp::InitInstance method. The code below is testing the dialog from a dialog app, but the app type doesn't matter. You can do the same from an SDI or MDI app.

    Code:
    BOOL CTestMFCApp::InitInstance()
    {
      CWinApp::InitInstance();
    
      SetRegistryKey(_T("Local AppWizard-Generated Applications"));
    
      //
      // Test your dialog here
      //
      CMyDialog dlg;
      dlg.DoModal( );
      // End of test
    
    
      // Original code
      CTestMFCDlg dlg;
      m_pMainWnd = &dlg;
    
      return FALSE;
    }
    If the dialog doesn't appear correctly, you know something is wrong with the dialog; if it does appear correctly, something is happening elsewhere.

  7. #7
    Join Date
    Apr 2008
    Posts
    62

    Re: calling dialogs

    ok
    i tried ur way and the dialog appeared the same Bad shape ...although i did the same thing to the first but it works ...
    what could be the difference between the two dialogs?
    i initialize them in the same way..!!!
    what do u think its wrong??
    thank u

  8. #8
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: calling dialogs

    Hard to say without seeing any code.

    How did you create the dialog class? Did you use the class wizard (or Add class option) or did you hand write the code?

  9. #9
    Join Date
    Apr 2008
    Posts
    62

    Re: calling dialogs

    actually its from an article here:
    http://www.codeguru.com/cpp/w-d/disl...cle.php/c4977/
    u will find the CBitmapdialog class my dialog is based on.
    and how it can be used.

  10. #10
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: calling dialogs

    Quote Originally Posted by lahom
    actually its from an article here:
    http://www.codeguru.com/cpp/w-d/disl...cle.php/c4977/
    u will find the CBitmapdialog class my dialog is based on.
    and how it can be used.
    Okay, how can I help you?

  11. #11
    Join Date
    Apr 2008
    Posts
    62

    Re: calling dialogs

    ok..thanks
    first i had aproblem when inserting a new dialog and then create a new class for it ..espically in choosing the base class( i couldnot find the CBitmapDialog)...where in the first time i did create adialog based on it...
    i dont know what goes wrong ... my head will explode soon
    please could u show me the right way to do it ...and what might cause this..
    and howcome the first one i created (a couple of days ago) could choose the base class but not now
    what am i missing??

  12. #12
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: calling dialogs

    Zip up the project and we'll take a look at it. Make sure it compiles, so include any dependencies in the zipped file.

  13. #13
    Join Date
    Apr 2008
    Posts
    62

    Re: calling dialogs

    ok ...
    sorry for the delay
    Attached Files Attached Files

  14. #14
    Join Date
    May 2006
    Location
    Dresden, Germany
    Posts
    458

    Smile Re: calling dialogs

    Hi,

    I downloaded the archive, unzipped it, compiled and:
    I had have the same "error": The SecondDlg did appear with the bitmap
    at a wrong place.

    Then I tried to find out the difference(s) between the working first dlg
    and the "wrong" second.

    It seems to me that you did not make any error.

    [b]But[(b]:

    There seems to be an error in the MakeWindowRgn() function of the CBitmapDialog class. The implementation works only if the dialog is the main
    app window and not a child dialog of another window.

    I changed the implementation as follows (and it worked fine afterwards):
    Code:
    void CBitmapDialog :: MakeWindowRgn ()
    {
    	if (!m_bTransparent)
    	{
    		// Set the window region to the full window
    		CRect rc;
    		GetWindowRect (rc);
    		CRgn rgn;
    		rgn.CreateRectRgn (0, 0, rc.Width(), rc.Height());
    		SetWindowRgn (rgn, TRUE);
    	}
    	else
    	{
    		// Set the region to the window rect minus the client rect
    		/*
    		CRect rcWnd;
    		GetWindowRect (rcWnd);
    
    		CRgn rgn;
    		rgn.CreateRectRgn (rcWnd.left, rcWnd.top, rcWnd.right, rcWnd.bottom);
    
    		CRect rcClient;
    		GetClientRect (rcClient);
    		ClientToScreen (rcClient);
    
    		CRgn rgnClient;
    		rgnClient.CreateRectRgn (rcClient.left, rcClient.top, rcClient.right,
    			rcClient.bottom);
    
    		// Subtract rgnClient from rgn
    		rgn.CombineRgn (&rgn, &rgnClient, RGN_XOR);
    		*/
    		CRect rcWnd;
    		GetClientRect (rcWnd);
    		CRect rcClient(rcWnd);
    		CRgn rgn,rgnClient;
    		rgn.CreateRectRgn (rcWnd.left, rcWnd.top, rcWnd.right, rcWnd.bottom);
    		rgnClient.CreateRectRgn (rcWnd.left, rcWnd.top, rcWnd.right, rcWnd.bottom);
    		rgn.CombineRgn (&rgn, &rgnClient, RGN_XOR);
    
    		// Get a DC for the bitmap
    		CDC dcImage;
    		dcImage.CreateCompatibleDC (NULL);
    		CBitmap *pOldBitmap = dcImage.SelectObject (m_bmBitmap);
    
    		// Get the bitmap for width and height information
    		BITMAP bm;
    		m_bmBitmap->GetBitmap (&bm);
    
    		// Get window width and height
    		CRect rc;
    		GetClientRect (rc);
    
    		// Use the minimum width and height
    		int width = min (bm.bmWidth, rc.Width());
    		int height = min (bm.bmHeight, rc.Height());
    
    		// Use RLE (run-length) style because it goes faster.
    		// Row start is where the first opaque pixel is found.  Once
    		// a transparent pixel is found, a line region is created.
    		// Then row_start becomes the next opaque pixel.
    		int row_start;
    
    		// Go through all rows
    		for (int y=0; y<height; y++)
    		{
    			// Start looking at the beginning
    			row_start = 0;
    
    			// Go through all columns
    			for (int x=0; x<width; x++)
    			{
    				// If this pixel is transparent
    				if (dcImage.GetPixel(x, y) == m_colTrans)
    				{
    					// If we haven't found an opaque pixel yet, keep searching
    					if (row_start == x) row_start ++;
    					else
    					{
    						// We have found the start (row_start) and end (x) of
    						// an opaque line.  Add it to the region.
    						CRgn rgnAdd;
    						rgnAdd.CreateRectRgn (rcClient.left+row_start,
    							rcClient.top+y, rcClient.left+x, rcClient.top+y+1);
    						rgn.CombineRgn (&rgn, &rgnAdd, RGN_OR);
    						row_start = x+1;
    					}
    				}
    			}
    
    			// If the last pixel is still opaque, make a region.
    			if (row_start != x)
    			{
    				CRgn rgnAdd;
    				rgnAdd.CreateRectRgn (rcClient.left+row_start, rcClient.top+y,
    					rcClient.left+x, rcClient.top+y+1);
    				rgn.CombineRgn (&rgn, &rgnAdd, RGN_OR);
    			}
    		}
    		
    		SetWindowRgn (rgn, TRUE);
    	}
    }
    Hope this was helpful.

    With regards
    Programartist
    Ingo Bochmann

  15. #15
    Join Date
    Apr 2008
    Posts
    62

    Re: calling dialogs

    hi
    thank u ProgramArtist ..... u were very helpful...the problem solved..
    but i still have what i believe is my last problem:
    now if insert a new dialog...and create a class for it ....when i come to the point where i choose the base class...i could not find CBitmapDialog among them....why?
    I am certain that when i inserted the second dialog (a week ago)i chose CBitmapDialog...
    howcome its different this time ....ohh what am i missing?
    pleease help me with this ...its driving me crazy.
    thank u for all ur help

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured