Bei Listview und deutlicher bei Tab-Ctrl sieht man als Markierung des Item mit Fokus einen unschönen gepunkteten Rahmen.
Diesen zu Entfernen ist (wenn man es endlich gefunden hat) doch recht simpel. Die folgende Funktion für die GUI aufrufen und alle Elemente der GUI bekommen das HIDEFOCUS-Setting. Man kann auch die Nachricht an ein beliebiges Ctrl auf der GUI senden. Dann wird die Nachricht hinauf geleitet bis zum Parent und von dort wieder hinunter zu allen Childs. - Was natürlich auch bedeutet, dass dieses Setting ein "all or nothing" Setting ist, keine Selektion auf einzelne Ctrl.
AutoIt
; required: #include <WinAPISysWin.au3>, #include <WinAPIConv.au3>
Func _RemoveFocus($_hWnd)
Local Const $UIS_SET = 1
Local Const $UISF_HIDEFOCUS = 0x1
_WinAPI_PostMessage($_hWnd, $WM_CHANGEUISTATE, _WinAPI_MakeLong($UIS_SET, $UISF_HIDEFOCUS), 0)
EndFunc
Hier ein Bsp.
AutoIt: CancelFocus.au3
#include <GuiConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WinAPISysWin.au3>
#include <WinAPIConv.au3>
#include <WindowsConstants.au3>
Global $g_hGui = GUICreate('Test')
Global $g_idLV = GUICtrlCreateListView('col 1|col 2|col 3|col 4', 10, 30, 380, 160, -1, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
For $i = 1 To 10
GUICtrlCreateListViewItem(StringFormat('%d|%d|%d|%d', Random(100,999,1), Random(100,999,1), Random(100,999,1), Random(100,999,1)), $g_idLV)
Next
Global $g_aTabItm[] = ['Alpha','Beta','Gamma','Delta']
GUICtrlCreateTab(10, 210, 380, 160)
For $i = 0 To UBound($g_aTabItm) -1
GUICtrlCreateTabItem($g_aTabItm[$i])
GUICtrlCreateTabItem('')
Next
; wird an alle Childs durchgereicht
_RemoveFocus($g_hGui)
GUISetState()
Do
Until GUIGetMsg() = -3
Func _RemoveFocus($_hWnd)
Local Const $UIS_SET = 1
Local Const $UISF_HIDEFOCUS = 0x1
_WinAPI_PostMessage($_hWnd, $WM_CHANGEUISTATE, _WinAPI_MakeLong($UIS_SET, $UISF_HIDEFOCUS), 0)
EndFunc
Alles anzeigen
Um das fokussierte Element aber besser zu sehen, vergrößere ich im folgenden Bsp. die Fontgröße von 14.5 auf 15 wenn es den Fokus erhält.
AutoIt: NoFocus.au3
#include <FontConstants.au3>
#include <GuiConstantsEx.au3>
#include <StructureConstants.au3>
#include <WinAPIGdi.au3>
#include <WinAPISysWin.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#include <GuiHeader.au3>
#include <GuiTab.au3>
#include <StructureConstants.au3>
; Focus Rectangle (gepunktete Linie) wird entfernt
; Element mit Focus erhält stattdessen Fontgröße 15.0 statt 14.5
Global $g_hGui = GUICreate('Test')
; ------------------------------------------------------ Listview
; [[bgColor,textColor]] colors as BGR
Global $g_aColumn[][2] = [[0xCC483F,0xFAFAFA],[0xF0F0F0,0x440000],[0x409340,0x00F2FF],[0x3030FF,0xFAFAFA]]
Global $g_idLV = GUICtrlCreateListView('col 1|col 2|col 3|col 4', 10, 10, 380, 180, -1, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
For $i = 1 To 10
GUICtrlCreateListViewItem(StringFormat('%d|%d|%d|%d', Random(100,999,1), Random(100,999,1), Random(100,999,1), Random(100,999,1)), $g_idLV)
Next
Global $g_hLV = GUICtrlGetHandle($g_idLV)
; ------------------------------------------------------ Tab-Ctrl
; [[Text,bgColor,textColor]] colors as BGR
Global $g_aTabItm[][3] = [['Alpha',0xCC483F,0xFAFAFA],['Beta',0xF0F0F0,0x440000],['Gamma',0x409340,0x00F2FF],['Delta',0x3030FF,0xFAFAFA]]
Global $g_hTab = GUICtrlGetHandle(GUICtrlCreateTab(10, 210, 380, 180, $TCS_OWNERDRAWFIXED))
; Create Tab items, coloring the tab page
For $i = 0 To UBound($g_aTabItm) -1
GUICtrlCreateTabItem($g_aTabItm[$i][0])
_GUICtrlTab_PageColor(_BGRvvRGB($g_aTabItm[$i][1]))
GUICtrlCreateTabItem('')
Next
; ------------------------------------------------------
GUIRegisterMsg($WM_DRAWITEM, "_WM_DRAWITEM")
GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")
GUISetState()
_RemoveFocus($g_hGui)
Do
Until GUIGetMsg() = -3
Func _WM_DRAWITEM($hWnd, $Msg, $wParam, $lParam)
Local Const $ODT_TAB = 101
Local Const $ODA_DRAWENTIRE = 0x1
Local $DIS = DllStructCreate("uint cType;uint cID;uint itmID;uint itmAction;uint itmState;" & _
"hwnd hItm;hwnd hDC;dword itmRect[4];dword itmData", $lParam) ; DRAWITEMSTRUCT
If $DIS.hItm <> $g_hTab Then Return $GUI_RUNDEFMSG
If BitAND($DIS.cType, $ODT_TAB) <> $ODT_TAB Then Return $GUI_RUNDEFMSG
If BitAND($DIS.itmAction, $ODA_DRAWENTIRE) <> $ODA_DRAWENTIRE Then Return $GUI_RUNDEFMSG
Local $tRect = DllStructCreate($tagRECT, DllStructGetPtr($DIS, 'itmRect'))
Local $bFocus = (_GUICtrlTab_GetCurFocus($DIS.hItm) = $DIS.itmID)
Local $itmText = _GUICtrlTab_GetItemText($DIS.hItm, $DIS.itmID)
Local $iFontSize = $bFocus ? 15 : 14.5
Local $hFont = _WinAPI_CreateFont($iFontSize, 0, 0, 0, 400, False, False, False, $DEFAULT_CHARSET, _
$OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, 0, 'Lucida Sans Unicode Standard')
Local $hOldFont = _WinAPI_SelectObject($DIS.hDC, $hFont)
; draw and fill rect
Local $hBrush = _WinAPI_CreateSolidBrush($g_aTabItm[$DIS.itmID][1])
Local $hOldBrush = _WinAPI_SelectObject($DIS.hDC, $hBrush)
_WinAPI_Rectangle($DIS.hDC, $tRect)
; draw text
_WinAPI_SetTextColor($DIS.hDC, $g_aTabItm[$DIS.itmID][2])
_WinAPI_SetBkColor($DIS.hDC, $g_aTabItm[$DIS.itmID][1])
; move text rect with focus
If $bFocus Then
_WinAPI_OffsetRect($tRect, 0, 3)
Else
_WinAPI_OffsetRect($tRect, 0, 1)
EndIf
_WinAPI_DrawText($DIS.hDC, $itmText, $tRect, BitOR($DT_BOTTOM,$DT_CENTER))
; clear ressources
_WinAPI_SelectObject($DIS.hDC, $hOldFont)
_WinAPI_DeleteObject($hFont)
_WinAPI_SelectObject($DIS.hDC, $hOldBrush)
_WinAPI_DeleteObject($hBrush)
Return 0
EndFunc
Func _WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)
Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR
$tNMHDR = DllStructCreate($tagNMHDR, $lParam)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
$iCode = DllStructGetData($tNMHDR, "Code")
If $hWndFrom <> $g_hLV Then Return $GUI_RUNDEFMSG
Switch $hWndFrom
Case $g_hLV
Switch $iCode
Case $NM_CUSTOMDRAW
Local $tCustDraw = DllStructCreate($tagNMLVCUSTOMDRAW, $lParam)
Local $iDrawStage, $iItem, $iSubitem, $hDC = $tCustDraw.hdc, $tRect, $hFont
$iDrawStage = $tCustDraw.dwDrawStage
Switch $iDrawStage
Case $CDDS_ITEMPREPAINT
Return $CDRF_NOTIFYSUBITEMDRAW
Case BitOR($CDDS_ITEMPREPAINT, $CDDS_SUBITEM)
$iItem = $tCustDraw.dwItemSpec
$iSubitem = $tCustDraw.iSubItem
$tCustDraw.clrText = $g_aColumn[$iSubitem][1] ; (sub)item text color
$tCustDraw.clrTextBk = $g_aColumn[$iSubitem][0] ; (sub)item bg color
Local $iFontSize = BitAND($tCustDraw.uItemState, $CDIS_FOCUS) = $CDIS_FOCUS ? 15 : 14.5 ; enlarge focusssed item
$hFont = _WinAPI_CreateFont($iFontSize,0,0,0,$FW_NORMAL,False,False,False,$DEFAULT_CHARSET,$OUT_DEFAULT_PRECIS, _
$CLIP_DEFAULT_PRECIS,$DEFAULT_QUALITY,0,'Lucida Sans Unicode Standard')
_WinAPI_SelectObject($hDC, $hFont)
_WinAPI_DeleteObject($hFont)
Return $CDRF_NEWFONT
EndSwitch
EndSwitch
EndSwitch
EndFunc
Func _RemoveFocus($_hWnd)
Local Const $UIS_SET = 1
Local Const $UISF_HIDEFOCUS = 0x1
_WinAPI_PostMessage($_hWnd, $WM_CHANGEUISTATE, _WinAPI_MakeLong($UIS_SET, $UISF_HIDEFOCUS), 0)
EndFunc
Func _GUICtrlTab_PageColor($_bgCol)
; Tab position
Local $aTabPos = ControlGetPos($g_hGui, '', $g_hTab)
; size of user area
Local $aTabRect = _GUICtrlTab_GetItemRect($g_hTab, -1)
; Create label
GUICtrlCreateLabel('', $aTabPos[0] + 2, $aTabPos[1] + $aTabRect[3] + 4, $aTabPos[2] - 6, $aTabPos[3] - $aTabRect[3] - 7)
; set color
GUICtrlSetBkColor(-1, $_bgCol)
; Disable label
GUICtrlSetState(-1, $GUI_DISABLE)
EndFunc
Func _BGRvvRGB($_iCol) ; BGR to RGB and vice versa
Local $a = StringLeft(Hex($_iCol,6), 2)
Local $b = StringMid(Hex($_iCol,6), 3, 2)
Local $c = StringRight(Hex($_iCol,6), 2)
Return '0x' & $c & $b & $a
EndFunc
Alles anzeigen