15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


DoModal() and Hidden Window

D. A. Dunlap -- devincci@ix.netcom.com
Tuesday, January 28, 1997

 Environment: VC++ 4.0, Win 95

I've generated an AppWizard Dialog based Application.

Is there a way to prevent the application's main dialog 
window from appearing upon a call to DoModal()?

I know, why would I want to do this?
I just would like to know if this is possible?

I would like to have all the results of DoModal() 
except for the dialog appearing, while still loading into memory.

Would I have to call Create() for the dialog?
Or is there a hack to hide the window?

Curently, to accomplish this, I've set a timer in InitInstance() 
and then, in the OnTimer Event, I call ShowWindow(SW_HIDE)
 followed by KillTimer().  This produces a really unprofessional look
because the dialog appears for a split second then disappears....

Maybe .B ekiM can help me.....

Hopelessly unprofessional......
Thanks in Advance    





krishna@hclc.hclc-ggn.hcla.com
Wednesday, January 29, 1997

[Mini-digest: 7 responses]

Hi ,

For The window to be hidden in begining you have to call
the CWnd::ModifyStyle(WS_VISIBLE,WS_MINIMIZE,0);  before the default
CDialog::OnInitDialog();  member function is called .This will modify
the style
of window you are creating and remove WS_VISIBLE style from its present
style and open the main window in Minimized state.

/************************************************************************
****************
     *****Expert is a person called at last moment to share the blame  
******
/************************************************************************
****************
 ----------
>From: D. A. Dunlap
>To: mfc-l@netcom.com
>Subject: DoModal() and Hidden Window
>Date: Tuesday, January 28, 1997 11:07AM
>
> Environment: VC++ 4.0, Win 95
>
>I've generated an AppWizard Dialog based Application.
>
>Is there a way to prevent the application's main dialog
>window from appearing upon a call to DoModal()?
>
>I know, why would I want to do this?
>I just would like to know if this is possible?
>
>I would like to have all the results of DoModal()
>except for the dialog appearing, while still loading into memory.
>
>Would I have to call Create() for the dialog?
>Or is there a hack to hide the window?
>
>Curently, to accomplish this, I've set a timer in InitInstance()
>and then, in the OnTimer Event, I call ShowWindow(SW_HIDE)
> followed by KillTimer().  This produces a really unprofessional look
>because the dialog appears for a split second then disappears....
>
>Maybe .B ekiM can help me.....
>
>Hopelessly unprofessional......
>Thanks in Advance
>
>
>
-----From: Syed 

At 12:37 AM 1/28/97 -0500, you wrote:
> Environment: VC++ 4.0, Win 95
>
>I've generated an AppWizard Dialog based Application.
>
>Is there a way to prevent the application's main dialog 
>window from appearing upon a call to DoModal()?
>
I have not tried this, so there is no guarantee it will work but you can set
the visibility of the dialog to none (uncheck the WS_VISIBLE attribute) and
finf out if it works.


-----From: Roma 

D. A. Dunlap wrote:
> 
>  Environment: VC++ 4.0, Win 95
> 
> I've generated an AppWizard Dialog based Application.
> 
> Is there a way to prevent the application's main dialog
> window from appearing upon a call to DoModal()?
> 
[snip]

Hello!

I can think of two possible solutions (both not tested):
 1. Do not give WS_VISIBLE style to your dialog template.

 2. In the dialog template give to the dialog a coordinates which are
    outside the screen area, like (2000, 2000).
    This way you'll avoid appearing of your dialog for a split second.
    Than hide it and make MoveWindow() to the screen area.

HTH.
-Roma
-----From: David Little 

Why didn't you call ShowWindow(SW_HIDE) in OnInitDialog()?  =
WM_INITDIALOG is the last message posted before WM_PAINT, so that is =
your last chance to hide it without it flashing. =20

Oh, and ShowWindow(..) is hardly a hack........

----------
From: 	D. A. Dunlap[SMTP:devincci@ix.netcom.com]
Sent: 	Monday, January 27, 1997 11:37 PM
To: 	mfc-l@netcom.com
Subject: 	DoModal() and Hidden Window

 Environment: VC++ 4.0, Win 95

I've generated an AppWizard Dialog based Application.

Is there a way to prevent the application's main dialog=20
window from appearing upon a call to DoModal()?

I know, why would I want to do this?
I just would like to know if this is possible?

I would like to have all the results of DoModal()=20
except for the dialog appearing, while still loading into memory.

Would I have to call Create() for the dialog?
Or is there a hack to hide the window?

Curently, to accomplish this, I've set a timer in InitInstance()=20
and then, in the OnTimer Event, I call ShowWindow(SW_HIDE)
 followed by KillTimer().  This produces a really unprofessional look
because the dialog appears for a split second then disappears....

Maybe .B ekiM can help me.....

Hopelessly unprofessional......
Thanks in Advance   =20



-----From: "Doug Brubacher" 

     I agree this is an unusually thing to request, but I did a little 
     experimentation and found something that works.
     
     In your dialog override the WM_NCPAINT message.  This message does not 
     appear in Class Wizard but is fully documented.
     
     Declaration:
        afx_msg void OnNcPaint();
     
     Message Map entry
        ON_WM_NCPAINT() 
     
     Definition:
        void CMfcldlgDlg::OnNcPaint()
        {
           ShowWindow( SW_HIDE );
        }
     
     Regards,
     
     Doug Brubacher
     Doug_Brubacher@compuware.com

-----From: ybriklin@juno.com (Yuriy Briklin)

Hi.

Unfortunately I don't know any good solution to your problem. Maybe it
doesn't exist because
DoModal calls DialogBoxIndirect which always displays the dialog.
 In the Help I found:
	"Although an application can designate the WS_VISIBLE style,
Windows always displays a modal dialog box 		regardless of
whether the dialog box template specifies the WS_VISIBLE style."

My advice is to change the size of the dialog to zero before it is
visible.
I did it like this:
	BOOL CMyDlg::OnInitDialog()
	{
		CDialog::OnInitDialog();
		
		//Store Dialog size
		GetWindowRect(m_rectOriginalDlgSize);

		
		MoveWindow(0,0,0,0,FALSE);
		...
		...
	}

In this case the dialog will not appear on the screen until you restore
the original size of the dialog:	
	MoveWindow(m_rectOriginalDlgSize,TRUE);

I hope this will help you.

Yuriy Briklin
e-mail: ybriklin@juno.com


On Tue, 28 Jan 1997 00:37:42 -0500 "D. A. Dunlap"
 writes:
>  Environment: VC++ 4.0, Win 95
> 
> I've generated an AppWizard Dialog based Application.
> 
> Is there a way to prevent the application's main dialog 
> window from appearing upon a call to DoModal()?
> 
> I know, why would I want to do this?
> I just would like to know if this is possible?
> 
> I would like to have all the results of DoModal() 
> except for the dialog appearing, while still loading into memory.
> 
> Would I have to call Create() for the dialog?
> Or is there a hack to hide the window?
> 
> Curently, to accomplish this, I've set a timer in InitInstance() 
> and then, in the OnTimer Event, I call ShowWindow(SW_HIDE)
>  followed by KillTimer().  This produces a really unprofessional look
> because the dialog appears for a split second then disappears....
> 
> Maybe .B ekiM can help me.....
> 
> Hopelessly unprofessional......
> Thanks in Advance    
> 
> 
> 
-----From: hou@tfn.com (Bing Hou)


At near end of your OnInitDialog function, insert
       
        SetWindowPos(NULL, 0, 0, 0, 0, SWP_...);

to set the dialog's size to zero, so it won't show. However it still has 
the focus even though user doesn't see anything. You can set focus back to 
a window of your choice in the app's OnActivateApp function.


Bing Hou
hou@tfn.com
------------------------------------------------------------------------
  The shortest distance between two points is always under construction.
                                                         - Noelie Alito




______________________________ Reply Separator _________________________________
Subject: DoModal() and Hidden Window
Author:  "D. A. Dunlap"  at Internet
Date:    1/28/97 12:37 AM


 Environment: VC++ 4.0, Win 95
     
I've generated an AppWizard Dialog based Application.
     
Is there a way to prevent the application's main dialog 
window from appearing upon a call to DoModal()?
     
I know, why would I want to do this?
I just would like to know if this is possible?
     
I would like to have all the results of DoModal() 
except for the dialog appearing, while still loading into memory.
     
Would I have to call Create() for the dialog? 
Or is there a hack to hide the window?
     
Curently, to accomplish this, I've set a timer in InitInstance() 
and then, in the OnTimer Event, I call ShowWindow(SW_HIDE)
 followed by KillTimer().  This produces a really unprofessional look
because the dialog appears for a split second then disappears....
     
Maybe .B ekiM can help me.....
     
Hopelessly unprofessional......
Thanks in Advance    
     
     



mark -- mark@radmail.rad.co.il
Thursday, January 30, 1997

Set invisible style of dialog resource or override OnInitDialog() and do 
ShowWindow(SW_HIDE)there. 


D. A. Dunlap wrote:
> 
>  Environment: VC++ 4.0, Win 95
> 
> I've generated an AppWizard Dialog based Application.
> 
> Is there a way to prevent the application's main dialog
> window from appearing upon a call to DoModal()?
> 
> I know, why would I want to do this?
> I just would like to know if this is possible?
> 
> I would like to have all the results of DoModal()
> except for the dialog appearing, while still loading into memory.
> 
> Would I have to call Create() for the dialog?
> Or is there a hack to hide the window?
> 
> Curently, to accomplish this, I've set a timer in InitInstance()
> and then, in the OnTimer Event, I call ShowWindow(SW_HIDE)
>  followed by KillTimer().  This produces a really unprofessional look
> because the dialog appears for a split second then disappears....
> 
> Maybe .B ekiM can help me.....
> 
> Hopelessly unprofessional......
> Thanks in Advance



David Shoots -- dshoots@lmcorp.com
Monday, February 03, 1997

 writes:
Is there a way to prevent the application's main dialog 
window from appearing upon a call to DoModal()?

I know, why would I want to do this?
I just would like to know if this is possible?

Here's my little trick to do this.  Add the m_bKeepHidden to the dialog and
set it to FALSE in the constructor.  When you want it to be visible, set it
to TRUE and call ShowWindow (SW_SHOW).

void CMainDlg::OnWindowPosChanging(WINDOWPOS FAR* lpwndpos) 
{
	if ( m_bKeepHidden )
	{
#ifndef NDEBUG
		if ( lpwndpos->flags & SWP_SHOWWINDOW )
			TRACE0 ( "Preventing Dialog from being shown\n" ) ;
#endif

		lpwndpos->flags &= ~SWP_SHOWWINDOW ;
	}

	CDialog::OnWindowPosChanging(lpwndpos);
}





| Вернуться в корень Архива |