Sign in to follow this  
Followers 0
Hiyoal

Transparent Background on Slider...PLZ HELP!

3 posts in this topic

Hey guys,

Ive made an application with a slider ontop of a background. How can I make it that the Slider background color is transparent.

Hiyoal

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Hey guys,

Ive made an application with a slider ontop of a background. How can I make it that the Slider background color is transparent.

Hiyoal

Try this, I found a portion of the code on here and was able to alter it. I've implimented into my GUI so the slider sits on the GUI instead of Child/Parent window

#include <GUIConstantsEx.au3>


$LevelSet = 0;Start at 0

$Gui = GUICreate("Transparent", 200, 130)

$Level = GUICtrlCreateSlider(26, 32, 150, 40)
$Label = GUICtrlCreateLabel($LevelSet & " Tranparent Level", 72, 10)

GUICtrlSetLimit($Level, 4, 0);End at 4

GUISetState()

Opt("WinTitleMatchMode", 1); Match 1st word in window title



$UpdateChange=""
While 1
$msg = GUIGetMsg()

$LevelSet = GUICtrlRead($Level)

If $LevelSet <> $UpdateChange Then
GUICtrlSetData($Label, $LevelSet & " Tranparent Level")
$UpdateChange = $LevelSet
EndIf

If GUICtrlRead($Level) = 0 Then 
WinSetTrans("Transparent", "", -1);Transparent is the title of this gui,
EndIf           ;Rename it to what ever window you want it transparents


If GUICtrlRead($Level) = 1 Then 
WinSetTrans("Transparent", "", 200);200 is the level of transparency and so on
EndIf

If GUICtrlRead($Level) = 2 Then 
WinSetTrans("Transparent", "", 150)
EndIf

If GUICtrlRead($Level) = 3 Then 
WinSetTrans("Transparent", "", 100)
EndIf

If GUICtrlRead($Level) = 4 Then 
WinSetTrans("Transparent", "", 50)
EndIf

If $msg = $GUI_EVENT_CLOSE Then
ExitLoop
EndIf
WEnd
Exit
Edited by astrax

Share this post


Link to post
Share on other sites

To have a slider with a transparent background over an area which is not transparent you need to create another window, but not a child window. Set that window to have the extended style $WS_EX_LAYERED, set the slider on that window and set the transparent colour to be the GUI background colour.

Then you will need to register $WM_MOVE so that you can keep the slider window in the correct place.

Here is an example of making the background of a normal window transparent with sliders. You need the subclassed sliders or you will get the dotted border which will ruin the transparent effect.

In your case you need a popup window not a normal window as in my example, but I did that so you can drag it around to see the transparent effect.

;subclassing by aec see
;http://www.autoitscript.com/forum/index.php?s=&showtopic=53986&view=findpost&p=516869
#include <GuiConstants.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
#include <GuiSlider.au3>
Opt("PixelCoordMode", 2)

$Gui = GUICreate("Subclassed Slider without Focus Border", 300, 200,200,200,-1,$WS_EX_LAYERED)
;GUISetBkColor(0xabcdef)
$Vertical_Label = GUICtrlCreateLabel("Vertical Slider Read: 0", 20, 20, 200)
$Horizontal_Label = GUICtrlCreateLabel("Horizontal Slider Read: 0", 80, 120, 200)
$Vertical_Slider = GUICtrlCreateSlider(20, 50, 30, 120, BitOr($GUI_SS_DEFAULT_SLIDER, $TBS_VERT))
$Horizontal_Slider = GUICtrlCreateSlider(60, 150, 160, 30)

; Register callback function and obtain a handle to the new slider WindowProc
$hNewSliderProc = DllCallbackRegister("_NoFocusBorderWindowProc", "int", "hwnd;uint;wparam;lparam")
; Get a pointer to the new WindowProc
$pNewSliderProc = DllCallbackGetPtr($hNewSliderProc)

; Subclass horizontal slider and retrieve a pointer to the original slider WindowProc
$pOriginalSliderProc = _WinSubclass(GUICtrlGetHandle($Horizontal_Slider), $pNewSliderProc)


; Subclass vertical slider
_WinSubclass(GUICtrlGetHandle($Vertical_Slider), $pNewSliderProc)

GUISetState()
 $TestCol = PixelGetColor(15,20);get the gui background colour
; ConsoleWrite("test col = " & Hex($TestCol,6) & @CRLF)
_API_SetLayeredWindowAttributes($gui,$TestCol,255);set special colour fully transparent
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            GuiDelete($Gui)
           ; Free
            DllCallBackFree($hNewSliderProc)
            Exit
    EndSwitch
WEnd


Func _NoFocusBorderWindowProc($hWnd, $uiMsg, $wParam, $lParam)
   ;handle setfocus because it is focussing which gives the dotted lines
    If $uiMsg = $WM_SETFOCUS Then Return 0
   
   ;other messages are handled with the original slider proc
    Return _WinAPI_CallWindowProc($pOriginalSliderProc, $hWnd, $uiMsg, $wParam, $lParam)
EndFunc

Func _WinSubclass($hWnd, $pNewWindowProc)
    Local $a_res
  ;$GWL_WNDPROC = -4
    $a_res = DllCall("user32.dll", "ptr", "SetWindowLong", "hwnd", $hWnd, "int", -4, "ptr", $pNewWindowProc)

    If @error Then Return SetError(1, 0, 0)
    If $a_res[0] = 0 Then Return SetError(1, 0, 0)
    Return $a_res[0]
EndFunc

;===============================================================================
;
; Function Name:   _API_SetLayeredWindowAttributes
; Description:: Sets Layered Window Attributes:) See MSDN for more informaion
; Parameter(s):
;                 $hwnd - Handle of GUI to work on
;                 $i_transcolor - Transparent color
;                 $Transparency - Set Transparancy of GUI
;                 $isColorRef - If True, $i_transcolor is a COLORREF-Strucure, else an RGB-Color
; Requirement(s):  Layered Windows
; Return Value(s): Success: 1
;                 Error: 0
;                  @error: 1 to 3 - Error from DllCall
;                  @error: 4 - Function did not succeed - use
;                              _WinAPI_GetLastErrorMessage or _WinAPI_GetLastError to get more information
; Author(s):       Prog@ndy
;
;===============================================================================
;
Func _API_SetLayeredWindowAttributes($hwnd, $i_transcolor, $Transparency = 255, $isColorRef = False)

    Local Const $AC_SRC_ALPHA = 1
    Local Const $ULW_ALPHA = 2
    Local Const $LWA_ALPHA = 0x2
    Local Const $LWA_COLORKEY = 0x1
    If Not $isColorRef Then
        $i_transcolor = Hex(String($i_transcolor), 6)
        $i_transcolor = Execute('0x00' & StringMid($i_transcolor, 5, 2) & StringMid($i_transcolor, 3, 2) & StringMid($i_transcolor, 1, 2))
    EndIf
    Local $Ret = DllCall("user32.dll", "int", "SetLayeredWindowAttributes", "hwnd", $hwnd, "long", $i_transcolor, "byte", $Transparency, "long", $LWA_COLORKEY + $LWA_ALPHA)
    Select
        Case @error
            Return SetError(@error, 0, 0)
        Case $Ret[0] = 0
            Return SetError(4, 0, 0)
        Case Else
            Return 1
    EndSelect
EndFunc ;==>_API_SetLayeredWindowAttributes

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.

Share this post


Link to post
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
Sign in to follow this  
Followers 0