Jump to content

Resources UDF


Zedna
 Share

Recommended Posts

Zedna, in your UDF I found a small bug related to memory leaks when using the _SetBitmapToCtrl(). After reading that, I corrected it.

Func _SetBitmapToCtrl($CtrlId, $hBitmap)

    Local Const $STM_SETIMAGE = 0x0172
    Local Const $STM_GETIMAGE = 0x0173
    Local Const $IMAGE_BITMAP = 0
    Local Const $SS_BITMAP = 0x0E
    Local Const $GWL_STYLE = -16

    Local $hWnd, $hPrev, $Style

    $hWnd = GUICtrlGetHandle($CtrlId)
    If $hWnd = 0 Then
        Return SetError(1, 0, 0)
    EndIf
    $Style = _WinAPI_GetWindowLong($hWnd, $GWL_STYLE)
    If @error Then
        Return SetError(2, 0, 0)
    EndIf
    _WinAPI_SetWindowLong($hWnd, $GWL_STYLE, BitOR($Style, $SS_BITMAP))
    If @error Then
        Return SetError(3, 0, 0)
    EndIf
    $hPrev = _SendMessage($hWnd, $STM_SETIMAGE, $IMAGE_BITMAP, 0)
    If $hPrev Then
        _WinAPI_DeleteObject($hPrev)
    EndIf
    _SendMessage($hWnd, $STM_SETIMAGE, $IMAGE_BITMAP, $hBitmap)
    If @error Then
        Return SetError(4, 0, 0)
    EndIf
    $hPrev = _SendMessage($hWnd, $STM_GETIMAGE, $IMAGE_BITMAP, 0)
    If (@error) Or ($hBitmap = $hPrev) Then
        $hBitmap = 0
    EndIf
    If $hBitmap Then
        _WinAPI_DeleteObject($hBitmap)
    EndIf

    Return 1
EndFunc   ;==>_SetBitmapToCtrl
Link to comment
Share on other sites

Zedna, in your UDF I found a small bug related to memory leaks when using the _SetBitmapToCtrl(). After reading that, I corrected it.

Thanks for the code Yashied!

I read that MSDN article already but I didn't know what exact code should be the  best clear solution without memory leaks

so I did only my simplified version in hope it will be OK.

I will correct my UDF with your code but be patient please.

Edited by Zedna
Link to comment
Share on other sites

  • 1 month later...

hi , _ResourceSaveToFile() hasn't have support for .ico type resources ?

The following code doesn't work properly

#Region
#AutoIt3Wrapper_icon=PentagramRed.ico
#AutoIt3Wrapper_UseUpx=n
#AutoIt3Wrapper_Run_After=ResHacker.exe -add %out%, %out%, icon.ico, rcdata, RCOMP_ICON_1, 0
#AutoIt3Wrapper_Run_After=upx.exe --best --compress-resources=0 "%out%"
;=============================================================
;  icon.ico , upx.exe , ResHacker.exe are in the script directory 
; _ResourceSaveToFile() works with other resource like exe , gif , dat and others ...
;=============================================================
#EndRegion
#NoTrayIcon
#RequireAdmin
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <File.au3>
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <GuiStatusBar.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include "resources.au3"
_ResourceSaveToFile("C:\icon.ico", "RCOMP_ICON_1")
if @error Then
    MsgBox(0,0,@error) ; returns 1 ...
EndIf

EDIT

I Found what caused the problem , ResHacker is unable to add icon trough directive "#AutoIt3Wrapper_Run_After=ResHacker.exe -add %out%, %out%, iconname.ico, rcdata, ICON_IDENT, 0" as RCData resource" ... , but if you add the resource using other way it works well

Edited by Azraelsub7
Link to comment
Share on other sites

EDIT

I Found what caused the problem , ResHacker is unable to add icon trough directive "#AutoIt3Wrapper_Run_After=ResHacker.exe -add %out%, %out%, iconname.ico, rcdata, ICON_IDENT, 0" as RCData resource" ... , but if you add the resource using other way it works well

Use $RT_ICON type instead of $RT_RCDATA then.

Link to comment
Share on other sites

  • 4 weeks later...
  • Moderators

Zedna,

Following on from the discussion we had in this topic, I have been looking into the problem of getting images on to buttons as well as static controls. I have come up with an amendment to your _SetBitmapToCtrl function which uses an API call (you already include WinAPI.au3 in the basic UDF) to get the Class name of the control and so determine which Constants to use. It has worked fine under my Alpha testing so far, so I offer it to the wider community for a more stringent Beta regime :( .

; internal helper function
Func _SetBitmapToCtrl($CtrlId, $hBitmap)  ; - <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Yashied's version of the function from post #363

    Local Const $STM_SETIMAGE = 0x0172
    Local Const $STM_GETIMAGE = 0x0173
    Local Const $BM_SETIMAGE = 0xF7
    Local Const $BM_GETIMAGE = 0xF6
    Local Const $IMAGE_BITMAP = 0
    Local Const $SS_BITMAP = 0x0E
    Local Const $BS_BITMAP = 0x0080
    Local Const $GWL_STYLE = -16

    Local $hWnd, $hPrev, $Style, $iCtrl_SETIMAGE, $iCtrl_GETIMAGE, $iCtrl_BITMAP

    ; determine control class and adjust constants accordingly    ;- <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Melba23's addition
    Switch _WinAPI_GetClassName($CtrlId)
        Case "Button"
            $iCtrl_SETIMAGE = $BM_SETIMAGE
            $iCtrl_GETIMAGE = $BM_GETIMAGE
            $iCtrl_BITMAP = $BS_BITMAP
        Case "Static"
            $iCtrl_SETIMAGE = $STM_SETIMAGE
            $iCtrl_GETIMAGE = $STM_GETIMAGE
            $iCtrl_BITMAP = $SS_BITMAP
        Case Else
            Return SetError(1, 0, 0)
    EndSwitch                            ;-<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< to here

    $hWnd = GUICtrlGetHandle($CtrlId)
    If $hWnd = 0 Then
        Return SetError(1, 0, 0)
    EndIf
    $Style = _WinAPI_GetWindowLong($hWnd, $GWL_STYLE)
    If @error Then
        Return SetError(2, 0, 0)
    EndIf
    _WinAPI_SetWindowLong($hWnd, $GWL_STYLE, BitOR($Style, $iCtrl_BITMAP))
    If @error Then
    Return SetError(3, 0, 0)
    EndIf
    $hPrev = _SendMessage($hWnd, $iCtrl_SETIMAGE, $IMAGE_BITMAP, 0)
    If $hPrev Then
        WinAPI_DeleteObject($hPrev)
    EndIf
    _SendMessage($hWnd, $iCtrl_SETIMAGE, $IMAGE_BITMAP, $hBitmap)
    If @error Then
        Return SetError(4, 0, 0)
    EndIf
    $hPrev = _SendMessage($hWnd, $iCtrl_GETIMAGE, $IMAGE_BITMAP, 0)
    If (@error) Or ($hBitmap = $hPrev) Then
        $hBitmap = 0
    EndIf
    If $hBitmap Then
        _WinAPI_DeleteObject($hBitmap)
    EndIf

    Return 1
EndFunc   ;==>_SetBitmapToCtrl

If anyone comes across any problems or has any suggestions/improvements, please let me know - I am getting about as deep as I ever do here and it is quite likely that I have gone out of my depth a little >_< .

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Zedna,

Following on from the discussion we had in this topic, I have been looking into the problem of getting images on to buttons as well as static controls. I have come up with an amendment to your _SetBitmapToCtrl function which uses an API call (you already include WinAPI.au3 in the basic UDF) to get the Class name of the control and so determine which Constants to use. It has worked fine under my Alpha testing so far, so I offer it to the wider community for a more stringent Beta regime :( .

If anyone comes across any problems or has any suggestions/improvements, please let me know - I am getting about as deep as I ever do here and it is quite likely that I have gone out of my depth a little >_< .

M23

Thanks Melba!

It's exactly what I planned to do :-)

Now I have no time for testing/adding this to my UDF, so be patient.

In the future I will add this good adition to my UDF.

Link to comment
Share on other sites

  • 4 weeks later...

Zedna,

Following on from the discussion we had in this topic, I have been looking into the problem of getting images on to buttons as well as static controls.  I have come up with an amendment to your _SetBitmapToCtrl function which uses an API call (you already include WinAPI.au3 in the basic UDF) to get the Class name of the control and so determine which Constants to use.  It has worked fine under my Alpha testing so far, so I offer it to the wider community for a more stringent Beta regime :D .

If anyone comes across any problems or has any suggestions/improvements, please let me know - I am getting about as deep as I ever do here and it is quite likely that I have gone out of my depth a little :D  .  

M23

It looks OK to me. Works fine with buttons amd also with other controls like before (labels,picture controls).

Here is testing script which works fine for BMP and also GIF pictures.

#AutoIt3Wrapper_useupx=n
#AutoIt3Wrapper_run_after=ResHacker.exe -add %out%, %out%, img-info1.bmp, bitmap, TEST_IMG_INFO1, 0
#AutoIt3Wrapper_run_after=ResHacker.exe -add %out%, %out%, img-info2.gif, rcdata, TEST_IMG_INFO2, 0
#AutoIt3Wrapper_run_after=upx.exe --best --compress-resources=0 "%out%"

#include "resources.au3"
 
$gui = GUICreate("Data from resources example",300,200)
$btn1 = GUICtrlCreateButton("Button1 (BMP)",100,50,100,25)
$btn2 = GUICtrlCreateButton("Button2 (GIF)",100,80,100,25)
GUISetState(@SW_SHOW)

While 1
    $msg = GUIGetMsg()
    If $msg = -3 Then Exit
    If $msg = $btn1 Then _ResourceSetImageToCtrl($btn1, "TEST_IMG_INFO1", $RT_BITMAP) ; BMP
    If $msg = $btn2 Then _ResourceSetImageToCtrl($btn2, "TEST_IMG_INFO2", $RT_RCDATA) ; GIF
WEnd

Note:

Used _SetBitmapToCtrl() from post #367

It's Yashied's version of the function from post #363 with addition from Melba23

images.zip: img-info1.bmp, img-info2.gif

images.zip

Edited by Zedna
Link to comment
Share on other sites

  • 3 weeks later...

Not sure what I am doing wrong?

This UDF is great. Now if I can just get it to work for me.

For the most part I have been able to get everything to work, but started playing creating a game that uses a series of images. I had been just loading the images in to variables and then using something like “GUICtrlCreatePic($pictures[$rd]” to load the images in to the control. But I wanted to try and load all the images in to the app. and then load them from there at runtime.

Here is what I have done.

This seems to load the files ok, because the Splatter.jpg displays as it should.

#AutoIt3Wrapper_useupx=n
#AutoIt3Wrapper_run_after="C:\Program Files\AutoIt3\ResHack\ResHacker.exe" -add %out%, %out%, H:\AutoIt\MyApps\games\splatter\images\Splatter.jpg, rcdata, Splatter_JPG_1, 0
#AutoIt3Wrapper_run_after="C:\Program Files\AutoIt3\ResHack\ResHacker.exe" -add %out%, %out%, H:\AutoIt\MyApps\games\splatter\images\0.jpg, rcdata, 0_JPG_1, 0
#AutoIt3Wrapper_run_after="C:\Program Files\AutoIt3\ResHack\ResHacker.exe" -add %out%, %out%, H:\AutoIt\MyApps\games\splatter\images\1.jpg, rcdata, 1_JPG_1, 0
#AutoIt3Wrapper_run_after="C:\Program Files\AutoIt3\ResHack\ResHacker.exe" -add %out%, %out%, H:\AutoIt\MyApps\games\splatter\images\2.jpg, rcdata, 2_JPG_1, 0
#AutoIt3Wrapper_run_after="C:\Program Files\AutoIt3\ResHack\ResHacker.exe" -add %out%, %out%, H:\AutoIt\MyApps\games\splatter\images\3.jpg, rcdata, 3_JPG_1, 0
#AutoIt3Wrapper_run_after="C:\Program Files\AutoIt3\ResHack\ResHacker.exe" -add %out%, %out%, H:\AutoIt\MyApps\games\splatter\images\4.jpg, rcdata, 4_JPG_1, 0
#AutoIt3Wrapper_run_after="C:\Program Files\AutoIt3\Aut2Exe\upx.exe" --best --compress-resources=0 "%out%"

Here I load the resource names in to an array.

$pictures[0] = "0_JPG_1"
$pictures[1] = "1_JPG_1"
$pictures[2] = "2_JPG_1"
$pictures[3] = "3_JPG_1"
$pictures[4] = "4_JPG_1"

Here is were I create the play area using the images as blocks. But when I use _ResourceSetImageToCtrl to load the pic control they don't display. And does not matter if I use GUICtrlCreatePic("",.. instead. I need to be able to change the image as needed.

$bCountX = 0
    While $bCountX < 9
        $bCountY = 0
        While $bCountY < 9
            $rd = Random(0,3,1)
            $Block[$bCountX][$bCountY] = GUICtrlCreatePic($pictures[$rd], $bCountX * $BlockWidth , $MenuHeight + ($bCountY * $BlockHeight), $BlockWidth, $BlockHeight, $SS_NOTIFY)
            _ResourceSetImageToCtrl($Block[$bCountX][$bCountY], $pictures[$rd]) ; set JPG image to picture control from resource
            $BlockValue[$bCountX][$bCountY] = $rd
            GUICtrlSetOnEvent($Block[$bCountX][$bCountY],"BlockClicked")
            $bCountY = $bCountY + 1
        WEnd
        $bCountX = $bCountX + 1
    WEnd

I do the am thing here, but I don't use a variable where the resource name would go and this works.

$MyAd = GUICtrlCreatePic($pictures[5], 0, $MenuHeight + $PlayAreaHeight, $WindowWidth, $MyAdHeight, $SS_NOTIFY)
    _ResourceSetImageToCtrl($MyAd, "Splatter_JPG_1") ; set JPG image to picture control from resource

Can't the resource name be a variable?

Any ideas?

Thanks

Link to comment
Share on other sites

@WebRaider

Your code looks good. Resource names stored in variables shouldn't be problem (but not tested).

I would try this:

- look at your compiled EXE by reshacker if resources are OK

- don't use resource names begining with numbers: 0_JPG_1 --> JPG_0, 1_JPG_1 --> JPG_1, 2_JPG_1 --> JPG_2

- check if you use correct width x height in GUICtrlCreatePic() - the same as size of jpg pictures

- do some error checking: test return values/@error after calling functions from my UDF to see where it's OK and where not

--> the same apply also for UDF itself: make your local copy of resource.au3 and place some testing (@error) code inside it.

Link to comment
Share on other sites

To prove the theory about problematic resource names in varibles try this:

use correct resource name

$bCountX = 0
    While $bCountX < 9
        $bCountY = 0
        While $bCountY < 9
            $rd = Random(0,3,1)
            $Block[$bCountX][$bCountY] = GUICtrlCreatePic($pictures[$rd], $bCountX * $BlockWidth , $MenuHeight + ($bCountY * $BlockHeight), $BlockWidth, $BlockHeight, $SS_NOTIFY)
;            _ResourceSetImageToCtrl($Block[$bCountX][$bCountY], $pictures[$rd]) ; set JPG image to picture control from resource
            _ResourceSetImageToCtrl($Block[$bCountX][$bCountY], "0_JPG_1") ; set JPG image to picture control from resource
            $BlockValue[$bCountX][$bCountY] = $rd
            GUICtrlSetOnEvent($Block[$bCountX][$bCountY],"BlockClicked")
            $bCountY = $bCountY + 1
        WEnd
        $bCountX = $bCountX + 1
    WEnd

If it will show this image on all pieces then there is problem with resource names in variable.

Link to comment
Share on other sites

Ok, I have done some playing around with this and got my game app. to work. But I had to do some work-a-rounds to get all the resources to play together.

Just to make things clear, I am not a programmer, but I like to play. So the issues and work-a-rounds below may not make sense, but it what I had to do (or not) to get it to work.

I found out that it can be resource name. It seems to work better using upper case letter and to start the name with letters not numbers.

If I added the resource names to an array I had to call the resource name in the array directly not using a variable. Example:

$Picture[1] = “RESOURCE_NAME_1”
$Picture[2] = “RESOURCE_NAME_2”
$Picture[3] = “RESOURCE_NAME_3”
$Picture[4] = “RESOURCE_NAME_4”

This would not work.

$rd = random(0,4,1)
_ResourceSetImageToCtrl($Block[$bCountX][$bCountY],$Picture[$rd])

But using this would

_ResourceSetImageToCtrl($Block[$bCountX][$bCountY],$Picture[1])

If I loaded a number of similar resource (LEVEL_1, LEVEL_2, LEVEL_3,…) in to the array, it would cause none of the images with similar resource names to be displayed. Even though I could see them in the .exe file using ResHacker.

I can’t explain why this would not work. So what I did was to make a couple of functions that would return the resource name or just play the sound in the function using the resource name.

I have included the resource files and source file. Yes, I know I did not use comments and the source is not very pretty. The images are kind of ugly, but it works.

#AutoIt3Wrapper_useupx=n
; Images
#AutoIt3Wrapper_run_after=C:\PROGRA~1\AutoIt3\ResHack\ResHacker.exe -add %out%, %out%, images\scoreside.jpg, rcdata, BOARD_JPG, 0
#AutoIt3Wrapper_run_after=C:\PROGRA~1\AutoIt3\ResHack\ResHacker.exe -add %out%, %out%, images\Splatter.jpg, rcdata, SPLATTER_JPG, 0
#AutoIt3Wrapper_run_after=C:\PROGRA~1\AutoIt3\ResHack\ResHacker.exe -add %out%, %out%, images\0.jpg, rcdata, A_level_0, 0
#AutoIt3Wrapper_run_after=C:\PROGRA~1\AutoIt3\ResHack\ResHacker.exe -add %out%, %out%, images\1.jpg, rcdata, B_level_1, 0
#AutoIt3Wrapper_run_after=C:\PROGRA~1\AutoIt3\ResHack\ResHacker.exe -add %out%, %out%, images\2.jpg, rcdata, C_level_2, 0
#AutoIt3Wrapper_run_after=C:\PROGRA~1\AutoIt3\ResHack\ResHacker.exe -add %out%, %out%, images\3.jpg, rcdata, D_level_3, 0
#AutoIt3Wrapper_run_after=C:\PROGRA~1\AutoIt3\ResHack\ResHacker.exe -add %out%, %out%, images\4.jpg, rcdata, E_level_4, 0
; Sounds - Clicks
#AutoIt3Wrapper_run_after=C:\PROGRA~1\AutoIt3\ResHack\ResHacker.exe -add %out%, %out%, sounds\click1.wav, sound, A_CLICK_1, 0
#AutoIt3Wrapper_run_after=C:\PROGRA~1\AutoIt3\ResHack\ResHacker.exe -add %out%, %out%, sounds\click2.wav, sound, B_CLICK_2, 0
#AutoIt3Wrapper_run_after=C:\PROGRA~1\AutoIt3\ResHack\ResHacker.exe -add %out%, %out%, sounds\click3.wav, sound, C_CLICK_3, 0
#AutoIt3Wrapper_run_after=C:\PROGRA~1\AutoIt3\ResHack\ResHacker.exe -add %out%, %out%, sounds\boing1.wav, sound, A_BOING_1, 0
#AutoIt3Wrapper_run_after=C:\PROGRA~1\AutoIt3\ResHack\ResHacker.exe -add %out%, %out%, sounds\boing2.wav, sound, B_BOING_2, 0
; Sounds - Pops
#AutoIt3Wrapper_run_after=C:\PROGRA~1\AutoIt3\ResHack\ResHacker.exe -add %out%, %out%, sounds\pop1.wav, sound, A_POP_1, 0
#AutoIt3Wrapper_run_after=C:\PROGRA~1\AutoIt3\ResHack\ResHacker.exe -add %out%, %out%, sounds\pop2.wav, sound, B_POP_2, 0
#AutoIt3Wrapper_run_after=C:\PROGRA~1\AutoIt3\ResHack\ResHacker.exe -add %out%, %out%, sounds\pop3.wav, sound, C_POP_3, 0
#AutoIt3Wrapper_run_after=C:\PROGRA~1\AutoIt3\ResHack\ResHacker.exe -add %out%, %out%, sounds\pop4.wav, sound, D_POP_4, 0
#AutoIt3Wrapper_run_after=C:\PROGRA~1\AutoIt3\ResHack\ResHacker.exe -add %out%, %out%, sounds\pop5.wav, sound, E_POP_5, 0
#AutoIt3Wrapper_run_after=C:\PROGRA~1\AutoIt3\ResHack\ResHacker.exe -add %out%, %out%, sounds\pop6.wav, sound, F_POP_6, 0
#AutoIt3Wrapper_run_after=C:\PROGRA~1\AutoIt3\ResHack\ResHacker.exe -add %out%, %out%, sounds\splat1.wav, sound, A_SPLAT_1, 0
#AutoIt3Wrapper_run_after=C:\PROGRA~1\AutoIt3\ResHack\ResHacker.exe -add %out%, %out%, sounds\splat2.wav, sound, B_SPLAT_2, 0
; Sounds - Cheers
#AutoIt3Wrapper_run_after=C:\PROGRA~1\AutoIt3\ResHack\ResHacker.exe -add %out%, %out%, sounds\cheer1.wav, sound, A_CHEER_1, 0
;
#AutoIt3Wrapper_run_after=C:\PROGRA~1\AutoIt3\Aut2Exe\upx.exe --best --compress-resources=0 "%out%"

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

#include <Sound.au3>
#include <resources.au3>

; Opt('MustDeclareVars', 1)
Opt("GUIOnEventMode", 1)

; Folders
$images = "images"
$sounds = "sounds"

Dim $Block[9][9]
Dim $BlockValue[9][9]

Dim $File, $Help, $MyAd, $score, $scoreMultipler = 1, $BlockInfo, $BlockInfo1, $IClicked, $dropsID
dim $drops = 10, $dropCount = 1, $DropsMultiplier = 1, $NoMorePoped, $Level = 1, $levelID


HotKeySet("+{esc}","MyExit")

Window()

While 1
    Sleep(5)
    CheckForPop()
    If CheckForCompleteLevel() = 0 Then
        MsgBox(48,"LEVEL COMPLETED!","LEVEL COMPLETED!",2)
        $Level = $Level + 1
        GUICtrlSetData($levelID,$Level)
        ;_SoundPlay($CheerSound[1])
        GetRandomCheerSoundResource()
        ResetBlocks()
        $DropsMultiplier = $DropsMultiplier - .05
        $scoreMultipler = $scoreMultipler + 1
    EndIf

WEnd

MyExit()

Func MyExit()
    Exit
EndFunc

Func fileMenu()
    If MsgBox(4+16,"File Menu","Exit!") = 6 Then MyExit()
EndFunc

Func helpMenu()
    MsgBox(16,"Help Menu","")
EndFunc

Func MyAd()
    MsgBox(16,"My Add!","Splatter!")
EndFunc

Func Window()
    $WindowHeigth = 550
    $WindowWidth = 640

    ; Menu Area
    $MenuHeight = 25

    ; Create 8 x 8 grid
    $BlockWidth = 50
    $BlockHeight = 50

    $ButtonWidth = 40
    $ButtonHeight = $MenuHeight

    $Form1 = GUICreate("Shooter", $WindowWidth, $WindowHeigth, -1, -1)
    GUISetOnEvent($GUI_EVENT_CLOSE,"MyExit",$Form1)
    $File = GUICtrlCreateButton("File", 0, 0, $ButtonWidth, $ButtonHeight, 0)
    GUICtrlSetOnEvent($File,"fileMenu")
    $Help = GUICtrlCreateButton("Help", $ButtonWidth, 0, $ButtonWidth, $ButtonHeight, 0)
    GUICtrlSetOnEvent($Help,"helpMenu")
    $Button0 = GUICtrlCreateButton("", $ButtonWidth*2, 0, $WindowWidth - 80, $MenuHeight, 0)

    $bCountX = 0
    While $bCountX < 9
        $bCountY = 0
        While $bCountY < 9
            $rd = Random(0,3,1)
            $Block[$bCountX][$bCountY] = GUICtrlCreatePic("", $bCountX * $BlockWidth , $MenuHeight + ($bCountY * $BlockHeight), $BlockWidth, $BlockHeight, $SS_NOTIFY)
            _ResourceSetImageToCtrl($Block[$bCountX][$bCountY], GetRandomImageResource($rd )) ; set JPG image to picture control from resource
            $BlockValue[$bCountX][$bCountY] = $rd
            GUICtrlSetOnEvent($Block[$bCountX][$bCountY],"BlockClicked")
            $bCountY = $bCountY + 1
        WEnd
        $bCountX = $bCountX + 1
    WEnd
    $PlayAreaWidth = $bCountX*$BlockWidth
    $PlayAreaHeight = $bCountY*$BlockHeight

    $MyAdHeight = 100
    $MyAd = GUICtrlCreatePic("", 0, $MenuHeight + $PlayAreaHeight, $WindowWidth, $MyAdHeight, $SS_NOTIFY)
    _ResourceSetImageToCtrl($MyAd, "SPLATTER_JPG") ; set JPG image to picture control from resource
    GUICtrlSetOnEvent($MyAd,"MyAd")
    
    $InfoGroup = GUICtrlCreatePic("", $PlayAreaWidth, $MenuHeight, $WindowWidth - $PlayAreaWidth, $WindowHeigth - $MyAdHeight)
    _ResourceSetImageToCtrl($InfoGroup, "BOARD_JPG") ; set JPG image to picture control from resource
    GUICtrlCreateLabel ("SCORE!",$PlayAreaWidth + (($WindowWidth - $PlayAreaWidth)/2) - 25,$MenuHeight+2,50,15,$SS_CENTER)
    GUICtrlSetBkColor (-1,$GUI_BKCOLOR_TRANSPARENT)
    $score = GUICtrlCreateLabel("0",$PlayAreaWidth + (($WindowWidth - $PlayAreaWidth)/2) - 40,$MenuHeight+2+17,80,15,$SS_CENTER)
    GUICtrlSetBkColor (-1,$GUI_BKCOLOR_TRANSPARENT)

    GUICtrlCreateLabel ("DROPS LEFT!",$PlayAreaWidth + (($WindowWidth - $PlayAreaWidth)/2) - 25,$MenuHeight+2+(17*2),50,15,$SS_CENTER)
    GUICtrlSetBkColor (-1,$GUI_BKCOLOR_TRANSPARENT)
    $dropsID = GUICtrlCreateLabel($drops,$PlayAreaWidth + (($WindowWidth - $PlayAreaWidth)/2) - 40,$MenuHeight+2+(17*3),80,15,$SS_CENTER)
    GUICtrlSetBkColor (-1,$GUI_BKCOLOR_TRANSPARENT)

    GUICtrlCreateLabel ("LEVEL!",$PlayAreaWidth + (($WindowWidth - $PlayAreaWidth)/2) - 25,$MenuHeight+2+(17*4),50,15,$SS_CENTER)
    GUICtrlSetBkColor (-1,$GUI_BKCOLOR_TRANSPARENT)
    $levelID = GUICtrlCreateLabel($level,$PlayAreaWidth + (($WindowWidth - $PlayAreaWidth)/2) - 40,$MenuHeight+2+(17*5),80,15,$SS_CENTER)
    GUICtrlSetBkColor (-1,$GUI_BKCOLOR_TRANSPARENT)

#cs
    ; This is for testing
    $MoveItDownForTesting = 10
    $BlockInfo = GUICtrlCreateLabel("",$PlayAreaWidth + (($WindowWidth - $PlayAreaWidth)/2) - 40,$MenuHeight+2+(17*$MoveItDownForTesting),80,15,$SS_CENTER)
    GUICtrlSetBkColor (-1,$GUI_BKCOLOR_TRANSPARENT)

    $BlockInfo1 = GUICtrlCreateLabel("",$PlayAreaWidth + (($WindowWidth - $PlayAreaWidth)/2) - 40,$MenuHeight+2+(17*($MoveItDownForTesting+1)),80,15,$SS_CENTER)
    GUICtrlSetBkColor (-1,$GUI_BKCOLOR_TRANSPARENT)
#ce
    GUISetState(@SW_SHOW)
EndFunc

Func BlockClicked()
    $split = StringSplit(GetBlock(),"|")
    $bCountX = $split[1]
    $bCountY = $split[2]

    GetRandomClickSoundResource()
    
    $NewDrops = GUICtrlRead($dropsID) - 1
    GUICtrlSetData($dropsID,$NewDrops)
    ;GUICtrlSetData($BlockInfo, $bCountX & " : " & $bCountY)
    ;GUICtrlSetData($BlockInfo1,$BlockValue[$bCountX][$bCountY])
    BlockUpdate($BlockValue[$bCountX][$bCountY],$bCountX,$bCountY)

    If GUICtrlRead($dropsID) = 0 Then GameOver()
EndFunc

Func GetBlock()
    Local $bCountX, $bCountY

    $bCountX = 0
    While $bCountX < 9
        $bCountY = 0
        While $bCountY < 9
            If @GUI_CTRLID = $Block[$bCountX][$bCountY] Then
                    $bLocation = $bCountX & "|" & $bCountY
                Return $bLocation
            EndIf
            $bCountY = $bCountY + 1
        WEnd
        $bCountX = $bCountX + 1
    WEnd
EndFunc

Func BlockUpdate($bValue,$bCountX,$bCounty)
    $BlockValue[$bCountX][$bCountY] = $bValue + 1
    _ResourceSetImageToCtrl($Block[$bCountX][$bCountY], GetRandomImageResource($BlockValue[$bCountX][$bCountY])) ; set JPG image to picture control from resource
    GUICtrlSetData($BlockInfo1,$BlockValue[$bCountX][$bCountY])
EndFunc

Func CheckForPop()
    Local $bCountX, $bCountY

    $bCountX = 0
    While $bCountX < 9
        $bCountY = 0
        While $bCountY < 9
            if $BlockValue[$bCountX][$bCountY] = 4 Then
                GetRandomPopSoundResource()
                Sleep(250)
                $BlockValue[$bCountX][$bCountY] = 0
                _ResourceSetImageToCtrl($Block[$bCountX][$bCountY], GetRandomImageResource($BlockValue[$bCountX][$bCountY])) ; set JPG image to picture control from resource
                GUICtrlSetData($BlockInfo1,$BlockValue[$bCountX][$bCountY])
                $NewScore = GUICtrlRead($score) + (1 * $scoreMultipler)
                GUICtrlSetData($score,$NewScore)
                If Int($dropCount*$DropsMultiplier) >= 1 Then
                    $NewDrops = GUICtrlRead($dropsID) + 1
                    GUICtrlSetData($dropsID,$NewDrops)
                    $dropCount = 0
                EndIf
                $dropCount = $dropCount + 1
                CheckForCloseBlocks($bCountX,$bCountY)
            EndIf
            $bCountY = $bCountY + 1
        WEnd
        $bCountX = $bCountX + 1
    WEnd
EndFunc

Func CheckForCloseBlocks($CurrentBlockX,$CurrentBlockY)
    Local $bCountX, $bCountY

    ; Check UP
    If $CurrentBlockY - 1 >= 0 Then
        If $BlockValue[$CurrentBlockX][$CurrentBlockY-1] > 0 Then
            $bCountX = $CurrentBlockX
            If $bCountX < 0 Then $bCountX = 0
            If $bCountX > 8 Then $bCountX = 8
            $bCountY = $CurrentBlockY-1
            If $bCountY < 0 Then $bCountY = 0
            If $bCountY > 8 Then $bCountY = 8
            $BlockValue[$bCountX][$bCountY] = $BlockValue[$bCountX][$bCountY] + 1
            If $BlockValue[$bCountX][$bCountY] > 4 Then $BlockValue[$bCountX][$bCountY] = 4
            _ResourceSetImageToCtrl($Block[$bCountX][$bCountY], GetRandomImageResource($BlockValue[$bCountX][$bCountY])) ; set JPG image to picture control from resource
            GUICtrlSetData($BlockInfo1,$BlockValue[$bCountX][$bCountY])
        EndIf
    EndIf
    ; Check RIGHT
    If $CurrentBlockX + 1 <= 8 Then
        If $BlockValue[$CurrentBlockX+1][$CurrentBlockY] > 0 Then
            $bCountX = $CurrentBlockX+1
            If $bCountX < 0 Then $bCountX = 0
            If $bCountX > 8 Then $bCountX = 8
            $bCountY = $CurrentBlockY
            If $bCountY < 0 Then $bCountY = 0
            If $bCountY > 8 Then $bCountY = 8
            $BlockValue[$bCountX][$bCountY] = $BlockValue[$bCountX][$bCountY] + 1
            If $BlockValue[$bCountX][$bCountY] > 4 Then $BlockValue[$bCountX][$bCountY] = 4
            _ResourceSetImageToCtrl($Block[$bCountX][$bCountY], GetRandomImageResource($BlockValue[$bCountX][$bCountY])) ; set JPG image to picture control from resource
            GUICtrlSetData($BlockInfo1,$BlockValue[$bCountX][$bCountY])
        EndIf
    EndIf
    ; Check DOWN
    If $CurrentBlockY + 1 <= 8 Then
        If $BlockValue[$CurrentBlockX][$CurrentBlockY+1] > 0 Then
            $bCountX = $CurrentBlockX
            If $bCountX < 0 Then $bCountX = 0
            If $bCountX > 8 Then $bCountX = 8
            $bCountY = $CurrentBlockY+1
            If $bCountY < 0 Then $bCountY = 0
            If $bCountY > 8 Then $bCountY = 8
            $BlockValue[$bCountX][$bCountY] = $BlockValue[$bCountX][$bCountY] + 1
            If $BlockValue[$bCountX][$bCountY] > 4 Then $BlockValue[$bCountX][$bCountY] = 4
            _ResourceSetImageToCtrl($Block[$bCountX][$bCountY], GetRandomImageResource($BlockValue[$bCountX][$bCountY])) ; set JPG image to picture control from resource
            GUICtrlSetData($BlockInfo1,$BlockValue[$bCountX][$bCountY])
        EndIf
    EndIf
    ; Check LEFT
    If $CurrentBlockX - 1 >= 0 Then
        If $BlockValue[$CurrentBlockX-1][$CurrentBlockY] > 0 Then
            $bCountX = $CurrentBlockX-1
            If $bCountX < 0 Then $bCountX = 0
            If $bCountX > 8 Then $bCountX = 8
            $bCountY = $CurrentBlockY
            If $bCountY < 0 Then $bCountY = 0
            If $bCountY > 8 Then $bCountY = 8
            $BlockValue[$bCountX][$bCountY] = $BlockValue[$bCountX][$bCountY] + 1
            If $BlockValue[$bCountX][$bCountY] > 4 Then $BlockValue[$bCountX][$bCountY] = 4
            _ResourceSetImageToCtrl($Block[$bCountX][$bCountY], GetRandomImageResource($BlockValue[$bCountX][$bCountY])) ; set JPG image to picture control from resource
            GUICtrlSetData($BlockInfo1,$BlockValue[$bCountX][$bCountY])
        EndIf
    EndIf
EndFunc

Func CheckForCompleteLevel()
    Local $bCountX, $bCountY
    $bCountX = 0
    While $bCountX < 9
        $bCountY = 0
        While $bCountY < 9
            if $BlockValue[$bCountX][$bCountY] > 0 Then
                Return 1
            EndIf
            $bCountY = $bCountY + 1
        WEnd
        $bCountX = $bCountX + 1
    WEnd
    Return 0
EndFunc

Func ResetBlocks()
    $bCountX = 0
    While $bCountX < 9
        $bCountY = 0
        While $bCountY < 9
            $rd = Random(0,3,1)
            $BlockValue[$bCountX][$bCountY] = $rd
            _ResourceSetImageToCtrl($Block[$bCountX][$bCountY], GetRandomImageResource($BlockValue[$bCountX][$bCountY])) ; set JPG image to picture control from resource
            $bCountY = $bCountY + 1
        WEnd
        $bCountX = $bCountX + 1
    WEnd
EndFunc

Func ResetGame()
    $drops = 10
    $dropCount = 1
    $DropsMultiplier = 1
    $Level = 1

    GUICtrlSetData($dropsID,$drops)
    GUICtrlSetData($levelID,$Level)
    GUICtrlSetData($score,0)

    ResetBlocks()
EndFunc

Func GameOver()
    If MsgBox(4+48,"GAME OVER!","GAME OVER!" & @CRLF & "Retry!") = 6 Then
        ResetGame()
    Else
        MyExit()
    EndIf
EndFunc

Func GetRandomImageResource($value)
    If $value = 0 Then Return "A_level_0"
    If $value = 1 Then Return "B_level_1"
    If $value = 2 Then Return "C_level_2"
    If $value = 3 Then Return "D_level_3"
    If $value = 4 Then Return "E_level_4"
    Return -1
EndFunc

Func GetRandomClickSoundResource()
    ; Sounds - Clicks
    $value = Random(0,4,1)
    If $value = 0 Then _ResourcePlaySound("A_CLICK_1",1)
    If $value = 1 Then _ResourcePlaySound("B_CLICK_2",1)
    If $value = 2 Then _ResourcePlaySound("C_CLICK_3",1)
    If $value = 3 Then _ResourcePlaySound("A_BOING_1",1)
    If $value = 4 Then _ResourcePlaySound("B_BOING_2",1)
    
EndFunc

Func GetRandomPopSoundResource()
    ; Sounds - Pops
    $value = Random(0,8,1)
    If $value = 0 Then _ResourcePlaySound("A_POP_1",1)
    If $value = 1 Then _ResourcePlaySound("B_POP_2",1)
    If $value = 2 Then _ResourcePlaySound("C_POP_3",1)
    If $value = 3 Then _ResourcePlaySound("D_POP_4",1)
    If $value = 4 Then _ResourcePlaySound("E_POP_5",1)
    If $value = 5 Then _ResourcePlaySound("F_POP_6",1)
    If $value = 6 Then _ResourcePlaySound("A_SPLAT_1",1)
    If $value = 6 Then _ResourcePlaySound("B_SPLAT_2",1)
EndFunc

Func GetRandomCheerSoundResource()
    ; Sounds - Cheers
    $value = Random(0,0,1)
    If $value = 0 Then _ResourcePlaySound("A_CHEER_1")
EndFunc

splatter_resource_folders.zip

Splatter.au3.zip

Edited by WebRaider
Link to comment
Share on other sites

  • 2 weeks later...

does anyone have any examples of how to add a .exe file as a resource??

Add EXE file as resource is simple.

But problem is with create new process (Run) directly from EXE stored in memory.

As far as I know there is some Windows' limitation but maybe someone know some trick/hack for this.

For DLL files (invoke function from DLL stored in memory) I saw some hacks but for EXE files not.

Edited by Zedna
Link to comment
Share on other sites

what limitations does windows have?

Probably when you create new process (Run) you must specify disk location instead of directly running EXE stored in memory (parametres of Win32 API).

Maybe some privileges limitations because EXE is stored in memory area of original script (which may have different privileges than EXE stored in memory)?

But I'm not sure about that, just my uncompetent guesses.

Link to comment
Share on other sites

  • 2 weeks later...

You can embed any binary data into your AutoIt compiled EXE files in it's resources at compile time. As opposite to FileInstall() with resources you can use your embedded data directly without any temporary files on disk.

G'day Zedna

This looks like what I've been looking for. I have a quick question (I haven't read all 18 pages of the thread yet) that perhaps you can answer. Will this UDF allow me to have the script interact with the bundled resource? What I'm looking for is a way to put a large text file inside a EXE script and give the user the opportunity to perform searches (using the script itself) on that text file, and have search results from it exported to some external file. Do you think your UDF is suited for that? In other words, the user can't steal the entire text file but he can access it using searches and search results exported to a separate file.

I look forward to your reply.

Samuel

Link to comment
Share on other sites

G'day Zedna

This looks like what I've been looking for. I have a quick question (I haven't read all 18 pages of the thread yet) that perhaps you can answer. Will this UDF allow me to have the script interact with the bundled resource? What I'm looking for is a way to put a large text file inside a EXE script and give the user the opportunity to perform searches (using the script itself) on that text file, and have search results from it exported to some external file. Do you think your UDF is suited for that? In other words, the user can't steal the entire text file but he can access it using searches and search results exported to a separate file.

I look forward to your reply.

Samuel

It would be sufficient if you read only whole first post (#1) in this topic :-)

My answer to your question is in your original topic here

#740821

Edited by Zedna
Link to comment
Share on other sites

It would be sufficient if you read only whole first post (#1) in this topic :-)

I understood from your first post that I can add text files to the EXE but it wasn't clear to me whether I could let the EXE interact with the text file in the same way that a script might interact with an external text file. I wrote the other post after I wrote this one. Thanks for your answer in that other thread.

Link to comment
Share on other sites

Embedding AVI into the resource.

This is probably already common knowledge, and doesn't really having anything to do with Zednas resource script as such but it was along the same lines and I used this method along with Zednas Resource UDF to add the background images etc.. it so thought I'd share it for those that don't know.

The Issue:

I was hoping to have animation embedded into my gui, although Gifs are great, it appears they cannot be above another image, for example a background image. Hoping to embed several animations into the executable, using Zednas resources UDF I found I had to break the background image into separate sections and rebuild the Gif with a part of the background image for it to work correctly. Although this method worked it was a pain to control the Gif Image for example Hiding and Showing the control. AVI's don't appear to have these issues, although AVIs are larger than Gifs, so the file will be slightly larger, but for my animations it was like 10kb bigger. So using the same context as adding image resources and then calling the avi(s) from the excutable worked like a charm.

For example

#AutoIt3Wrapper_Run_After=ResHacker.exe -add %out%,%out%,%scriptdir%\Resources\AVI_Ani1.avi,avi,101,0
#AutoIt3Wrapper_Run_After=ResHacker.exe -add %out%,%out%,%scriptdir%\Resources\AVI_Ani2.avi,avi,102,0

...
GUICtrlCreateAvi(@ScriptFullPath,101,20,20,15,15,$ACS_AUTOPLAY+$ACS_TIMER)
GUICtrlCreateAvi(@ScriptFullPath,102,40,20,15,15,$ACS_AUTOPLAY+$ACS_TIMER)
...

Hope that helps someone.

Cheers

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