Jump to content

Can't add images to my GUI


Moist
 Share

Recommended Posts

Hello guys,

I've seen people having trouble with adding .png images to GUI, but were able to add .bmp image. Well, I can't seem to add anything.

Here's an example:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
GUICreate("", 300, 300, 500, 500)
$Pic = GUICtrlCreatePic(@ScriptDir&"\1.bmp", 10, 10, 50, 45)
GUISetState(@SW_SHOW)

While 1

   $Msg = GUIGetMsg()
   Switch $Msg
   Case $GUI_EVENT_CLOSE

   EndSwitch
WEnd
 

The GUI appears, but there is no image.

Link to comment
Share on other sites

Script is fine, just make sure your bitmap is where is suppose to be, in the right location.

Maybe adding this line to check the file before would help you.

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

If Not FileExists(@ScriptDir&"\1.bmp") Then MsgBox(0,'','File not exists!')

GUICreate("", 300, 300, 500, 500)
$Pic = GUICtrlCreatePic(@ScriptDir&"\1.bmp", 10, 10, 50, 45)
GUISetState(@SW_SHOW)

While 1

   $Msg = GUIGetMsg()
   Switch $Msg
   Case $GUI_EVENT_CLOSE
        Exit
   EndSwitch
WEnd

 

Edited by Andreik
Link to comment
Share on other sites

Your bitmap has BITMAPV5HEADER and this seems to be unsupported by these functions. Something like this might be a workaround.

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

GUICreate("", 300, 300)
$Pic = GUICtrlCreatePic('', 10, 10, 50, 45)
SetBitmapToCtrl(@ScriptDir & '\1.bmp', $Pic)
GUISetState(@SW_SHOW)

While 1

   $Msg = GUIGetMsg()
   Switch $Msg
   Case $GUI_EVENT_CLOSE
        Exit
   EndSwitch
WEnd

Func SetBitmapToCtrl($sPath, $iCtrl)
    _GDIPlus_Startup()
    $hPic = _GDIPlus_BitmapCreateFromFile($sPath)
    $hHBITMAP = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hPic)
    _WinAPI_DeleteObject(GUICtrlSendMsg($iCtrl,0x0172,0,$hHBITMAP))
    _WinAPI_DeleteObject($hHBITMAP)
    _GDIPlus_BitmapDispose($hPic)
    _GDIPlus_Shutdown()
EndFunc

 

Edited by Andreik
Link to comment
Share on other sites

1 hour ago, Subz said:

Couldn't get it working either, however I just opened your 1.bmp with Paint and then saved it again as 1.bmp and it worked fine after that so something wrong with the original bmp.

Thanks, that solved it for me.

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