Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version
Go to top

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

, 7 Aug 2002
Although sometimes useful, message boxes used to display information are often just annoying. This article describes a non-modal replacement.
balloonhelpr2_demo.zip
BalloonTest.exe
res
BalloonTest.ico
BalloonTest.manifest
BalloonTest.dsw
BalloonTest.dsp
balloonhelpr2_src.zip
balloonhelpr3_demo.zip
BalloonTest.ico
BalloonTest.manifest
BalloonTest.dsw
BalloonTest.dsp
BalloonTest.exe
balloonhelpr3_src.zip
balloonhelp_demo.zip
BalloonTest.exe
BalloonTest.ico
BalloonTest.manifest
BalloonTest.dsw
BalloonTest.dsp
balloonhelp_src.zip
bh-atl.zip
BalloonTest.dsp
BalloonTest.dsw
BalloonTestps.mk
BalloonTestps.def
BalloonTest.rgs
BalloonTest.ico
BalloonTest.manifest
BalloonTest.suo
wtl_balloonhelp_demo.zip
BalloonTest
BalloonTest.dsp
Release
BalloonTest.exe
res
BalloonTest.exe.manifest
BalloonTest.ico
bob.bmp
#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)

Share

About the Author

Shog9
Software Developer
United States United States
Poke...

| Advertise | Privacy | Mobile
Web04 | 2.8.140922.1 | Last Updated 8 Aug 2002
Article Copyright 2001 by Shog9
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid