Как в ListView изменить стиль (Курсив, Подчеркнутиый и т..) шрифта?
Для изменения размера шрифта использую _GUICtrlListView_SetFont (давным давно нашол в одной из тем на офф. форуме), там же можно поменять и стиль. Но тогда он поменяеться для всего ListView, а мне надо только для определенных строк
Скрипт
Для изменения размера шрифта использую _GUICtrlListView_SetFont (давным давно нашол в одной из тем на офф. форуме), там же можно поменять и стиль. Но тогда он поменяеться для всего ListView, а мне надо только для определенных строк
Скрипт
Код:
#include <FontConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <SendMessage.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
#NoTrayIcon
Dim $aItems[100][2]
For $i = 0 To 99
$aItems[$i][0] = Random(1000, 9999, 1)
$aItems[$i][1] = "Normal \ No Style"
If $aItems[$i][0] >= 1000 And $aItems[$i][0] <= 2000 Then $aItems[$i][1] = "Italic"
If $aItems[$i][0] >= 3000 And $aItems[$i][0] <= 4000 Then $aItems[$i][1] = "Strike"
If $aItems[$i][0] >= 5000 And $aItems[$i][0] <= 7000 Then $aItems[$i][1] = "Underline"
Next
$Form = GUICreate("Form1", 615, 440, -1, -1)
$ListView = GUICtrlCreateListView("", 5, 5, 610, 435)
_GUICtrlListView_InsertColumn($ListView, 0, "Value", 100, 2)
_GUICtrlListView_InsertColumn($ListView, 1, "FontStyle", 200, 0)
_GUICtrlListView_SetFont($ListView, 14, 0, 14)
For $i = 0 To UBound($aItems, 1) - 1
$iRow = _GUICtrlListView_InsertItem($ListView, $aItems[$i][0])
_GUICtrlListView_SetItemText($ListView, $iRow, $aItems[$i][1], 1)
Next
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
Func _GUICtrlListView_SetFont($_hTable, $_iBFSize = 12, $_iBFStyle = 0, $_iHFSize = 12)
Local $aReturn, $hHeader, $hUxThemeDll
Local $hTabel = $_hTable
Local $iFWNormal = 400, $iFWBold = 800, $sFFTahoma = "Tahoma"
Local $fFSItalic = False, $fFSUnderline = False, $fFSStrikeout = False
If Not IsHWnd($hTabel) Then $hTabel = GUICtrlGetHandle($hTabel)
$hHeader = HWnd(_GUICtrlListView_GetHeader($hTabel)) ; Get handle to header control
If BitAnd($_iBFStyle, 2) Then $fFSItalic = True
If BitAnd($_iBFStyle, 4) Then $fFSUnderline = True
If BitAnd($_iBFStyle, 8) Then $fFSStrikeout = True
$hBodyFont = _WinAPI_CreateFont($_iBFSize, 0, 0, 0, $iFWNormal, $fFSItalic, $fFSUnderline, $fFSStrikeout, $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, 0, $sFFTahoma)
$hHeadFont = _WinAPI_CreateFont($_iHFSize, 0, 0, 0, $iFWBold, False, False, False, $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, 0, $sFFTahoma)
_SendMessage($hTabel, $__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($hHeadFont) Then ; set font for items and if available separate font for header
_SendMessage($hTabel, $__LISTVIEWCONSTANT_WM_SETFONT, $hBodyFont, True, 0, "hwnd")
_SendMessage($hHeader, $__LISTVIEWCONSTANT_WM_SETFONT, $hHeadFont, 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($hTabel, $__LISTVIEWCONSTANT_WM_SETREDRAW, 1) ; enable repainting
_SendMessage($hTabel, $__LISTVIEWCONSTANT_WM_SETFONT, $hBodyFont, 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($hTabel, $__LISTVIEWCONSTANT_WM_SETREDRAW, 1) ; enable repainting
_WinAPI_RedrawWindow($hTabel, 0, 0, $RDW_INVALIDATE)
Return SetError(0, 0, $aReturn[0] <> 1)
EndFunc ;==>_GUICtrlListView_SetFont