|
|||||||||||||||||||||
|
|||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
Release #3:
Previous release:
Ports:
Update NotesThe primary reason for this release is a bug I found with the open location
feature: it would access deallocated memory! In addition, I've worked in a few
other changes to make writing custom
I want to add some new demos, there are more things that can be done with this than what I'm currently demonstrating, but I felt these bug fixes needed to be released, and I'm probably too lazy to get the demos done as soon as i'd like anyway. So, I'll do another update when they are finished. In the meantime, Rama Krishna either has already, or will soon be releasing his .NET Version, so there'll be plenty of Balloon Goodness around. :)
Introduction IntroductionI hate message boxes.Or really, I hate But worse yet are programs that feel the need to inform you, after performing
an action that you explicitly requested, that the action has indeed been
performed, using – you guessed it – OK...Enough hypocritical griping however. Solutions do exist – creating message boxes with check boxes or “yes to all” / “no to all” buttons is not difficult. For the purpose of feedback, displaying a short message in a status bar will often suffice, or possibly adding a log pane. But both of these options really only work for the main window of an application, and have other drawbacks in terms of visibility and screen real-estate as well. With Windows 2000, Microsoft began a practice of using balloons (of the comic
strip dialog variety) for displaying messages from system tray icons. This
seems to work quite well; when I dial into the Internet, once the connection is
made, a small icon appears in the tray, along with a balloon giving details on
my connection speed. A Note that balloons as described above are not ToolTips. ToolTips, also in use by tray icons by the way, serve well in their current form: small unobtrusive pieces of text that show up when you hover the mouse over a control, and disappear immediately upon moving the mouse away. Anyone who has used BalloonHelp on the MacOS (Ref: http://developer.apple.com/techpubs/mac/HIGuidelines/HIGuidelines-240.html) should know the advantages Microsoft's ToolTips have when used for this purpose. With Internet Explorer 5 and later, Microsoft make the Balloon ToolTip style
available for general use (via the So get to the point already...The point of all this of course is that I've written an easy to use balloon
control. I stress easy to use: in order to convince myself and others to go
this way, I wanted it to be as easy to pop up a help balloon as popping up a Using CBalloonHelpAdd BalloonHelp.cpp and BalloonHelp.h in your project. APIThe important stuffThe easiest way to create a balloon is to use the LaunchBalloon() static function: void CBalloonHelp::LaunchBalloon(const CString& strTitle, const CString& strContent, const CPoint& ptAnchor, LPCTSTR szIcon /*= IDI_EXCLAMATION*/ unsigned int unOptions /*= unSHOW_CLOSE_BUTTON*/, CWnd* pParentWnd /*= NULL*/, const CString strURL /*= ""*/, unsigned int unTimeout /*= 10000*/)
This will allocate a new strTitle // Title of balloon strContent // Content of balloon ptAnchor // point tail of balloon will be "anchor"ed to. // This is in client coordinates if pParentWnd is given, // otherwise it is in screen coordinates. szIcon // One of: // IDI_APPLICATION // IDI_INFORMATION IDI_ASTERISK (same) // IDI_ERROR IDI_HAND (same) // IDI_EXCLAMATION IDI_WARNING (same) // IDI_QUESTION // IDI_WINLOGO unOptions /* One or more of: unCLOSE_ON_LBUTTON_DOWN | closes window on WM_LBUTTON_DOWN unCLOSE_ON_MBUTTON_DOWN | closes window on WM_MBUTTON_DOWN unCLOSE_ON_RBUTTON_DOWN | closes window on WM_RBUTTON_DOWN unCLOSE_ON_LBUTTON_UP | closes window on WM_LBUTTON_UP unCLOSE_ON_MBUTTON_UP | closes window on WM_MBUTTON_UP unCLOSE_ON_RBUTTON_UP | closes window on WM_RBUTTON_UP unCLOSE_ON_MOUSE_MOVE | closes window when user moves mouse | past threshhold unCLOSE_ON_KEYPRESS | closes window on the next keypress message sent to this thread. unCLOSE_ON_ANYTHING | all of the above. unDELAY_CLOSE | when a user action triggers the close, | begins timer. closes when timer expires. unSHOW_CLOSE_BUTTON | shows close button in upper right unSHOW_INNER_SHADOW | draw inner shadow in balloon unSHOW_TOPMOST | place balloon above all other windows unDISABLE_XP_SHADOW | disable Windows XP's drop-shadow effect | (overrides system and user settings) unDISABLE_FADE | disable the fade-in/fade-out effects | (overrides system and user settings) unDISABLE_FADEIN | disable the fade-in effect unDISABLE_FADEOUT | disable the fade-out effect */ pParentWnd // Parent window/anchor window. If NULL, balloon will be // anchored in screen coordinates, and owned by the // application's main window. strURL // If not empty, when the balloon is clicked ShellExecute() // will be called, with strURL passed in. unTimeout // If not 0, balloon will automatically close after unTimeout // milliseconds. Use:CBalloonHelp::LaunchBalloon("BoogaBooga", "What the hell is \"Booga Booga\" supposed to mean, anyway?", CPoint(0,0)); CBalloonHelp::LaunchBalloon("You are holding down the right mouse button!", "Blah", Cpoint(0,0), IDI_WARNING, CballoonHelp::unCLOSE_ON_RBUTTON_UP|CBalloonHelp::unSHOW_INNER_SHADOW, this, "", 0); The first line above will show a balloon with the title “BoogaBooga” and associated message anchored to the top left corner of the screen (point is in screen coordinates). Ideally, you'd anchor it to something more meaningful, such as the center of a control, or a status bar icon. The default options will cause this balloon to disappear after 10 seconds, and to show the standard information icon at top left, and a close button at top right. The second line above will show a balloon, this time anchored to the top left
corner of the window represented by It is also possible to create a balloon using the Complete API"API Create">BOOL CBalloonHelp::Create(const CString& strTitle, const CString& strContent, const CPoint& ptAnchor, unsigned int unOptions, CWnd* pParentWnd /*=NULL*/, const CString strURL /*= ""*/, unsigned int unTimeout /*= 0*/, HICON hIcon /*= NULL*/); This will create and display a balloon window. Title and content override any
set for the object prior to this call. CBalloonHelp::unCLOSE_ON_LBUTTON_DOWN // closes window on WM_LBUTTON_DOWN CBalloonHelp::unCLOSE_ON_MBUTTON_DOWN // closes window on WM_MBUTTON_DOWN CBalloonHelp::unCLOSE_ON_RBUTTON_DOWN // closes window on WM_RBUTTON_DOWN CBalloonHelp::unCLOSE_ON_LBUTTON_UP // closes window on WM_LBUTTON_UP CBalloonHelp::unCLOSE_ON_MBUTTON_UP // closes window on WM_MBUTTON_UP CBalloonHelp::unCLOSE_ON_RBUTTON_UP // closes window on WM_RBUTTON_UP CBalloonHelp::unCLOSE_ON_RBUTTON_UP // closes window on WM_RBUTTON_UP CBalloonHelp::unCLOSE_ON_MOUSE_MOVE // closes window when user moves mouse past // threshhold CBalloonHelp::unCLOSE_ON_KEYPRESS // closes window on the next keypress message sent // to this thread. CBalloonHelp::unCLOSE_ON_ANYTHING; // all of the above CBalloonHelp::unDELAY_CLOSE; // when a user action triggers the close, // begins timer. closes when timer expires. CBalloonHelp::unDELETE_THIS_ON_CLOSE // deletes object when window is closed. Used by // LaunchBalloon(), use with care CBalloonHelp::unSHOW_CLOSE_BUTTON // shows close button in upper right CBalloonHelp::unSHOW_INNER_SHADOW // draw inner shadow in balloon CBalloonHelp::unSHOW_TOPMOST // place balloon above all other windows CBalloonHelp::unDISABLE_XP_SHADOW; // disable Windows XP's drop-shadow effect // (overrides system and user settings) CBalloonHelp::unDISABLE_FADE // disable the fade-in/fade-out effects // (overrides system and user settings) CBalloonHelp::unDISABLE_FADEIN // disable the fade-in effect CBalloonHelp::unDISABLE_FADEOUT // disable the fade-out effect
If "API SetAnchorPoint">void CBalloonHelp::SetAnchorPoint(CPoint ptAnchor, CWnd* pWndAnchor = NULL); Sets the point to which the balloon is anchored (the point the balloon's tail
attaches to). Calling this before the balloon is created has no effect, since
the anchor is a required parameter of "API SetBackgroundColor">void CBalloonHelp::SetBackgroundColor(COLORREF crBackground); Sets the background color of the balloon. Can be called before or after the balloon is created. "API SetForegroundColor">void CBalloonHelp::SetForegroundColor(COLORREF crForeground); Sets the foreground (borders & text) color of the balloon. Can be called before or after the balloon is created. "API SetTitle">void CBalloonHelp::SetTitle(const CString& strTitle); Sets the title of the balloon. Can be called before or after the balloon is created. "API SetContent">void CBalloonHelp::SetContent(const CString& strContent); Sets the content of the balloon. Can be called before or after the balloon is created. "API SetTitleFont">void CBalloonHelp::SetTitleFont(CFont* pFont); Sets the font used to draw the title of the balloon. Can be called before or after the balloon is created. The font and the CFont object are stored and eventually deleted by the balloon; do not use either after calling this function. "API SetContentFont">void CBalloonHelp::SetContentFont(CFont* pFont); Sets the font used to draw the contents of the balloon. Can be called before or
after the balloon is created. If this is called before creation, and the title
font is not explicitly set (via "API SetURL">void CBalloonHelp::SetURL(const CString& strURL); Sets the URL or file to be opened by the balloon when clicked. Set to "" to disable. Can be called before or after the balloon is created. "API SetIcon">void CBalloonHelp::SetIcon(HICON hIcon); Sets the icon shown at the top left of the balloon. Pass in NULL to show no icon. Icon will not be scaled. Can be called before or after the balloon is created. void CBalloonHelp::SetIcon(HBITMAP hBitmap, COLORREF crMask);
Sets the icon shown at the top left of the balloon. void CBalloonHelp::SetIcon(HBITMAP hBitmap, HBITMAP hMask);
Sets the icon shown at the top left of the balloon. void CBalloonHelp::SetIcon(CImageList* pImageList, int nIconIndex); Sets the icon shown at the top left of the balloon. "API LaunchBalloon">void CBalloonHelp::LaunchBalloon(const CString& strTitle, const CString& strContent, const CPoint& ptAnchor, LPCTSTR szIcon /*= IDI_EXCLAMATION*/, unsigned int unOptions /*= unSHOW_CLOSE_BUTTON*/, CWnd* pParentWnd /*= NULL*/, const CString strURL /*= ""*/, unsigned int unTimeout /*= 10000*/) Creates and shows a balloon. This is a static function, so calling this on an
instance of CBalloonHelp is not too useful. If you need more control, create a
derived class, or use Features
CompatibilityTested on Windows XP, 2000, 98, and 95 Compiles with VC++ 6.0 / MFC 6 and VC++.NET / MFC 7 Internals
The window is created hidden, and then the size of the content and title are calculated. Margins and space for the tail are added to this, and the window is sized and positioned relative to the anchor point. Finally, the window region is set and the window is shown. Tip: when doing shaped windows, put the shaped bits in the non-client area; it's a lot easier to deal with if you don't have to account for that stuff when dealing with drawing the client area.
Messsage hooks are used to determine when closing mouse actions occur. Andrew Nosenko's Updates8/2/02
5/30/02
1/23/02
12/31/01
12/21/01
12/12/01
Related Articles
TODOClean up code a bit... most of it is pretty straight forward, but documentation could be better. Move to straight Win32, not MFC derived class. Add better code walkthrough to this article. Thanks......Jan van den Baard for showing me the right way to use AnimateWindow(), and
for demonstrating how ...Maximilian Hänel for his WTL port, and for demonstrating therein a nicer way to handle message hooks. ...To all the people who've provided feedback, positive and negative. It all helps. ...To Mustafa Demirhan, for his suggestion and information on using keyboard hooks. ...To The Code Project, for providing a useable forum for all of us. | ||||||||||||||||||||