INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Activex

Clear BG and longer labels for ListView Icons by wgcs
Posted: 16 Mar 04 (Edited 16 Mar 04)

The ListView control is great for displaying items much like windows explorer.

However, it suffers from some limitations that Windows Explorer also has such as:
  The background for unselected icon labels is never clear.
  The length of the labels on a listview icon in "Icon View" is limited by the system-wide "Icon spacing" setting in Windows.
  
ListView was designed so that these can both be changed, but the Common Controls ActiveX wrapper doesn't provide an interface for changing them.
You can provide your own interface in VFP7+ without much trouble, if you know how...

Here's How:
  1. Create a subclass of the ListView ActiveX control:
    • Command Prompt: CREATE CLASS ?
    • give the class a name (say: myListBox)
    • select it to be based on "OLEControl"
    • select a vcx class library file to store it in (or create a new one by entering a name that doesn't exist)
    • click "ok"
    • in the "Insert Object" dialog, select "Insert Control" and "Microsoft ListView Control 6.0", click "OK"  
  2. In the Class Designer for the control you just created:
    • Choose "New Method" from the "Class" menu
    • Enter "GetHWnd" for the new method name, Click "Add" then "Close"
    • Open the "GetHwnd" method from the properties list, Enter this for the method code:

      CODE

      LOCAL lcHwnd1, lcHwnd2
      lcHwnd2 = 0
      DECLARE INTEGER FindWindowEx in win32api as apiFindWindowEx ;
          INTEGER nParent, INTEGER nChildAfter, ;
          STRING cClass, STRING cName
      *If you're on VFP6, you'll have to find THISFORM's hWnd value a different way:
      lcHwnd1 = apiFindWindowEx( THISFORM.HWnd, 0, 'CtlFrameWork_ReflectWindow', 0 )
      IF lcHWnd1>0
        lcHwnd2 = apiFindWindowEx( lcHwnd1, 0, 'ListView20WndClass', 0 )
      ENDIF
      RETURN lcHwnd2
    • Using the steps above, add a method called "SetIconSpacing" and put this as its code:

      CODE

      LPARAMETERS tnCX, tnCY
      *!*    LVM_FIRST=0x1000
      *!*    LVM_SETICONSPACING = LVM_FIRST + 53  = 4149

      LOCAL lnHWND, lnLPrm
      lnHWND = THIS.GetHwnd()
      IF lnHWND>0
        LVM_SETICONSPACING = 4149
        DECLARE LONG SendMessage IN WIN32API as apiSendMessage ;
          LONG whnd, LONG Msg, SHORT WParam, LONG LParam
        lnLPrm = BITLSHIFT(tnCX,16) + tnCY
        apiSendMessage( lnHWND, LVM_SETICONSPACING, 0, lnLPrm )
      ENDIF
    • Using the steps above again, add a method called "SetTextBkColor" and put this as its code:

      CODE

      LPARAMETERS tnBkClr
      *!*    LVM_FIRST=0x1000
      *!*    LVM_SETTEXTBKCOLOR = LVM_FIRST + 38  = 4134

      LOCAL lnHWND, lnLPrm, LVM_SETTEXTBKCOLOR, lnBkClr
      lnHWND = THIS.GetHwnd()
      IF lnHWND>0
        * If no color spec'd, default to clear:
        lnBkClr = IIF(VARTYPE(tnBkClr)='N', tnBkClr, 0xFFFFFFFF )
        LVM_SETTEXTBKCOLOR = 4134
        DECLARE LONG SendMessage IN WIN32API as apiSendMessage ;
          LONG whnd, LONG Msg, SHORT WParam, LONG LParam
        lnLPrm = BITLSHIFT(tnCX,16) + tnCY
        apiSendMessage( lnHWND, LVM_SETTEXTBKCOLOR, 0, lnBkClr )
      ENDIF
Now, you can use this control on a form.   After putting it on the form, put calls to those two methods in the INIT event method of the form or of the listview control, something like this:

CODE

THISFORM.lstView.SetIconSpacing(100,100)
THISFORM.lstView.SetTextBkColor()  && Defaults to clear
You can also set a graphic for the "Picture" property to provide wallpaper on the listview, and to show that the background of the captions really is clear.  Because of setting the Icon Spacing so big, the icons will space out better, and the text in the caption will be allowed to be longer before it gets truncated, ending with "...".

You can also set up properties for these settings on your ListView class which would be read and interpreted in the .Init event of the ListView, but that takes more code and is too complicated for illustrative purposes.

The same method can be used to toy with the Windows Desktop, to make those icons space out differently, or to make the Text Captions' backgrounds transparent.

Have Fun!

Back to Microsoft: Visual FoxPro FAQ Index
Back to Microsoft: Visual FoxPro Forum

My Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close