Jump to content

Image as a button


Recommended Posts

I have tried multiple controls (including GUICtrlSetImage, GUiSetIcon, GUICtrlSetColor, GUICtrlSetBKColor, GuiCtrlSetGraphic for labels, buttons, input fields, and just certain coordinates on the screen ), multiple GUICtrlSetState/Styles. and many different images (including .icos, .jpgs, .pngs, .bmps) to try and simply have an image that sits on top of my background image and when you push it, it does stuff. The closest I've gotten is a blank white field that has the text I want and performs the function I want, but it is just a white spot, no picture. I have searched the forums for an hour and a half now, so please, any pointers would be great...

Christianity: In the beginning, there was God, who always was there and created everything.Atheism: In the beginning, there was nothing, which exploded. Both sides look bad...

Link to comment
Share on other sites

1: Did you search the GUI help forum?

2: GuiCtrlSetState(-1,$GUI_DISABLE) on the background picture

3: GuiCtrlSetImage(-1,*image path*) after the button

Link to comment
Share on other sites

This works for me. Replace the pictures' paths

#include <GUIConstants.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 633, 454, 193, 138)
$Pic1 = GUICtrlCreatePic(@WindowsDir & "\A pescar.bmp",0,0,633,454)
GUICtrlSetState(-1,$GUI_DISABLE)
$Pic2 = GUICtrlCreatePic(@WindowsDir & "\Viento.bmp", 208, 148, 157, 100)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Pic2
            MsgBox(0,"","Pic pressed")

    EndSwitch
WEnd
Link to comment
Share on other sites

Yeah here's the code, you'll see what I'm trying to do. In this case I made it open firefox just so i know it works. I'm including basically the whole code even though this is part of a bigger project.

CODE
$GUI = GUICreate("Window Slide In", @DesktopWidth, 300, 0, @DesktopHeight - 80, $WS_POPUP, "", WinGetHandle("Program Manager")) ;80

GUISetState()

$WPos = WinGetPos($GUI)

WinSetOnTop($GUI, "", 1)

WinSetOnTop("[class:Shell_TrayWnd]", "", 1)

$topped = True

$bkimg = GUICtrlCreatePic("C:\Program Files\AutoIt3\Scripts\black_background2.jpg", 0, 0, @DesktopWidth, $WPos[3]) ;background image

GuiCtrlSetState(-1,$GUI_DISABLE)

$exit = GUICtrlCreateButton("X", 100, 100, 30, 15) ;red exit button

GUICtrlSetBkColor($exit, 0xff0000)

$AIM = GUICtrlCreateButton("Launch AIM", 200, 100, 100, 50)

GUICtrlSetImage($AIM, "C:\Program Files\AutoIt3\Scripts\1_aim6.ico")

$firefox = GUICtrlCreateButton("Launch Firefox", 305, 100, 100, 50)

$ffimage = GUICtrlSetImage($firefox, "C:\Program Files\AutoIt3\Scripts\3_firefox.ico")

$itunes = GUICtrlCreateButton("Launch iTunes", 405, 100, 100, 50)

GUICtrlSetImage($itunes, @ProgramFilesDir & "AutoIt3\Scripts\01_iTunes.ico")

GUIRegisterMsg($WM_VSCROLL, "WM_HVSCROLL")

$Vertical_Label = GUICtrlCreateLabel("Master Volume: 0", @DesktopWidth - 140, 50, 120)

GUICtrlSetBkColor($Vertical_Label, 0xA0A0A4)

$Vertical_Slider = GUICtrlCreateSlider(@DesktopWidth - 50, 80, 30, 120,BitOr($GUI_SS_DEFAULT_SLIDER, $TBS_VERT))

GUICtrlSetBkColor($Vertical_Slider, 0xA0A0A4)

GUICtrlSetData($Vertical_Slider,100)

While 1

If WinActive($GUI) And Not $topped Then

WinSetOnTop("[class:Shell_TrayWnd]", "", 1)

$topped = True

Else

$topped = False

EndIf

Sleep(100)

$msg = GUIGetMsg()

$MPos = MouseGetPos()

If ($MPos[0] >= $WPos[0]) And ($MPos[0] <= ($WPos[0] + $WPos[2])) And _

($MPos[1] >= $WPos[1]) And ($MPos[1] <= ($WPos[1] + $WPos[3])) Then

WinMove($GUI, "", 0, @DesktopHeight - 280, @DesktopWidth, 300, 3)

ElseIf ($MPos[0] < $WPos[0]) Or ($MPos[0] > ($WPos[0] + $WPos[2])) Or _

($MPos[1] < ($WPos[1] - 200)) Or ($MPos[1] > ($WPos[1] + $WPos[3])) Then

WinMove($GUI, "", 0, @DesktopHeight - 80, @DesktopWidth, 300, 3)

ElseIf $msg = $exit Then

Exit

ElseIf $msg = $AIM Then

Run(@ProgramFilesDir & "\AIM6\aim6.exe")

ElseIF $msg = $firefox Then

Run(@ProgramFilesDir & "\Mozilla Firefox\firefox.exe")

ElseIf $msg = $itunes Then

Run(@ProgramFilesDir & "\iTunes\itunes.exe")

EndIf

If GUIGetMsg() = -3 Then Exit

WEnd

Func WM_HVSCROLL($hWndGUI, $MsgID, $WParam, $LParam)

Switch $LParam

Case GUICtrlGetHandle($Vertical_Slider)

$Vertical_val=100-GUICtrlRead($Vertical_Slider)

ConsoleWrite($Vertical_val&@LF)

GUICtrlSetData($Vertical_Label, "Master Volume: " & $Vertical_val)

_SoundSetMasterVolume($Vertical_val)

Case GUICtrlGetHandle($Horizontal_Slider)

GUICtrlSetData($Horizontal_Label, "Horizontal Slider Read: " & GUICtrlRead($Horizontal_Slider))

EndSwitch

EndFunc

Not too pretty yet, still trying to make it work. any other tips are great too

Christianity: In the beginning, there was God, who always was there and created everything.Atheism: In the beginning, there was nothing, which exploded. Both sides look bad...

Link to comment
Share on other sites

This works for me. Replace the pictures' paths

#include <GUIConstants.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 633, 454, 193, 138)
$Pic1 = GUICtrlCreatePic(@WindowsDir & "\A pescar.bmp",0,0,633,454)
GUICtrlSetState(-1,$GUI_DISABLE)
$Pic2 = GUICtrlCreatePic(@WindowsDir & "\Viento.bmp", 208, 148, 157, 100)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Pic2
            MsgBox(0,"","Pic pressed")

    EndSwitch
WEnd
All it did for me was a regular background, no pics at all, and a message box popping up as soon as the other was closed saying the pic was pressed. But there were no pics at all, and I didn't click anywhere....

Christianity: In the beginning, there was God, who always was there and created everything.Atheism: In the beginning, there was nothing, which exploded. Both sides look bad...

Link to comment
Share on other sites

This works for me. Replace the pictures' paths

#include <GUIConstants.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 633, 454, 193, 138)
$Pic1 = GUICtrlCreatePic(@WindowsDir & "\A pescar.bmp",0,0,633,454)
GUICtrlSetState(-1,$GUI_DISABLE)
$Pic2 = GUICtrlCreatePic(@WindowsDir & "\Viento.bmp", 208, 148, 157, 100)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Pic2
            MsgBox(0,"","Pic pressed")

    EndSwitch
WEnd
And by the way, what exactly is the #Region bit? I've never used that before...

Christianity: In the beginning, there was God, who always was there and created everything.Atheism: In the beginning, there was nothing, which exploded. Both sides look bad...

Link to comment
Share on other sites

I have tried multiple controls (including GUICtrlSetImage, GUiSetIcon, GUICtrlSetColor, GUICtrlSetBKColor, GuiCtrlSetGraphic for labels, buttons, input fields, and just certain coordinates on the screen ), multiple GUICtrlSetState/Styles. and many different images (including .icos, .jpgs, .pngs, .bmps) to try and simply have an image that sits on top of my background image and when you push it, it does stuff. The closest I've gotten is a blank white field that has the text I want and performs the function I want, but it is just a white spot, no picture. I have searched the forums for an hour and a half now, so please, any pointers would be great...

@theholycow

it always helps to post a 'working' example with includes,

declared variables and any lines commented out if they refer to areas of code not included.

and any required images included or at least replaced with stand-in w2k,xp,w2k3 or vista OS images.

so those helping don't have to do all the work of shaping your code into a workable example.

MVP Dale Hohm calls them 'reproducers', the smallest number of lines of code that demonstrate the problem.

having said that, here's your code working as an example.

button controls with icon and bitmap imagelists and a bitmap button

BTW, Regions are a feature of the SciTE editor

more or less markers for areas of code, they can be removed.

see SciTE helpfile.

#include <GUIConstantsEX.au3>
#include <Constants.au3>
#include <WindowsConstants.au3>
#include <GuiSlider.au3>
#include <GuiButton.au3>
#include <GuiImageList.au3>
#Include <WinAPI.au3>

$GUI = GUICreate("Window Slide In", @DesktopWidth, 300, 0, @DesktopHeight - 80, BitOR($WS_POPUP, $WS_CLIPCHILDREN), $WS_EX_LAYERED , _
WinGetHandle("Program Manager")) ;80

$WPos = WinGetPos($GUI)

WinSetOnTop($GUI, "", 1)
WinSetOnTop("[class:Shell_TrayWnd]", "", 1)
$topped = True

$bkimg = GUICtrlCreatePic(@WindowsDir & "\Web\Wallpaper\Windows XP.jpg", _
0, 0, @DesktopWidth, $WPos[3]) ;background image
GUICtrlSetState(-1, $GUI_DISABLE)

$exit = GUICtrlCreateButton("X", 100, 100, 16, 16) ;red exit button
GUICtrlSetFont(-1, 12, 800, 0, "Arial")
GUICtrlSetBkColor($exit, 0xFF0000)

;single state image Icon
$AIM = GUICtrlCreateButton("Launch" & @lf & "AIM", 200, 100, 100, 50, BitOR($BS_MULTILINE, $BS_CENTER))
$hImagebtn1 = _GUIImageList_Create(32, 32, 5, 3)
_GUIImageList_AddIcon($hImagebtn1, @ProgramFilesDir & "\Messenger\msmsgs.exe", 0, True)
;_GUIImageList_AddIcon($hImagebtn1, "C:\Program Files\AutoIt3\Scripts\1_aim6.ico", 0, True)
_GUICtrlButton_SetImageList($AIM, $hImagebtn1)

;single state image Icon
$firefox = GUICtrlCreateButton("Launch" & @lf & "Firefox", 305, 100, 100, 50, BitOR($BS_MULTILINE, $BS_CENTER))
$hImagebtn2 = _GUIImageList_Create(32, 32, 5, 3)
_GUIImageList_AddIcon($hImagebtn2, @ProgramFilesDir & "\Mozilla Firefox\firefox.exe", 0, True)
;_GUIImageList_AddIcon($hImagebtn2, "C:\Program Files\AutoIt3\Scripts\3_firefox.ico", 0, True)
_GUICtrlButton_SetImageList($firefox, $hImagebtn2)

;single state image Icon
$itunes = GUICtrlCreateButton("Launch" & @lf & "iTunes", 405, 100, 100, 50, BitOR($BS_MULTILINE, $BS_CENTER))
$hImagebtn3 = _GUIImageList_Create(32, 32, 5, 3)
_GUIImageList_AddIcon($hImagebtn3, "shell32.dll", 168, True)
;_GUIImageList_AddIcon($hImagebtn3, @ProgramFilesDir & "AutoIt3\Scripts\01_iTunes.ico", 0, True)
_GUICtrlButton_SetImageList($itunes, $hImagebtn3)
    
;single state image Bitmap
$WinXP1 = GUICtrlCreateButton("", 505, 100, 100, 50, $BS_MULTILINE)
GUICtrlSetTip(-1, "Multi state bitmap imagelist")
$hImagebtn4 = _GUIImageList_Create(32, 32, 4, 3)
_GUIImageList_AddBitmap($hImagebtn4, @AppDataCommonDir & "\Microsoft\User Account Pictures\Default Pictures\dirt bike.bmp");1 - Normal
_GUIImageList_AddBitmap($hImagebtn4, @AppDataCommonDir & "\Microsoft\User Account Pictures\Default Pictures\airplane.bmp");2 - Hot
_GUIImageList_AddBitmap($hImagebtn4, @AppDataCommonDir & "\Microsoft\User Account Pictures\Default Pictures\lift-off.bmp");3 - Pressed
_GUIImageList_AddBitmap($hImagebtn4, @AppDataCommonDir & "\Microsoft\User Account Pictures\Default Pictures\astronaut.bmp");4 - Disabled
_GUIImageList_AddBitmap($hImagebtn4, @AppDataCommonDir & "\Microsoft\User Account Pictures\Default Pictures\car.bmp");5 - Defaulted
_GUIImageList_AddBitmap($hImagebtn4, @AppDataCommonDir & "\Microsoft\User Account Pictures\Default Pictures\airplane.bmp");6 - Stylus Hot (tablet computers only)
_GUICtrlButton_SetImageList($WinXP1, $hImagebtn4, 0)

;single state image Bitmap - sized same as button with no button border
$WinXP2 = GUICtrlCreateButton("WinXP", 610, 93, 64, 64)
GUICtrlSetTip(-1, "Multi state bitmap imagelist")
$hImagebtn5 = _GUIImageList_Create(64, 64, 4, 3)
_GUIImageList_AddBitmap($hImagebtn5, @WindowsDir & "\Prairie Wind.bmp");1 - Normal
_GUIImageList_AddBitmap($hImagebtn5, @WindowsDir & "\Soap Bubbles.bmp");2 - Hot
_GUIImageList_AddBitmap($hImagebtn5, @WindowsDir & "\Greenstone.bmp");3 - Pressed
_GUIImageList_AddBitmap($hImagebtn5, @WindowsDir & "\Rhododendron.bmp");4 - Disabled
_GUIImageList_AddBitmap($hImagebtn5, @WindowsDir & "\River Sumida.bmp");5 - Defaulted
_GUIImageList_AddBitmap($hImagebtn5, @WindowsDir & "\Soap Bubbles.bmp");6 - Stylus Hot (tablet computers only)
_GUICtrlButton_SetImageList($WinXP2, $hImagebtn5, 4)


GUIRegisterMsg($WM_VSCROLL, "WM_HVSCROLL")

$Vertical_Label = GUICtrlCreateLabel("Master Volume: 0", @DesktopWidth - 140, 50, 120)
GUICtrlSetBkColor($Vertical_Label, 0xA0A0A4)

$Vertical_Slider = GUICtrlCreateSlider(@DesktopWidth - 50, 80, 30, 120, _
BitOR($GUI_SS_DEFAULT_SLIDER, $TBS_VERT))
GUICtrlSetBkColor($Vertical_Slider, 0xA0A0A4)
GUICtrlSetData($Vertical_Slider, 100)

_API_SetLayeredWindowAttributes($GUI, 0xABCDEF, 255) ; set transparency from 0 to 255 (opaque)
GUISetState()

While 1
    $msg = GUIGetMsg()
    If WinActive($GUI) And Not $topped Then
        WinSetOnTop("[class:Shell_TrayWnd]", "", 1)
        $topped = True
    Else
        $topped = False
    EndIf
    ;Sleep(100)
    
    $MPos = MouseGetPos()

    If ($MPos[0] >= $WPos[0]) And ($MPos[0] <= ($WPos[0] + $WPos[2])) And _
            ($MPos[1] >= $WPos[1]) And ($MPos[1] <= ($WPos[1] + $WPos[3])) Then
        WinMove($GUI, "", 0, @DesktopHeight - 280, @DesktopWidth, 300, 3)
    ElseIf ($MPos[0] < $WPos[0]) Or ($MPos[0] > ($WPos[0] + $WPos[2])) Or _
            ($MPos[1] < ($WPos[1] - 200)) Or ($MPos[1] > ($WPos[1] + $WPos[3])) Then
        WinMove($GUI, "", 0, @DesktopHeight - 80, @DesktopWidth, 300, 3)
    EndIf
    
    Switch $msg
        Case $exit, $GUI_EVENT_CLOSE
            Exit
        Case $AIM
            Run(@ProgramFilesDir & "\AIM6\aim6.exe")
        Case $firefox
            Run(@ProgramFilesDir & "\Mozilla Firefox\firefox.exe")
        Case $itunes
            Run(@ProgramFilesDir & "\iTunes\itunes.exe")
        Case $WinXP1
            Beep(1000,5)
        Case $WinXP2
            Beep(2000,5)
    EndSwitch
WEnd


Func WM_HVSCROLL($hWndGUI, $MsgID, $WParam, $LParam)
    Switch $LParam
        Case GUICtrlGetHandle($Vertical_Slider)
            $Vertical_val = 100 - GUICtrlRead($Vertical_Slider)
            ConsoleWrite($Vertical_val & @LF)
            GUICtrlSetData($Vertical_Label, "Master Volume: " & $Vertical_val)
            ;_SoundSetMasterVolume($Vertical_val)

        ;Case GUICtrlGetHandle($Horizontal_Slider)
            ;GUICtrlSetData($Horizontal_Label, "Horizontal Slider Read: " & GUICtrlRead($Horizontal_Slider))

    EndSwitch
EndFunc   ;==>WM_HVSCROLL


;===============================================================================
;
; 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
    #forceref $AC_SRC_ALPHA, $ULW_ALPHA
    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

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