Visual Basic Text API Routines
SendMessage: Add Balloon Tips to a Combo 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


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

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).

Like text box balloon tips (SendMessage: Add Balloon Tips to a Text Box), combo tips for Combo styles 0 or 1 can be displayed by using SendMessage after obtaining the hwnd to the edit portion of the combo control. And like the text/rich text version, pretty well the same functionality applies.

In a combo, the tip always points to start of the combo edit box regardless of the current cursor position within the control. Like the text version, it 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 edit control. 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/Combo balloon tips are only available under Windows XP or later. In order to develop, see and test the balloon tip for combos, 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).

 BAS Module Code

 Form Code
Add a combo (Combo1) 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)

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

Private Type RECT
   Left As Long
   Top As Long
   Right As Long
   Bottom As Long
End Type

   cbSize As Long
   rcItem As RECT
   rcButton As RECT
   stateButton  As Long
   hwndCombo  As Long
   hwndEdit  As Long
   hwndList As Long
End Type

Private Declare Function GetComboBoxInfo Lib "user32" _
  (ByVal hwndCombo As Long, _

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.

End Sub

Private Sub Form_Load()

   Command1.Caption = "Show Tip"
   Command1.TabIndex = 0
   Combo1.Text = "Florida"
End Sub

Private Sub Command1_Click()

   Dim hEdit As Long

   hEdit = GetComboEditHandle(Combo1)
   With ebt
      .cbStruct = Len(ebt)
      .pszTitle = StrConv("US Vacations", vbUnicode)
      .pszText = StrConv("Select your holiday destination", vbUnicode)
      .ttiIcon = 1
   End With

   Call SendMessage(hEdit, EM_SHOWBALLOONTIP, 0&, ebt)
End Sub

Private Function GetComboEditHandle(ctl As ComboBox) As Long


   CBI.cbSize = Len(CBI)
   Call GetComboBoxInfo(ctl.hwnd, CBI)
   GetComboEditHandle = CBI.hwndEdit
End Function
This is a sample manifest file to provide XP styles in VB applications:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> 
   <description>Enter your Description Here</description>


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