Jump to content

[Solved]Slider focus ring removal


LIMITER
 Share

Recommended Posts

Still not fixed :| If the window loses and then gets focus the dotted border still appears :)

Cheers,

L|M|TER

Post #16 in that same thread might do what you want.
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

It does not working if I set the background color to black :)

Cheers,

L|M|TER

If you mean when the window regains focus then does this fix it for you?

#include <windowsconstants.au3>
#include <GUIConstantsEX.au3>

Opt("mousecoordmode", 2)

$Form1 = GUICreate("Form1", 633, 454, 193, 115)

$Slider1 = _GUICtrlCreateSliderB(120, 96, 185, 45)
GUISetBkColor(0)
GUISetState(@SW_SHOW)

GUIRegisterMsg($WM_ACTIVATE, "On_Activate")

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch

WEnd

Func On_Activate($wParam, $lParam)
    DllCall("user32.dll", "int", "InvalidateRect", "hwnd", $Form1, "ptr", 0, "int", 1)
EndFunc

;idea first done by smashly, from idea by BigDod
Func _GUICtrlCreateSliderB($x, $y, $w, $h)
    Local $sld = GUICtrlCreateSlider($x, $y, $w, $h);, $WS_CLIPSIBLINGS)
    
    GUICtrlCreateLabel("", $x, $y - 1, $w, 2)
    GUICtrlSetState(-1, $GUI_DISABLE)
    GUICtrlCreateLabel("", $x, $y + $h - 1, $w, 2)
    GUICtrlSetState(-1, $GUI_DISABLE)
    GUICtrlCreateLabel("", $x - 1, $y, 2, $h)
    GUICtrlSetState(-1, $GUI_DISABLE)
    GUICtrlCreateLabel("", $x + $w - 1, $y, 2, $y)
    GUICtrlSetState(-1, $GUI_DISABLE)
    
    Return $sld
EndFunc  ;==>_GUICtrlCreateSliderB

Changed to use WM_ACTIVATE

Edited by martin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

focus rectangle overpainting GDI example

user32.dll is missing a DrawFocusRectColor function available in CE that allows changing the focus rectangle colour.

DrawFocusRect API when called will erase a previously existing focus rectangle, but subsequent calls create a new focus rectangle.

#include <GUIConstantsEX.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>

Opt('GUIOnEventMode', 1)
Opt('MustDeclareVars', 1)

Global $hGUI, $hSlider, $iBuffer, $tRectSlider, $cSlider, $label
Global $iBkCol = 0x000000
Global $aSlider[4] = [25,25,200,50]

$hGUI = GUICreate("Slider focus rectangle", 250, 100)
GUISetBkColor($iBkCol)
GUISetOnEvent($GUI_EVENT_CLOSE, '_Exit')

$cSlider = GUICtrlCreateSlider($aSlider[0], $aSlider[1], $aSlider[2], $aSlider[3])
$hSlider = GUICtrlGetHandle($cSlider)
GUICtrlSetBkColor(-1, $iBkCol)
Global $tRectSlider = _Rect($aSlider)

$label = GUICtrlCreateLabel("0", 115, 80, 20, 15)
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetFont(-1, 10, 800, -1, "Arial")

GUIRegisterMsg($WM_ACTIVATE, "WM_HANDLER")
GUIRegisterMsg($WM_PAINT, "WM_HANDLER")
GUIRegisterMsg($WM_HSCROLL, "WM_HANDLER") ; horizontal sliders
;GUIRegisterMsg($WM_VSCROLL, "WM_HANDLER"); vertical sliders
GUISetState()

;initial paint over slider focus rectangle after gui shown
DrawRectangle($hGUI, $hSlider, $tRectSlider, $iBkCol)

Do
    Sleep(100)
Until 0

Func _Exit()
    GUIDelete()
    Exit
EndFunc  ;==>_Exit

Func WM_HANDLER($hWnd, $Msg, $wParam, $lParam)
    #forceref $hWnd, $Msg, $wParam, $lParam
    Switch $Msg
        Case $WM_PAINT, $WM_ACTIVATE
            DrawRectangle($hGUI, $hSlider, $tRectSlider, $iBkCol)
        Case $WM_HSCROLL, $WM_VSCROLL
            Switch $lParam
                Case $hSlider
                    Local $iSliderData = GUICtrlRead($cSlider)
                    If $iBuffer <> $iSliderData Then
                        $iBuffer = $iSliderData
                        GUICtrlSetData($label, $iBuffer)
                    EndIf
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc  ;==>WM_ACTIVATE

Func DrawRectangle($hWndGUI, $hWndSlider, ByRef $tRect, $iColor)
    _WinAPI_RedrawWindow($hWndSlider, 0, 0, $RDW_UPDATENOW)
    Local $hDCGUI = _WinAPI_GetDC($hWndGUI)
    Local $hBrush = _WinAPI_CreateSolidBrush($iColor)
    _WinAPI_FrameRect($hDCGUI, DllStructGetPtr($tRect), $hBrush)
    _WinAPI_DeleteObject($hBrush)
    _WinAPI_ReleaseDC($hWndGUI, $hDCGUI)
    Return 1
EndFunc

Func _Rect(ByRef $aRect)
    Local $tRect = DllStructCreate("int;int;int;int")
    DllStructSetData($tRect, 1, $aRect[0])
    DllStructSetData($tRect, 2, $aRect[1])
    DllStructSetData($tRect, 3, $aRect[2]+$aRect[0])
    DllStructSetData($tRect, 4, $aRect[3]+$aRect[1])
    Return $tRect
EndFunc

I see fascists...

Link to comment
Share on other sites

focus rectangle overpainting GDI example

user32.dll is missing a DrawFocusRectColor function available in CE that allows changing the focus rectangle colour.

DrawFocusRect API when called will erase a previously existing focus rectangle, but subsequent calls create a new focus rectangle.

#include <GUIConstantsEX.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>

Opt('GUIOnEventMode', 1)
Opt('MustDeclareVars', 1)

Global $hGUI, $hSlider, $iBuffer, $tRectSlider, $cSlider, $label
Global $iBkCol = 0x000000
Global $aSlider[4] = [25,25,200,50]

$hGUI = GUICreate("Slider focus rectangle", 250, 100)
GUISetBkColor($iBkCol)
GUISetOnEvent($GUI_EVENT_CLOSE, '_Exit')

$cSlider = GUICtrlCreateSlider($aSlider[0], $aSlider[1], $aSlider[2], $aSlider[3])
$hSlider = GUICtrlGetHandle($cSlider)
GUICtrlSetBkColor(-1, $iBkCol)
Global $tRectSlider = _Rect($aSlider)

$label = GUICtrlCreateLabel("0", 115, 80, 20, 15)
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetFont(-1, 10, 800, -1, "Arial")

GUIRegisterMsg($WM_ACTIVATE, "WM_HANDLER")
GUIRegisterMsg($WM_PAINT, "WM_HANDLER")
GUIRegisterMsg($WM_HSCROLL, "WM_HANDLER"); horizontal sliders
;GUIRegisterMsg($WM_VSCROLL, "WM_HANDLER"); vertical sliders
GUISetState()

;initial paint over slider focus rectangle after gui shown
DrawRectangle($hGUI, $hSlider, $tRectSlider, $iBkCol)

Do
    Sleep(100)
Until 0

Func _Exit()
    GUIDelete()
    Exit
EndFunc ;==>_Exit

Func WM_HANDLER($hWnd, $Msg, $wParam, $lParam)
    #forceref $hWnd, $Msg, $wParam, $lParam
    Switch $Msg
        Case $WM_PAINT, $WM_ACTIVATE
            DrawRectangle($hGUI, $hSlider, $tRectSlider, $iBkCol)
        Case $WM_HSCROLL, $WM_VSCROLL
            Switch $lParam
                Case $hSlider
                    Local $iSliderData = GUICtrlRead($cSlider)
                    If $iBuffer <> $iSliderData Then
                        $iBuffer = $iSliderData
                        GUICtrlSetData($label, $iBuffer)
                    EndIf
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc ;==>WM_ACTIVATE

Func DrawRectangle($hWndGUI, $hWndSlider, ByRef $tRect, $iColor)
    _WinAPI_RedrawWindow($hWndSlider, 0, 0, $RDW_UPDATENOW)
    Local $hDCGUI = _WinAPI_GetDC($hWndGUI)
    Local $hBrush = _WinAPI_CreateSolidBrush($iColor)
    _WinAPI_FrameRect($hDCGUI, DllStructGetPtr($tRect), $hBrush)
    _WinAPI_DeleteObject($hBrush)
    _WinAPI_ReleaseDC($hWndGUI, $hDCGUI)
    Return 1
EndFunc

Func _Rect(ByRef $aRect)
    Local $tRect = DllStructCreate("int;int;int;int")
    DllStructSetData($tRect, 1, $aRect[0])
    DllStructSetData($tRect, 2, $aRect[1])
    DllStructSetData($tRect, 3, $aRect[2]+$aRect[0])
    DllStructSetData($tRect, 4, $aRect[3]+$aRect[1])
    Return $tRect
EndFunc
That's good rover. If you switch to another window which doesn't cover the slider window then Alt Tab back to the slider window the dotted line comes back. If you switch to another window and then grab the caption bar of the slider window the dotted line comes back as well. I think this small change fixes it.

;by rover
#include <GUIConstantsEX.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
Global Const $WM_EXITSIZEMOVE=0x0232
Global Const $WM_ENTERSIZEMOVE=0x0231
Opt('GUIOnEventMode', 1)
Opt('MustDeclareVars', 1)

Global $hGUI, $hSlider, $iBuffer, $tRectSlider, $cSlider, $label
Global $iBkCol = 0x000000
Global $aSlider[4] = [25,25,200,50]

$hGUI = GUICreate("Slider focus rectangle", 250, 100)
GUISetBkColor($iBkCol)
GUISetOnEvent($GUI_EVENT_CLOSE, '_Exit')

$cSlider = GUICtrlCreateSlider($aSlider[0], $aSlider[1], $aSlider[2], $aSlider[3])
$hSlider = GUICtrlGetHandle($cSlider)
GUICtrlSetBkColor(-1, $iBkCol)
Global $tRectSlider = _Rect($aSlider)

$label = GUICtrlCreateLabel("0", 115, 80, 20, 15)
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetFont(-1, 10, 800, -1, "Arial")

GUIRegisterMsg($WM_ACTIVATE, "on_activate");<---added this
GUIRegisterMsg($WM_PAINT, "WM_HANDLER")
GUIRegisterMsg($WM_HSCROLL, "WM_HANDLER"); horizontal sliders
GUIRegisterMsg($WM_VSCROLL, "WM_HANDLER"); vertical sliders
GUISetState()

;initial paint over slider focus rectangle after gui shown
DrawRectangle($hGUI, $hSlider, $tRectSlider, $iBkCol)

Do
    Sleep(100)
Until 0

Func _Exit()
    GUIDelete()
    Exit
EndFunc ;==>_Exit

Func WM_HANDLER($hWnd, $Msg, $wParam, $lParam)
    #forceref $hWnd, $Msg, $wParam, $lParam
    Switch $Msg
        Case $WM_PAINT;, $WM_ACTIVATE <---- changed here
            DrawRectangle($hGUI, $hSlider, $tRectSlider, $iBkCol)
        Case $WM_HSCROLL, $WM_VSCROLL
            Switch $lParam
                Case $hSlider
                    Local $iSliderData = GUICtrlRead($cSlider)
                    If $iBuffer <> $iSliderData Then
                        $iBuffer = $iSliderData
                        GUICtrlSetData($label, $iBuffer)
                    EndIf
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc ;==>WM_ACTIVATE

Func DrawRectangle($hWndGUI, $hWndSlider, ByRef $tRect, $iColor)
    _WinAPI_RedrawWindow($hWndSlider, 0, 0, $RDW_UPDATENOW)
    Local $hDCGUI = _WinAPI_GetDC($hWndGUI)
    Local $hBrush = _WinAPI_CreateSolidBrush($iColor)
    _WinAPI_FrameRect($hDCGUI, DllStructGetPtr($tRect), $hBrush)
    _WinAPI_DeleteObject($hBrush)
    _WinAPI_ReleaseDC($hWndGUI, $hDCGUI)
    Return 1
EndFunc

Func _Rect(ByRef $aRect)
    Local $tRect = DllStructCreate("int;int;int;int")
    DllStructSetData($tRect, 1, $aRect[0])
    DllStructSetData($tRect, 2, $aRect[1])
    DllStructSetData($tRect, 3, $aRect[2]+$aRect[0])
    DllStructSetData($tRect, 4, $aRect[3]+$aRect[1])
    Return $tRect
EndFunc

Func On_Activate($wParam, $lParam)
    DllCall("user32.dll", "int", "InvalidateRect", "hwnd", $hGUI, "ptr", 0, "int", 1)
EndFunc
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

That's good rover. If you switch to another window which doesn't cover the slider window then Alt Tab back to the slider window the dotted line comes back. If you switch to another window and then grab the caption bar of the slider window the dotted line comes back as well. I think this small change fixes it.

good catch Martin, thanks

thanks Limiter

theme or 'skinning' dll's don't have this problem.

something in the uxtheme API I guess.

SystemParameterInfo has constants for changing the focus rectangle but they are system wide changes.

too bad the API for this is missing in XP.

never did like the look of a focus rectangle on a slider.

be seeing you

I see fascists...

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