Jump to content

ListView scrollbar


 Share

Recommended Posts

Is there any possibility to hide the listview vertical scrollbar, but be able to scroll? 

I've tried something with a listbox (the script below), but a listview gives more options (icons, multiple columns etc.):

#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

Global $hForm1, $hForm2, $hPic
$hForm1 = GUICreate("Form1", 150, 200,-1,-1,BitOR($WS_SYSMENU, $WS_POPUP), $WS_EX_LAYERED)

GUISetBkColor(0x000000)
$ListB = GUICtrlCreateList("", 10, 10, 130, 180, BitOR($LBS_NOTIFY,$LBS_SORT,$WS_BORDER), 0)
For $i = 1 To 50
    GUICtrlSetData(-1, "Line" & $i)
Next
GUICtrlSetFont(-1, 8, 400, 0, "Arial")
GUICtrlSetColor(-1, 0xFFCC00)
GUICtrlSetBkColor(-1,0x222222)

$hPic = GUICtrlCreatePic("", 100, 10, 50, 180)
WinSetTrans($hForm1,"",200)
GUISetState()

$pos1=WinGetPos($hForm1)
$hForm2 = GUICreate("Form2", 25, 49, $pos1[0]+$pos1[2]-40, $pos1[1]+60, BitOR($WS_SYSMENU,$WS_POPUP), $WS_EX_LAYERED)
GUISetBkColor(0x000000)
$hUp = GUICtrlCreateIcon(@ScriptDir & "\up.ico", -1, 4, 4, 16, 16)
GUICtrlSetCursor($hUp,0)
GUICtrlSetTip($hUp,"Up")
$hDown = GUICtrlCreateIcon(@ScriptDir & "\down.ico", -1, 4, 28, 16, 16)
GUICtrlSetCursor($hDown,0)
GUICtrlSetTip($hDown,"Down")
GUICtrlCreatePic("", 0, 0, 24, 48)
WinSetTrans($hForm2,"",50)
GUISetState(@SW_HIDE, $hForm2)

While 1
    Sleep(10)
    Local $mcur = GUIGetCursorInfo($hForm1)
    If $mcur[4] = $hPic then
        GUISetState(@SW_SHOW, $hForm2)
    Else
        GUISetState(@SW_HIDE, $hForm2)
    EndIf
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            GuiDelete()
            Exit
        Case $hDown
            While 1
                Sleep (10)
                Local $ind = _GUICtrlListBox_GetCurSel($ListB)
                _GUICtrlListBox_SetCurSel($ListB,$ind+5)
                ExitLoop
            WEnd
        Case $hUp
            While 1
                Sleep (10)
                Local $ind = _GUICtrlListBox_GetCurSel($ListB)
                If $ind<5 Then _GUICtrlListBox_SetCurSel($ListB,0)
                _GUICtrlListBox_SetCurSel($ListB,$ind-5)
                ExitLoop
            WEnd
    EndSwitch
WEnd

When you move the mouse over the right part of the listbox, it will appear a customized scrollbar that works with the listbox... Any chance with a listview? I've searched (and read and still do), but I didn't figure this out.

I've attached the icons used in the script, to see what I mean.

Thanks in advance! (for pointing me in the right direction)   :blink:

Screenshot of the listbox eith the customized scrollbar: Posted Image

Edited by taietel
Link to comment
Share on other sites

  • 1 year later...

Remove the vertical bar of the listview:

#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
#include <GuiScrollBars.au3>
#include <ScrollBarConstants.au3>
Global $hGui, $hListView, $hList, $iDLLUser32 = DllOpen("user32.dll")
Global $wProcNewLV, $wProcOldLV
$hGui = GUICreate("Scrollable ListView/ListBox without scrollbars", 300, 120, -1, -1)
Local $cListView = GUICtrlCreateListView("", 2, 2, 296, 100)
Local $exStyles = BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_DOUBLEBUFFER)
$hListView = GUICtrlGetHandle($cListView)
tira_barra($cListView)
; Add columns
_GUICtrlListView_InsertColumn($cListView, 0, "Column 1", 100)
_GUICtrlListView_InsertColumn($cListView, 1, "Column 2", 100)
; Add items
_GUICtrlListView_AddItem($cListView, "Row 1: Col 1")
_GUICtrlListView_AddItem($cListView, "Row 2: Col 1")
_GUICtrlListView_AddItem($cListView, "Row 3: Col 1")
_GUICtrlListView_AddItem($cListView, "Row 4: Col 1")
_GUICtrlListView_AddItem($cListView, "Row 6: Col 1")
_GUICtrlListView_AddItem($cListView, "Row 7: Col 1")
GUISetState()
GUISetState()
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
_Exit()
Func tira_barra($cListView)
$wProcNewLV = DllCallbackRegister("_LVWndProc", "ptr", "hwnd;uint;wparam;lparam")
$wProcOldLV = _WinAPI_SetWindowLong($hListView, $GWL_WNDPROC, DllCallbackGetPtr($wProcNewLV))
EndFunc   ;==>tira_barra
Func _Exit()
If $wProcOldLV Then _WinAPI_SetWindowLong($hListView, $GWL_WNDPROC, $wProcOldLV)
GUIDelete($hGui);prevents crash on exit caused by DllCallbackFree()
DllClose($iDLLUser32)
Exit
EndFunc   ;==>_Exit
Func _LVWndProc($hWnd, $Msg, $wParam, $lParam)
#forceref $hWnd, $Msg, $wParam, $lParam
Switch $Msg
  Case $WM_NCCALCSIZE
   _RemoveVHScroll($hWnd)
  Case $WM_WINDOWPOSCHANGING
   Local $tWINDOWPOS = DllStructCreate($tagWINDOWPOS, $lParam)
   ;uncomment for mouse scrolling - no mouse scrolling without, but border is not erased (vertical key scrolling flickers visibly))
   DllStructSetData($tWINDOWPOS, "Flags", _
     BitAND(DllStructGetData($tWINDOWPOS, "Flags"), BitNOT($SWP_FRAMECHANGED)))
EndSwitch
;pass the unhandled messages to default WindowProc
Local $aResult = DllCall($iDLLUser32, "lresult", "CallWindowProcW", "ptr", _
   $wProcOldLV, "hwnd", $hWnd, "uint", $Msg, "wparam", $wParam, "lparam", $lParam)
If @error Then Return -1
Return $aResult[0]
EndFunc   ;==>_LVWndProc
Func _RemoveVHScroll($hWnd)
Local $iLVStyle = _WinAPI_GetWindowLong($hWnd, $GWL_STYLE)
$iLVStyle = BitAND($iLVStyle, BitNOT($WS_VSCROLL))
$iLVStyle = BitAND($iLVStyle, BitNOT($WS_HSCROLL))
_WinAPI_SetWindowLong($hWnd, $GWL_STYLE, $iLVStyle)
EndFunc   ;==>_RemoveVHScroll
Link to comment
Share on other sites

Remove the vertical bar of the listview:

#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
#include <GuiScrollBars.au3>
#include <ScrollBarConstants.au3>
Global $hGui, $hListView, $hList, $iDLLUser32 = DllOpen("user32.dll")
Global $wProcNewLV, $wProcOldLV
$hGui = GUICreate("Scrollable ListView/ListBox without scrollbars", 300, 120, -1, -1)
Local $cListView = GUICtrlCreateListView("", 2, 2, 296, 100)
Local $exStyles = BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_DOUBLEBUFFER)
$hListView = GUICtrlGetHandle($cListView)
tira_barra($cListView)
; Add columns
_GUICtrlListView_InsertColumn($cListView, 0, "Column 1", 100)
_GUICtrlListView_InsertColumn($cListView, 1, "Column 2", 100)
; Add items
_GUICtrlListView_AddItem($cListView, "Row 1: Col 1")
_GUICtrlListView_AddItem($cListView, "Row 2: Col 1")
_GUICtrlListView_AddItem($cListView, "Row 3: Col 1")
_GUICtrlListView_AddItem($cListView, "Row 4: Col 1")
_GUICtrlListView_AddItem($cListView, "Row 6: Col 1")
_GUICtrlListView_AddItem($cListView, "Row 7: Col 1")
GUISetState()
GUISetState()
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
_Exit()
Func tira_barra($cListView)
$wProcNewLV = DllCallbackRegister("_LVWndProc", "ptr", "hwnd;uint;wparam;lparam")
$wProcOldLV = _WinAPI_SetWindowLong($hListView, $GWL_WNDPROC, DllCallbackGetPtr($wProcNewLV))
EndFunc   ;==>tira_barra
Func _Exit()
If $wProcOldLV Then _WinAPI_SetWindowLong($hListView, $GWL_WNDPROC, $wProcOldLV)
GUIDelete($hGui);prevents crash on exit caused by DllCallbackFree()
DllClose($iDLLUser32)
Exit
EndFunc   ;==>_Exit
Func _LVWndProc($hWnd, $Msg, $wParam, $lParam)
#forceref $hWnd, $Msg, $wParam, $lParam
Switch $Msg
  Case $WM_NCCALCSIZE
   _RemoveVHScroll($hWnd)
  Case $WM_WINDOWPOSCHANGING
   Local $tWINDOWPOS = DllStructCreate($tagWINDOWPOS, $lParam)
   ;uncomment for mouse scrolling - no mouse scrolling without, but border is not erased (vertical key scrolling flickers visibly))
   DllStructSetData($tWINDOWPOS, "Flags", _
     BitAND(DllStructGetData($tWINDOWPOS, "Flags"), BitNOT($SWP_FRAMECHANGED)))
EndSwitch
;pass the unhandled messages to default WindowProc
Local $aResult = DllCall($iDLLUser32, "lresult", "CallWindowProcW", "ptr", _
   $wProcOldLV, "hwnd", $hWnd, "uint", $Msg, "wparam", $wParam, "lparam", $lParam)
If @error Then Return -1
Return $aResult[0]
EndFunc   ;==>_LVWndProc
Func _RemoveVHScroll($hWnd)
Local $iLVStyle = _WinAPI_GetWindowLong($hWnd, $GWL_STYLE)
$iLVStyle = BitAND($iLVStyle, BitNOT($WS_VSCROLL))
$iLVStyle = BitAND($iLVStyle, BitNOT($WS_HSCROLL))
_WinAPI_SetWindowLong($hWnd, $GWL_STYLE, $iLVStyle)
EndFunc   ;==>_RemoveVHScroll

It's unfinished code and does not address several issues.

Next time try linking to the original post and/or accrediting the author.

ListView without ScrollBar ?

I see fascists...

Link to comment
Share on other sites

the code was posted in another forum that did not include the author's name, I'll pay more attention going forward.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...