Using the List View API in Gfa Basic


In this example we show how to use the Win32 API in a listview object

in Gfa Basic.


The listview control in Gfa Basic has a number of methods provided for

by the use of the Gfa Basic object syntax.


It is one of the common controls built into the 32 bit Windows subsystem.


It is also the most complex control and can take on different appearances.

This example uses the Report View.


The C Type API code this example extends the number methods for the

listview in Gfa Basic by integrating with the operating system and directly

sending messages to the handle of the listview by the use of the Windows

sendmessage API function.


The zip file includes the example with the forms needed to run the example

in Gfa Basic.


Click here to download ReportView_API_ListviewExample.zip


'Allan Shura

'neotreksoftware.com



'*Listview Reportview API example*


'**************

'note: this is in rough and is the

'not the complete API

'**************


'*********


'To Do:


'Add All useable Report View

'sendmessage API in Gfa Basic


'simularly this can be done for other

'objects ie: rtf, listbox, combobox

'they also use the set of win32

'sendmessage and or macros


Option Base 0


@InitListviewConstantsAll

@InitW32Types

@InitGlobal

@CreateListviewTemplate


LoadForm frmLvColor Hidden

frmLvColor.Enabled = False

LoadForm frmLvItems Hidden

frmLvItems.Enabled = False

LoadForm frmLvSubItems Hidden

frmLvSubItems.Enabled = False

LoadForm frmLVColumns Hidden

frmLVColumns.Enabled = False

LoadForm frmParam Hidden

frmParam.Enabled = False

DoEvents


Do : Sleep : Until Me Is Nothing


Procedure InitGlobal


Global Button&, Shift&, x!, y!

Global b%, h&, id&, param%, title$, w&, x&, y&, Code&, Shift& 'EDIT API PARAMETERS


Global blue|, green|, red|

Global n_lp% 'generic loop

Global txtx%, txty% 'text position on form only


Global dwError As Double


Global n, m As Double

Global lin, col As Double

Global ret As Long 'return


Itemtext$ = "New"

Global Itemtext$

Global ITEMA As LV_ITEM

Global COLUMN As LV_COLUMN

Global ADDRITEM As Long

ADDRITEM = V:ITEMA


Global ItemIdx As Int 'generic listview item index

Global ICOUNT As Long '32 bit Integer to place listview ITEMCOUNT

Global COLORREF As Long '32 bit Integer first 3 bytes are rrbbgg


Global rect As RECT_C


Global Rec_frmlvCellParam As RECT 'form

Global Rec_lv1 As RECT 'listview


Return

Procedure CreateListviewTemplate

'scrollbar lv adjust

Global Int LVx, LVy, linh


Global lvNumCols As Double

Global lvNumRows As Double


'create listveiw object

LoadForm frmlvCellParam

DoEvents

frmlvCellParam.AutoRedraw = True


'if not defined in the form editor

'Ocx ListView lv = , 20, 20, 495, 305


lv.Left = 20

lv.Top = 20

lv.Width = 495

lv.Height = 305

lv.Appearance = 1

lv.TextBackColor = RGB(180, 200, 220)

lv.BackColor = RGB(200, 180, 240)

lv.View = 3 'report view

lv.FullRowSelect = 1

lv.HideSelection = 0

lv.LabelEdit = 1 'can edit first line, the line label

lv.MultiSelect = 0

lv.GridLines = 1 'gridlines = True

lv.SetFocus

lv.SelectedItem = lv(1)


'list view parameters

lvNumCols = 9

lvNumRows = 44


'list view parameters

Global ColWidth$(lvNumCols)

Global TotColWidth%(lvNumCols)


For n_lp% = 1 To lvNumCols 'add the row (items) to the top column header

lv.ColumnHeaders.Add _

( , , "Column" + Str(n_lp% - 1)).Width = 600 _

+ n_lp% * 273

Next n_lp%


For n_lp% = 1 To lvNumRows

lv.Add

lv(n_lp%).AllText = _

"Line" + Str(n_lp%) + ";" _

+ Str(n_lp%) + ";" _

+ Str(27 - n_lp%) + ";" _

+ Chr(n_lp% + 64) + ";" _

+ Chr(27 - n_lp% + 64)

Next n_lp%


'font

lv.FontName = "Arial"

'MsgBox lv.FontSize

'MsgBox lv.FontName

lv.FontSize = 8

lv.FontBold = False

lv.FontItalic = False

lv.FontStrikethru = False

lv.FontUnderline = False


Return

Procedure InitW32Types

Type MSG

hwnd As Long

MessageVar As Long 'Message is reserved in gb32 so MessageVar

wParam As Long

lParam As Long

time As Long

pt As POINTAPI

'CRgb As Int

EndType


Global WMSG As MSG


Type RECT

Left As Long

Top As Long

Right As Long

Bottom As Long

EndType


Type RECT_C

x As Long

y As Long

w As Long

h As Long

EndType


Type POINTAPI

x As Long

y As Long

EndType


Type NMHDR

hwndFrom As Long ' 4b Pointer

idFrom As Integer ' 4b

code As Integer ' 4b

EndType


Dim HDR As NMHDR


Type NM_LISTVIEW

hdr As String*12

iItem As Integer ' 4b

iSubItem As Integer ' 4b

uNewState As Integer ' 4b

uOldState As Integer ' 4b

uChanged As Integer ' 4b

ptAction As Integer ' 4b

lParam As Long ' 4b Pointer

EndType


Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long


Return

Procedure InitListviewConstantsAll


' LISTVIEW CONTROL


'The lv_ITEM structure specifies or receives the attributes of a list view item.

'Members


'mask

'A set of bit flags that specify attributes of this data structure or of an operation that is using this structure.

'The following bit flags specify the members of the lv_ITEM structure that contain valid data or need to be filled in. One or more of these bit flags may be set:

'Value

'lvIF_TEXT The pszText member is valid or needs to be filled in.

'lvIF_IMAGE The iImage member is valid or needs to be filled in.

'lvIF_PARAM The lParam member is valid or needs to be filled in.

'lvIF_STATE The state member is valid or needs to be filled in..

'The following bit flag is used with the lvN_GETDISPINFO notification message:


'Value

'lvIF_DI_SETITEM The operating system should store the requested

'list item information, and not ask for it again.


'iItem

'Item that this structure refers to.

'iSubItem

'Subitem that this structure refers to, or zero.

'state And(statemask)

'Current state of the item, and the valid states of the item.

'This member can be any valid combination of state flags.


'pszText

'Pointer to a null-terminated string that contains the

'item text if the structure specifies item attributes.

'If this member is the LPSTR_TEXTCALLBACK value, the item

'is a callback item. Do not set the pszText member

'to LPSTR_TEXTCALLBACK if the list view control has

'lvS_SORTASCENDING or lvS_SORTDESCENDING style.

'If the structure is receiving item attributes,

'this member is the pointer to the buffer that receives

'the item text.


'cchTextMax

'Size of the buffer pointed to by the pszText member if

'the structure is receiving item attributes. If the

'structure specifies item attributes, this member is ignored.


'iImage

'Index of the list view item's icon in the icon and small icon image lists. If this member is the I_IMAGECALLBACK value, the item is a callback item.


'Remarks

'The lv_ITEM structure is used with a number of messages,

'including LVM_GETITEM, LVM_SETITEM, LVM_INSERTITEM, and

'LVM_DELETEITEM.


Type LV_ITEM

mask As Long

iItem As Long

iSubItem As Long

STATE As Long

stateMask As Long

pszText As Long

cchTextMax As Long

iImage As Long

lParam As Long

iIndent As Long

iGroupId As Long

cColumns As Long 'tile view columns

puColumns As Long

End Type


Type LVITEM

mask As Long

iItem As Long

iSubItem As Long

STATE As Long

stateMask As Long

pszText As Long

cchTextMax As Long

iImage As Long

lParam As Long

iIndent As Long

iGroupId As Long

cColumns As Long 'tile view columns

puColumns As Long

End Type


Type SIZE ' (windef.h)

cx As Long

cy As Long

End Type


Type NMCUSTOMDRAW

hdr As NMHDR

dwDrawStage As Long

hdc As Long

rc As RECT

dwItemSpec As Long ' this is control specific, but it's how to specify an item. valid only with CDDS_ITEM bit set

uItemState As Long

lItemlParam As Long

End Type


Type NMTTCUSTOMDRAW

nmcd As NMCUSTOMDRAW

uDrawFlags As Long

End Type


Public Const WC_LISTVIEW = "SysListView32"


'appearance views, styles and behaviors

Global Const LVM_FIRST = &H1000 ' ListView messages

Global Const LVN_FIRST = 0 - 100

Global Const LVN_LAST = 0 - 199

Global Const LVS_ICON = &H00000000

Global Const LVS_REPORT = &H00000001

Global Const LVS_SMALLICON = &H00000002

Global Const LVS_LIST = &H00000003

Global Const LVS_TYPEMASK = &H00000003

Global Const LVS_SINGLESEL = &H00000004

Global Const LVS_SHOWSELALWAYS = &H00000008

Global Const LVS_SORTASCENDING = &H00000010

Global Const LVS_SORTDESCENDING = &H00000020

Global Const LVS_SHAREIMAGELISTS = &H00000040

Global Const LVS_NOLABELWRAP = &H00000080

Global Const LVS_AUTOARRANGE = &H00000100

Global Const LVS_EDITLABELS = &H00000200

Global Const LVS_OWNERDATA = &H00001000

Global Const LVS_NOSCROLL = &H00002000

Global Const LVS_TYPESTYLEMASK = &H0000FC00

Global Const LVS_ALIGNTOP = &H00000000

Global Const LVS_ALIGNLEFT = &H00000800

Global Const LVS_ALIGNMASK = &H00000C00

Global Const LVS_OWNERDRAWFIXED = &H00000400

Global Const LVS_NOCOLUMNHEADER = &H00004000

Global Const LVS_NOSORTHEADER = &H00008000


'Item states

Global Const LVSIL_NORMAL = 0 'imagelist

Global Const LVSIL_SMALL = 1 'imagelist only

Global Const LVSIL_STATE = 2 'imagelist only


Global Const LVIF_TEXT = &H0001 '*The pszText member is valid or needs to be filled in.

Global Const LVIF_IMAGE = &H0002 '*The iImage member is valid or needs to be filled in.

Global Const LVIF_PARAM = &H0004 '*The lParam member is valid or needs to be filled in.

Global Const LVIF_STATE = &H0008 '*The state member is valid or needs to be filled in.

Global Const LVIF_INDENT = &H0010

Global Const LVIF_NORECOMPUTE = &H0800

Global Const LVIF_GROUPID = &H0100

Global Const LVIF_COLUMNS = &H0200

Global Const LVIS_FOCUSED = &H0001

Global Const LVIS_SELECTED = &H0002

Global Const LVIS_CUT = &H0004

Global Const LVIS_DROPHILITED = &H0008

Global Const LVIS_GLOW = &H0010 'have not successfully implemented in xp

Global Const LVIS_ACTIVATING = &H0020


Global Const LVIS_OVERLAYMASK = &H00F00

Global Const LVIS_STATEIMAGEMASK = &H0F000


Global Const ITSIM = 1


Global Const I_INDENTCALLBACK = -1


Global Const I_GROUPIDCALLBACK = -1

Global Const I_GROUPIDNONE = -2


Global Const I_IMAGECALLBACK = -1

Global Const I_IMAGENONE = -2


'Global Const LVM_SETUNICODEFORMAT = CCM_SETUNICODEFORMAT

'Global Const LVM_GETUNICODEFORMAT = CCM_GETUNICODEFORMAT

Global Const LVM_SETIMAGELIST = LVM_FIRST + 3


Global Const LVM_SUBITEMHITTEST = LVM_FIRST + 57

Global Const LVM_GETEDITCONTROL = LVM_FIRST + 24

Global Const LVM_GETITEMCOUNT = LVM_FIRST + 4 '*

Global Const LVM_GETBKCOLOR = LVM_FIRST + 0 '*

Global Const LVM_SETBKCOLOR = LVM_FIRST + 1 '*

Global Const LVM_GETIMAGELIST = LVM_FIRST + 2

Global Const LVM_GETITEM = LVM_FIRST + 5 '*

Global Const LVM_GETITEMW = LVM_FIRST + 75 'unicode

Global Const LVM_SETITEM = LVM_FIRST + 6 '*

Global Const LVM_SETITEMW = LVM_FIRST + 76 'unicode

Global Const LVM_INSERTITEM = LVM_FIRST + 7 '*

Global Const LVM_INSERTITEMW = LVM_FIRST + 77 'unicode

Global Const LVM_DELETEITEM = LVM_FIRST + 8 '*

Global Const LVM_DELETEALLITEMS = LVM_FIRST + 9 '*

Global Const LVM_GETCALLBACKMASK = LVM_FIRST + 10

Global Const LVM_SETCALLBACKMASK = LVM_FIRST + 11


Global Const LVNI_ALL = &H0000

Global Const LVNI_FOCUSED = &H0001

Global Const LVNI_SELECTED = &H0002

Global Const LVNI_CUT = &H0004

Global Const LVNI_DROPHILITED = &H0008


Global Const LVNI_ABOVE = &H0100

Global Const LVNI_BELOW = &H0200

Global Const LVNI_TOLEFT = &H0400

Global Const LVNI_TORIGHT = &H0800


'With FINDITEM and LV_FINDINFO only in conjuction with LV_ITEM

Global Const LVFI_PARAM = &H0001 'Searches based on the lParam member.

Global Const LVFI_STRING = &H0002 'Searches exact ItemText of psz member of ITEM_INFO

Global Const LVFI_PARTIAL = &H0008 'Matches if the item text begins with the string pointed to by the psz member.

Global Const LVFI_WRAP = &H0020 'Continues the search at the beginning if no match is found.

Global Const LVFI_NEARESTXY = &H0040 'Finds the item nearest the specified position in the specified direction.


Type LV_FINDINFO

flags As Long

psz As Long

lParam As Long

pt As POINTAPI

vkDirection As Long

End Type


Type LVFINDINFO

flags As Long

psz As Long

lParam As Long

pt As POINTAPI

vkDirection As Long

End Type


Global Const LVM_FINDITEM = LVM_FIRST + 13

Global Const LVM_FINDITEMW = LVM_FIRST + 83 'unicode


Global Const LVIR_BOUNDS = 0

Global Const LVIR_ICON = 1

Global Const LVIR_LABEL = 2

Global Const LVIR_SELECTBOUNDS = 3

Global Const LVHT_NOWHERE = &H0001

Global Const LVHT_ONITEMICON = &H0002

Global Const LVHT_ONITEMLABEL = &H0004

Global Const LVHT_ONITEMSTATEICON = &H0008

Global Const LVHT_ONITEM = (LVHT_ONITEMICON Or LVHT_ONITEMLABEL Or LVHT_ONITEMSTATEICON)


Global Const LVHT_ABOVE = &H0008

Global Const LVHT_BELOW = &H0010

Global Const LVHT_TORIGHT = &H0020

Global Const LVHT_TOLEFT = &H0040


Type LV_HITTESTINFO

pt As POINTAPI

flags As Long

iItem As Long

End Type


Type LVHITTESTINFO

pt As POINTAPI

flags As Long

iItem As Long

iSubItem As Long

End Type


Global Const LVM_HITTEST = LVM_FIRST + 18

Global Const LVM_ENSUREVISIBLE = LVM_FIRST + 19

Global Const LVM_SCROLL = LVM_FIRST + 20 '*

Global Const LVM_REDRAWITEMS = LVM_FIRST + 21 '*


Type NMLVSCROLL

hdr As NMHDR

dx As Long

dy As Long

End Type


Global Const LVN_BEGINSCROLL = LVN_FIRST - 80

Global Const LVN_ENDSCROLL = LVN_FIRST - 81


Global Const LVA_DEFAULT = &H0000

Global Const LVA_ALIGNLEFT = &H0001

Global Const LVA_ALIGNTOP = &H0002

Global Const LVA_SNAPTOGRID = &H0005


Global Const LVM_ARRANGE = LVM_FIRST + 22

Global Const LVM_EDITLABEL = LVM_FIRST + 23

Global Const LVM_EDITLABELW = LVM_FIRST + 118

Global Const LVM_GETEDITCONTROL = LVM_FIRST + 24


Global Const LVM_GETITEMRECT = LVM_FIRST + 14 '* returned 1/2 pixel height?

Global Const LVM_SETITEMPOSITION = LVM_FIRST + 15

Global Const LVM_GETITEMPOSITION = LVM_FIRST + 16

Global Const LVM_GETSTRINGWIDTH = LVM_FIRST + 17

Global Const LVM_GETSTRINGWIDTHW = LVM_FIRST + 87

Global Const LVM_GETNEXTITEM = LVM_FIRST + 12 '*


Type LV_COLUMN

mask As Long

fmt As Long

cx As Long

pszText As Long

cchTextMax As Long

iSubItem As Long

iImage As Long

iOrder As Long

End Type


Type LVCOLUMN

mask As Long

fmt As Long

cx As Long

pszText As Long

cchTextMax As Long

iSubItem As Long

iImage As Long

iOrder As Long

End Type


Global Const LVCF_FMT = &H0001

Global Const LVCF_WIDTH = &H0002

Global Const LVCF_TEXT = &H0004

Global Const LVCF_SUBITEM = &H0008

Global Const LVCF_IMAGE = &H0010

Global Const LVCF_ORDER = &H0020



Global Const LVCFMT_LEFT = &H00000000

Global Const LVCFMT_RIGHT = &H00000001

Global Const LVCFMT_CENTER = &H00000002

Global Const LVCFMT_JUSTIFYMASK = &H00000003

Global Const LVCFMT_IMAGE = &H00000800

Global Const LVCFMT_BITMAP_ON_RIGHT = &H00001000

Global Const LVCFMT_COL_HAS_IMAGES = &H00008000


Global Const LVM_GETCOLUMN = LVM_FIRST + 25

Global Const LVM_GETCOLUMNW = LVM_FIRST + 95 'unicode

Global Const LVM_SETCOLUMN = LVM_FIRST + 26

Global Const LVM_SETCOLUMNW = LVM_FIRST + 96 'unicode

Global Const LVM_INSERTCOLUMN = LVM_FIRST + 27 '*

Global Const LVM_INSERTCOLUMNW = LVM_FIRST + 97 'unicode

Global Const LVM_GETCOLUMNWIDTH = LVM_FIRST + 29 '*

Global Const LVM_SETCOLUMNWIDTH = LVM_FIRST + 30 '*


'lparam for column width

Global Const LVSCW_AUTOSIZE = -1 '* Automatically sizes the column.

Global Const LVSCW_AUTOSIZE_USEHEADER = -2 '* Automatically sizes the column to fit the header text.


Global Const LVM_GETHEADER = LVM_FIRST + 31

Global Const LVM_CREATEDRAGIMAGE = LVM_FIRST + 33


Global Const LVM_GETVIEWRECT = LVM_FIRST + 34

Global Const LVM_GETTEXTCOLOR = LVM_FIRST + 35 '*

Global Const LVM_SETTEXTCOLOR = LVM_FIRST + 36 '*

Global Const LVM_GETTEXTBKCOLOR = LVM_FIRST + 37 '*

Global Const LVM_SETTEXTBKCOLOR = LVM_FIRST + 38 '*

Global Const LVM_GETTOPINDEX = LVM_FIRST + 39 '*


Global Const LVM_GETCOUNTPERPAGE = LVM_FIRST + 40

Global Const LVM_GETORIGIN = LVM_FIRST + 41 '* only in icon view 0 or 1

Global Const LVM_UPDATE = LVM_FIRST + 42


Global Const LVM_SETITEMSTATE = LVM_FIRST + 43

Global Const LVM_GETITEMSTATE = LVM_FIRST + 44


Global Const LVM_GETITEMTEXT = (LVM_FIRST + 45) '*

Global Const LVM_GETITEMTEXTW = (LVM_FIRST + 115) 'unicode

Global Const LVM_SETITEMTEXT = LVM_FIRST + 46 '*

Global Const LVM_SETITEMTEXTW = LVM_FIRST + 116 'unicode


' these flags only apply to LVS_OWNERDATA listviews in report or list mode

Global Const LVSICF_NOINVALIDATEALL = &H00000001

Global Const LVSICF_NOSCROLL = &H00000002


Global Const LVM_SETITEMCOUNT = LVM_FIRST + 47

Global Const LVM_SORTITEMS = LVM_FIRST + 48

Global Const LVM_SETITEMPOSITION32 = LVM_FIRST + 49

Global Const LVM_GETSELECTEDCOUNT = LVM_FIRST + 50

Global Const LVM_GETITEMSPACING = LVM_FIRST + 51 '* only in icon view 0 or 1

Global Const LVM_GETISEARCHSTRING = LVM_FIRST + 52

Global Const LVM_GETISEARCHSTRINGW = LVM_FIRST + 117

Global Const LVM_SETICONSPACING = LVM_FIRST + 53


Global Const LVM_GETSUBITEMRECT = LVM_FIRST + 56

Global Const LVM_SUBITEMHITTEST = LVM_FIRST + 57

Global Const LVM_SETCOLUMNORDERARRAY = LVM_FIRST + 58

Global Const LVM_GETCOLUMNORDERARRAY = LVM_FIRST + 59

Global Const LVM_SETHOTITEM = LVM_FIRST + 60

Global Const LVM_GETHOTITEM = LVM_FIRST + 61

Global Const LVM_SETHOTCURSOR = LVM_FIRST + 62

Global Const LVM_GETHOTCURSOR = LVM_FIRST + 63

Global Const LVM_APPROXIMATEVIEWRECT = LVM_FIRST + 64

Global Const LV_MAX_WORKAREAS = 16

Global Const LVM_SETWORKAREAS = LVM_FIRST + 65

Global Const LVM_GETWORKAREAS = LVM_FIRST + 70

Global Const LVM_GETNUMBEROFWORKAREAS = LVM_FIRST + 73

Global Const LVM_GETSELECTIONMARK = LVM_FIRST + 66

Global Const LVM_SETSELECTIONMARK = LVM_FIRST + 67

Global Const LVM_SETHOVERTIME = LVM_FIRST + 71

Global Const LVM_GETHOVERTIME = LVM_FIRST + 72

Global Const LVM_SETTOOLTIPS = LVM_FIRST + 74

Global Const LVM_GETTOOLTIPS = LVM_FIRST + 78

Global Const LVM_SORTITEMSEX = LVM_FIRST + 81


Type LVBKIMAGE

ulFlags As Long ' LVBKIF_*

hbm As Long

pszImage As Long

cchImageMax As Long

xOffsetPercent As Long

yOffsetPercent As Long

End Type


Global Const LVBKIF_SOURCE_NONE = &H00000000

Global Const LVBKIF_SOURCE_HBITMAP = &H00000001

Global Const LVBKIF_SOURCE_URL = &H00000002

Global Const LVBKIF_SOURCE_MASK = &H00000003

Global Const LVBKIF_STYLE_NORMAL = &H00000000

Global Const LVBKIF_STYLE_TILE = &H00000010

Global Const LVBKIF_STYLE_MASK = &H00000010

Global Const LVBKIF_FLAG_TILEOFFSET = &H00000100

Global Const LVBKIF_TYPE_WATERMARK = &H10000000


Global Const LVM_SETBKIMAGE = LVM_FIRST + 68

Global Const LVM_SETBKIMAGEW = LVM_FIRST + 138

Global Const LVM_GETBKIMAGE = LVM_FIRST + 69

Global Const LVM_GETBKIMAGEW = LVM_FIRST + 139


Global Const LVM_SETSELECTEDCOLUMN = (LVM_FIRST + 140)

Global Const LVM_SETTILEWIDTH = (LVM_FIRST + 141)

Global Const LV_VIEW_ICON = &H0000

Global Const LV_VIEW_DETAILS = &H0001

Global Const LV_VIEW_SMALLICON = &H0002

Global Const LV_VIEW_LIST = &H0003

Global Const LV_VIEW_TILE = &H0004

Global Const LV_VIEW_MAX = &H0004


Global Const LVM_SETVIEW = (LVM_FIRST + 142)

Global Const LVM_GETVIEW = (LVM_FIRST + 143)

Global Const LVGF_NONE = &H00000000

Global Const LVGF_HEADER = &H00000001

Global Const LVGF_FOOTER = &H00000002

Global Const LVGF_STATE = &H00000004

Global Const LVGF_ALIGN = &H00000008

Global Const LVGF_GROUPID = &H00000010


Global Const LVGS_NORMAL = &H00000000

Global Const LVGS_COLLAPSED = &H00000001

Global Const LVGS_HIDDEN = &H00000002


Global Const LVGA_HEADER_LEFT = &H00000001

Global Const LVGA_HEADER_CENTER = &H00000002

Global Const LVGA_HEADER_RIGHT = &H00000004 ' Don't forget to validate exclusivity

Global Const LVGA_FOOTER_LEFT = &H00000008

Global Const LVGA_FOOTER_CENTER = &H00000010

Global Const LVGA_FOOTER_RIGHT = &H00000020 ' Don't forget to validate exclusivity


' MSDN documents this type as LV_GROUP

Type LVGROUP

cbSize As Long

mask As Long

pszHeader As Long ' UnicodeZ string ptr

cchHeader As Long

pszFooter As Long ' UnicodeZ string ptr

cchFooter As Long

iGroupId As Long

stateMask As Long

state As Long

uAlign As Long

End Type


Global Const LVM_INSERTGROUP = (LVM_FIRST + 145)

Global Const LVM_SETGROUPINFO = (LVM_FIRST + 147)

Global Const LVM_GETGROUPINFO = (LVM_FIRST + 149)

Global Const LVM_REMOVEGROUP = (LVM_FIRST + 150)

Global Const LVM_MOVEGROUP = (LVM_FIRST + 151)

Global Const LVM_MOVEITEMTOGROUP = (LVM_FIRST + 154)

Global Const LVGMF_NONE = &H00000000

Global Const LVGMF_BORDERSIZE = &H00000001

Global Const LVGMF_BORDERCOLOR = &H00000002

Global Const LVGMF_TEXTCOLOR = &H00000004


Type LVGROUPMETRICS

cbSize As Long

mask As Long

nLeft As Long

nTop As Long

nRight As Long

nBottom As Long

crLeft As Long

crTop As Long

crRight As Long

crBottom As Long

crHeader As Long

crFooter As Long

End Type


Global Const LVM_SETGROUPMETRICS = (LVM_FIRST + 155)

Global Const LVM_GETGROUPMETRICS = (LVM_FIRST + 156)

Global Const LVM_ENABLEGROUPVIEW = (LVM_FIRST + 157)

Global Const LVM_SORTGROUPS = (LVM_FIRST + 158)


Type LVINSERTGROUPSORTED

pfnGroupCompare As Long

pvData As Long

lvGrp As LVGROUP

End Type


Global Const LVM_INSERTGROUPSORTED = (LVM_FIRST + 159)


' MSDN documents a third index parameter, apparently incorrectly.

Global Const LVM_REMOVEALLGROUPS = (LVM_FIRST + 160)

Global Const LVM_HASGROUP = (LVM_FIRST + 161)


'LVTV tile view only

Global Const LVTVIF_AUTOSIZE = &H00000000

Global Const LVTVIF_FIXEDWIDTH = &H00000001

Global Const LVTVIF_FIXEDHEIGHT = &H00000002

Global Const LVTVIF_FIXEDSIZE = &H00000003


Global Const LVTVIM_TILESIZE = &H00000001

Global Const LVTVIM_COLUMNS = &H00000002

Global Const LVTVIM_LABELMARGIN = &H00000004


Type LVTILEVIEWINFO

cbSize As Long

dwMask As Long ' LVTVIM_

dwFlags As Long ' LVTVIF_

sizeTile As SIZE

cLines As Long

rcLabelMargin As RECT

End Type


Type LVTILEINFO

cbSize As Long

iItem As Long

cColumns As Long

puColumns As Long

End Type


'tile view

Global Const LVM_SETTILEVIEWINFO = (LVM_FIRST + 162)

Global Const LVM_GETTILEVIEWINFO = (LVM_FIRST + 163)

Global Const LVM_SETTILEINFO = (LVM_FIRST + 164)

Global Const LVM_GETTILEINFO = (LVM_FIRST + 165)


Type LVINSERTMARK

cbSize As Long

dwFlags As Long

iItem As Long

dwReserved As Long

End Type


Global Const LVIM_AFTER = &H00000001 ' TRUE = insert After iItem, otherwise before

Global Const LVM_SETINSERTMARK = (LVM_FIRST + 166)

Global Const LVM_GETINSERTMARK = (LVM_FIRST + 167)

Global Const LVM_INSERTMARKHITTEST = (LVM_FIRST + 168)

Global Const LVM_GETINSERTMARKRECT = (LVM_FIRST + 169)

Global Const LVM_SETINSERTMARKCOLOR = (LVM_FIRST + 170)

Global Const LVM_GETINSERTMARKCOLOR = (LVM_FIRST + 171)


Type LVSETINFOTIP

cbSize As Long

dwFlags As Long

pszText As Long ' Unicode string ptr

iItem As Long

iSubItem As Long

End Type


Global Const LVM_SETINFOTIP = (LVM_FIRST + 173)

Global Const LVM_GETSELECTEDCOLUMN = (LVM_FIRST + 174)

Global Const LVM_ISGROUPVIEWENABLED = (LVM_FIRST + 175)

Global Const LVM_GETOUTLINECOLOR = (LVM_FIRST + 176)

Global Const LVM_SETOUTLINECOLOR = (LVM_FIRST + 177)

Global Const LVM_CANCELEDITLABEL = (LVM_FIRST + 179)


' These next to methods make it easy to identify an item

' that can be repositioned within listview.

' For example: Many developers use the lParam to store an

' identifier that is unique.

' Unfortunately, in order to find this item, they have to

' iterate through all of the items in the listview.

' Listview will maintain a unique identifier.

' The upper bound is the size of a Long.


Global Const LVM_MAPINDEXTOID = (LVM_FIRST + 180)

Global Const LVM_MAPIDTOINDEX = (LVM_FIRST + 181)


Type NM_LISTVIEW

hdr As NMHDR

iItem As Long

iSubItem As Long

uNewState As Long

uOldState As Long

uChanged As Long

ptAction As POINTAPI

lParam As Long

End Type


Type NMLISTVIEW

hdr As NMHDR

iItem As Long

iSubItem As Long

uNewState As Long

uOldState As Long

uChanged As Long

ptAction As POINTAPI

lParam As Long

End Type


' NMITEMACTIVATE is used instead of NMLISTVIEW in IE >= 0x400

' therefore all the fields are the same except for extra uKeyFlags

' they are used to store key flags at the time of the single click with

' delayed activation - because by the time the timer goes off a user may

' not hold the keys (shift, ctrl) any more


Type NMITEMACTIVATE

hdr As NMHDR

iItem As Long

iSubItem As Long

uNewState As Long

uOldState As Long

uChanged As Long

ptAction As POINTAPI

lParam As Long

uKeyFlags As Long

End Type


' key flags stored in uKeyFlags

Global Const LVKF_ALT = &H0001

Global Const LVKF_CONTROL = &H0002

Global Const LVKF_SHIFT = &H0004


Type NMLVCUSTOMDRAW

nmcd As NMCUSTOMDRAW

clrText As Long

clrTextBk As Long

iSubItem As Long

dwItemType As Long

' Item custom draw

clrFace As Long

iIconEffect As Long

iIconPhase As Long

iPartId As Long

iStateId As Long

' Group Custom Draw

rcText As RECT

uAlign As Long ' Alignment. Use LVGA_HEADER_CENTER, LVGA_HEADER_RIGHT, LVGA_HEADER_LEFT

End Type


' dwItemType

Global Const LVCDI_ITEM = &H00000000

Global Const LVCDI_GROUP = &H00000001


' ListView custom draw return values

Global Const LVCDRF_NOSELECT = &H00010000

Global Const LVCDRF_NOGROUPFRAME = &H00020000


Type NMLVCACHEHINT

hdr As NMHDR

iFrom As Long

iTo As Long

End Type


Type NM_CACHEHINT

hdr As NMHDR

iFrom As Long

iTo As Long

End Type


Type NMLVFINDITEM

hdr As NMHDR

iStart As Long

lvfi As LVFINDINFO

End Type


Type NM_FINDITEM

hdr As NMHDR

iStart As Long

lvfi As LVFINDINFO

End Type


Type NMLVODSTATECHANGE

hdr As NMHDR

iFrom As Long

iTo As Long

uNewState As Long

uOldState As Long

End Type


Type NM_ODSTATECHANGE

hdr As NMHDR

iFrom As Long

iTo As Long

uNewState As Long

uOldState As Long

End Type


'LVN WM_NOTIFY event messages sent to parent window or form

Global Const LVN_ITEMCHANGING = LVN_FIRST

Global Const LVN_ITEMCHANGED = LVN_FIRST - 1

Global Const LVN_INSERTITEM = LVN_FIRST - 2 '* parent window notification

Global Const LVN_DELETEITEM = LVN_FIRST - 3 '* parent window notification

Global Const LVN_DELETEALLITEMS = LVN_FIRST - 4 '* parent window notification

Global Const LVN_BEGINLABELEDIT = LVN_FIRST - 5

Global Const LVN_BEGINLABELEDITW = LVN_FIRST - 75

Global Const LVN_ENDLABELEDIT = LVN_FIRST - 6

Global Const LVN_ENDLABELEDITW = LVN_FIRST - 76

Global Const LVN_COLUMNCLICK = LVN_FIRST - 8

Global Const LVN_BEGINDRAG = LVN_FIRST - 9

Global Const LVN_BEGINRDRAG = LVN_FIRST - 11


Global Const LVN_ODCACHEHINT = LVN_FIRST - 13

Global Const LVN_ODFINDITEM = LVN_FIRST - 52

Global Const LVN_ODFINDITEMW = LVN_FIRST - 79


Global Const LVN_ITEMACTIVATE = LVN_FIRST - 14

Global Const LVN_ODSTATECHANGED = LVN_FIRST - 15


Global Const LVN_HOTTRACK = LVN_FIRST - 21


Global Const LVN_GETDISPINFO = LVN_FIRST - 50

Global Const LVN_GETDISPINFOW = LVN_FIRST - 77

Global Const LVN_SETDISPINFO = LVN_FIRST - 51

Global Const LVN_SETDISPINFOW = LVN_FIRST - 78


Global Const LVIF_DI_SETITEM = &H1000


Type LV_DISPINFO

hdr As NMHDR

item As LV_ITEM

End Type


Type NMLVDISPINFO

hdr As NMHDR

item As LVITEM

End Type


Global Const LVN_KEYDOWN = LVN_FIRST - 55


°Type LV_KEYDOWN Packed 1

°hdr As NMHDR

°wVKey As Word

°flags As Long

°End Type

°

°Type NMLVKEYDOWN Packed 1

°hdr As NMHDR

°wVKey As Word

°flags As Long

°End Type


Global Const LVN_MARQUEEBEGIN = LVN_FIRST - 56


Type NMLVGETINFOTIP

hdr As NMHDR

dwFlags As Long

pszText As Long

cchTextMax As Long

iItem As Long

iSubItem As Long

lParam As Long

End Type


' NMLVGETINFOTIPA.dwFlag values


Global Const LVGIT_UNFOLDED = &H0001


Global Const LVN_GETINFOTIP = LVN_FIRST - 57

Global Const LVN_GETINFOTIPW = LVN_FIRST - 58


'************************************************

'extended appearance styles and behaviors

' -1 for cx and cy means we'll use the default (system settings)

' 0 for cx or cy means use the current setting (allows you to change just one param)

Global Const LVM_SETEXTENDEDLISTVIEWSTYLE = LVM_FIRST + 54 ' optional wParam == mask

Global Const LVM_GETEXTENDEDLISTVIEWSTYLE = LVM_FIRST + 55


'***available only in some newer common control DLL

'versions 4.73, 6.0 or Vista only

'and may not be available for previous versions

'of windows

Global Const LVS_EX_GRIDLINES = &H00000001

Global Const LVS_EX_SUBITEMIMAGES = &H00000002

Global Const LVS_EX_CHECKBOXES = &H00000004

Global Const LVS_EX_TRACKSELECT = &H00000008

Global Const LVS_EX_HEADERDRAGDROP = &H00000010

Global Const LVS_EX_FULLROWSELECT = &H00000020 ' applies to report mode only


Global Const LVS_EX_ONECLICKACTIVATE = &H00000040

Global Const LVS_EX_TWOCLICKACTIVATE = &H00000080

Global Const LVS_EX_FLATSB = &H00000100

Global Const LVS_EX_REGIONAL = &H00000200

Global Const LVS_EX_INFOTIP = &H00000400 ' listview does InfoTips for you

Global Const LVS_EX_UNDERLINEHOT = &H00000800

Global Const LVS_EX_UNDERLINECOLD = &H00001000

Global Const LVS_EX_MULTIWORKAREAS = &H00002000

Global Const LVS_EX_LABELTIP = &H00004000 ' listview unfolds partly hidden labels if it does not have infotip text

Global Const LVS_EX_BORDERSELECT = &H00008000 ' border selection style instead of highlight

Global Const LVS_EX_DOUBLEBUFFER = &H00010000

Global Const LVS_EX_HIDELABELS = &H00020000

Global Const LVS_EX_SINGLEROW = &H00040000

Global Const LVS_EX_SNAPTOGRID = &H00080000 ' Icons automatically snap to grid.

Global Const LVS_EX_SIMPLESELECT = &H00100000 ' Also changes overlay rendering to top right for icon mode.


Return

Sub cmdParam_Click


Try

frmParam.Enabled = True

frmParam.Visible = True

lbParam.Clear

Catch 'still need this after a close

LoadForm frmParam

frmParam.Enabled = True

frmParam.Visible = True

lbParam.Clear

EndCatch

~SetForegroundWindow(frmParam.hWnd)

@GetListviewDimensions


EndSub

Procedure GetListviewDimensions


Local lvNumItems As Int

lvNumItems = SendMessage(lv.hWnd, LVM_GETITEMCOUNT, 0, 0)


For n_lp% = 1 To lvNumCols


ret = SendMessage(lv.hWnd, LVM_GETCOLUMNWIDTH, n_lp%, 0)


If ret > 0

ColWidth$(n_lp%) = " cell width = " + Str(Round(ret, 2)) + " "

lbParam.AddItem "Listview column #" + Str(n_lp%) + " cell width = " + Str(Round(ret, 2)) + " "

Else

'MsgBox "list-view control is not in incremental search mode"

EndIf


Next n_lp%


Return

Sub lvCellParam_Close(Cancel?)

Set frmLvColor = Nothing

End

EndSub

Sub cmdGETBKCOLOR_Click

COLORREF = SendMessage(lv.hWnd, LVM_GETBKCOLOR, 0, 0)

'The COLORREF value is a 32-bit value used to specify an RGB color.

'When specifying an explicit RGB color, the COLORREF value has the

'following hexadecimal form:

'0x00bbggrr

red| = Peek(V:COLORREF)

green| = Peek(V:COLORREF + 1)

blue| = Peek(V:COLORREF + 2)

MsgBox "The color GETBKCOLOR is RGB(" + Str(red|) + "," + Str(green|) + "," + Str(blue|) + ")"


EndSub

Sub cmdSETBKCOLOR_Click


Local CRgb|(3)

Local CRgb%

CRgb|(0) = 136 'r

CRgb|(1) = 0 'g

CRgb|(2) = 255 'b

BMove V:CRgb|(0), V:CRgb%, 3

'0x00bbggrr


ret = SendMessage(lv.hWnd, LVM_SETBKCOLOR, 0, CRgb%)

'must redraw to show

ICOUNT = SendMessage(lv.hWnd, LVM_GETITEMCOUNT, 0, 0) 'items

ret = SendMessage(lv.hWnd, LVM_REDRAWITEMS , 0, ICOUNT) 'redraw


DoEvents

MsgBox "The color SETBKCOLOR is RGB(" + Str(CRgb|(0)) + "," + Str(CRgb|(1)) + "," + Str(CRgb|(2)) + ")"


'equivilent to

'red| = 136

'green| = 0

'blue| = 255

'lv.BackColor = RGB(red|, green|, blue|)

EndSub

Sub cmdGETTEXTCOLOR_Click


COLORREF = SendMessage(lv.hWnd, LVM_GETTEXTCOLOR, 0, 0)

red| = Peek(V:COLORREF)

green| = Peek(V:COLORREF + 1)

blue| = Peek(V:COLORREF + 2)

MsgBox "The color GETTEXTCOLOR is RGB(" + Str(red|) + "," + Str(green|) + "," + Str(blue|) + ")"


'no equivilent in object parameters build 1166

EndSub

Sub cmdSETTEXTCOLOR_Click


Local CRgb|(3)

Local CRgb%

CRgb|(0) = 136 'r

CRgb|(1) = 0 'g

CRgb|(2) = 255 'b

BMove V:CRgb|(0), V:CRgb%, 3

'0x00bbggrr


ret = SendMessage(lv.hWnd, LVM_SETTEXTCOLOR, 0, CRgb%) 'cell text color

'must redraw to show

ICOUNT = SendMessage(lv.hWnd, LVM_GETITEMCOUNT, 0, 0) 'items

ret = SendMessage(lv.hWnd, LVM_REDRAWITEMS , 0, ICOUNT) 'redraw

DoEvents

MsgBox "The color SETTEXTCOLOR is RGB(" + Str(CRgb|(0)) + "," + Str(CRgb|(1)) + "," + Str(CRgb|(2)) + ")"


'equivilent to

'red| = 0

'green| = 0

'blue| = 255

'lv.ForeColor = RGB(red|, green|, blue|)

EndSub

Sub cmdSETTEXTBKCOLOR_Click


Local CRgb|(3)

Local CRgb%

CRgb|(0) = 240 'r

CRgb|(1) = 255 'g

CRgb|(2) = 255 'b

BMove V:CRgb|(0), V:CRgb%, 3

'0x00bbggrr


ret = SendMessage(lv.hWnd, LVM_SETTEXTBKCOLOR, 0, CRgb%) 'cell text color

'must redraw to show

ICOUNT = SendMessage(lv.hWnd, LVM_GETITEMCOUNT, 0, 0) 'items

ret = SendMessage(lv.hWnd, LVM_REDRAWITEMS , 0, ICOUNT) 'redraw

DoEvents

MsgBox "The color SETTEXTBKCOLOR is RGB(" + Str(CRgb|(0)) + "," + Str(CRgb|(1)) + "," + Str(CRgb|(2)) + ")"

EndSub

Sub cmdGETTEXTBKCOLOR_Click


COLORREF = SendMessage(lv.hWnd, LVM_GETTEXTBKCOLOR, 0, 0)

red| = Peek(V:COLORREF)

green| = Peek(V:COLORREF + 1)

blue| = Peek(V:COLORREF + 2)

MsgBox "The color GETTEXTBKCOLOR is RGB(" + Str(red|) + "," + Str(green|) + "," + Str(blue|) + ")"


'no equivilent in gb32 object

EndSub

Sub cmdADDITEM_Click

MsgBox "Using method: No single corresponding constant for AddItem "

Local li As ListItem

Set li = lv.AddItem

EndSub

Sub cmdINSERTITEM_Click


'************************

MsgBox "Incomplete in GFA Basic Use AddItem"

'************************


'pointer to win 32 structure

'Dim ITEMA As LV_ITEM

'ADDRITEM = V:ITEMA

'ICOUNT = SendMessage(lv.hWnd, LVM_GETITEMCOUNT, 0, 0) 'items

'MsgBox Str(ICOUNT)

'Itemtext$ = ""


'ITEMA.mask = LVIF_STATE

'ITEMA.iItem = 4

'ITEMA.iSubItem = 0

'ITEMA.STATE = LVIF_STATE

'ITEMA.stateMask = LVIF_STATE

'ITEMA.pszText = V:Itemtext$

'ITEMA.cchTextMax = 0

'ITEMA.iImage = 0

'ITEMA.lParam = 0



'ret = SendMessage(lv.hWnd, LVM_SETITEMCOUNT, 41, 0)

'MsgBox Str(ret)

'ICOUNT = SendMessage(lv.hWnd, LVM_GETITEMCOUNT, 0, 0) 'items

'MsgBox Str(ICOUNT)

'Try

'ret = SendMessage(lv.hWnd, LVM_INSERTITEM , 0 , ADDRITEM)

'MsgBox Str(ret)

'Stop

'Catch

'If dwError <> 0

'dwError = Err.LastDllError

'EndIf

'EndCatch

'-----------------------------

'WM_NOTIFY the parent window

'Local NOTIFYLV As NM_LISTVIEW

'The iItem member identifies the deleted item,

'and the other members are zero. no return vaue.

'NOTIFYLV.iItem = ADDRITEM

'~SendMessage(frmlvCellParam.hWnd, LVN_INSERTITEM, 0, V:NOTIFYLV)

'Note: This could also be flagged in application code and

'may not be nessessary depending on the need.

'ret = SendMessage(lv.hWnd, LVM_REDRAWITEMS , 0, ICOUNT) 'redraw


'Pause 8

'Stop

'MsgBox "Index First Column, Overwrite Text in Row: " + Str(ITEMA.iItem) + " " + Itemtext$



EndSub

Sub cmdGETNEXTITEM_Click


MsgBox "Selects placement before or after a selected item"

'could be used for fast placement of listview item minus scrolling


Set lv.SelectedItem = lv.ListItems(30)

Try

ret = SendMessage(lv.hWnd, LVM_GETNEXTITEM, -1, LVNI_SELECTED | LVNI_ALL )

Catch

If dwError <> 0

dwError = Err.LastDllError

EndIf

EndCatch

MsgBox Str(ret) + " is before the selected item."

'iStart

'Index of the item to begin the searching with, or -1 to find the first item that matches the specified flags. The specified item itself is excluded from the search.

'flags

'Geometric relation of the requested item to the specified item and, if specified, the state of the requested item.

'The geometric relation can be one of the following values:

'Value Meaning

'LVNI_ABOVE Searches for an item that is above the specified item.

'LVNI_ALL Searches for a subsequent item by index (the default value).

'LVNI_BELOW Searches for an item that is below the specified item.

'LVNI_TOLEFT Searches for an item to the left of the specified item.

'LVNI_TORIGHT Searches for an item to the right of the specified item.


EndSub

Sub cmdSETITEM_Click


MsgBox "added cell highliting"

'pointer to win 32 structure

Local Itemtext$

Itemtext$ = "New Item"

'MsgBox SizeOf(LV_ITEM)

ADDRITEM = V:ITEMA

ITEMA.mask = LVIF_TEXT

ITEMA.iItem = 3

ITEMA.iSubItem = 3 'must or should be set to 0. use SETITEM TEXT for text in the general case

ITEMA.STATE = LVIS_SELECTED

ITEMA.stateMask = LVIS_SELECTED

ITEMA.pszText = V:Itemtext$

ITEMA.cchTextMax = 100

ITEMA.iImage = 0

ITEMA.lParam = 0


Local CRgb|(3)

Local CRgb%

CRgb|(0) = 136 'r

CRgb|(1) = 0 'g

CRgb|(2) = 255 'b

BMove V:CRgb|(0), V:CRgb%, 3

'0x00bbggrr


ret = SendMessage(lv.hWnd, LVM_SETTEXTCOLOR, 0, CRgb%) 'cell text color

'~SendMessage(lv.hWnd, LVM_SETITEMSTATE , 3 , V:ITEMA)

ret = SendMessage(lv.hWnd, LVM_SETITEM, ITEMA.iItem - 1, ADDRITEM)

MsgBox "SETITEM Item Index: " + Str(ITEMA.iItem) + " in Subitem Column: " + Str(ITEMA.iSubItem) + " Text: " + Itemtext$

CRgb|(0) = 0 'r

CRgb|(1) = 0 'g

CRgb|(2) = 0 'b

BMove V:CRgb|(0), V:CRgb%, 3

'0x00bbggrr


ret = SendMessage(lv.hWnd, LVM_SETTEXTCOLOR, 0, CRgb%) 'cell text color

EndSub

Sub cmdGETITEM_Click


'returns info from an item struct buffer, probably known anyway


Itemtext$ = "Get Item"


ITEMA.mask = LVIF_TEXT

ITEMA.iItem = 3

ITEMA.iSubItem = 0 'must or should be set to 0

ITEMA.STATE = 0

ITEMA.stateMask = LVIF_TEXT

ITEMA.pszText = V:Itemtext$


ret = SendMessage(lv.hWnd, LVM_SETITEM, ITEMA.iItem - 1, ADDRITEM)

Try

ret = SendMessage(lv.hWnd, LVM_GETITEM, ITEMA.iItem - 1, ADDRITEM)

Catch

If dwError <> 0

dwError = Err.LastDllError

EndIf

EndCatch

MsgBox "GETITEM info after buffered, Index: " + Str(ITEMA.iItem) + " in Subitem Column: " + Str(ITEMA.iSubItem) + " Text: " + Itemtext$


EndSub

Sub cmdDELETEITEM_Click


Local DELITEM = 6

'for item Option Base 0

'in the item array index 6 = Item 7

Try

ret = SendMessage(lv.hWnd, LVM_DELETEITEM, DELITEM , 0)

Catch

If dwError <> 0

dwError = Err.LastDllError

EndIf

EndCatch

MsgBox "Deleted Line Item: " + Str(DELITEM + 1) + " Item Index: " + Str(DELITEM)


'-----------------------------

'WM_NOTIFY the parent window

Local NOTIFYLV As NM_LISTVIEW

'The iItem member identifies the deleted item,

'and the other members are zero. no return vaue.

NOTIFYLV.iItem = DELITEM

~SendMessage(frmlvCellParam.hWnd, LVN_DELETEITEM, 0, V:NOTIFYLV)

'Note: This could also be flagged in application code and

'may not be nessessary depending on the need.


EndSub

Sub cmdDELETEALLITEMS_Click


Try

ret = SendMessage(lv.hWnd, LVM_DELETEALLITEMS, 0 , 0)

Catch

If dwError <> 0

dwError = Err.LastDllError

EndIf

EndCatch

MsgBox "All Items Deleted"


'The LVN_DELETEALLITEMS notification message notifies

'a list view control's parent window that all items in

'the control were deleted. This notification message

'is sent in the form of a WM_NOTIFY message.


'notify parent window

'Note: This could also be flagged in application code and may not be needed.

Local NOTIFYLV As NM_LISTVIEW

NOTIFYLV.iItem = -1

~SendMessage(frmlvCellParam.hWnd, LVN_DELETEALLITEMS, 0, V:NOTIFYLV)


EndSub

Sub cmdGETITEMTEXT_Click


'returns info from an item struct buffer, probably known anyway


Itemtext$ = "Get SubItem"


ITEMA.mask = LVIF_TEXT

ITEMA.iItem = 3

ITEMA.iSubItem = 3

ITEMA.STATE = 0

ITEMA.stateMask = LVIF_TEXT

ITEMA.pszText = V:Itemtext$


ret = SendMessage(lv.hWnd, LVM_SETITEMTEXT, ITEMA.iItem - 1, ADDRITEM)

Try

ret = SendMessage(lv.hWnd, LVM_GETITEMTEXT, ITEMA.iItem - 1, ADDRITEM)

Catch

If dwError <> 0

dwError = Err.LastDllError

EndIf

EndCatch

MsgBox "GETSUBITEM info in buffered, Set Index: " + Str(ITEMA.iItem) + " in Subitem Column: " + Str(ITEMA.iSubItem) + " Text: " + Itemtext$


EndSub

Sub cmdSETITEMTEXT_Click


'pointer to win 32 structure

Local Itemtext$

Itemtext$ = "New SubItem"

'MsgBox SizeOf(LV_ITEM)

ADDRITEM = V:ITEMA

ITEMA.mask = LVIF_TEXT

ITEMA.iItem = 4

ITEMA.iSubItem = 2

ITEMA.STATE = 0

ITEMA.stateMask = LVIF_TEXT

ITEMA.pszText = V:Itemtext$

ITEMA.cchTextMax = 32767

ITEMA.iImage = 0

ITEMA.lParam = 0

ret = SendMessage(lv.hWnd, LVM_SETITEMTEXT, ITEMA.iItem - 1, ADDRITEM)

MsgBox "SETITEMTXT Item Index: " + Str(ITEMA.iItem) + " in Subitem Column: " + Str(ITEMA.iSubItem) + " Text: " + Itemtext$


EndSub

Sub cmdGETTOPINDEX_Click

If lv.View = 2 Or lv.View = 3 'list or report view

MsgBox "Returns the topmost visible item when in list or report view only."

ret = SendMessage(lv.hWnd, LVM_GETTOPINDEX, 0, 0)

MsgBox "The Top Visible Item is currently " + Str(ret + 1) + " after the columnheader."

EndIf

EndSub

Sub cmdGETITEMCOUNT_Click

ret = SendMessage(lv.hWnd, LVM_GETITEMCOUNT, 0, 0)

MsgBox "The Item Count is currently " + Str(ret) + " after the columnheader."

EndSub

Sub cmdGETITEMSTATE_Click

'returns info from an item struct buffer, probably known anyway


Itemtext$ = "Get SubItem"


ITEMA.mask = LVIF_STATE

ITEMA.iItem = 3

ITEMA.iSubItem = 3

ITEMA.STATE = LVIF_STATE

ITEMA.stateMask = LVIF_STATE

ITEMA.pszText = V:Itemtext$


'wparam is the index of the list view item

Try

ret = SendMessage(lv.hWnd, LVM_GETITEMSTATE, 1, ADDRITEM)

Catch

If dwError <> 0

dwError = Err.LastDllError

EndIf

EndCatch

MsgBox "GETSUBITEM STATE info in buffered LV_ITEM Get Index: " + Str(ITEMA.iItem) + " in Subitem Column: " + Str(ITEMA.iSubItem) + " STATE flags returned: " + Str(ret)


EndSub

Sub cmdSETITEMSTATE_Click

lv.FullRowSelect = False


'thus far unable to select an indivisual cell or cell textcolor

'Local CRgb|(3)

'Local CRgb%

'CRgb|(0) = 136 'r

'CRgb|(1) = 0 'g

'CRgb|(2) = 255 'b

'BMove V:CRgb|(0), V:CRgb%, 3

'0x00bbggrr

'ret = SendMessage(lv.hWnd, LVM_SETTEXTCOLOR, 1, CRgb%) 'cell text color


MsgBox "Uses FullRowSelect True or False, if False then first or label column only."

Local a$ = "Item Text"

ITEMA.mask = LVIF_STATE

ITEMA.iItem = 1 'row

ITEMA.iSubItem = 3 'column

ITEMA.pszText = V:a$

ITEMA.cchTextMax = 32

ITEMA.stateMask = LVIS_SELECTED

ITEMA.STATE = LVIS_SELECTED


~SendMessage(lv.hWnd, LVM_SETITEMSTATE , 1 , V:ITEMA)

ret = SendMessage(lv.hWnd, LVM_REDRAWITEMS , 1, 1) 'redraw

If LVIS_SELECTED Then

MsgBox "Selected: " + a$

Else

MsgBox "Was not selected"

EndIf


EndSub

Sub cmdGETCOUNTPERPAGE_Click

ret = SendMessage(lv.hWnd, LVM_GETCOUNTPERPAGE , 0 , 0)

MsgBox "Viewable cells in page " + Str(ret)

EndSub

Sub cmdINSERTCOLUMN_Click


'insert first column:

COLUMN.mask = LVCF_WIDTH Or LVCF_TEXT

COLUMN.cx = 90

Itemtext$ = "New Column"

COLUMN.pszText = V:Itemtext$

~SendMessage(lv.hWnd, LVM_INSERTCOLUMN , 1 , V:COLUMN)

MsgBox "Column to be inserted Second Position"

MsgBox "The columheader label was changed!"


EndSub

Sub cmdGETCOLUMNWIDTH_Click

ret = SendMessage(lv.hWnd, LVM_GETCOLUMNWIDTH, 2, 0)

MsgBox "Column 2 Width" + Str(ret)

EndSub

Sub cmdSETCOLUMNWIDTH_Click

'wparam is the column

'LVSCW_AUTOSIZE Automatically sizes the column

'LVSCW_AUTOSIZE_USEHEADER Automatically sizes the column to fit the header text.

'or size width to listview coordinates

ret = SendMessage(lv.hWnd, LVM_SETCOLUMNWIDTH, 2, 170)

MsgBox "Column 2 Width Resized to 170"

EndSub

Sub cmdGETORIGIN_Click

If lv.View < 2

Local OriPt As POINTAPI 'type point for location

ret = SendMessage(lv.hWnd, LVM_GETORIGIN , 0, V:OriPt)

MsgBox "Listview Origin x =" + Str(OriPt.x) = " y =" + Str(OriPt.y)

Else

MsgBox "Listview is not in Icon mode for GETORIGIN."

EndIf

EndSub

Sub cmdGETITEMPOSITION_Click

Local OriPt As POINTAPI 'type point for location

Local iNum As Int

iNum = 5

ret = SendMessage(lv.hWnd, LVM_GETITEMPOSITION , iNum, V:OriPt)

MsgBox "Listview Item 2 x =" + Str(OriPt.x) + " y =" + Str(OriPt.y)

EndSub

Sub cmdFINDITEM_Click


'flags

'Type of search to perform. This member can be one or more of the following values:

'Value Meaning

'LVFI_PARAM Searches based on the lParam member.

'The lParam member of the matching item's LV_ITEM structure must match

' the lParam member of this structure.If this value is specified, all other values are ignored.

'LVFI_PARTIAL Matches if the item text begins with the string pointed to by the psz member.

'This value implies use of LVFI_STRING.

'LVFI_STRING Searches based on the item text. Unless additional values are specified,

'the item text of the matching item must exactly match the string pointed to by the psz member.

'LVFI_WRAP Continues the search at the beginning if no match is found.

'LVFI_NEARESTXY Finds the item nearest the specified position in the specified direction.


Local iNum As Int

iNum = 0

Itemtext$ = "Line 22"

ITEMA.mask = LVIF_TEXT

ITEMA.iItem = iNum

ITEMA.iSubItem = 0

ITEMA.STATE = 0

ITEMA.stateMask = LVIF_TEXT

ITEMA.pszText = V:Itemtext$


Local LvFindi As LV_FINDINFO

LvFindi.flags = LVFI_STRING 'LVFI_PARTIAL''

LvFindi.psz = V:Itemtext$

ret = SendMessage(lv.hWnd, LVM_FINDITEM, iNum, V:LvFindi)

MsgBox "Match Item Number =" + Str(ret + 1)


EndSub

Sub lvCellParam_Paint

frmlvCellParam.PaintHeight

frmlvCellParam.PaintLeft

frmlvCellParam.PaintTop

frmlvCellParam.PaintWidth

DoEvents

EndSub

Sub frmLvItems_Close(Cancel?)

frmLvItems.Enabled = False

frmLvItems.Visible = False

EndSub

Sub frmLvColor_Close(Cancel?)

frmLvColor.Enabled = False

frmLvColor.Visible = False

EndSub

Sub frmLvSubItems_Close(Cancel?)

frmLvSubItems.Enabled = False

frmLvSubItems.Visible = False

EndSub

Sub frmParam_Close(Cancel?)

frmParam.Enabled = False

frmParam.Visible = False

EndSub

Sub frmLVColumns_Close(Cancel?)

frmLVColumns.Enabled = False

frmLVColumns.Visible = False

EndSub

Sub frmlvCellParam_Close(Cancel?)

Set frmLvColor = Nothing

Set frmLvItems = Nothing

Set frmLvSubItems = Nothing

Set frmLVColumns = Nothing

Set frmParam = Nothing

EndSub

Sub cmdlvColors_Click

Try

frmLvColor.Enabled = True

frmLvColor.Visible = True

Catch 'still need this after a close

LoadForm frmLvColor

frmLvColor.Enabled = True

frmLvColor.Visible = True

EndCatch

~SetForegroundWindow(frmLvColor.hWnd)

EndSub

Sub cmdLVItems_Click

Try

frmLvItems.Enabled = True

frmLvItems.Visible = True

Catch 'still need this after a close

LoadForm frmLvItems

frmLvItems.Enabled = True

frmLvItems.Visible = True

EndCatch

~SetForegroundWindow(frmLvItems.hWnd)

EndSub

Sub cmdlvColumns_Click

Try

frmLVColumns.Enabled = True

frmLVColumns.Visible = True

Catch 'still need this after a close

LoadForm frmLVColumns

frmLVColumns.Enabled = True

frmLVColumns.Visible = True

EndCatch

~SetForegroundWindow(frmLVColumns.hWnd)

EndSub

Sub cmdLvLocate_Click

Try

frmLvCells.Enabled = True

frmLvCells.Visible = True

Catch 'still need this after a close

LoadForm frmLvCells

frmLvCells.Enabled = True

frmLvCells.Visible = True

EndCatch

~SetForegroundWindow(frmLvCells.hWnd)

EndSub

Sub cmdLVSubItems_Click

Try

frmLvSubItems.Enabled = True

frmLvSubItems.Visible = True

Catch 'still need this after a close

LoadForm frmLvSubItems

frmLvSubItems.Enabled = True

frmLvSubItems.Visible = True

EndCatch

~SetForegroundWindow(frmLvSubItems.hWnd)

EndSub

Sub frmlvCellParam_Message(hWnd%, Mess%, wParam%, lParam%)


'workaround for awful bug in xp gridines with manifest

If MouseX > lv.Left + lv.Width - 24

If MouseX < lv.Left + lv.Width

If MouseY > lv.Top

If MouseY < lv.Top + lv.Height

If MouseK > 0

lv.GridLines = False

lv.Refresh

Else

lv.GridLines = True

lv.Refresh

EndIf

EndIf

EndIf

EndIf

EndIf


EndSub