Что нового

[Элементы GUI] Как в ListView отключить ScrollBar

XpycT

Скриптер
Сообщения
380
Репутация
133
Всем привет,

Есть два ListView, необходимо отключить вертикальный ScrollBar для ListView_1.

Решил наложить один ListView_2 на ListView_1, что бы спрятать ScrollBar, но при прокрутке он (ScrollBar у ListView_1) появляеться.

Код:
#Region Includes
#include <FontConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <WindowsConstants.au3>
#EndRegion Includes
#NoTrayIcon

$hGUI = GUICreate("ListView", 400, 300, -1, -1)

$cListView_1 = GUICtrlCreateListView("", 5, 0, 110, 300, BitOR($LVS_REPORT, $LVS_SINGLESEL, $LVS_NOSORTHEADER), $WS_EX_STATICEDGE)
_GUICtrlListView_SetExtendedListViewStyle($cListView_1, BitOR($LVS_EX_DOUBLEBUFFER, $LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES, $WS_EX_STATICEDGE))

_GUICtrlListView_InsertColumn($cListView_1, 0, "Date", 90, 2)

_GUICtrlListView_SetFont($cListView_1)

$cListView_2 = GUICtrlCreateListView("", 95, 0, 300, 300, BitOR($LVS_REPORT, $LVS_SINGLESEL, $LVS_NOSORTHEADER), $WS_EX_STATICEDGE)
_GUICtrlListView_SetExtendedListViewStyle($cListView_2, BitOR($LVS_EX_DOUBLEBUFFER, $LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES, $WS_EX_STATICEDGE))

_GUICtrlListView_InsertColumn($cListView_2, 0, "Time", 140, 2)
_GUICtrlListView_InsertColumn($cListView_2, 1, "Count", 140, 2)

_GUICtrlListView_SetFont($cListView_2)


For $i = 0 To 59
	$iListView_1_Item = _GUICtrlListView_InsertItem($cListView_1, StringFormat("%02d", Random(1, 20, 1)) & ". " & StringFormat("%02d", Random(1, 12, 1)) & "." & Random(2010, 2011, 1))

	$iListView_2_Item = _GUICtrlListView_InsertItem($cListView_2, StringFormat("%02d", Random(0, 23, 1)) & ":" & StringFormat("%02d", Random(0, 59, 1)))
	_GUICtrlListView_SetItemText($cListView_2, $iListView_2_Item, StringFormat("%02d", Random(0, 99, 1)), 1)
Next

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUISetState(@SW_SHOW, $hGUI)

While 1
	$GUIMsg = GUIGetMsg()
	Switch $GUIMsg
	Case $GUI_EVENT_CLOSE
		Exit
	EndSwitch
WEnd

Func _GUICtrlListView_SetFont($_hDataTable)
	Local $DataTabel = $_hDataTable
	Local $aReturn, $hHeader, $hDLL

	If Not IsHWnd($DataTabel) Then $DataTabel = GUICtrlGetHandle($DataTabel)

	$hHeader = HWnd(_GUICtrlListView_GetHeader($DataTabel)) ; Get handle to header control

	$HeadFont = _WinAPI_CreateFont(12, 0, 0, 0, 800, False, False, False, $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, 0, "Tahoma")
	$BodyFont = _WinAPI_CreateFont(12, 0, 0, 0, 400, False, False, False, $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, 0, "Tahoma")

	_SendMessage($DataTabel, $__LISTVIEWCONSTANT_WM_SETREDRAW, 0) ; disable repainting

; Turn Off Theme For Header Control to Enable Header Autosizing
	$hUxThemeDll = DllOpen("UxTheme.dll")
	$aReturn = DllCall($hUxThemeDll, "int", "SetWindowTheme", "hwnd", $hHeader, "wstr", "", "wstr", "")
	If @error Or $aReturn[0] Then
	DllClose($hUxThemeDll)
	Return SetError(2, 0, False)
	EndIf

	If IsPtr($HeadFont) Then ; set font for items and if available separate font for header
	_SendMessage($DataTabel, $__LISTVIEWCONSTANT_WM_SETFONT, $BodyFont, True, 0, "hwnd")
	_SendMessage($hHeader, $__LISTVIEWCONSTANT_WM_SETFONT, $HeadFont, True, 0, "hwnd")
	Else ; set same font for header and items
; 	resizing header down to a smaller font size causes listview repaint problems, so repainting is enabled
	_SendMessage($DataTabel, $__LISTVIEWCONSTANT_WM_SETREDRAW, 1) ; enable repainting
	_SendMessage($DataTabel, $__LISTVIEWCONSTANT_WM_SETFONT, $BodyFont, True, 0, "hwnd")
	EndIf

; 	restore control theme painting
	$aReturn = DllCall($hUxThemeDll, "int", "SetWindowTheme", "hwnd", $hHeader, "ptr", 0, "ptr", 0)
	If @error Or $aReturn[0] Then
	DllClose($hUxThemeDll)
	Return SetError(3, 0, False)
	EndIf
	DllClose($hUxThemeDll)

	_SendMessage($DataTabel, $__LISTVIEWCONSTANT_WM_SETREDRAW, 1) ; enable repainting
	_WinAPI_RedrawWindow($DataTabel, 0, 0, $RDW_INVALIDATE)

	Return SetError(0, 0, $aReturn[0] <> 1)
EndFunc   ;==>_GUICtrlListView_SetFont

Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)
	Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR

	Local $aDataTable[2] = [GUICtrlGetHandle($cListView_1), GUICtrlGetHandle($cListView_2)]

	$tNMHDR = DllStructCreate($tagNMHDR, $lParam)
	$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
	$iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
	$iCode = DllStructGetData($tNMHDR, "Code")

	If $hWndFrom = $aDataTable[1] And $iCode = $LVN_BEGINSCROLL Then
		Local $tNMLVSCROLL = DllStructCreate($tagNMLVSCROLL, $lParam)
		GUICtrlSendMsg($cListView_1, $LVM_SCROLL, DllStructGetData($tNMLVSCROLL, "dx"), DllStructGetData($tNMLVSCROLL, "dy") * 16)
	EndIf

	Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY
 

Zaramot

I ♥ AutoIt
Сообщения
1,160
Репутация
660
необходимо отключить вертикальный ScrollBar для ListView_1
Подключи библиотеку TreeviewConstants.au3 и добавь стиль $TVS_NOSCROLL:
Код:
#Region Includes
#include <FontConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <WindowsConstants.au3>
#include <TreeviewConstants.au3>
#EndRegion Includes
#NoTrayIcon

$hGUI = GUICreate("ListView", 410, 300, -1, -1)

$cListView_1 = GUICtrlCreateListView("", 0, 0, 110, 300, BitOR($LVS_REPORT, $LVS_SINGLESEL, $LVS_NOSORTHEADER, $TVS_NOSCROLL))
_GUICtrlListView_SetExtendedListViewStyle($cListView_1, BitOR($LVS_EX_DOUBLEBUFFER, $LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES, $WS_EX_STATICEDGE))

_GUICtrlListView_InsertColumn($cListView_1, 0, "Date", 90, 2)

_GUICtrlListView_SetFont($cListView_1)

$cListView_2 = GUICtrlCreateListView("", 110, 0, 300, 300, BitOR($LVS_REPORT, $LVS_SINGLESEL, $LVS_NOSORTHEADER), $WS_EX_STATICEDGE)
_GUICtrlListView_SetExtendedListViewStyle($cListView_2, BitOR($LVS_EX_DOUBLEBUFFER, $LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES, $WS_EX_STATICEDGE))

_GUICtrlListView_InsertColumn($cListView_2, 0, "Time", 140, 2)
_GUICtrlListView_InsertColumn($cListView_2, 1, "Count", 140, 2)

_GUICtrlListView_SetFont($cListView_2)


For $i = 0 To 59
    $iListView_1_Item = _GUICtrlListView_InsertItem($cListView_1, StringFormat("%02d", Random(1, 20, 1)) & ". " & StringFormat("%02d", Random(1, 12, 1)) & "." & Random(2010, 2011, 1))

    $iListView_2_Item = _GUICtrlListView_InsertItem($cListView_2, StringFormat("%02d", Random(0, 23, 1)) & ":" & StringFormat("%02d", Random(0, 59, 1)))
    _GUICtrlListView_SetItemText($cListView_2, $iListView_2_Item, StringFormat("%02d", Random(0, 99, 1)), 1)
Next

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUISetState(@SW_SHOW, $hGUI)

While 1
    $GUIMsg = GUIGetMsg()
    Switch $GUIMsg
    Case $GUI_EVENT_CLOSE
        Exit
    EndSwitch
WEnd

Func _GUICtrlListView_SetFont($_hDataTable)
    Local $DataTabel = $_hDataTable
    Local $aReturn, $hHeader, $hDLL

    If Not IsHWnd($DataTabel) Then $DataTabel = GUICtrlGetHandle($DataTabel)

    $hHeader = HWnd(_GUICtrlListView_GetHeader($DataTabel)) ; Get handle to header control

    $HeadFont = _WinAPI_CreateFont(12, 0, 0, 0, 800, False, False, False, $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, 0, "Tahoma")
    $BodyFont = _WinAPI_CreateFont(12, 0, 0, 0, 400, False, False, False, $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, 0, "Tahoma")

    _SendMessage($DataTabel, $__LISTVIEWCONSTANT_WM_SETREDRAW, 0) ; disable repainting

; Turn Off Theme For Header Control to Enable Header Autosizing
    $hUxThemeDll = DllOpen("UxTheme.dll")
    $aReturn = DllCall($hUxThemeDll, "int", "SetWindowTheme", "hwnd", $hHeader, "wstr", "", "wstr", "")
    If @error Or $aReturn[0] Then
    DllClose($hUxThemeDll)
    Return SetError(2, 0, False)
    EndIf

    If IsPtr($HeadFont) Then ; set font for items and if available separate font for header
    _SendMessage($DataTabel, $__LISTVIEWCONSTANT_WM_SETFONT, $BodyFont, True, 0, "hwnd")
    _SendMessage($hHeader, $__LISTVIEWCONSTANT_WM_SETFONT, $HeadFont, True, 0, "hwnd")
    Else ; set same font for header and items
;   resizing header down to a smaller font size causes listview repaint problems, so repainting is enabled
    _SendMessage($DataTabel, $__LISTVIEWCONSTANT_WM_SETREDRAW, 1) ; enable repainting
    _SendMessage($DataTabel, $__LISTVIEWCONSTANT_WM_SETFONT, $BodyFont, True, 0, "hwnd")
    EndIf

;   restore control theme painting
    $aReturn = DllCall($hUxThemeDll, "int", "SetWindowTheme", "hwnd", $hHeader, "ptr", 0, "ptr", 0)
    If @error Or $aReturn[0] Then
    DllClose($hUxThemeDll)
    Return SetError(3, 0, False)
    EndIf
    DllClose($hUxThemeDll)

    _SendMessage($DataTabel, $__LISTVIEWCONSTANT_WM_SETREDRAW, 1) ; enable repainting
    _WinAPI_RedrawWindow($DataTabel, 0, 0, $RDW_INVALIDATE)

    Return SetError(0, 0, $aReturn[0] <> 1)
EndFunc   ;==>_GUICtrlListView_SetFont

Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR

    Local $aDataTable[2] = [GUICtrlGetHandle($cListView_1), GUICtrlGetHandle($cListView_2)]

    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")

    If $hWndFrom = $aDataTable[1] And $iCode = $LVN_BEGINSCROLL Then
        Local $tNMLVSCROLL = DllStructCreate($tagNMLVSCROLL, $lParam)
        GUICtrlSendMsg($cListView_1, $LVM_SCROLL, DllStructGetData($tNMLVSCROLL, "dx"), DllStructGetData($tNMLVSCROLL, "dy") * 16)
    EndIf

    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY
 

Yashied

Модератор
Команда форума
Глобальный модератор
Сообщения
5,379
Репутация
2,724
$LVS_NOSCROLL
 
Автор
X

XpycT

Скриптер
Сообщения
380
Репутация
133
Zaramot [?]
добавь стиль $TVS_NOSCROLL
Тогда не работает синхронная прокрутка

Yashied [?]
строки не на одном уровне

Нашел решение на офф. форуме

Код:
#Region Includes
#include <FontConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <WindowsConstants.au3>
#EndRegion Includes
#NoTrayIcon

$hGUI = GUICreate("ListView", 400, 300, -1, -1)

$cListView_1 = GUICtrlCreateListView("", 5, 0, 110, 300, BitOR($LVS_REPORT, $LVS_SINGLESEL, $LVS_NOSORTHEADER), $WS_EX_STATICEDGE)
_GUICtrlListView_SetExtendedListViewStyle($cListView_1, BitOR($LVS_EX_DOUBLEBUFFER, $LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES, $WS_EX_STATICEDGE))

$DllCall = DllCall("gdi32.dll", "int", "CreateRoundRectRgn", "int", 0, "int", 0, "int", 90, "int", 300, "int", 0, "int", 0)
DllCall("user32.dll", "int", "SetWindowRgn", "hwnd",GUICtrlGetHandle($cListView_1), "int", $DllCall[0], "int", True)

_GUICtrlListView_InsertColumn($cListView_1, 0, "Date", 90, 2)

_GUICtrlListView_SetFont($cListView_1)

$cListView_2 = GUICtrlCreateListView("", 95, 0, 300, 300, BitOR($LVS_REPORT, $LVS_SINGLESEL, $LVS_NOSORTHEADER), $WS_EX_STATICEDGE)
_GUICtrlListView_SetExtendedListViewStyle($cListView_2, BitOR($LVS_EX_DOUBLEBUFFER, $LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES, $WS_EX_STATICEDGE))

_GUICtrlListView_InsertColumn($cListView_2, 0, "Time", 140, 2)
_GUICtrlListView_InsertColumn($cListView_2, 1, "Count", 140, 2)

_GUICtrlListView_SetFont($cListView_2)


For $i = 0 To 59
  $iListView_1_Item = _GUICtrlListView_InsertItem($cListView_1, StringFormat("%02d", Random(1, 20, 1)) & ". " & StringFormat("%02d", Random(1, 12, 1)) & "." & Random(2010, 2011, 1))

  $iListView_2_Item = _GUICtrlListView_InsertItem($cListView_2, StringFormat("%02d", Random(0, 23, 1)) & ":" & StringFormat("%02d", Random(0, 59, 1)))
  _GUICtrlListView_SetItemText($cListView_2, $iListView_2_Item, StringFormat("%02d", Random(0, 99, 1)), 1)
Next

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUISetState(@SW_SHOW, $hGUI)

While 1
  $GUIMsg = GUIGetMsg()
  Switch $GUIMsg
  Case $GUI_EVENT_CLOSE
    Exit
  EndSwitch
WEnd

Func _ControlToRoundedRectangle($aControl,$X1,$Y1,$X2,$Y2,$X3)
    Local $l
    Local $handle = GUICtrlGetHandle($aControl)
    $l = DllCall("gdi32.dll","int","CreateRoundRectRgn","int",$X1,"int",$Y1,"int",$X2,"int",$Y2,"int",$X3,"int",$X3)
    If @Error Then ConsoleWrite("@Error = " & @Error & @Cr)
    DllCall("user32.dll","int","SetWindowRgn","hwnd",$handle,"int",$l[0],"int",True)
EndFunc

Func _GUICtrlListView_SetFont($_hDataTable)
  Local $DataTabel = $_hDataTable
  Local $aReturn, $hHeader, $hDLL

  If Not IsHWnd($DataTabel) Then $DataTabel = GUICtrlGetHandle($DataTabel)

  $hHeader = HWnd(_GUICtrlListView_GetHeader($DataTabel)) ; Get handle to header control

  $HeadFont = _WinAPI_CreateFont(12, 0, 0, 0, 800, False, False, False, $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, 0, "Tahoma")
  $BodyFont = _WinAPI_CreateFont(12, 0, 0, 0, 400, False, False, False, $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, 0, "Tahoma")

  _SendMessage($DataTabel, $__LISTVIEWCONSTANT_WM_SETREDRAW, 0) ; disable repainting

; Turn Off Theme For Header Control to Enable Header Autosizing
  $hUxThemeDll = DllOpen("UxTheme.dll")
  $aReturn = DllCall($hUxThemeDll, "int", "SetWindowTheme", "hwnd", $hHeader, "wstr", "", "wstr", "")
  If @error Or $aReturn[0] Then
  DllClose($hUxThemeDll)
  Return SetError(2, 0, False)
  EndIf

  If IsPtr($HeadFont) Then ; set font for items and if available separate font for header
  _SendMessage($DataTabel, $__LISTVIEWCONSTANT_WM_SETFONT, $BodyFont, True, 0, "hwnd")
  _SendMessage($hHeader, $__LISTVIEWCONSTANT_WM_SETFONT, $HeadFont, True, 0, "hwnd")
  Else ; set same font for header and items
;   resizing header down to a smaller font size causes listview repaint problems, so repainting is enabled
  _SendMessage($DataTabel, $__LISTVIEWCONSTANT_WM_SETREDRAW, 1) ; enable repainting
  _SendMessage($DataTabel, $__LISTVIEWCONSTANT_WM_SETFONT, $BodyFont, True, 0, "hwnd")
  EndIf

;   restore control theme painting
  $aReturn = DllCall($hUxThemeDll, "int", "SetWindowTheme", "hwnd", $hHeader, "ptr", 0, "ptr", 0)
  If @error Or $aReturn[0] Then
  DllClose($hUxThemeDll)
  Return SetError(3, 0, False)
  EndIf
  DllClose($hUxThemeDll)

  _SendMessage($DataTabel, $__LISTVIEWCONSTANT_WM_SETREDRAW, 1) ; enable repainting
  _WinAPI_RedrawWindow($DataTabel, 0, 0, $RDW_INVALIDATE)

  Return SetError(0, 0, $aReturn[0] <> 1)
EndFunc   ;==>_GUICtrlListView_SetFont

Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)
  Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR

  Local $aDataTable[2] = [GUICtrlGetHandle($cListView_1), GUICtrlGetHandle($cListView_2)]

  $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
  $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
  $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
  $iCode = DllStructGetData($tNMHDR, "Code")

  If $hWndFrom = $aDataTable[1] And $iCode = $LVN_BEGINSCROLL Then
    Local $tNMLVSCROLL = DllStructCreate($tagNMLVSCROLL, $lParam)
    GUICtrlSendMsg($cListView_1, $LVM_SCROLL, DllStructGetData($tNMLVSCROLL, "dx"), DllStructGetData($tNMLVSCROLL, "dy") * 16)
  EndIf

  Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY
 
Верх