Jump to content
Sign in to follow this  
ShadowOps

Image Help!

Recommended Posts

ShadowOps

I need help embedding bitmap images into a compiled script, so that my program is only one file, and not five (the script and 4 bitmaps). I am completely new to Autoit and this forum, so forgive me if I have not included enough detail, or posted wrong, or something...

Share this post


Link to post
Share on other sites
monoceres

Hi and welcome.

Please check the FileInstall() function in the help file. It does exactly what you need.


Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites
ShadowOps

I already tried, with no success. :D

Could you give an example on how to use it? And if I do use it, what would I do for the image location? (GuiCtrlCreatePic("???",200,40,25,25))

Share this post


Link to post
Share on other sites
ShadowOps

Oops! :D How do I delete a double post?

Share this post


Link to post
Share on other sites
monoceres

The FileInstall function requires at least a temporary file during runtime.

If you want to completely skip the files part you'll have to use Zedna's resource UDF

Edited by monoceres

Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites
ShadowOps

The FileInstall function requires at least a temporary file during runtime.

If you want to completely skip the files part you'll have to use Zedna's resource UDF

But could you give me an example script? I am completely new so...

Share this post


Link to post
Share on other sites
Authenticity

#include <GuiConstants.au3>

FileInstall('C:\FullPath_ToFile\smile.jpg', @ScriptDir)

Dim $hGUI = GUICreate('Test', 200, 200)
Dim $Pic = GUICtrlCreatePic(@ScriptDir & '\smile.jpg', 0, 0)

GUISetState()

Do
    Sleep(20)
Until GUIGetMsg() = $GUI_EVENT_CLOSE

GUIDelete()

Change the file path and name, read the help file it must be a literal string (no interpolation of @macro or variables). Compile and test.

Share this post


Link to post
Share on other sites
ShadowOps

#include <GuiConstants.au3>

FileInstall('C:\FullPath_ToFile\smile.jpg', @ScriptDir)

Dim $hGUI = GUICreate('Test', 200, 200)
Dim $Pic = GUICtrlCreatePic(@ScriptDir & '\smile.jpg', 0, 0)

GUISetState()

Do
    Sleep(20)
Until GUIGetMsg() = $GUI_EVENT_CLOSE

GUIDelete()

Change the file path and name, read the help file it must be a literal string (no interpolation of @macro or variables). Compile and test.

Do I need the "Dim", or can I just use this:

GUICtrlCreatePic(@ScriptDir & '\smile.jpg', 0, 0)

Share this post


Link to post
Share on other sites
CodyBarrett

you need the variables if you want to recall functions to that control.. but DIM not unless you have OPT('MustDeclareAllVars',1)

Share this post


Link to post
Share on other sites
ShadowOps

So than why does the below script not show an image:

#include <GuiConstants.au3>
#include <WindowsConstants.au3>
#include <TabConstants.au3>
FileInstall('C:\image.bmp', @ScriptDir)
Dim $hGUI = GuiCreate("Test", 300, 300,Default,Default,-1,$WS_EX_TOOLWINDOW)
GUISetState(@SW_SHOW)
sleep(50)
GuiCtrlCreateTab(2,2,297,397)
GuiCtrlCreateTabItem("Legend")
Dim $Pic = GuiCtrlCreatePic(@ScriptDir & '\image.bmp',20,20,220,280)
While GuiGetMsg() <> $GUI_EVENT_CLOSE
WEnd
Exit

Share this post


Link to post
Share on other sites
CodyBarrett

put GUISETSTATE() beneath everything but above the While

EDIT here try this

#include <GuiConstants.au3>
#include <WindowsConstants.au3>
#include <TabConstants.au3>
FileInstall('C:\image.bmp', @ScriptDir & '\Image.bmp')
Dim $hGUI = GuiCreate("Test", 300, 300,Default,Default,-1,$WS_EX_TOOLWINDOW)
sleep(50)
GuiCtrlCreateTab(2,2,297,397)
GuiCtrlCreateTabItem("Legend")
$Pic = GuiCtrlCreatePic(@ScriptDir & '\image.bmp',20,20,220,280)
GUISetState(@SW_SHOW)

While 1
$m=Guigetmsg()
if $m=$GUI_EVENT_CLOSE then exit
WEnd
Edited by CodyBarrett

Share this post


Link to post
Share on other sites
CodyBarrett

yeah cause it looked like you werent even extracting the file... try having a file name in the dest.. like i posted

Share this post


Link to post
Share on other sites
ShadowOps

Forgive me...

It's actually like this:

FileInstall('C:\image.bmp', @ScriptDir & '\')
Thanks, that worked! But now I want to replace "@ScriptDir" to the temp folder (C:\Documents and Settings\(USERNAME)\Local Settings\Temp). Is there a variable to that location?

Share this post


Link to post
Share on other sites
CodyBarrett

autoit helpfile>Autoit>Marco Reference

@TempDir

Share this post


Link to post
Share on other sites
ShadowOps

autoit helpfile>Autoit>Marco Reference

@TempDir

Thank you for all your help, but one last thing! Now how can I delete the .bmp files in the @TempDir when I exit my script?

Share this post


Link to post
Share on other sites
ShadowOps

$sFile = @TempDir & '\smile.jpg'
If FileExist($sFile) Then FileDelete($sFile)

Read the help file next time. ;]

Wait... Than gives me an "unknown function name" error...

Share this post


Link to post
Share on other sites
Authenticity

lol Sorry, it's actually FileExists. Anyway, read the help file (F1 from SciTE editor), it's much faster way.

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.