Visual Basic Common Control API Routines
SendMessage: HTML-Like Tracking Effects in a ListView
Posted:   Saturday March 1, 1997
Updated:   Monday December 26, 2011
Applies to:   VB4-32, VB5, VB6
Developed with:   VB4-32, Windows 95
OS restrictions:   None
Author:   VBnet - Randy Birch
This method is intended for Visual Basic 5 or Visual Basic 6 where the Common Control library used is the MSComCtl 5 version (comctl32.ocx). Because the VB6-specific mscomctl.ocx (Common Controls 6) is a complete implementation of comctl32.dll and not reliant on the version of comctl32.dll installed, this routine may not work when applied to a listview created from the VB6-specific mscomctl.ocx.

Enhanced Comctl32 functionality is only available to users with comctl32.dll version 4.70 or greater installed. This dll is typically installed with IE3.x or greater.

vbnsLVClicks.gif (8818 bytes)The methods presented here are a bit different. The first (Check1) causes the mouse cursor to change into a hand, and as it moves over the ListView items, causes the item below to become underlined as a visual aid. This is similar to the visual clue in Internet Explorer when a hyperlink is encountered.

The second (Check2) leaves the the mouse cursor as the standard pointer icon until an item is clicked. As the cursor is moved over ListView the item below the cursor changes colour and becomes underlined when clicked. At that point the cursor turns into the hand.

This example does not contain all code required to construct the illustration shown. The routine provided here is designed to be applied to an existing project utilizing a ListView control with subitems.

 BAS Module Code
Place the following code into the general declarations area of a bas module:

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.
Public Declare Function SendMessage Lib "user32" _
   Alias "SendMessageA" _ 
  (ByVal hwnd As Long, _
   ByVal Msg As Long, _ 
   ByVal wParam As Long, _
   lParam As Any) As Long

Public Const LVM_FIRST As Long = &H1000

Public Const LVS_EX_FULLROWSELECT As Long = &H20
Public Const LVS_EX_GRIDLINES As Long = &H1
Public Const LVS_EX_CHECKBOXES As Long = &H4
Public Const LVS_EX_HEADERDRAGDROP As Long = &H10
Public Const LVS_EX_TRACKSELECT As Long = &H8
 Form Code
Add two check buttons to the project (Check1 and Check2) with the captions "One Click Activate" and "Two Click Activate". Set both button's initial values to 0. Add the following code to the check button sub:

Option Explicit

Private Sub Check1_Click()

   Dim state As Long
  'state will be true when the checkbox
  'style is 1 (checked) or False when
   state = Check1.Value = 1
  'set the new listview style
   Call SendMessage(ListView1.hwnd, _
                    LVS_EX_ONECLICKACTIVATE, ByVal state)

End Sub

Private Sub Check2_Click()

   Dim state As Long
  'state will be true when the checkbox
  'style is 1 (checked) or False when
   state = Check2.Value = 1
  'set the new listview style
   Call SendMessage(ListView1.hwnd, _
                    LVS_EX_TWOCLICKACTIVATE, ByVal state)

End Sub
Run your project. Selecting Check1 will cause the cursor to assume the "web finger" pointer, and Check2 uses the default pointer.


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