Jump to content

Resources UDF


Zedna
 Share

Recommended Posts

Well, my fault. Once, this worked for me to use a label instead of a pic to avoid resizing, but this won't work anymore...

So you have to use GUICtrlSetPos.

#AutoIt3Wrapper_useupx=n
#AutoIt3Wrapper_run_after=ResHacker.exe -add %out%, %out%, image1.bmp, bitmap, TEST_BMP_1, 0

#AutoIt3Wrapper_run_after=upx.exe --best --compress-resources=0 "%out%"

#include "resources.au3"
 
$gui = GUICreate("Data from resources example",820,400)
$pic1 = GUICtrlCreatePic("",0,0,4,3)
$pic2 = GUICtrlCreatePic("",400,0,4,3)

GUISetState(@SW_SHOW)


; set BMP image to picture control from resource  bitmap
_ResourceSetImageToCtrl($pic1, "TEST_BMP_1", $RT_BITMAP)

_ResourceSetImageToCtrl($pic2, "TEST_BMP_1", $RT_BITMAP)
_SizeControlToImage($pic2)

MsgBox(0,"","Right image has proper size - minimize and restore to see")

While 1
    If GUIGetMsg() = -3 Then Exit
WEnd

; Prog@ndy
Func _SizeControlToImage($hCtrl)
    Local Const $STM_GETIMAGE = 0x173
    Local Const $IMAGE_BITMAP = 0
    Local $ControlBMP = GUICtrlSendMsg($hCtrl, $STM_GETIMAGE, $IMAGE_BITMAP,0)
    If Not $ControlBMP Then Return SetError(1,0,0)
    Local $size = _GetBitMapSize($ControlBMP)
    If @error Then Return SetError(2,0,0)
    Return GUICtrlSetPos($hCtrl,Default,Default,$size[0],$size[1])
EndFunc
; Returns Array with w and h
; Prog@ndy
Func _GetBitMapSize($hBitmap)
    Local $RetArray[2] = [-1,-1]
    Local $BITMAP = DllStructCreate("LONG   bmType; LONG   bmWidth; LONG   bmHeight; LONG   bmWidthBytes; ubyte   bmPlanes; ubyte   bmBitsPixel; ptr bmBits;")
    Local $res = _WinAPI_GetObject($hBitmap,DllStructGetSize($BITMAP),DllStructGetPtr($BITMAP))
    If @error Or $res = 0 Then Return SetError(1,0,$RetArray)
    Local $RetArray[2] = [DllStructGetData($BITMAP,2),DllStructGetData($BITMAP,3)]
    Return $RetArray
EndFunc

//Edit: image is image1.bmp from post 1

Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

  • 1 month later...

Zedna,

What am I doing wrong?

I placed the Test2.txt file in the same directory as the script.

Why can't I see the text in the MsgBox?

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Run_After=ResHacker.exe -add %out%, %out%, Test2.txt, rcdata, TEST_TXT, 0
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

#include<Resources.au3>

;$sFile = _ResourceGetAsString("TEST_TXT")
$sFile = _ResourceGetAsStringW("TEST_TXT")
MsgBox(0,"File", "_" & $sFile)

The textfile containes 10 characters.

[list][font="Century Gothic"]If nothing is certain, everything is possible.[/font][/list][font="Century Gothic"]Experience is something you get, just after you need it.[/font]

Link to comment
Share on other sites

Zedna,

What am I doing wrong?

I placed the Test2.txt file in the same directory as the script.

Why can't I see the text in the MsgBox?

The textfile containes 10 characters.

Try this

#AutoIt3Wrapper_useupx=n
#AutoIt3Wrapper_Run_After=ResHacker.exe -add %out%, %out%, Test2.txt, rcdata, TEST_TXT, 0
#AutoIt3Wrapper_run_after=upx.exe --best --compress-resources=0 "%out%"

#include<Resources.au3>

;$sFile = _ResourceGetAsString("TEST_TXT")
$sFile = _ResourceGetAsStringW("TEST_TXT")
MsgBox(0,"File", "_" & $sFile)

Also make sure you have ResHacker.exe and upx.exe in your Windows PATH

Link to comment
Share on other sites

Zedna,

Thanks, now it's working perfect.

Greetings.

PS. nice topic.

[list][font="Century Gothic"]If nothing is certain, everything is possible.[/font][/list][font="Century Gothic"]Experience is something you get, just after you need it.[/font]

Link to comment
Share on other sites

  • 2 weeks later...

Seems I can't get it to work with resizing images?

I got:

#AutoIt3Wrapper_useupx=n
#AutoIt3Wrapper_run_after=ResHacker.exe -add %out%, %out%, "image1.jpg", rcdata, OS_LOGO_1, 0
#AutoIt3Wrapper_run_after=ResHacker.exe -add %out%, %out%, "image2.jpg", rcdata, OS_LOGO_2, 0
#AutoIt3Wrapper_run_after="c:\Program Files\AutoIt3\Aut2Exe\upx.exe" --best --compress-resources=0 "%out%"

#include "resources.au3"
......
$Pic1 = GUICtrlCreatePic("", 8, 8, 161, 73, BitOR($SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS))
$Pic2 = GUICtrlCreatePic("", 176, 0, 305, 81, BitOR($SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS))
_ResourceSetImageToCtrl($Pic1, "OS_LOGO_1");
_ResourceSetImageToCtrl($Pic2, "OS_LOGO_2");
.........

So $pic2 size should be 305x81, but since the image2.jpg is actually larger than the control, I was using the control to resize the image. But the ResourceSetImageToCtrl seems to override that size setting. it puts the pic at full size

Edited by DssTrainer
Link to comment
Share on other sites

Seems I can't get it to work with resizing images?

I got:

#AutoIt3Wrapper_useupx=n
#AutoIt3Wrapper_run_after=ResHacker.exe -add %out%, %out%, "image1.jpg", rcdata, OS_LOGO_1, 0
#AutoIt3Wrapper_run_after=ResHacker.exe -add %out%, %out%, "image2.jpg", rcdata, OS_LOGO_2, 0
#AutoIt3Wrapper_run_after="c:\Program Files\AutoIt3\Aut2Exe\upx.exe" --best --compress-resources=0 "%out%"

#include "resources.au3"
......
$Pic1 = GUICtrlCreatePic("", 8, 8, 161, 73, BitOR($SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS))
$Pic2 = GUICtrlCreatePic("", 176, 0, 305, 81, BitOR($SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS))
_ResourceSetImageToCtrl($Pic1, "OS_LOGO_1");
_ResourceSetImageToCtrl($Pic2, "OS_LOGO_2");
.........

So $pic2 size should be 305x81, but since the image2.jpg is actually larger than the control, I was using the control to resize the image. But the ResourceSetImageToCtrl seems to override that size setting. it puts the pic at full size

In that case try to use _ResourceGetAsImage() or _ResourceGetAsBitmap() and use your own drawing over GUI/picture control using GDI/GDI+ API functions as StretchBlt.

I will try to look over the forum and make some example for that. But this may take a long time.

Link to comment
Share on other sites

Seems I can't get it to work with resizing images?

I got:

#AutoIt3Wrapper_useupx=n
#AutoIt3Wrapper_run_after=ResHacker.exe -add %out%, %out%, "image1.jpg", rcdata, OS_LOGO_1, 0
#AutoIt3Wrapper_run_after=ResHacker.exe -add %out%, %out%, "image2.jpg", rcdata, OS_LOGO_2, 0
#AutoIt3Wrapper_run_after="c:\Program Files\AutoIt3\Aut2Exe\upx.exe" --best --compress-resources=0 "%out%"

#include "resources.au3"
......
$Pic1 = GUICtrlCreatePic("", 8, 8, 161, 73, BitOR($SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS))
$Pic2 = GUICtrlCreatePic("", 176, 0, 305, 81, BitOR($SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS))
_ResourceSetImageToCtrl($Pic1, "OS_LOGO_1");
_ResourceSetImageToCtrl($Pic2, "OS_LOGO_2");
.........

So $pic2 size should be 305x81, but since the image2.jpg is actually larger than the control, I was using the control to resize the image. But the ResourceSetImageToCtrl seems to override that size setting. it puts the pic at full size

@DssTrainer

ok let's try this again

try SetWindowPos API to set initial size of image

#AutoIt3Wrapper_useupx=n
#AutoIt3Wrapper_run_after=ResHacker.exe -add %out%, %out%, "image1.jpg", rcdata, OS_LOGO_1, 0
#AutoIt3Wrapper_run_after=ResHacker.exe -add %out%, %out%, "image2.jpg", rcdata, OS_LOGO_2, 0
#AutoIt3Wrapper_run_after="c:\Program Files\AutoIt3\Aut2Exe\upx.exe" --best --compress-resources=0 "%out%"

#include <Constants.au3>
#include <WinAPI.au3>
#include "resources.au3"

$Pic1 = GUICtrlCreatePic("", 8, 8, 161, 73, BitOR($SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS))
$Pic2 = GUICtrlCreatePic("", 176, 0, 305, 81, BitOR($SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS))
Local $iFlags = BitOR($SWP_NOZORDER, $SWP_NOREDRAW, $SWP_NOACTIVATE)
_ResourceSetImageToCtrl($Pic1, "OS_LOGO_1");
_WinAPI_SetWindowPos(GUICtrlGetHandle($pic1), $HWND_TOP, 8, 8, 161, 73, $iFlags)
_ResourceSetImageToCtrl($Pic2, "OS_LOGO_2");
_WinAPI_SetWindowPos(GUICtrlGetHandle($pic2), $HWND_TOP, 176, 0, 305, 81, $iFlags)

I see fascists...

Link to comment
Share on other sites

This is great Zedna, thanks so much. But i'm having an issue... I really really hope someone can help me here.

I use a PNG file for a splash screen in my script, previously it was done with...

Global $splashImage = _GDIPlus_ImageLoadFromFile("dat\ss.png")

...and the $splashImage var was used later in a function with fancy GDI+ work for fading and whatnot. Now I manually added the PNG file to "data.dll" as the first post defines, as RC Data, and the name is simply "SS". Language is 0 (neutral). However, this causes AutoIt3 to crash -

Global $splashImage = _ResourceGetAsImage("SS", $RT_RCDATA, "data.dll")

What's wrong? Why does it die? :)

EDIT: I tried using this...

Global $splashImage = _ResourceGet("SS", $RT_RCDATA, 0, "data.dll")

...which stops it from crashing on that exact command, but then it crashes when it tries to actually draw/place the PNG graphic. Assuming I have to use GetAsImage for PNG. Unless.... nope, just checked - PNG Resource Type is non-standard, has to either be BITMAP or RCDATA...

Edited by DanielC
Link to comment
Share on other sites

  • Moderators

DanielC,

Have you looked at Example 3 (written by Zedna!) in the Help file under GUICtrlCreatePic? Using that example and Zedna's UDF to get the picture into the compiled .exe I have succesfully drawn .pngs in the past.

I just replaced the $hImage = _GDIPlus_ImageLoadFromFile("MAIN.png") line in the example with $hImage = _ResourceGetAsImage($ResName) - I did not need any other parameters as the .png image was in the .exe itself.

Have you tried loading the .png in the compiled .exe rather than an external "data.dll"?

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

DanielC,

Have you looked at Example 3 (written by Zedna!) in the Help file under GUICtrlCreatePic? Using that example and Zedna's UDF to get the picture into the compiled .exe I have succesfully drawn .pngs in the past.

I just replaced the $hImage = _GDIPlus_ImageLoadFromFile("MAIN.png") line in the example with $hImage = _ResourceGetAsImage($ResName) - I did not need any other parameters as the .png image was in the .exe itself.

Have you tried loading the .png in the compiled .exe rather than an external "data.dll"?

M23

Hey wow, thanks so much for the quick reply.

Well I understand everything you said, so I went ahead and tried putting it into the compiled EXE instead of a DLL and test that. I think i found the problem - for some reason, ResourceHacker outputs a corrupt EXE no matter what I do! The common "not a valid Win32 application", even though Resource Hacker can read the corrupt file fine. Wierd... going to try to re-download Reshacker.

Link to comment
Share on other sites

Oh my gosh! It freakin' works! Thanks so much Melba23, and Zedna, it must just be my dodgy DLL file haha! I will sort it out now, at least I know the PNG's fully work - this rocks....! THANKS AGAIN!

EDIT: OK, i tried an experiment. Compiling and EXE loading the resource from itself with these lines...

#AutoIt3Wrapper_run_after=ResHacker.exe -add "%out%", "%out%", ss.png, rcdata, PNG_01, 0
...
Global $splashImage = _ResourceGetAsImage("PNG_01")

...it works 100% and compiles as "tool.exe". However, modifying the splashimage line above to something like...

Global $splashImage = _ResourceGetAsImage("PNG_01", $RT_RCDATA, @ScriptDir & "\tool.exe")

...then recompiling THAT to "tool2.exe" causes the exact same crash (illegal operation). Either there is a problem trying to load a resource from another DLL, or im doing something wrong. Do I need to preload the DLL with another AutoIt command beforehand or something? Or is there a certain type of DLL I need to build for my resources (and will i need Visual Basic for this).

Edited by DanielC
Link to comment
Share on other sites

  • Moderators

DanielC,

Firstly, ResHacker gives you the "not a valid Win32 application" message when you have compressed the .exe with upx. Do not compress and ResHacker works fine - once you have checked it all loads you can compress again. Use the following lines in your script:

#AutoIt3Wrapper_UseUpx=n

...

#AutoIt3Wrapper_Run_After=ResHacker.exe .....

...

#AutoIt3Wrapper_Run_After=M:\Program\UPX\upx.exe --best "%out%" ; Comment this out when testing

Secondly, I believe that Zedna's UDF deals only with resources that have been loaded into the compiled .exe. If you want to load your .png from an external .dll then it is not the way to go. You will need to look at the Dll functions - and here I am no expert! But others are - try searching the forums - it must have been done before somewhere.

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

Well I already solved the "not a valid Win32 application" by turning off the compression as you said, yeah.

But Zedna's UDF here doesn't support external resources!?! Even though it's clearly listed in the examples and changelog???? I guess you mean it's a work in progress, or just doesnt work for PNG graphics.....

Well thanks for your advice, I shall do some more searching on the forums then =) Cheers!

Link to comment
Share on other sites

  • Moderators

DanielC,

My apologies, you are quite correct - I just have not used it other than for internal resources.

M23

Edit: I cannot get it to work with an external dll either. We will have to wait for Zedna to come and tell us what we are doing wrong! :-)

Edited by Melba23

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

DanielC,

My apologies, you are quite correct - I just have not used it other than for internal resources.

M23

Edit: I cannot get it to work with an external dll either. We will have to wait for Zedna to come and tell us what we are doing wrong! :-)

Can somebody of you post here some DLL with PNG files (and code you use)?

I will take a look at this part and I will do some tests.

EDIT: I added loading resources also from external DLL files upon idea/code from other people but I don't use this in any of my projects.

Edited by Zedna
Link to comment
Share on other sites

You got it Zedna!!!!

I have included three versions, in the three subfolders within the zip file-

- InDLL (Not Working) (Can be run uncompiled)

This is the one that crashes

- InEXE (Working) (Must be compiled)

This includes ResHacker.exe, resources.au3 and the tool.exe already compiled, as well as all source

- InPNG (Original script before Zednas resources.au3)

Just a sample that can be run on any machine before I put resources.au3 into it

I included "About to load PNG..." and "...just loaded PNG!" message boxes for testing purposes. The DLL was made in VC++ 2008 Express as per the MSDN sample article on creating an emtpy DLL for resource purposes. And of course, I do remember to compile via F7 in SciTE :think:

It's a 800KB ZIP file, so i will be removing this as soon we sort this out (we only get a megabyte!) Thanks heaps for taking a look Zedna!

P.S. Melba23, I couldn't find anything specific to my problem via a forum search. I did find one "load PNG from DLL", however it doesnt support alpha/translucency, and it uses the "SetImageToCtrl" thing, but i'm directly using GDI+ there is no control to set hehe :)

EDIT: Sorry I was going to post just the DLL and code, but it's fairly long and I wanted to show you that i'm definately not making my own silly mistake. Hope it isn't too much hassle... I reattatched just the DLL file, and here is just the code:

#NoTrayIcon
#include <GUIConstants.au3>
#include <GDIPlus.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <StaticConstants.au3>
#include <ProgressConstants.au3>
#include <AVIConstants.au3>
#include "resources.au3"

Opt("GUIOnEventMode", 1)
Opt("GUICloseOnESC", 0)

#Region;~~~~~~~~~~Load the PNG Graphic and fade it in
;_GDIPlus_Startup();~~~~~~~~~~Not needed anymore, Zedna's UDF already did it
    MsgBox (16, "Tool", "About to load PNG...")
;Global $splashImage = _GDIPlus_ImageLoadFromFile("ss.png");~~~~~~~~~~used for original non-bundled PNG (pre resources,au3)
;Global $splashImage = _ResourceGetAsImage("PNG_01");~~~~~~~~~~used for "InEXE" method
    Global $splashImage = _ResourceGetAsImage("PNG_01", 10, @ScriptDir & "\data.dll");~~~~~~~~~~used for "InDLL" method
    MsgBox (16, "Tool", "Just loaded!")
    Const $AC_SRC_ALPHA = 1
    $splashGUI = GUICreate("Splash", 600, 300, -1, -1, $WS_POPUP, $WS_EX_LAYERED + $WS_EX_TOPMOST + $WS_EX_TOOLWINDOW)
        GUISetState()
    For $i = 0 To 255 Step 5
        drawPNG($i)
    Next
    Sleep(100)
#EndRegion

;Hold the splash for 3 seconds or so, all the loading stuff will eventually go here
Sleep(3000)

#Region;~~~~~~~~~~Fade out the splash PNG, kill the GUI, and unload GDI+
    For $i = 255 To 0 Step -5
        drawPNG($i)
    Next
    GUIDelete($splashGUI)
    _GDIPlus_ShutDown()
#EndRegion

Sleep(100)


;~~~~~~~~~~Functions below


Func drawPNG($i)
    Local $hScrDC, $hMemDC, $hBitmap, $hOld, $pSize, $tSize, $pSource, $tSource, $pBlend, $tBlend
    $hScrDC = _WinAPI_GetDC(0)
    $hMemDC = _WinAPI_CreateCompatibleDC($hScrDC)
    $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($splashImage)
    $hOld = _WinAPI_SelectObject($hMemDC, $hBitmap)
    $tSize = DllStructCreate($tagSIZE)
    $pSize = DllStructGetPtr($tSize)
    DllStructSetData($tSize, "X", _GDIPlus_ImageGetWidth($splashImage))
    DllStructSetData($tSize, "Y", _GDIPlus_ImageGetHeight($splashImage))
    $tSource = DllStructCreate($tagPOINT)
    $pSource = DllStructGetPtr($tSource)
    $tBlend = DllStructCreate($tagBLENDFUNCTION)
    $pBlend = DllStructGetPtr($tBlend)
    DllStructSetData($tBlend, "Alpha", $i)
    DllStructSetData($tBlend, "Format", $AC_SRC_ALPHA)
    _WinAPI_UpdateLayeredWindow($splashGUI, $hScrDC, 0, $pSize, $hMemDC, $pSource, 0, $pBlend, $ULW_ALPHA)
    _WinAPI_ReleaseDC(0, $hScrDC)
    _WinAPI_SelectObject($hMemDC, $hOld)
    _WinAPI_DeleteObject($hBitmap)
    _WinAPI_DeleteDC($hMemDC)
    Sleep(5)
    GUISetState()
EndFunc

EDIT2: In resources.au3, it appears that the following line:

_MemMoveMemory($ResData,$pData,$nSize)

...is what makes the autoit3 compiler crash. I might be able to debug (because I figured that out), but sadly I have no idea how to fix this (AutoIt3 help file links to MSDN, and then I was lost way over my head :lmao:)

tooltester.zip

data.dll

Edited by DanielC
Link to comment
Share on other sites

@DanielC

In case of problems always look at @error codes returned from my functions.

I did it and added some debug ConsoleWrite lines into my UDF:

_ResourceSaveToFile('c:\png_01_orig.png', "PNG_01", 10, 0, 0, "c:\data.dll")
ConsoleWrite(@error & @CRLF)

The source of problem was in _ResourceGet()

$hInstance = _WinAPI_LoadLibrary($DLL)

This code try to call DllMain but in resource-only DLL there is no DllMain function

so LoadLibrary failed with @error

So I replaced it by

$hInstance = _WinAPI_LoadLibraryEx($DLL, $LOAD_LIBRARY_AS_DATAFILE )

and it loaded DLL successfully.

Unfortunatelly it hard crashed somewhere after that (memory read AV).

I didn't find that second problem yet.

So you can manually fix _WinAPI_LoadLibrary($DLL) by _WinAPI_LoadLibraryEx($DLL, $LOAD_LIBRARY_AS_DATAFILE )

and try it until I will do some more tests.

Edited by Zedna
Link to comment
Share on other sites

  • Moderators

Zedna,

I have managed to get a .png displayed if I use the _ResourceGetAsImage function to get the image from an external dll as shown in the Help file for GUICtrlCreatePic:

;----- example 3 PNG work around by Zedna
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Resources.au3>
#include <GDIPlus.au3>
#Include <WinAPI.au3>

Global $hGUI, $hImage, $hGraphic, $hImage1

; Create GUI
$hGUI = GUICreate("Show PNG", 350, 301)

; Load PNG image
_GDIPlus_StartUp()
$hImage   = _ResourceGetAsImage("PIC", 10, "M:\Program\Au3 Scripts\Test\Melba.dll")
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)

GUIRegisterMsg($WM_PAINT, "MY_WM_PAINT")
GUISetState()

; Loop until user exits
do
until GUIGetMsg() = $GUI_EVENT_CLOSE

; Clean up resources
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_ImageDispose($hImage)
_GDIPlus_ShutDown()

; Draw PNG image
Func MY_WM_PAINT($hWnd, $Msg, $wParam, $lParam)
    _WinAPI_RedrawWindow($hGUI, 0, 0, $RDW_UPDATENOW)
    _GDIPlus_GraphicsDrawImage($hGraphic, $hImage, 0, 0)
    _WinAPI_RedrawWindow($hGUI, 0, 0, $RDW_VALIDATE)
    Return $GUI_RUNDEFMSG
EndFunc

I have always been able to get a .png displayed from an internal resource:

#AutoIt3Wrapper_UseUpx=n
#AutoIt3Wrapper_Run_After=M:\Program\ResHacker\ResHacker.exe -add %out%, %out%, M:\Program\Au3 Scripts\Test\Test.PNG, rcdata, PIC, 0

#include <GUIConstantsEx.au3>
#include <Resources.au3>

; Create GUI
Global $hGUI = GUICreate("Show PNG", 300, 300)

Global $hPic = GUICtrlCreatePic("", 1, 1, 300, 300)
_ResourceSetImageToCtrl($hPic, "PIC")

GUISetState()

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

What i cannot do is get _ResourceSetImageToCtrl to display a .png from an external dll. This crashes:

#include <Resources.au3>
#include <GUIConstantsEx.au3>

; Create GUI
Global $hGUI = GUICreate("Show PNG", 300, 300)

Global $hPic = GUICtrlCreatePic("", 1, 1, 300, 300)

_ResourceSetImageToCtrl($hPic, "PIC", 10, "M:\Program\Au3 Scripts\Test\Melba.dll")

GUISetState()

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

And this does not work:

#include <Resources.au3>
#include <GUIConstantsEx.au3>

; Create GUI
Global $hGUI = GUICreate("Show PNG", 300, 300)

Global $hPic = GUICtrlCreatePic("", 1, 1, 300, 300)

$dll = DllOpen("M:\Program\Au3 Scripts\Test\Melba.dll")
_ResourceSetImageToCtrl($hPic, "PIC", 10, $dll)
DllClose($dll)

GUISetState()

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

I attach the .dll file I have been using - but as I have it working in one case, I think it is a valid file. I made it using tlem's RDG DLL Generator.

If you need any more info or I can help in any way, please do not hesitate to ask.

M23

Edited by Melba23

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,

I have managed to get a .png displayed if I use the _ResourceGetAsImage function to get the image from an external dll as shown in the Help file for GUICtrlCreatePic:

;----- example 3 PNG work around by Zedna

...

I attach the .dll file I have been using - but as I have it working in one case, I think it is a valid file. I made it using tlem's RDG DLL Generator.

If you need any more info or I can help in any way, please do not hesitate to ask.

M23

Many thanks Melba for these usefull information!

I will definitely look at yours and DanielC's stuff

but this may take some time ...

Edited by Zedna
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...