Windows 10/11 haben ja nun diese Flat - gestrickten Fenster. Da Ctrl nix anderes als Fenster sind, sehen auch die genauso verbaselt aus.
Ränder sind kaum noch auszumachen, umso hässlicher macht sich dann der gepunktete Rahmen des Tab-Item mit Focus aus.
Damit man die Item überhaupt sieht, nutze ich jetzt selbst gezeichnete Item. Das kann man dann auch schön bunt (wenn man mag für jedes Item anders) gestalten. Aber ich finde ums Verrecken nicht heraus, wie ich das Zeichnen des Focusrahmens verhindern kann.
Hier mal ein Code-Bsp. - hat jemand 'ne Idee, wie ich dem Focusrahmen beikommen kann?
AutoIt
#include <FontConstants.au3>
#include <GuiConstantsEx.au3>
#include <GuiTab.au3>
#include <StructureConstants.au3>
#include <WinAPIGdi.au3>
#include <WindowsConstants.au3>
Global $g_hGui = GUICreate('Test')
Global $g_hTab = GUICtrlGetHandle(GUICtrlCreateTab(10, 10, 380, 200, BitOR($TCS_MULTILINE,$TCS_OWNERDRAWFIXED)))
GUICtrlCreateTabItem('Alpha')
GUICtrlCreateTabItem('Beta')
GUICtrlCreateTabItem('Gamma')
GUICtrlCreateTabItem('Delta')
GUICtrlCreateTabItem('Epsilon')
GUICtrlCreateTabItem('Zeta')
GUICtrlCreateTabItem('Eta')
GUICtrlCreateTabItem('Theta')
GUICtrlCreateTabItem('Iota')
GUICtrlCreateTabItem('Kappa')
GUICtrlCreateTabItem('Lambda')
GUICtrlCreateTabItem('My')
GUICtrlCreateTabItem('Ny')
GUICtrlCreateTabItem('Xi')
GUICtrlCreateTabItem('Omikron')
GUICtrlCreateTabItem('Pi')
GUICtrlCreateTabItem('Rho')
GUICtrlCreateTabItem('Sigma')
GUICtrlCreateTabItem('Tau')
GUICtrlCreateTabItem('Ypsilon')
GUICtrlCreateTabItem('Phi')
GUICtrlCreateTabItem('Chi')
GUICtrlCreateTabItem('Psi')
GUICtrlCreateTabItem('Omega')
; Tab item color:
;~ Global $g_BGcolor = 0xCC483F ; hellblau
;~ Global $g_BGcolor = 0x409340 ; grün
;~ Global $g_BGcolor = 0x3030FF ; rot
;~ Global $g_BGcolor = 0xE3E3E3 ; dunkelgrau
Global $g_BGcolor = 0xF0F0F0 ; lichtgrau
;~ Global $g_BGcolor = 0x000000 ; schwarz
GUIRegisterMsg($WM_DRAWITEM, "WM_DRAWITEM")
GUISetState()
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 $hFont = _WinAPI_CreateFont(14.5, 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_BGcolor)
Local $hOldBrush = _WinAPI_SelectObject($DIS.hDC, $hBrush)
_WinAPI_Rectangle($DIS.hDC, $tRect)
; draw text
_WinAPI_SetTextColor($DIS.hDC, _GuiCtrl_GetColorContrast($g_BGcolor))
_WinAPI_SetBkColor($DIS.hDC, $g_BGcolor)
; move text rect by focus
If $bFocus Then
_WinAPI_InflateRect($tRect, 0, -2) ; reduce rectangle
_WinAPI_OffsetRect($tRect, 0, 2) ; move rectangle down by 2px
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
; #FUNCTION# =======================================================================================
; Name ..........: _GuiCtrl_GetColorContrast
; Description ...: The appropriate contrast color for the text is determined depending
; ...............: on the brightness of the BG color.
; Parameter(s)...: $_BkCol The background color
; ....[optional].: $_ColOnDark The text color if BG is dark (Default: -1, almost white)
; ....[optional].: $_ColOnBright The text color if BG is bright (Default: -1, very deep blue)
; Return values .: Text color
; Author ........: BugFix
; ==================================================================================================
Func _GuiCtrl_GetColorContrast($_BkCol, $_ColOnDark=-1, $_ColOnBright=-1)
$_ColOnDark = $_ColOnDark = -1 ? 0xFAFAFA : $_ColOnDark
;~ $_ColOnBright = $_ColOnBright = -1 ? 0x000088 : $_ColOnBright ; RGB
$_ColOnBright = $_ColOnBright = -1 ? 0x440000 : $_ColOnBright ; BGR
; get contrast
Local $R = BitAND(BitShift($_BkCol, 16), 0xFF)
Local $G = BitAND(BitShift($_BkCol, 8), 0xFF)
Local $B = BitAND($_BkCol, 0xFF)
Local $Brightness = Sqrt($R^2*0.299 + $G^2*0.587 + $B^2*0.114)
Return ($Brightness < 140 ? $_ColOnDark : $_ColOnBright)
EndFunc
Alles anzeigen