Jump to content

FileInstall and GUICtrlCreatePic


Meerecat
 Share

Recommended Posts

Hello

I am using the following to copy a picture to the user's PC:

FileInstall ("C:\Users\Sienna X\Desktop\AutoIT Scripts\meerekat.jpg", @AppDataDir & "\Meerecat\FolderLock\meerekat.jpg")

The following code inserts the picture into my GUI:

GUICtrlCreatePic(@AppDataDir & "\Meerecat\FolderLock\Meerekat.jpg", 0, 0, 137, 217)

This works fine, but doesn't show the picture on first run of the program, only on subsequent runs.

How do I stop it from continuing until the file is in place, thereby showing the picture on the first run? I have tried a sleep command after the file copy but this does not work either.

Many Thanks

M

Lack of planning on your part does not constitute an emergency on my part.-The biggest idiot can ask questions the smartest man cannot answer.

Link to comment
Share on other sites

Hello

I am using the following to copy a picture to the user's PC:

FileInstall ("C:\Users\Sienna X\Desktop\AutoIT Scripts\meerekat.jpg", @AppDataDir & "\Meerecat\FolderLock\meerekat.jpg")

The following code inserts the picture into my GUI:

GUICtrlCreatePic(@AppDataDir & "\Meerecat\FolderLock\Meerekat.jpg", 0, 0, 137, 217)

This works fine, but doesn't show the picture on first run of the program, only on subsequent runs.

How do I stop it from continuing until the file is in place, thereby showing the picture on the first run? I have tried a sleep command after the file copy but this does not work either.

Many Thanks

M

Not having much luck are you Meerekat?

Can I recommend you look at Resources.au3:

In implementation, you can do the following:

* Either use Resource Hacker to put the image into the compiled application:

#AutoIt3Wrapper_Run_After="C:\Program Files\Resource Hacker\ResHacker.exe" -add %out%, %out%, C:\Users\Sienna X\Desktop\AutoIT Scripts\meerekat.jpg, rcdata, meerekat, 0

* Use that "Add" component of AutoIT3Wrapper (Haven't tested this cos I know the above just works):

#AutoIt3Wrapper_Add=C:\Users\Sienna X\Desktop\AutoIT Scripts\meerekat.jpg, rcdata, meerekat, 0

This means that when the file is Compiled you can extract the image directly from memory and insert it into a control:

#include <Resources.au3>
Local $LOGO = GUICtrlCreatePic("", 0, 0, 137, 217)
_ResourceSetImageToCtrl($LOGO, "meerekat")

Are you telling me something I need to know or something I want to know?

Link to comment
Share on other sites

Thanks, I'll take a look at that at lunch time.

No not having much luck lol, but I'll keep plodding on. The penny will drop eventually lol :)

Lack of planning on your part does not constitute an emergency on my part.-The biggest idiot can ask questions the smartest man cannot answer.

Link to comment
Share on other sites

I have added the following code to the top of my script:

#include <Resources.au3>
#AutoIt3Wrapper_Run_After="C:\Users\LeeM.SIENNAX\Desktop\reshack\ResHacker.exe" -add %out%, %out%, C:\Users\LeeM.SIENNAX\Desktop\AutoIT Scripts\meerekat.jpg, rcdata, meerekat, 0

I have replaced my picture code with:

Local $LOGO = GUICtrlCreatePic("", 0, 0, 137, 217)
_ResourceSetImageToCtrl($LOGO, "meerekat")

But the picture still does not display. Have I missed something obvious?

Many Thanks

Lack of planning on your part does not constitute an emergency on my part.-The biggest idiot can ask questions the smartest man cannot answer.

Link to comment
Share on other sites

Okay, first things first then...

Your AutoIT3Wrapper section is used to define compiled file parameters. It's written to be part of a range, see AutoIT3Wrapper Documentation.

Your script would want to look something like the following:

; #AUTOIT3 WRAPPER# =============================================================================================================
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Version=beta
#AutoIt3Wrapper_UseUpx=n
://////=__=
#AutoIt3Wrapper_Res_Comment=Meerekats Program
#AutoIt3Wrapper_Res_Description=Some program by Meerekat
#AutoIt3Wrapper_Res_Fileversion=1.0.1.965
#AutoIt3Wrapper_Res_FileVersion_AutoIncrement=y
#AutoIt3Wrapper_Res_LegalCopyright=Meerekat 2011
#AutoIt3Wrapper_Au3Check_Stop_OnWarning=y
#AutoIt3Wrapper_Icon=C:\Users\LeeM.SIENNAX\Desktop\AddRemoveIcons.ico
#AutoIt3Wrapper_Run_After="C:\Users\LeeM.SIENNAX\Desktop\reshack\ResHacker.exe" -add %out%, %out%, C:\Users\LeeM.SIENNAX\Desktop\AutoIT Scripts\meerekat.jpg, rcdata, meerekat, 0
#AutoIt3Wrapper_Run_Tidy=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
; ===============================================================================================================================

#include <Resources.au3> ; Assuming you have copied "Resources.au3" to your "%Programfiles%\AutoIT\Includes" folder
; And other includes as necessary

Opt("MustDeclareVars", 0) ; For ease of use, make sure all variables are declared


$wMain = GUICreate($appTitle & " - " & $appName & " v" & $appVer, $wWidth, $wHeight, -1, -1)
Local $LOGO = GUICtrlCreatePic("", 0, 0, 137, 217)
_ResourceSetImageToCtrl($LOGO, "meerekat")

Next, your script needs to fully compile, so ensure you have the latest script editor and when you have all the elements together, press F7 to run the compile.

Once compiled, check the EXE has the resources included by opening the program in ResHacker and verifying there is a MEEREKAT entry under RCDATA, being a JPG image you should also be able to see the image by clicking on the 0 subkey.

Now try running the file... see what it does.

EDIT: Example is mostly for structure purposes, I've just added example variable names so I don't have to think about it too much, hopefully you'll get the idea

Edited by Mallie99

Are you telling me something I need to know or something I want to know?

Link to comment
Share on other sites

Hello

Many thanks for your help. When running I get the following error:

"C:\Program Files (x86)\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\Users\LeeM.SIENNAX\Desktop\AutoIT Scripts\Folder Lock v2.au3"

C:\Users\LeeM.SIENNAX\Desktop\AutoIT Scripts\Folder Lock v2.au3 (73) : ==> Error in expression.:

Local $LOGO = GUICtrlCreatePic("", 0, 0, 137, 217) _ResourceSetImageToCtrl($LOGO, "meerekat")

Local $LOGO = ^ ERROR

>Exit code: 1 Time: 4.623

I really appreciate the help.

M

Lack of planning on your part does not constitute an emergency on my part.-The biggest idiot can ask questions the smartest man cannot answer.

Link to comment
Share on other sites

Hello

Many thanks for your help. When running I get the following error:

"C:\Program Files (x86)\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\Users\LeeM.SIENNAX\Desktop\AutoIT Scripts\Folder Lock v2.au3"

C:\Users\LeeM.SIENNAX\Desktop\AutoIT Scripts\Folder Lock v2.au3 (73) : ==> Error in expression.:

Local $LOGO = GUICtrlCreatePic("", 0, 0, 137, 217) _ResourceSetImageToCtrl($LOGO, "meerekat")

Local $LOGO = ^ ERROR

>Exit code: 1 Time: 4.623

I really appreciate the help.

M

Is there a break between "GUICtrlCreatePic("", 0, 0, 137, 217)" and "_ResourceSetImageToCtrl($LOGO, "meerekat")"? They should be on separate lines as in the example above.

Are you telling me something I need to know or something I want to know?

Link to comment
Share on other sites

I missed the break. I have now corrected it so it looks as above. The program runs without errors, but does not show my picture :)

Lack of planning on your part does not constitute an emergency on my part.-The biggest idiot can ask questions the smartest man cannot answer.

Link to comment
Share on other sites

As I am failing miserably to make this work (I am sure it is something I am doing wrong), is there a way to use FileInstall and still display the image on first run?

Or should I just write this one off?

Many thanks for your help (and patience).

M

Lack of planning on your part does not constitute an emergency on my part.-The biggest idiot can ask questions the smartest man cannot answer.

Link to comment
Share on other sites

You can try using a GUICtrlSetImage($LOGO, @AppDataDir & "\Meerecat\FolderLock\Meerekat.jpg") later in the script to set the control to the image. If that doesn't work, it may be because of possible spaces in the @Appdatadir and you may need to surround the whole line in quotes.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Hi,

you have to create the subfolder first and after FileInstall. Try this scipt:

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_UseUpx=n
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <GUIConstants.au3>
$sMyAppPath = @AppDataDir & "\Meerecat\FolderLock\"
if not FileExists($sMyAppPath) Then DirCreate($sMyAppPath)

FileInstall ("C:\Users\Sienna X\Desktop\AutoIT Scripts\meerekat.jpg", $sMyAppPath & "meerekat.jpg")



#region - GUI Create
GUICreate('Test')
GUICtrlCreatePic($sMyAppPath & "meerekat.jpg", 0, 0, 137, 217)
GUISetState()
#endregion

#region - GUI SelectLoop
While GUIGetMsg() <> $GUI_EVENT_CLOSE
WEnd
#endregion

mfg autoBert

Link to comment
Share on other sites

Good point autoBert, easy to forget that part if you're not careful.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Many thanks for the alternative fileinstall script above, it seems to do what I want.

A special thanks to Mallie99 who has spent ages today trying to help me with this. It appears to be a problem with my specific pc, as the files compiled fine for him.

Thanks again everyone.

Lack of planning on your part does not constitute an emergency on my part.-The biggest idiot can ask questions the smartest man cannot answer.

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