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...
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)
in the "Insert Object" dialog, select "Insert Control" and "Microsoft ListView Control 6.0", click "OK"
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:
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:
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:
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:
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.