Jump to content

Recommended Posts

Posted

When AU3 script is run from right-click > run script, the background images, on the forms, are displayed correctly. However, when the compiled EXE is run, the background images are missing. Advice? Suggestions? Thanks in advance.

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

Global $Form_Intro = GUICreate("Intro form", 463, 266, -1, -1, $WS_POPUP & BITOR($WS_EX_LAYERED, $WS_EX_TOOLWINDOW))
Global $Pic_Intro = GUICtrlCreatePic(@ScriptDir & "\intro.jpg", 0, 0, 463, 266, $GUI_DISABLE)
Global $Button1_Intro = GUICtrlCreateButton("One", 175, 234, 49, 25)
Global $Button2_Intro = GUICtrlCreateButton("Two", 229, 234, 49, 25)
Global $Button3_Intro = GUICtrlCreateButton("Three", 283, 234, 49, 25)
Global $Button4_Intro = GUICtrlCreateButton("Cancel", 358, 234, 97, 25)

_Intro()

Func _Intro()
    WinSetOnTop($Form_Intro, "", $WINDOWS_ONTOP)
    GUISetState(@SW_SHOW, $Form_Intro)
    While 1
        $Msg_Welcome = GUIGetMsg()
        Switch $Msg_Welcome
            Case $Button1_Intro
                GUISetState(@SW_HIDE, $Form_Intro)
                _One_Ask()
                Exit
            Case $Button2_Intro
                GUISetState(@SW_HIDE, $Form_Intro)
                _Two_Ask()
                Exit
            Case $Button3_Intro
                GUISetState(@SW_HIDE, $Form_Intro)
                _Three_Ask()
                Exit
            Case $Button4_Intro
                GUISetState(@SW_HIDE, $Form_Intro)
                _Cancel_Ask()
        EndSwitch
    WEnd
EndFunc

 

Posted

Hi @StMaSi 👋 ,

this is not reproducable on my side. The intro.jpg is displayed as running script and also as running *.exe. Are you sure your intro.jpg is a JPG/JPEG? Because PNG is not visible out of the box in your shown way. Please try with an other JPG image.

Best regards
Sven

Stay innovative!

Spoiler

🌍 Au3Forums

🎲 AutoIt (en) Cheat Sheet

📊 AutoIt limits/defaults

💎 Code Katas: [...] (comming soon)

🎭 Collection of GitHub users with AutoIt projects

🐞 False-Positives

🔮 Me on GitHub

💬 Opinion about new forum sub category

📑 UDF wiki list

✂ VSCode-AutoItSnippets

📑 WebDriver FAQs

👨‍🏫 WebDriver Tutorial (coming soon)

Posted

Yes @Nine, that's come on top of it. But the wrong style will be ignored and the image is shown (at least with my "intro.jpg").

Stay innovative!

Spoiler

🌍 Au3Forums

🎲 AutoIt (en) Cheat Sheet

📊 AutoIt limits/defaults

💎 Code Katas: [...] (comming soon)

🎭 Collection of GitHub users with AutoIt projects

🐞 False-Positives

🔮 Me on GitHub

💬 Opinion about new forum sub category

📑 UDF wiki list

✂ VSCode-AutoItSnippets

📑 WebDriver FAQs

👨‍🏫 WebDriver Tutorial (coming soon)

Posted

SOLVE-SMART, yes, the images are JPG files as I created them myself in GIMP and exported as JPG. I have tried with many JPGs, even generic ones downloaded from the net. Unfortunately, after further testing, the EXE is functioning properly on other computers, so it may be just this one computer having some unknown issue.

 

Nine, unfortunately, the change in the GUI create didn't make a difference.

Posted

The scriptdir contains the au3 file and all jpg files. From within SciTE, I compile (Tools > Compile) the au3 from that folder. No errors or issues during compilation. After that, I transfer only the compiled EXE to computers. So, far, it is just this single computer that isn't showing the background images. Just can't wrap my head around it. No errors in the Windows event viewer and nothing out of the ordinary showing up in ProcMon, so I'm at a loss.

  • Developers
Posted (edited)

Long story for a simple question Yes/No! ;) 

The reason it won't show is that you load the image with this statement.. right?:

Global $Pic_Intro = GUICtrlCreatePic(@ScriptDir & "\intro.jpg", 0, 0, 463, 266, $GUI_DISABLE)

So when you compile the script into an exe, the @scripdir macro variable will contain the subdirectory the exe is moved to, which doesn't contain the jpg...right?

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

  • Developers
Posted
Just now, StMaSi said:

So, there's no way to "include" the jpg files into the EXE?

This is not what I said, merely explained why it isn't working.
Yes there are several options to include the jpg file. Have you tried searching for this, as this is asked before? 

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Posted (edited)

@StMaSi  Well, I wanted to have simple clean script to show any JPG directly included inside the EXE.  So this is what end up with :

#AutoIt3Wrapper_Res_File_Add=Intro.jpg, rt_rcdata, ResFile

#include <GUIConstants.au3>
#include <WinAPISys.au3>
#include <WinAPIRes.au3>
#include <Memory.au3>
#include <GDIPlus.au3>
#include <WinAPICom.au3>
#include <StaticConstants.au3>

Opt("MustDeclareVars", True)

If Not @Compiled Then Exit MsgBox($MB_OK, "Error", "This script needs to be compiled")

Example()

Func Example()
  Local $hGUI = GUICreate("Example", 500, 400, -1, -1, $WS_POPUP, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST, $WS_EX_CONTROLPARENT))
  Local $idBackGround = GUICtrlCreatePic("", 0, 0, 500, 400, $GUI_DISABLE)
  Local $idCancel = GUICtrlCreateButton("Cancel", 400, 370, 90, 25)

  Local $hBitmap = GetResImage("ResFile", 500, 400)
  GUICtrlSendMsg($idBackGround, $STM_SETIMAGE, $IMAGE_BITMAP, $hBitmap)
  _WinAPI_DeleteObject($hBitmap)

  GUISetState()
  While True
    Switch GUIGetMsg()
      Case $idCancel
        ExitLoop
    EndSwitch
  WEnd
EndFunc   ;==>Example

Func GetResImage($sName, $iWidth = Default, $iHeight = Default)
  _GDIPlus_Startup()
  Local $hInstance = _WinAPI_GetModuleHandle(0)
  Local $hResource = _WinAPI_FindResource($hInstance, $RT_RCDATA, $sName)
  Local $nSize = _WinAPI_SizeOfResource($hInstance, $hResource)
  Local $hData = _WinAPI_LoadResource($hInstance, $hResource)
  Local $pResData = _WinAPI_LockResource($hData)

  $hData = _MemGlobalAlloc($nSize, $GMEM_MOVEABLE)
  Local $pData = _MemGlobalLock($hData)
  _MemMoveMemory($pResData, $pData, $nSize)
  _MemGlobalUnlock($hData)
  Local $pStream = _WinAPI_CreateStreamOnHGlobal($hData, True)
  Local $hImage = _GDIPlus_BitmapCreateFromStream($pStream)
  _WinAPI_ReleaseStream($pStream)

  Local $hResize, $hBitmap
  If $iWidth <> Default Or $iHeight <> Default Then
    If $iWidth = Default Then $iWidth = _GDIPlus_ImageGetWidth($hImage)
    If $iHeight = Default Then $iHeight = _GDIPlus_ImageGetHeight($hImage)
    $hResize = _GDIPlus_ImageResize($hImage, $iWidth, $iHeight)
    $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hResize)
    _GDIPlus_ImageDispose($hResize)
  Else
    $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
  EndIf
  _GDIPlus_ImageDispose($hImage)
  _GDIPlus_Shutdown()
  Return $hBitmap
EndFunc   ;==>GetResImage

 

Edited by Nine
Revised code
  • Developers
Posted
8 hours ago, Nine said:

Well, I wanted to have simple clean script to show any JPG directly included inside the EXE.

@StMaSi, this example requires the Separate SciTE4AutoIt3 installer which includes AutoIt3Wrapper required for the first line directive. 

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...