Jump to content

Remove vertical movement in listview.


Belini
 Share

Recommended Posts

I used this script posted by Rover to remove the scrollbars further moves vertically using arrows left and right, how to solve?

Rover script written by:

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
#include <GuiConstantsEx.au3>
#include <GuiListView.au3>

#include <GUIListBox.au3>
#Include <GuiScrollBars.au3>
#include <ScrollBarConstants.au3>

Opt('MustDeclareVars', 1)


Global $hGui, $hListView, $hList, $iDLLUser32 = DllOpen("user32.dll")
Global $wProcNewLV, $wProcOldLV, $wProcNewLB, $wProcOldLB

Example_UDF_Created()

Func Example_UDF_Created()
    $hGui = GUICreate("Scrollable ListView/ListBox without scrollbars", 600, 550, -1, -1)

    Local $cListView = GUICtrlCreateListView("", 2, 2, 596, 293)
    Local $exStyles = BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_DOUBLEBUFFER)
    $hListView = GUICtrlGetHandle($cListView)
    _GUICtrlListView_SetExtendedListViewStyle($hListView, $exStyles)

    ;subclass listview
    $wProcNewLV = DllCallbackRegister("_LVWndProc", "ptr", "hwnd;uint;wparam;lparam")
    $wProcOldLV = _WinAPI_SetWindowLong($hListView, $GWL_WNDPROC, DllCallbackGetPtr($wProcNewLV))

    _GUICtrlListView_InsertColumn($cListView, 0, "Column 1", 100)
    _GUICtrlListView_InsertColumn($cListView, 1, "Column 2", 100)
    _GUICtrlListView_InsertColumn($cListView, 2, "Column 3", 100)
    _GUICtrlListView_InsertColumn($cListView, 3, "Column 4", 292)

    For $i = 0 To 41
        _GUICtrlListView_AddItem($cListView, "Row " & $i + 1 & ": Col 1")
        _GUICtrlListView_AddSubItem($cListView, $i, "Row " & $i + 1 & ": Col 2", 1)
        _GUICtrlListView_AddSubItem($cListView, $i, "Row " & $i + 1 & ": Col 3", 2)
        _GUICtrlListView_AddSubItem($cListView, $i, "Row " & $i + 1 & ": Col 4", 3)
    Next

    Local $sTxt
    For $i = 0 To 50
        $sTxt &= "Line " & $i & "|"
    Next
    Local $cList = GUICtrlCreateList("", 2, 320, 596, 200)
    GUICtrlSetData(-1, $sTxt)
    Local $hList = GUICtrlGetHandle(-1)

;works without this, but seems to remove sliver of scrollbar button on right edge
    _GUIScrollBars_EnableScrollBar($hList, $SB_BOTH, $ESB_DISABLE_BOTH)

    _GUIScrollBars_ShowScrollBar($hList, $SB_BOTH, False)
    ;subclass listbox
    $wProcNewLB = DllCallbackRegister("_LBWndProc", "ptr", "hwnd;uint;wparam;lparam")
    $wProcOldLB = _WinAPI_SetWindowLong($hList, $GWL_WNDPROC, DllCallbackGetPtr($wProcNewLB))

    ;mouse won't scroll list until top index item is one greater than visible items
    _GUICtrlListBox_SetTopIndex($hList, 15);set to item one greater than visible items
    _GUICtrlListBox_SetTopIndex($hList, 0);rest back to first item - scrolling by mouse now works
    ;on restore from minimize, scrolling stops again until selected item one greater than visible items
;_WinAPI_SetWindowPos($hList, 0, 0, 0, 0, 0, BitOR($SWP_FRAMECHANGED, $SWP_NOMOVE, $SWP_NOSIZE, $SWP_NOZORDER))

    GUISetState()

    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    _Exit()
EndFunc


Func _Exit()
    If $wProcOldLV Then _WinAPI_SetWindowLong($hListView, $GWL_WNDPROC, $wProcOldLV)
    If $wProcOldLB Then _WinAPI_SetWindowLong($hList, $GWL_WNDPROC, $wProcOldLB)
    GUIDelete($hGui);prevents crash on exit caused by DllCallbackFree()
    DllClose($iDLLUser32)
    If $wProcNewLV Then DllCallbackFree($wProcNewLV)
    If $wProcNewLB Then DllCallbackFree($wProcNewLB)
    Exit
EndFunc


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 _LBWndProc($hWnd, $Msg, $wParam, $lParam)
    #forceref $hWnd, $Msg, $wParam, $lParam
    Switch $Msg
        Case $WM_NCCALCSIZE
            _RemoveVHScroll($hWnd) ;listview will add these styles again when restored from minimize
        Case $WM_WINDOWPOSCHANGING
            Local $tWINDOWPOS = DllStructCreate($tagWINDOWPOS, $lParam)
            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", _
    $wProcOldLB, "hwnd", $hWnd, "uint", $Msg, "wparam", $wParam, "lparam", $lParam)
    If @error Then Return -1
    Return $aResult[0]
EndFunc   ;==>_LBWndProc


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
Edited by Belini
Link to comment
Share on other sites

Do you mean like this

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
#include <GUIListBox.au3>
#Include <GuiScrollBars.au3>
#include <ScrollBarConstants.au3>
Opt('MustDeclareVars', 1)
Global Const $iScrollBarWidth = 17 ;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Global $hGui, $hListView, $hList, $iDLLUser32 = DllOpen("user32.dll")
Global $wProcNewLV, $wProcOldLV, $wProcNewLB, $wProcOldLB
Example_UDF_Created()
Func Example_UDF_Created()
    $hGui = GUICreate("Scrollable ListView/ListBox without scrollbars", 600, 550, -1, -1)
    Local $cListView = GUICtrlCreateListView("", 2, 2, 596, 293)
    Local $exStyles = BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_DOUBLEBUFFER)
    $hListView = GUICtrlGetHandle($cListView)
    _GUICtrlListView_SetExtendedListViewStyle($hListView, $exStyles)
    ;subclass listview
    $wProcNewLV = DllCallbackRegister("_LVWndProc", "ptr", "hwnd;uint;wparam;lparam")
    $wProcOldLV = _WinAPI_SetWindowLong($hListView, $GWL_WNDPROC, DllCallbackGetPtr($wProcNewLV))
    _GUICtrlListView_InsertColumn($cListView, 0, "Column 1", 100)
    _GUICtrlListView_InsertColumn($cListView, 1, "Column 2", 100)
    _GUICtrlListView_InsertColumn($cListView, 2, "Column 3", 100)
    _GUICtrlListView_InsertColumn($cListView, 3, "Column 4", 292-$iScrollBarWidth) ;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    For $i = 0 To 41
        _GUICtrlListView_AddItem($cListView, "Row " & $i + 1 & ": Col 1")
        _GUICtrlListView_AddSubItem($cListView, $i, "Row " & $i + 1 & ": Col 2", 1)
        _GUICtrlListView_AddSubItem($cListView, $i, "Row " & $i + 1 & ": Col 3", 2)
        _GUICtrlListView_AddSubItem($cListView, $i, "Row " & $i + 1 & ": Col 4", 3)
    Next
    Local $sTxt
    For $i = 0 To 50
        $sTxt &= "Line " & $i & "|"
    Next
    Local $cList = GUICtrlCreateList("", 2, 320, 596, 200)
    GUICtrlSetData(-1, $sTxt)
    Local $hList = GUICtrlGetHandle(-1)
;works without this, but seems to remove sliver of scrollbar button on right edge
    _GUIScrollBars_EnableScrollBar($hList, $SB_BOTH, $ESB_DISABLE_BOTH)
    _GUIScrollBars_ShowScrollBar($hList, $SB_BOTH, False)
    ;subclass listbox
    $wProcNewLB = DllCallbackRegister("_LBWndProc", "ptr", "hwnd;uint;wparam;lparam")
    $wProcOldLB = _WinAPI_SetWindowLong($hList, $GWL_WNDPROC, DllCallbackGetPtr($wProcNewLB))
    ;mouse won't scroll list until top index item is one greater than visible items
    _GUICtrlListBox_SetTopIndex($hList, 15);set to item one greater than visible items
    _GUICtrlListBox_SetTopIndex($hList, 0);rest back to first item - scrolling by mouse now works
    ;on restore from minimize, scrolling stops again until selected item one greater than visible items
;_WinAPI_SetWindowPos($hList, 0, 0, 0, 0, 0, BitOR($SWP_FRAMECHANGED, $SWP_NOMOVE, $SWP_NOSIZE, $SWP_NOZORDER))
    GUISetState()
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    _Exit()
EndFunc

Func _Exit()
    If $wProcOldLV Then _WinAPI_SetWindowLong($hListView, $GWL_WNDPROC, $wProcOldLV)
    If $wProcOldLB Then _WinAPI_SetWindowLong($hList, $GWL_WNDPROC, $wProcOldLB)
    GUIDelete($hGui);prevents crash on exit caused by DllCallbackFree()
    DllClose($iDLLUser32)
    If $wProcNewLV Then DllCallbackFree($wProcNewLV)
    If $wProcNewLB Then DllCallbackFree($wProcNewLB)
    Exit
EndFunc

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 _LBWndProc($hWnd, $Msg, $wParam, $lParam)
    #forceref $hWnd, $Msg, $wParam, $lParam
    Switch $Msg
        Case $WM_NCCALCSIZE
            _RemoveVHScroll($hWnd) ;listview will add these styles again when restored from minimize
        Case $WM_WINDOWPOSCHANGING
            Local $tWINDOWPOS = DllStructCreate($tagWINDOWPOS, $lParam)
            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", _
    $wProcOldLB, "hwnd", $hWnd, "uint", $Msg, "wparam", $wParam, "lparam", $lParam)
    If @error Then Return -1
    Return $aResult[0]
EndFunc   ;==>_LBWndProc

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
Link to comment
Share on other sites

This is the same as I indicated, it moves vertically when you press right arrow or left.

post-69288-0-65667600-1334096919_thumb.j

Edited by Belini
Link to comment
Share on other sites

Just make sure that the sum of the column widths + $iScrollBarWidth < the width of the listview. Adjust the width of the last column in the listview.

Edited by LarsJ
Link to comment
Share on other sites

Link to comment
Share on other sites

Resize the GUI, or the listview, or the listview columns, or any combination of the 3 to eliminate that issue. The version of _ArrayDisplay that I have in my _Array.au3 UDF (link is in my signature) does this for the array display in the listview.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

@ BrewManNH the only way is to leave a space after the last column and do not want this space in the listview, must not only move vertically.

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...