Visual Basic Text API Routines
SendMessage: Add Balloon Tips to a Text Box
     
Posted:   Monday March 10, 2003
Updated:   Monday December 26, 2011
     
Applies to:   VB5, VB6
Developed with:   VB6, Windows XP
OS restrictions:   Windows XP or later
Author:   VBnet - Randy Birch
     

Related:  

Pure VB: Cue Banners for the XP Impaired
Manifests: Make the VB IDE use Windows XP Styles
SendMessage: Use Cue Banners to Prompt Users
CreateWindowEx: 21st Century ToolTips for VB - The Basics
Shell_NotifyIcon: Windows Systray NOTIFYICONDATA Overview
Shell_NotifyIcon: Add Icon to Windows System Tray
Shell_NotifyIcon: Respond to Systray Icon/Menu Interaction
Shell_NotifyIcon: Respond to Systray Icon/Menu Interaction in a MDI App

Shell_NotifyIcon: Animate the System Tray Icon
Shell_NotifyIcon: Display Systray Balloon Tips

Shell_NotifyIcon: Respond to Systray Balloon Tip Clicks
Shell_NotifyIcon: Use SetTimer to Define Balloon Tip Life
SendMessage: Add Balloon Tips to a Combo Edit Box

SendMessage: Add Balloon Tips to a Text Box

     
 Prerequisites
Windows XP or later.

Note: In order for EM_HIDEBALLOONTIP to function correctly users must not have disabled the "Enable balloon tip" setting on the system. Using TweakUI for XP, this is located under the Taskbar group of options. It is also directly accessible as a registry entry under HKEY_CURRENT_USER \ Software \ Microsoft \ Windows \ CurrentVersion \ Explorer \ Advanced at the key "EnableBalloonTips"=dword:00000001 (1 to enable, 0 to disable).


Tool tips are so 1995. And message boxes are usually dismissed without reading because they're so intrusive. So here's how to (judiciously) spice up your application by displaying a balloon tip using a standard VB text box or rich text box via SendMessage.

The tip always points to the current cursor position within the control, and is dismissed by either clicking on it, by moving focus to a control other than the control the tip is assigned to, or by typing into the text box. Showing the tip automatically sets focus to the control at the last cursor position. A form can not show more than one tip at a time, and if the tip is repeatedly shown, the previous tip is destroyed first. Tips never get focus, and there is no message sent when the tip is dismissed. If the tip is displayed up to the system timeout value for tool tips, it automatically disappears leaving focus on the control. In addition, the EM_HIDEBALLOONTIP message (wparam=0, lparam=ByVal 0)  can be sent from a timer to dismiss a tip at any time via code.

Text balloon tips are only available under Windows XP or later. In order to develop, see and test the balloon tip for text boxes or rich text boxes, the IDE must also have a manifest as outline at Manifests: Make the VB IDE use Windows XP Styles . Furthermore, in order for the tip to appear in a distributed app, the user must be running XP and the application must be distributed with a manifest file to enable the XP styles in the VB application (also detailed on that page).

This demo calls the tip from a command click event; you'd probably want to use it in a validation routine to draw attention back to the control containing the invalid data.

For displaying the tip on a combo box, see SendMessage: Add Balloon Tips to a Combo Edit Box.

 BAS Module Code
None.

 Form Code
Add a label (Label1), textbox (Text1) and command button (Command1) to the form along with the following code:

Option Explicit
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Copyright 1996-2011 VBnet/Randy Birch, All Rights Reserved.
' Some pages may also contain other copyrights by the author.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Distribution: You can freely use this code in your own
'               applications, but you may not reproduce 
'               or publish this code on any web site,
'               online service, or distribute as source 
'               on any media without express permission.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Const ECM_FIRST As Long = &H1500
Private Const EM_SHOWBALLOONTIP As Long = (ECM_FIRST + 3)
Private Const EM_HIDEBALLOONTIP As Long = (ECM_FIRST + 4)

Private Type EDITBALLOONTIP
   cbStruct As Long
   pszTitle As String
   pszText As String
   ttiIcon As Long
End Type

Private Declare Function SendMessage Lib "user32" _
   Alias "SendMessageA" _
  (ByVal hwnd As Long, _
   ByVal wMsg As Long, _
   ByVal wParam As Long, _
   lParam As Any) As Long

Private Declare Function InitCommonControls Lib "comctl32" () As Long


Private Sub Form_Initialize()

  'InitCommonControls must be called
  'before the interface is created,
  'so calling in the Load event is
  'often too late. Placing the call in
  'either the application's Sub Main
  'entry point, or in the Initialize
  'allows the XP styles to be applied.
   InitCommonControls

End Sub


Private Sub Form_Load()

   Text1.Text = vbNullString
   Label1.Caption = "Enter the number of blackbirds in a pie:"
   Command1.Caption = "Show Tip"
   Command1.TabIndex = 0
   
End Sub


Private Sub Command1_Click()

   Dim ebt As EDITBALLOONTIP
   
   With ebt
      .cbStruct = Len(ebt)
      .pszTitle = StrConv("Moron!", vbUnicode)
      .pszText = StrConv("What part of 'enter a number' don't you understand?", vbUnicode)
      .ttiIcon = 1
   End With

   Call SendMessage(Text1.hwnd, EM_SHOWBALLOONTIP, 0&, ebt)
 
End Sub
 Comments
This is a sample manifest file to provide XP styles in VB applications:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> 
<assembly 
   xmlns="urn:schemas-microsoft-com:asm.v1" 
   manifestVersion="1.0">
   <assemblyIdentity 
      type="win32" 
      processorArchitecture="*" 
      version="6.0.0.0"
      name="test"
   /> 
   <description>Enter your Description Here</description>
   <dependency> 
      <dependentAssembly> 
         <assemblyIdentity 
            type="win32"
            name="Microsoft.Windows.Common-Controls" 
            version="6.0.0.0" 
            language="*"
            processorArchitecture="*" 
            publicKeyToken="6595b64144ccf1df"
         />
      </dependentAssembly> 
   </dependency> 
</assembly>

 
 

PayPal Link
Make payments with PayPal - it's fast, free and secure!

 
 
 
 

Copyright 1996-2011 VBnet and Randy Birch. All Rights Reserved.
Terms of Use  |  Your Privacy

 

Hit Counter