Jump to content
Sign in to follow this  
Peter86

How to control GuiCtrlCreateIcon transparency or background colour

Recommended Posts

Peter86

Hi,

I'm trying to create a script that mimics the dialog shown in the attachment. With the exception of a problem with the icon transparency, I have been able to do this. The icon control seems to thing that the transparent regions of the icon should be set to the form colour, not simply see-through, and I can't seem to set the background colour for the control.

Does anyone have any idea how you set the background colour for an icon control?

Regards,

Peter

Dialog I'm trying to recreate:

post-20142-1211172161_thumb.png

Code that I've got:

#include <GUIConstants.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>

$Form1 = GUICreate("Confirmation", 420, 150, 377, 409, BitOR($WS_BORDER,$WS_CLIPSIBLINGS))
GUICtrlCreateGroup("", -5, 75, 430, 10)
 GUICtrlCreateLabel("", 0, 0, 420, 81, $SS_WHITERECT)
GUICtrlCreateGroup("", -99, -99, 1, 1)

$cboNeverShow = GUICtrlCreateCheckbox("Don't &ask me this again", 12, 96, 140, 17)
$btnYes = GUICtrlCreateButton("&Yes", 245, 91, 75, 25, 0)
$btnNo = GUICtrlCreateButton("&No", 328, 91, 75, 25, 0)

GUICtrlSetDefBkColor(0xFFFFFF)
$icon = GUICtrlCreateIcon ("user32.dll",102,20,20,32,32 )
GUICtrlSetBkColor($icon,0xFFFFFF)
GUICtrlCreateLabel("Would you like to be hit on the head with a blunt instrument?", 70, 20, 320, 40)

GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $btnYes
            MsgBox(16,"Error!","Unhandled exception has occured!")
            Exit
        Case $btnNo
            Exit
    EndSwitch
WEnd

OS: Windows XP SP2, AutoIt version: 3.2.12.0

Share this post


Link to post
Share on other sites
rasim

Try this:

#include <GUIConstants.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>

$Form1 = GUICreate("Confirmation", 420, 150, 377, 409, BitOR($WS_BORDER,$WS_CLIPSIBLINGS))
GUISetBkColor(0xFFFFFF)

GUICtrlCreateLabel("", 0, 80, 420, 40)
GUICtrlSetBkColor(-1, 0xECE9D8)
GUICtrlSetState(-1, $GUI_DISABLE)

$cboNeverShow = GUICtrlCreateCheckbox("Don't &ask me this again", 12, 96, 140, 17)
GUICtrlSetBkColor(-1, 0xECE9D8)

$btnYes = GUICtrlCreateButton("&Yes", 245, 91, 75, 25, 0)

$btnNo = GUICtrlCreateButton("&No", 328, 91, 75, 25, 0)

$icon = GUICtrlCreateIcon("user32.dll",102,20,20,32,32 )

GUICtrlCreateLabel("Would you like to be hit on the head with a blunt instrument?", 70, 20, 320, 40)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)

GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $btnYes
            MsgBox(16,"Error!","Unhandled exception has occured!")
            Exit
        Case $btnNo
            Exit
    EndSwitch
WEnd

Share this post


Link to post
Share on other sites
ProgAndy

THe "GRay" Color isn't right. Try this:

Small WorkAround: Use a GUI as White BG:

CODE
#include <GUIConstants.au3>

#include <WindowsConstants.au3>

#include <StaticConstants.au3>

#include <WinApi.au3>

$Form1 = GUICreate("Confirmation", 420, 150, 377, 409, BitOR($WS_BORDER,$WS_CLIPCHILDREN))

$x = GUICreate("", 420, 81,0, 0,$WS_CHILD+$WS_POPUP,0,$Form1)

GUISetBkColor(0xFFFFFF)

$icon = GUICtrlCreateIcon ("",0,20,20,32,32)

GUICtrlSetImage(-1,"user32.dll",102)

_WinAPI_SetParent($x,$Form1)

GUISetState()

GUISwitch($Form1)

GUICtrlCreateLabel("Would you like to be hit on the head with a blunt instrument?", 70, 20, 320, 40)

GUICtrlSetBkColor(-1,$GUI_BKCOLOR_TRANSPARENT)

GUICtrlCreateLabel("",0,81,420,3,$SS_SUNKEN)

$cboNeverShow = GUICtrlCreateCheckbox("Don't &ask me this again", 12, 96, 140, 17)

$btnYes = GUICtrlCreateButton("&Yes", 245, 91, 75, 25, 0)

$btnNo = GUICtrlCreateButton("&No", 328, 91, 75, 25, 0)

GUISetState(@SW_SHOW)

While 1

$nMsg = GUIGetMsg()

Switch $nMsg

Case $GUI_EVENT_CLOSE

Exit

Case $btnYes

MsgBox(16,"Error!","Unhandled exception has occured!")

Exit

Case $btnNo

Exit

EndSwitch

WEnd

Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites
Peter86

Thanks rasim, that worked perfectly!

@ProgAndy, thanks for your suggestion, that did the job also.

regards,

Peter

Try this:

#include <GUIConstants.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>

$Form1 = GUICreate("Confirmation", 420, 150, 377, 409, BitOR($WS_BORDER,$WS_CLIPSIBLINGS))
GUISetBkColor(0xFFFFFF)

GUICtrlCreateLabel("", 0, 80, 420, 40)
GUICtrlSetBkColor(-1, 0xECE9D8)
GUICtrlSetState(-1, $GUI_DISABLE)

$cboNeverShow = GUICtrlCreateCheckbox("Don't &ask me this again", 12, 96, 140, 17)
GUICtrlSetBkColor(-1, 0xECE9D8)

$btnYes = GUICtrlCreateButton("&Yes", 245, 91, 75, 25, 0)

$btnNo = GUICtrlCreateButton("&No", 328, 91, 75, 25, 0)

$icon = GUICtrlCreateIcon("user32.dll",102,20,20,32,32 )

GUICtrlCreateLabel("Would you like to be hit on the head with a blunt instrument?", 70, 20, 320, 40)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)

GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $btnYes
            MsgBox(16,"Error!","Unhandled exception has occured!")
            Exit
        Case $btnNo
            Exit
    EndSwitch
WEnd

OS: Windows XP SP2, AutoIt version: 3.2.12.0

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  

×