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

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


Splash screens

Richard Steadman -- rsteadma@mmltd.com
Tuesday, July 16, 1996

	Environment: VC++ 1.5 / Win 95

Hi.

Is there an easy way to implement a splash screen with MFC? I tried to
copy from the Superpad example with VC 1.5, but I ended up creating a
child window of an invisible window (I think). When minimized, the
window went to the bottom left corner of the screen, not the bar at the
bottom of the screen in Win95.

Thanks,
Richard Steadman
rsteadma@micromedia.on.ca

Here's the InitInstance function as I tried it:

BOOL CSplashApp::InitInstance()
{
	SetDialogBkColor();
	CSingleDocTemplate* pDocTemplate;
	pDocTemplate = new CSingleDocTemplate(
		IDR_MAINFRAME,
		RUNTIME_CLASS(CSplashDoc),
		RUNTIME_CLASS(CMainFrame),     // main SDI frame window
		RUNTIME_CLASS(CSplashView));
	AddDocTemplate(pDocTemplate);
    
        // create main window
	CMainFrame* pMainFrame = new CMainFrame;
	if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
		return FALSE;
	m_pMainWnd = pMainFrame;
	int nCmdShow = m_nCmdShow;

	// setup main window
	nCmdShow = SW_HIDE;
	m_nCmdShow = SW_HIDE;
	// ((CMainFrame*)m_pMainWnd)->InitialShowWindow(nCmdShow);
        ((CMainFrame*)m_pMainWnd)->ShowWindow(nCmdShow);

	m_pMainWnd->UpdateWindow();

	if (!m_pMainWnd->IsIconic() && !m_lpCmdLine[0] && m_splash.Create(m_pMainWnd)) {
		m_splash.ShowWindow(SW_SHOW);
		m_splash.UpdateWindow();
	}
	sleep(1);   // Wait one second
	m_splash.DestroyWindow();
        OnFileNew();
	return TRUE;
}




Chandra Venkatraman -- chandru@fcpl.co.in
Sunday, July 21, 1996

[Mini-digest: 2 responses]
[Moderator's note: Since he specified VC++ 1.5, I tossed the VC++ 4.x
specific solutions.]

----------
> From: Richard Steadman 
> To: mfc-l@netcom.com
> Subject: Splash screens
> Date: Tuesday, July 16, 1996 11:05 PM
> 
> 	Environment: VC++ 1.5 / Win 95
> 
> Hi.
> 
> Is there an easy way to implement a splash screen with MFC? I tried to
> copy from the Superpad example with VC 1.5, but I ended up creating a
> child window of an invisible window (I think). When minimized, the
> window went to the bottom left corner of the screen, not the bar at the
> bottom of the screen in Win95.
> 
> Thanks,
> Richard Steadman
> rsteadma@micromedia.on.ca
> 
> Here's the InitInstance function as I tried it:
> 
> BOOL CSplashApp::InitInstance()
> {
> 	SetDialogBkColor();
> 	CSingleDocTemplate* pDocTemplate;
> 	pDocTemplate = new CSingleDocTemplate(
> 		IDR_MAINFRAME,
> 		RUNTIME_CLASS(CSplashDoc),
> 		RUNTIME_CLASS(CMainFrame),     // main SDI frame window
> 		RUNTIME_CLASS(CSplashView));
> 	AddDocTemplate(pDocTemplate);
>     
>         // create main window
> 	CMainFrame* pMainFrame = new CMainFrame;
> 	if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
> 		return FALSE;
> 	m_pMainWnd = pMainFrame;
> 	int nCmdShow = m_nCmdShow;
> 
> 	// setup main window
> 	nCmdShow = SW_HIDE;
> 	m_nCmdShow = SW_HIDE;
> 	// ((CMainFrame*)m_pMainWnd)->InitialShowWindow(nCmdShow);
>         ((CMainFrame*)m_pMainWnd)->ShowWindow(nCmdShow);
> 
> 	m_pMainWnd->UpdateWindow();
> 
> 	if (!m_pMainWnd->IsIconic() && !m_lpCmdLine[0] &&
m_splash.Create(m_pMainWnd)) {
> 		m_splash.ShowWindow(SW_SHOW);
> 		m_splash.UpdateWindow();
> 	}
> 	sleep(1);   // Wait one second
> 	m_splash.DestroyWindow();
>         OnFileNew();
> 	return TRUE;
> }

You Donot Use sleep(1) or any such code to Stop Windows from Loading the
Parent.
You must override the "OnIdle" Function of the App.

In your OnIdle Loop Setup a Timer for the time interval for which you would
like the Splash 
Window to appear. If the time limit is reached, Destroy the Splash Window
and Enable the
MainFrame

Hope this Helps

Happ MFC Prog
Chandru

                                   			Chandrasekar Venkataraman 
----------------------------------------------------------------------------
----------------------
Residence :				Office :
Room no. 19,				Frontier Computers (P) Ltd.
J.P.Trivedi Guest House,			Vastu Chambers, IInd Floor,
Ghole Road,				1202/39, Shirole Road,
Shivaji Nagar,				Shivaji Nagar,
Pune - 411005				Pune - 411004

Tel : (0212) - 323474			Tel : (0212) - 321536
----------------------------------------------------------------------------
----------------------
    "Results! Why, man, I have gotten a lot of results. 
     I know several thousand things that won't work."
						Thomas A. Edison
----------------------------------------------------------------------------
----------------------



-----From: sja@gte.net

	What I've done before is to make the CAboutdlg become the splash screen. 
Add some code to the InitDialog function to start a timer which closes the 
dialog when it expires, add some code to the constructor which sets a flag 
indicating whether or not to splash:

---
in MyApp.h (manually moved here from MyApp.cpp AppWizard):
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
	CAboutDlg(BOOL splashflg);

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

// Implementation
	BOOL	m_bSplash;	// True if splashing, False if direct
	UINT	m_nTimer;	// splash autoclose dialog timer
	
	virtual BOOL OnInitDialog();

protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//{{AFX_MSG(CAboutDlg)
	afx_msg void OnTimer(UINT nIDEvent);
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

---
in MyApp.cpp, InitInstance():
	// splash the about dialog
	CAboutDlg aboutDlg(TRUE);
	aboutDlg.DoModal();          

---
in MyApp.cpp, App Commands:
// App command to run the dialog
void CMyApp::OnAppAbout()
{
	// normal about dialog
	CAboutDlg aboutDlg(FALSE);
	aboutDlg.DoModal();
}

---
in MyApp.cpp, CAboutdlg:
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
CAboutDlg::CAboutDlg(BOOL splashflg) : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT

	m_bSplash = splashflg;
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
	ON_WM_TIMER()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

BOOL CAboutDlg::OnInitDialog()
{
	CDialog::OnInitDialog();
	CenterWindow();

	if (m_bSplash)
	{
		// hide the OK button
		GetDlgItem(IDOK)->ShowWindow(SW_HIDE);

		// start a timer that will eventually kill this dialog
		m_nTimer = CWnd::SetTimer(1, 2000, (TIMERPROC)NULL);
	}
	return TRUE;  // return TRUE  unless you set the focus to a control
}

/////////////////////////////////////////////////////////////////////////////
// CMyApp commands
void CAboutDlg::OnTimer(UINT nIDEvent)
{
	if (m_nTimer)
		CWnd::KillTimer(1);
	CDialog::OnOK();
}

---
Steven J. Ackerman, Consultant
ACS, Sarasota, FL
sja@gte.net
http://www.acscontrol.com




Mike Morel -- mmorel@mushroomsoft.com
Wednesday, July 31, 1996

There is a CSplasher class in the MFC For Yourself preview issue from April,
1995.  You can download it by going to http://www.mushroomsoft.com/mushroom
and navigating down to the MFC For Yourself previews.

The parent window creates the CSplasher on the heap, passing to the
destructor how long the splash window should exist.  After that, CSplasher
takes care of everything.  It sets a timer and / or reacts to a user click,
destroys the window when appropriate, and evens deletes itself (the C++
object).  It's very easy to use, and you can examine the code to see how it
works.

Mike Morel
Mushroom Software
  
At 01:35 PM 7/16/96 -0400, you wrote:
>	Environment: VC++ 1.5 / Win 95
>
>Hi.
>
>Is there an easy way to implement a splash screen with MFC? I tried to
>copy from the Superpad example with VC 1.5, but I ended up creating a
>child window of an invisible window (I think). When minimized, the
>window went to the bottom left corner of the screen, not the bar at the
>bottom of the screen in Win95.
>
>Thanks,
>Richard Steadman
>rsteadma@micromedia.on.ca
>
>Here's the InitInstance function as I tried it:
>
>BOOL CSplashApp::InitInstance()
>{
>	SetDialogBkColor();
>	CSingleDocTemplate* pDocTemplate;
>	pDocTemplate = new CSingleDocTemplate(
>		IDR_MAINFRAME,
>		RUNTIME_CLASS(CSplashDoc),
>		RUNTIME_CLASS(CMainFrame),     // main SDI frame window
>		RUNTIME_CLASS(CSplashView));
>	AddDocTemplate(pDocTemplate);
>    
>        // create main window
>	CMainFrame* pMainFrame = new CMainFrame;
>	if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
>		return FALSE;
>	m_pMainWnd = pMainFrame;
>	int nCmdShow = m_nCmdShow;
>
>	// setup main window
>	nCmdShow = SW_HIDE;
>	m_nCmdShow = SW_HIDE;
>	// ((CMainFrame*)m_pMainWnd)->InitialShowWindow(nCmdShow);
>        ((CMainFrame*)m_pMainWnd)->ShowWindow(nCmdShow);
>
>	m_pMainWnd->UpdateWindow();
>
>	if (!m_pMainWnd->IsIconic() && !m_lpCmdLine[0] &&
m_splash.Create(m_pMainWnd)) {
>		m_splash.ShowWindow(SW_SHOW);
>		m_splash.UpdateWindow();
>	}
>	sleep(1);   // Wait one second
>	m_splash.DestroyWindow();
>        OnFileNew();
>	return TRUE;
>}
>
>
>
>
Mike Morel
Mushroom Software
mmorel@mushroomsoft.com
216-659-4743





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