Sign in to follow this  
Followers 0
samm

PNG button image

16 posts in this topic

#1 ·  Posted (edited)

Hi,

Instead of the standard windows button, I would like to use this PNG button (so it would support transparency):

StepForwardDisabled.png

Is it possible to make the above PNG image clickable button, working as the standard one?

I've been looking on google & through the examples scripts but havent found anything.

Regards

Edited by samm

Share this post


Link to post
Share on other sites



Search the forum for "png bm_setimage button".

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

Search the forum for "png bm_setimage button".

Br,

UEZ

 

Default button is visible that way...

Share this post


Link to post
Share on other sites

#include <ButtonConstants.au3>
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>

_GDIPlus_Startup()
Global Const $hGUI = GUICreate("Test", 300, 200)
GUISetBkColor(0x404040)
Global Const $iBtn = GUICtrlCreateButton("", 10, 10, 138, 138, BitOR($BS_BITMAP, $BS_CENTER))
Global Const $hImage = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\StepForwardDisabled.png")
Global Const $hHBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
_WinAPI_DeleteObject(_SendMessage(GUICtrlGetHandle($iBtn), $BM_SETIMAGE, $IMAGE_BITMAP, $hHBitmap))
GUISetState()

Do
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            _Exit()
        Case $iBtn
            MsgBox($MB_APPLMODAL, "Test", "Button was pressed")
    EndSwitch
Until False

Func _Exit()
    _WinAPI_DeleteObject($hHBitmap)
    _GDIPlus_ImageDispose($hImage)
    _GDIPlus_Shutdown()
    GUIDelete()
    Exit
EndFunc

Br,

UEZ

1 person likes this

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

YRbhsIo.png

Default button is still visible. I want only the "StepForwardDisabled.png" to be visible & clickable on the GUI.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

#include <ButtonConstants.au3>
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <StaticConstants.au3>

_GDIPlus_Startup()
Global Const $hGUI = GUICreate("Test", 300, 200), $STM_SETIMAGE = 0x0172
GUISetBkColor(0x404040)
Global Const $iPic = GUICtrlCreatePic("", 10, 10, 138, 138)
Global Const $hImage = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\StepForwardDisabled.png")
Global Const $hHBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
_WinAPI_DeleteObject(GUICtrlSendMsg($iPic, $STM_SETIMAGE, $IMAGE_BITMAP, $hHBitmap))
GUISetState()

Do
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            _Exit()
        Case $iPic
            MsgBox($MB_APPLMODAL, "Test", "Button was pressed")
    EndSwitch
Until False

Func _Exit()
    _WinAPI_DeleteObject($hHBitmap)
    _GDIPlus_ImageDispose($hImage)
    _GDIPlus_Shutdown()
    GUIDelete()
    Exit
EndFunc
Br,

UEZ

Edited by UEZ
1 person likes this

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

Thank you so much UEZ.

Merry Christmas.

Share this post


Link to post
Share on other sites

Your are welcome and merry xmas.

Btw, I updated the code a little bit.

Br,

UEZ

1 person likes this

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

Thank you once again.

Btw, 5pOhu2z.png

This is displaying while I run the script, while I change the

#include <MsgBoxConstants.au3>

into the

#include <Constants.au3>

It works. Do I need to leave it like this or I'd have to update something?

Regards

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Sorry, forgot to modify this line. MsgBoxConstants.au3 is from the current final release and not included in previous versions.

If your code works than it works - no need to update something.

Br,

UEZ

Edited by UEZ
1 person likes this

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

UEZ, I am using the GDI Plus as well to display my GUI PNG image background, when I add the code responsible for the button, it does clean my GUI background to white leaving only the button visible. Is it possible to have multiple GDI Plus images on the same GUI?

Regards

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

Use the same technique as shown but disable the background control.
 

#include <Constants.au3>
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>

_GDIPlus_Startup()
Global Const $hGUI = GUICreate("Test", 300, 200), $STM_SETIMAGE = 0x0172
Global Const $iPic_Bg = GUICtrlCreatePic("", 0, 0, 1024, 768)
GUICtrlSetState(-1, $GUI_DISABLE)
SendImageToPicControl("c:\Program Files (x86)\AutoIt3\Examples\GUI\msoobe.jpg", $iPic_Bg)
Global Const $iPic = GUICtrlCreatePic("", 10, 10, 128, 128)
SendImageToPicControl(@ScriptDir & "\StepForwardDisabled.png", $iPic)
GUISetState()

Do
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            _Exit()
        Case $iPic
            MsgBox($MB_APPLMODAL, "Test", "Button was pressed")
    EndSwitch
Until False

Func SendImageToPicControl($sImage, $iCtrlID)
    Local Const $hImage = _GDIPlus_ImageLoadFromFile($sImage)
    Local Const $hHBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
    _WinAPI_DeleteObject(GUICtrlSendMsg($iCtrlID, $STM_SETIMAGE, $IMAGE_BITMAP, $hHBitmap))
    _WinAPI_DeleteObject($hHBitmap)
    _GDIPlus_ImageDispose($hImage)
EndFunc

Func _Exit()
    _GDIPlus_Shutdown()
    GUIDelete()
    Exit
EndFunc

Br,
UEZ

Edited by UEZ
2 people like this

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

Func SendImageToPicControl($sImage, $iCtrlID) ;this way works only for Vista+ os

 

What about the XP systems? Is there any work-around to support this system?

Regards

Edited by samm

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

Just tested in my WinXP VM and it works, too.  I had something in mind that when disposed the bitmap just after sending it to the picture control the image was not shown. I'm not using WinXP anymore for a long time.

 

Otherwise you have to dispose the image when you exit the script -> _WinAPI_DeleteObject($hHBitmap).

Br,

UEZ

Edited by UEZ
1 person likes this

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

UEZ sorry if i'm bump another guy thread but i have an issue with this script:

#include <GUIConstantsEx.au3>
#include <Constants.au3>
#include <GDIPlus.au3>

_GDIPlus_Startup()

Global Const $STM_SETIMAGE = 0x0172

$hGUI = GUICreate("Test", 300, 200)
$iPic_Bg = GUICtrlCreatePic("", 0, 0, 300, 200)
GUICtrlSetState(-1, $GUI_DISABLE)
SendImageToPicControl(@ProgramFilesDir & "\AutoIt3\Examples\GUI\msoobe.jpg", $iPic_Bg)
$iPic = GUICtrlCreatePic("", 62, 15, 138, 138)
SendImageToPicControl(@ProgramFilesDir & "\AutoIt3\Examples\GUI\Torus.png", $iPic)
GUISetState()

Do
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            _Exit()
        Case $iPic
            MsgBox(0, "Test", "Button was pressed")
    EndSwitch
Until False

Func SendImageToPicControl($sImage, $iCtrlID)
    Local Const $hImage = _GDIPlus_ImageLoadFromFile($sImage)
    Local Const $hHBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
    _WinAPI_DeleteObject(GUICtrlSendMsg($iCtrlID, $STM_SETIMAGE, $IMAGE_BITMAP, $hHBitmap))
    _WinAPI_DeleteObject($hHBitmap)
    _GDIPlus_ImageDispose($hImage)
EndFunc

Func _Exit()
    _GDIPlus_Shutdown()
    GUIDelete()
    Exit
EndFunc

This is the screenshot when i open it:

23ke06s.jpg

But if i minimize the window, then click on the taskbar to "restore it" i have this:

2hyc7b5.jpg

What is that? :D

XP SP3 with Autoit 3.3.8.1, using Global Const etc. is the same

Merry xmas to all!

Edited by Terenz

Nothing is so strong as gentleness. Nothing is so gentle as real strength

 

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

You have to provide the real image resolutions:
 

$hGUI = GUICreate("Test", 300, 200)
$iPic_Bg = GUICtrlCreatePic("", 0, 0, 1024, 768)
GUICtrlSetState(-1, $GUI_DISABLE)
SendImageToPicControl(@ProgramFilesDir & "\AutoIt3\Examples\GUI\msoobe.jpg", $iPic_Bg)
$iPic = GUICtrlCreatePic("", 62, 15, 193, 184)
SendImageToPicControl(@ProgramFilesDir & "\AutoIt3\Examples\GUI\Torus.png", $iPic)
GUISetState()

Otherwise the image proportions will be malformed.

Or try to load the image directly:

$hGUI = GUICreate("Test", 300, 200)
$iPic_Bg = GUICtrlCreatePic(@ProgramFilesDir & "\AutoIt3\Examples\GUI\msoobe.jpg", 0, 0, 300, 200, 14)
GUICtrlSetState(-1, $GUI_DISABLE)
;~ SendImageToPicControl(@ProgramFilesDir & "\AutoIt3\Examples\GUI\msoobe.jpg", $iPic_Bg)
$iPic = GUICtrlCreatePic("", 62, 15, 193, 184)
SendImageToPicControl(@ProgramFilesDir & "\AutoIt3\Examples\GUI\Torus.png", $iPic)

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

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