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

Balloon Help as a non-modal replacement for MessageBox()

Rate me:
Please Sign up or sign in to vote.
4.98/5 (62 votes)
7 Aug 2002CPOL13 min read 1M   12.3K   228  
Although sometimes useful, message boxes used to display information are often just annoying. This article describes a non-modal replacement.
#ifndef __MAINDLG__H__
#define __MAINDLG__H__

#pragma once

#include "resource.h"


//
//			class CBalloonOptionCtrl
//
class CBalloonOptionCtrl
{
public:
	//
	void Init(HWND hWndCtrl, CBalloonHelp::BallonOptions Option)
	{
		ATLASSERT(::IsWindow(hWndCtrl));
		m_btn=hWndCtrl;
		m_Option=Option;
	}
	//
	DWORD GetOption()
	{
		ATLASSERT(m_btn.IsWindow());
		return m_btn.GetCheck()?m_Option:0;
	}
	//
	void UpdateState(const DWORD dwOptions)
	{
		ATLASSERT(m_btn.IsWindow());
		if(dwOptions&m_Option)
			m_btn.SetCheck(1);
		else
			m_btn.SetCheck(0);
	}
	//
	void Enable(BOOL bEnable)
	{
		ATLASSERT(m_btn.IsWindow());
		m_btn.EnableWindow(bEnable);
	}

protected:
	
	CButton m_btn;
	CBalloonHelp::BallonOptions	m_Option;

};// class CBalloonOptionCtrl



//
//			class CMainDlg
//
class CMainDlg: 
	public CDialogImpl<CMainDlg>
{
public:
	enum {IDD=IDD_MAINDLG};

	CMainDlg();

protected:
	
	DWORD GetBalloonOptions();
	void  UpdateOptions(DWORD dwOptions);
	void  EnableOptions(BOOL bEnable);
	void  ShowBallon(HWND hWndCenter);

	BEGIN_MSG_MAP_EX(CMainDlg)
		MSG_WM_INITDIALOG(OnInitDialog)
		COMMAND_ID_HANDLER_EX(IDOK, OnOK)
		COMMAND_ID_HANDLER_EX(IDCANCEL, OnCancel)
		COMMAND_ID_HANDLER_EX(IDC_BODefault, OnBoDefaultClicked)
		MSG_WM_HELP(OnHelp)
	ALT_MSG_MAP(1)
		// Josh finds out, that using MSG_WM_XY message crackers 
		// in ALT_MSG_MAP parts crashes the app when compiling under ATL 7.0.
		// Since I don't have ATL 7.0 I use the old MESSAGE_HANDLER
		// macro as a workaround.
		MESSAGE_HANDLER(WM_LBUTTONDOWN, OnTestLButtonDown)
	ALT_MSG_MAP(2)
		MESSAGE_HANDLER(WM_MBUTTONDOWN, OnTestMButtonDown)
	ALT_MSG_MAP(3)
		MESSAGE_HANDLER(WM_RBUTTONDOWN, OnTestRButtonDown)
	END_MSG_MAP()
	
protected:

	BOOL OnInitDialog(HWND, LPARAM);
	void OnMove(CPoint pt);
	void OnOK(WORD wNotifyCode, WORD wID, HWND hWndCtl){EndDialog(wID);}
	void OnCancel(WORD wNotifyCode, WORD wID, HWND hWndCtl){EndDialog(wID);}
	void OnBoDefaultClicked(WORD wNotifyCode, WORD wID, HWND hWndCtl);
	void OnHelp(LPHELPINFO pHelpInfo);

	LRESULT OnTestLButtonDown(UINT, WPARAM, LPARAM, BOOL&){ShowBallon(m_wndLButtonDown);return 0;}
	LRESULT OnTestMButtonDown(UINT, WPARAM, LPARAM, BOOL&){ShowBallon(m_wndMButtonDown);return 0;}
	LRESULT OnTestRButtonDown(UINT, WPARAM, LPARAM, BOOL&){ShowBallon(m_wndRButtonDown);return 0;}

protected:
	
	enum {MaxOptions=14};
	CBalloonOptionCtrl	m_OptionCtrls[MaxOptions];

	CButton				m_btnBoDefault;
	CButton				m_btnUseBitmap;
	CButton				m_btnFollowMe;
	
	CEdit				m_edtContent;
	CEdit				m_edtTitle;

	CBalloonHelp		m_wndBalloon;

	CContainedWindowT<CStatic>	m_wndLButtonDown;
	CContainedWindowT<CStatic>	m_wndMButtonDown;
	CContainedWindowT<CStatic>	m_wndRButtonDown;

};// class CMainDlg

#endif // #ifndef __MAINDLG__H__

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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
United States United States
Poke...

Comments and Discussions