Click here to Skip to main content
15,885,985 members
Articles / Desktop Programming / MFC

A thread-safe timed message box

Rate me:
Please Sign up or sign in to vote.
3.43/5 (4 votes)
12 Feb 2001 218.7K   3.5K   50  
The system Message Box that is closed atuomatically after some time
#ifndef __TIMES_MESSAGE_BOX_H__
#define __TIMES_MESSAGE_BOX_H__

//
// copyrights and infos 
// see timedmsgbox.cpp
//

/////////////////////////////////////////////////////////////////////////
//
// CDlgTimedMessageBox
//
/////////////////////////////////////////////////////////////////////////

// some ideas taken from TimedMessageBox, see Q181934

// 
// calling:
// -     CDlgTimedMessageBox::TimedMessageBox()
// -  or create a class-instance and call .ShowMessageBox

class CDlgTimedMessageBox
{
public:
	CDlgTimedMessageBox(UINT flags, LPCTSTR ptszMessage, LPCTSTR ptszTitle, 
							DWORD dwTimeout, UINT dDefaultReturn,
							LPCTSTR ptszMessageTimer=NULL, HWND hwndParent=NULL);
	virtual ~CDlgTimedMessageBox();
	
	UINT		ShowMessageBox(BOOL *pbStoppedByUser=NULL);
	void		GetWindowHandles(void);
	void		LocalTimerProc(void);

	// to call the messagebox within one line !
	static UINT	TimedMessageBox(UINT flags, LPCTSTR ptszMessage, LPCTSTR ptszTitle, 
							DWORD dwTimeout, UINT dDefaultReturn,
							LPCTSTR ptszMessageTimer=NULL, HWND hwndParent=NULL, BOOL *pbStoppedByUser=NULL);

protected:
	// the map is needed in the GlobalTimerProc 
	// to find the corresponding class for a timer-id
	static		CMapPtrToPtr		m_mapTimerIdToClassMe;
	// used to get thread-save
	static		CCriticalSection	m_sectMap;
	static void CALLBACK GlobalTimerProc(HWND hwnd, UINT uiMsg, UINT_PTR idEvent, DWORD dwTime);

	HWND		m_hParent,
				m_hMsgBox,
				m_hStaticText,
				m_hDefaultButton;
	CString		m_Message,
				m_MessageTimer,
				m_Title,
				m_CurrentMessage;
	UINT		m_flags;
	DWORD		m_dwTimeout,
				m_dwStarted;
	UINT		m_idTimer;
	BOOL		m_bRunning;
	BOOL		m_bStoppedByTimer;
	UINT		m_DefaultReturn;
};


#endif

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Germany Germany
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions