Jump to content

GUICtrlCreateButton() with Transparent background.


guinness
 Share

Recommended Posts

So I have solved the problem with using a 2nd GUI and the $WS_EX_MDICHILD ExStyle, but it's a little bit hacky (if I can use that as an adjective!?) So I was wondering is there a better approach for creating a button with a transparent background, instead of having the default grey border around it?

As ever the code is fully working, but I'm just looking for a different if not better approach. Thanks for the help!

Note: It should also be note that the GUI is sizable!

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>

_Main_1() ; Traditional Example
_Main_2() ; Traditional Example

Func _Main_1()
    Local $hGUI, $iButton
    $hGUI = GUICreate("_Main() - Before", 255, 40, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_SIZEBOX))

    GUICtrlCreatePic("C:\Program Files\AutoIt\Examples\GUI\mslogo.jpg", 0, 0, 255, 40)
    GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKSIZE + $GUI_DOCKTOP)
    GUICtrlSetState(-1, $GUI_DISABLE)

    $iButton = GUICtrlCreateButton("Button", 255 - 70, 5, 65, 20)
    GUICtrlSetResizing(-1, $GUI_DOCKRIGHT + $GUI_DOCKSIZE + $GUI_DOCKTOP)

    GUISetState(@SW_SHOW)

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop

            Case $iButton
                MsgBox(0, "ControlID = " & $iButton, "Button was Pressed!")

        EndSwitch
    WEnd
    GUIDelete($hGUI)
EndFunc   ;==>_Main_1

Func _Main_2()
    Local $aArray, $hButtonGUI, $hGUI, $iButton
    $hGUI = GUICreate("_Main() - After", 255, 40, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_SIZEBOX))

    $aArray = _GUICtrlCreateButton($hGUI, "Button", 255 - 75, 0, 65, 20) ; Returns 2D Array with GUI Handle & Button ControlID.
    $hButtonGUI = $aArray[0]
    $iButton = $aArray[1]

    GUICtrlCreatePic("C:\Program Files\AutoIt\Examples\GUI\mslogo.jpg", 0, 0, 255, 40)
    GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKSIZE + $GUI_DOCKTOP)
    GUICtrlSetState(-1, $GUI_DISABLE)

    GUISetState(@SW_SHOW, $hGUI)
    GUISetState(@SW_SHOW, $hButtonGUI) ; Show Button!

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop

            Case $iButton
                MsgBox(0, "ControlID = " & $iButton, "Button was Pressed!")

        EndSwitch
    WEnd
    GUIDelete($hGUI)
    GUIDelete($hButtonGUI)
EndFunc   ;==>_Main_2

Func _GUICtrlCreateButton($hHandle, $sText, $iLeft, $iTop, $iWidth, $iHeight, $iStyle = -1, $iExStyle = -1)
    Local $aReturn[2]

    $aReturn[0] = GUICreate($sText, $iWidth, $iHeight, $iLeft, $iTop, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $hHandle)
    GUISetBkColor(0xABCDEF)
    _WinAPI_SetLayeredWindowAttributes($aReturn[0], 0xABCDEF)
    $aReturn[1] = GUICtrlCreateButton($sText, 0, 0, $iWidth, $iHeight, $iStyle, $iExStyle)
    GUISwitch($hHandle)
    Return $aReturn
EndFunc   ;==>_GUICtrlCreateButton
Edited by guinness

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

look at the example script of _WinAPI_SetLayeredWindowAttributes() there you got your answer... also has his little bit hacky things, but works fine for this

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
$GUI = GUICreate("_Main() - Before", 255, 40, -1, -1, $GUI_SS_DEFAULT_GUI, $WS_EX_LAYERED)
GUISetBkColor(0xABCDEF)
GUICtrlCreatePic("C:\Program Files\AutoIt\Examples\GUI\mslogo.jpg", 0, 0, 255, 40)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKSIZE + $GUI_DOCKTOP)
GUICtrlSetState(-1, $GUI_DISABLE)
_WinAPI_SetLayeredWindowAttributes($GUI, 0xABCDEF,255,0x03)
$button1 = GUICtrlCreateButton("Button", 0, 0, 65,40)
GUISetState(@SW_SHOW)
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit

        Case $Button1
            MsgBox(0, "ControlID = " & $Button1, "Button was Pressed!")

    EndSwitch
WEnd
Link to comment
Share on other sites

Hey thanks for that! But the idea is the GUI is sizable, which is why I didn't want to make the Parent GUI Transparent. Cheers for answering.

I edit the OP.

Edited by guinness

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

I still don´t understand what you want... :S

I guess(not sure) you want a GUI wich can be...

...sizeable picking the corners and draging

...with a visible title(caption)

...with buttons to maximize and minimize

...with a pic inside that stretch when the windows change the size

...and a button

i don´t understand the transparency(?) of your second GUI

i don´t understand why! a second GUI(?)

If you explain it better we(me)i be able to participate :unsure:

sorry my bad english.. i´m from Argentina and speak(write - read) spasish.

EDIT: i have this so far...

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
$GUI = GUICreate("_Main() - Before", 255, 40, -1, -1,bitor($WS_MAXIMIZEBOX,$WS_MINIMIZEBOX,$WS_SIZEBOX)); $WS_EX_LAYERED) still doesn´t know why :S
GUISetBkColor(0xABCDEF)
GUICtrlCreatePic(@scriptdir&"\elitepvp.bmp", 0, 0, 255, 40) ; change the pic because i don´t have what you use
GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP)
GUICtrlSetState(-1, $GUI_DISABLE)
; SetLayeredWindowAttributes() it´s unnecessary because this is for transparen
;~ _WinAPI_SetLayeredWindowAttributes($GUI, 0xABCDEF,50,0x01); test different flags
$button1 = GUICtrlCreateButton("Button", 0, 0, 65,40)
GUISetState(@SW_SHOW)
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit

        Case $Button1
            MsgBox(0, "ControlID = " & $Button1, "Button was Pressed!")

    EndSwitch
WEnd
Edited by monoscout999
Link to comment
Share on other sites

..

sorry my bad english.. i´m from Argentina and speak(write - read) spasish.

..

I used to speak spasish, but I used it less and less as I became sober.

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

monoscout999 it's OK! The second Example I provided is what I am looking for, but I was hoping for a different approach to it.

I guess(not sure) you want a GUI wich can be...

...sizable picking the corners and dragging

Correct.

i don´t understand the transparency(?) of your second GUI

Because this allows me to have a button without the Default grey colour.

The problem is with GUICtrlCreateButton() you get this little grey line around the button, I tried to find an approach of getting rid of this (which I did) but I was hoping for different variations of my second Function. Does this explain a little better?

Edited by guinness

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

Because this allows me to have a button without the Default grey colour.

Aahhh so you want this...

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
 ; i change the size to adapt to my pic
$GUI = GUICreate("_Main() - Before", 255, 80, -1, -1,bitor($WS_MAXIMIZEBOX,$WS_MINIMIZEBOX,$WS_SIZEBOX))
GUISetBkColor(0xABCDEF)
GUICtrlCreatePic(@scriptdir&"\elitepvp.bmp", 0, 0, 255, 80) ; change the pic because i don´t have what you use
GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP)
GUICtrlSetState(-1, $GUI_DISABLE)
GUISetState()
; Second GUI POP_UP(no borders or caption) midchild(allow to move with the parent GUI)
GUICreate("",65,40,0,0,$WS_POPUP, $WS_EX_MDICHILD, $GUI)
; The button is a little outside the 2ndGUI to hide the color borders :)
$button1 = GUICtrlCreateButton("Button", -1, -1, 67,42)
GUISetState()
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit

        Case $Button1
            MsgBox(0, "ControlID = " & $Button1, "Button was Pressed!")

    EndSwitch
WEnd

maybe is another way to do it, because creating a GUI for each button it seems a little bit "crapy!" :unsure: it works.. but the other way to do it is creating buttons with picboxes and set the mouse event using GUIGetCursorInfo() to give the hover efects and the click effects... i have a tuorial on spanish to do that.. later i translate and put on the forum ^^

EDIT: the custom button can have the shape you want

Edited by monoscout999
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...