Click here to Skip to main content
12,401,832 members (62,024 online)
Click here to Skip to main content

Stats

187.1K views
3.2K downloads
49 bookmarked
Posted

A thread-safe timed message box

, 12 Feb 2001
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

Share

About the Author

Markus Loibl
Germany Germany
No Biography provided

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160721.1 | Last Updated 13 Feb 2001
Article Copyright 2000 by Markus Loibl
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid