Jump to content

Window with background image and buttons


Go to solution Solved by Andreik,

Recommended Posts

Attempting to create a window with background image and buttons. While the window shows and the button functions properly, I am not seeing the background image. What am I missing here? Thanks in advance.

#include <GUIConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Local $idWindow = GUICreate("Image",400,200,-1,-1,$WS_BORDER+$WS_POPUP,$WS_EX_TOOLWINDOW+$WS_EX_TOPMOST)
GUICtrlCreatePic("C:\temp\image.png",0,0,399,199)
GUICtrlSetState(-1,$GUI_DISABLE)
Local $idButton_Close = GUICtrlCreateButton("Close",360,120)
GUISetState(@SW_SHOW, $idWindow)
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE, $idButton_Close
            ExitLoop
    EndSwitch
WEnd

 

Link to comment
Share on other sites

  • Solution

GUICtrlCreatePic() supported types are BMP, JPG, GIF but no PNG.

If you really want to use png files, you can do it like here:

#include <GUIConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>

Local $idWindow = GUICreate("Image", 400, 200)
Local $cPic = GUICtrlCreatePic('', 0, 0, 400, 200)
ImageToCtrl("C:\temp\image.png", $cPic)
GUICtrlSetState($cPic, $GUI_DISABLE)
Local $idButton_Close = GUICtrlCreateButton("Close",360,120)
GUISetState(@SW_SHOW, $idWindow)
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE, $idButton_Close
            ExitLoop
    EndSwitch
WEnd

Func ImageToCtrl($sImage, $cCtrl)
    _GDIPlus_Startup()
    Local $hImage = _GDIPlus_ImageLoadFromFile($sImage)
    Local $iWidth = _GDIPlus_ImageGetWidth($hImage)
    Local $iHeight = _GDIPlus_ImageGetHeight($hImage)
    Local $hBitmap = _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight)
    Local $hGraphics = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    _GDIPlus_GraphicsDrawImageRect($hGraphics, $hImage, 0, 0, $iWidth, $iHeight)
    Local $hHBITMAP = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)
    _WinAPI_DeleteObject(GUICtrlSendMsg($cCtrl, 0x0172, 0, $hHBITMAP))
    _WinAPI_DeleteObject($hHBITMAP)
    _GDIPlus_GraphicsDispose($hGraphics)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_ImageDispose($hImage)
    _GDIPlus_Shutdown()
EndFunc

 

Edited by Andreik

When the words fail... music speaks.

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