Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
[blue][COLOR=green]' Derived from an enhanced Listview example written by Yumashin Alexey available on FreeVBCode.com [URL unfurl="true"]http://www.freevbcode.com/ShowCode.asp?ID=7175[/URL][/color]
Option Explicit
Private Declare Function LockWindowUpdate Lib "user32.dll" (ByVal hwndLock As Long) As Long
Private Const LVIF_IMAGE = &H2
Private OnceExecuted As Boolean
Private Sub chkNoFocus_Click()
ListView1.Refresh
ListView1.SetFocus
End Sub
Private Sub chkBorderOnly_Click()
ListView1.SetFocus
ListView1.Refresh
End Sub
Private Sub Form_Activate()
If Not OnceExecuted Then
PopulateListView
SubClass Me.hWnd
OnceExecuted = True
End If
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
UnSubClass
Set Form1 = Nothing
End Sub
Private Sub SubClass(ByVal hWnd As Long)
UnSubClass
mWndProcNext = SetWindowLong(hWnd, GWL_WNDPROC, AddressOf WindowProc)
If mWndProcNext Then mhWndSubClassed = hWnd
End Sub
Private Sub UnSubClass()
If mWndProcNext Then
SetWindowLong mhWndSubClassed, GWL_WNDPROC, mWndProcNext
mWndProcNext = 0
End If
End Sub
Private Sub PopulateListView()
Dim oldExStyle As Long
Dim i As Integer
Dim st As String
Dim tmp As Single
Dim lvItem As ListItem
Dim j As Integer
LockWindowUpdate ListView1.hWnd
ListView1.ColumnHeaders(4).Width = 0
For i = 1 To 30
Set lvItem = ListView1.ListItems.Add(i, , "This item contains text " & i, 3, 3)
With lvItem
.Tag = ""
st = Format$(DateSerial(2005, 1, 31 - i), "dd.mm.yyyy")
.ListSubItems.Add 1, , st
.ListSubItems(1).Tag = Format$(st, "yyyymmddHHMMSS")
tmp = Rnd * 10000
.ListSubItems.Add 2, , Format$(tmp, ".0000")
.ListSubItems(2).Tag = Format$(tmp, "000000000000.0000000000")
.ListSubItems.Add 3, , ""
.ListSubItems(3).Tag = ""
.SmallIcon = 1
.Bold = (i Mod 3 = 0)
.ListSubItems(1).Bold = (i Mod 3 = 0)
.ListSubItems(2).Bold = (i Mod 3 = 0)
If i Mod 4 = 0 Then
.ForeColor = vbRed
For j = 1 To .ListSubItems.Count
.ListSubItems(j).ForeColor = vbRed
Next
End If
End With
Next
ListView1.SortOrder = lvwDescending
ListView1.ListItems(1).Selected = True
LockWindowUpdate 0&
End Sub[/blue]
[blue][COLOR=green]' Derived from an enhanced Listview example written by Yumashin Alexey available on FreeVBCode.com [URL unfurl="true"]http://www.freevbcode.com/ShowCode.asp?ID=7175[/URL][/color]
Option Explicit
Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (lpvDest As Any, lpvSource As Any, ByVal cbCopy As Long)
Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal Hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByRef lParam As Any) As Long
Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal Hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal Hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function DeleteObject Lib "gdi32.dll" (ByVal hObject As Long) As Long
Private Declare Function FillRect Lib "user32.dll" (ByVal hdc As Long, ByRef lpRect As RECT, ByVal hBrush As Long) As Long
Private Declare Function DrawIconEx Lib "user32.dll" (ByVal hdc As Long, ByVal xLeft As Long, ByVal yTop As Long, ByVal hIcon As Long, ByVal cxWidth As Long, ByVal cyWidth As Long, ByVal istepIfAniCur As Long, ByVal hbrFlickerFreeDraw As Long, ByVal diFlags As Long) As Long
Private Declare Function CreateSolidBrush Lib "gdi32" (ByVal crColor As Long) As Long
Private Declare Function FrameRect Lib "user32.dll" (ByVal hdc As Long, ByRef lpRect As RECT, ByVal hBrush As Long) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Type POINTAPI
x As Long
y As Long
End Type
Private Type NMHDR
hwndFrom As Long
idfrom As Long
code As Long
End Type
Private 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
Private Type NMLVCUSTOMDRAW
nmcd As NMCUSTOMDRAW
clrText As Long
clrTextBk As Long
iSubItem As Long
End Type
Private Type lvItem
mask As Long
iItem As Long
iSubItem As Long
state As Long
stateMask As Long
pszText As String
cchTextMax As Long
iImage As Long
lParam As Long
iIndent As Long
End Type
Public Const GWL_WNDPROC = (-4)
Private Const DI_NORMAL As Long = &H3
Private Const NM_FIRST As Long = 0
Private Const NM_CUSTOMDRAW As Long = (NM_FIRST - 12)
Private Const WM_NOTIFY As Long = &H4E
' CustomDraw paint stages.
Private Const CDDS_PREPAINT = &H1
Private Const CDDS_ITEMPREPAINT = (&H10000 Or &H1)
Private Const CDDS_ITEMPOSTPAINT = (&H10000 Or &H2)
' CustomDraw return values.
Private Const CDRF_NOTIFYITEMDRAW = &H20
Private Const CDRF_NOTIFYPOSTPAINT As Long = &H10
Private Const CDRF_DODEFAULT As Long = &H0
Private Const CDRF_NEWFONT As Long = &H2
Private Const CDIS_FOCUS As Long = &H10
Private Const CDIS_SELECTED As Long = &H1
Private Const LVM_FIRST As Long = &H1000
Private Const LVM_GETITEMRECT As Long = (LVM_FIRST + 14)
Private Const LVM_GETSUBITEMRECT As Long = (LVM_FIRST + 56)
Private Const LVIR_ICON As Long = 1
Private Const LVIR_BOUNDS As Long = 0
Public mhWndSubClassed As Long
Public mWndProcNext As Long
Public Function WindowProc(ByVal Hwnd As Long, ByVal uMsg As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long
Dim tNMH As NMHDR
If uMsg = WM_NOTIFY Then
CopyMemory tNMH, ByVal lParam, Len(tNMH)
If tNMH.hwndFrom = Form1.ListView1.Hwnd And tNMH.code = NM_CUSTOMDRAW Then
WindowProc = plCustomDraw(lParam)
Exit Function
End If
End If
WindowProc = CallWindowProc(mWndProcNext, Hwnd, uMsg, wParam, ByVal lParam)
End Function
Private Function plCustomDraw(ByVal lParam As Long) As Long
Dim NMLVCD As NMLVCUSTOMDRAW
Dim lLen As Long
Dim hFont As Long
Dim lvRowIndex As Long
Dim rct As RECT
Dim hBr As Long, bgColor As Long, bdrColor As Long, tmp As Long
Dim LVI As lvItem
' Get the CustomDraw data.
lLen = Len(NMLVCD)
CopyMemory NMLVCD, ByVal lParam, lLen
lvRowIndex = NMLVCD.nmcd.dwItemSpec
Select Case NMLVCD.nmcd.dwDrawStage
Case CDDS_PREPAINT
' Tell it we want to be told when an item is drawn.
plCustomDraw = CDRF_NOTIFYITEMDRAW
Case CDDS_ITEMPREPAINT
If Not (NMLVCD.nmcd.lItemlParam = 0) Then
If Form1.chkNoFocus.Value = 1 Then
' removing focus rect:
NMLVCD.nmcd.uItemState = NMLVCD.nmcd.uItemState And (Not CDIS_FOCUS)
End If
If Form1.chkBorderOnly.Value = 1 Then
' removing standard selection:
NMLVCD.nmcd.uItemState = NMLVCD.nmcd.uItemState And (Not CDIS_SELECTED)
End If
CopyMemory ByVal lParam, NMLVCD, lLen
End If
plCustomDraw = CDRF_NOTIFYPOSTPAINT
Case CDDS_ITEMPOSTPAINT
' ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
If Form1.chkBorderOnly.Value = 1 Then
' replacing color filling with border:
If lvRowIndex + 1 = Form1.ListView1.SelectedItem.Index Then
rct.Left = LVIR_ICON
SendMessage Form1.ListView1.Hwnd, LVM_GETITEMRECT, lvRowIndex, rct
tmp = rct.Left
rct.Top = Form1.ListView1.ColumnHeaders.Count - 2 ' << "2", ò.ê. ïîñëåäíÿÿ êîëîíêà - äëÿ ñîðòèðîâêè
rct.Left = LVIR_BOUNDS
SendMessage Form1.ListView1.Hwnd, LVM_GETSUBITEMRECT, lvRowIndex, rct
rct.Left = tmp
hBr = CreateSolidBrush(RGB(0, 127, 0)) 'GetSysColorBrush(bdrColor)
FrameRect NMLVCD.nmcd.hdc, rct, hBr
DeleteObject hBr
End If
End If
plCustomDraw = CDRF_NEWFONT
Case Else
plCustomDraw = CDRF_DODEFAULT
End Select
End Function[/blue]
[blue] Case CDDS_ITEMPOSTPAINT
[COLOR=green]' ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::[/color]
If Form1.chkBorderOnly.Value = 1 Then
[COLOR=green]' replacing color filling with border:[/color]
If lvRowIndex + 1 = Form1.ListView1.SelectedItem.Index Then
rct.Left = LVIR_ICON
SendMessage Form1.ListView1.Hwnd, LVM_GETITEMRECT, lvRowIndex, rct
tmp = rct.Left
rct.Top = Form1.ListView1.ColumnHeaders.Count - 2 ' << "2", ò.ê. ïîñëåäíÿÿ êîëîíêà - äëÿ ñîðòèðîâêè
rct.Left = LVIR_BOUNDS
SendMessage Form1.ListView1.Hwnd, LVM_GETSUBITEMRECT, lvRowIndex, rct
rct.Left = tmp
[b][COLOR=#EF2929]rct.Top = rct.Top + 1[/color][/b]
hBr = CreateSolidBrush(RGB(0, 127, 0)) 'GetSysColorBrush(bdrColor)
FrameRect NMLVCD.nmcd.hdc, rct, hBr
DeleteObject hBr
End If
End If[/blue]