Jump to content

Embedded image to an Exe using GDIPlus


UEZ
 Share

Recommended Posts

Hi,

is there a way to embed an image to an Exe using a GDIPlus window?

Here an example:

#include <GUIConstants.au3>
#include <GDIPlus.au3>
#AutoIt3Wrapper_UseUpx=n

Global $ShowPic, $hGUI, $hWnd, $GUI_Name, $hGraphic, $xsize, $ysize

$xsize = 300
$ysize = 172
$GUI_Name = "Test"

$ShowPic = "<path to an image>"

$hGUI = GUICreate($GUI_Name, $xsize, $ysize, -1, -1)
$hWnd = WinGetHandle($GUI_Name)

GUISetState()
_GDIPlus_Startup ()

$hGraphic = _GDIPlus_GraphicsCreateFromHWND ($hWnd)
$hImage = _GDIPlus_ImageLoadFromFile($ShowPic)

DllCall($ghGDIPDll, "int", "GdipDrawImageRectI", "hwnd", $hGraphic, "hwnd", $hImage, "int", 0, "int", 0, "int", $xsize, "int", $ysize)


Do

Until GUIGetMsg() = $GUI_EVENT_CLOSE

_GDIPlus_GraphicsDispose ($hGraphic)
_GDIPlus_Shutdown ()

I tried it with the resource #include <resources.au3>, #AutoIt3Wrapper_Res_File_Add = "<path to an image>", bitmap, Logo_BMP_1

and _ResourceSetImageToCtrl($hImage, "Logo_BMP_1", $RT_BITMAP) but it didn't work - an imagecannot be seen in the window :-(

Anyone who can help?

THANX :)

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Hi,

is there a way to embed an image to an Exe using a GDIPlus window?

Here an example:

I tried it with the resource #include <resources.au3>, #AutoIt3Wrapper_Res_File_Add = "<path to an image>", bitmap, Logo_BMP_1

and _ResourceSetImageToCtrl($hImage, "Logo_BMP_1", $RT_BITMAP) but it didn't work - an imagecannot be seen in the window :-(

Anyone who can help?

THANX :)

Post your non working example using my resource UDF. It should work.

Link to comment
Share on other sites

I tried it this way:

#AutoIt3Wrapper_Res_File_Add=<path to image>, bitmap, Logo_BMP_1
#AutoIt3Wrapper_UseUpx=n
#include <GUIConstants.au3>
#include <GDIPlus.au3>
#include <Resources.au3>


Global $ShowPic, $hGUI, $hWnd, $GUI_Name, $hGraphic, $xsize, $ysize

$xsize = 300
$ysize = 172
$GUI_Name = "Test"

$ShowPic = ""

$hGUI = GUICreate($GUI_Name, $xsize, $ysize, -1, -1)
$hWnd = WinGetHandle($GUI_Name)

GUISetState()
_GDIPlus_Startup ()

$hGraphic = _GDIPlus_GraphicsCreateFromHWND ($hWnd)
$hImage = _GDIPlus_ImageLoadFromFile($ShowPic)

_ResourceSetImageToCtrl($hImage, "Logo_BMP_1", $RT_BITMAP)

DllCall($ghGDIPDll, "int", "GdipDrawImageRectI", "hwnd", $hGraphic, "hwnd", $hImage, "int", 0, "int", 0, "int", $xsize, "int", $ysize)


Do

Until GUIGetMsg() = $GUI_EVENT_CLOSE

_GDIPlus_GraphicsDispose ($hGraphic)
_GDIPlus_Shutdown ()

Made I something wrong? :)

UEZ :P

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Without GDI+

#AutoIt3Wrapper_UseUpx=n
#AutoIt3Wrapper_Res_File_Add=image1.bmp, bitmap, Logo_BMP_1

#include <GUIConstants.au3>
#include <Resources.au3>

Global $hWnd, $GUI_Name, $xsize, $ysize

$xsize = 300
$ysize = 172
$GUI_Name = "Test"

$hWnd = GUICreate($GUI_Name, $xsize, $ysize, -1, -1)
$pic1 = GUICtrlCreatePic("",0,0,$xsize,$ysize)
GUISetState()

_ResourceSetImageToCtrl($pic1, "Logo_BMP_1", $RT_BITMAP)

Do

Until GUIGetMsg() = $GUI_EVENT_CLOSE
Link to comment
Share on other sites

And with GDI+? :)

The reason is that I wrote this:

#include <GUIConstants.au3>
#include <GDIPlus.au3>
;#AutoIt3Wrapper_Compression=4
#AutoIt3Wrapper_UseUpx=n

Opt('MustDeclareVars', 1)
Opt ("TrayIconHide",1)

_Main()

Func _Main()    
    Local $hGUI, $hWnd, $hGraphic, $hBrush, $hFormat, $hFamily, $hFont, $tLayout, $hImage, $GUI_Name
    Local $xsize, $ysize, $font_size, $xpos, $ypos, $stRegion, $ShowPic
    Local $c, $i, $x
    Const $ver = "0.50 beta"
    Const $build = "2008-01-02"
    Const $appname = "Vertical Scroller"
    Dim $text[7]
    
    $GUI_Name = "Vertical Scroller"
    $xsize = 300
    $ysize = 172
    $font_size = 14
    $text[01] = "Program: " & $appname
    $text[02] = "Version: " & $ver & " " & $build
    $text[03] = "Coding by: UEZ"
    $text[04] = ""
    $text[05] = ""
    $text[06] = "Press ESC to quit ;-)"
    $xpos = 7
    $i = $ysize + $font_size
    $ShowPic = "<path+filename of any image 300x172>"
    $hGUI = GUICreate($GUI_Name, $xsize, $ysize, -1, -1, BitOR($WS_SYSMENU,$WS_POPUP,$WS_POPUPWINDOW,$WS_BORDER,$WS_CLIPSIBLINGS), $WS_EX_TOPMOST)
    $hWnd = WinGetHandle($GUI_Name)
        
    GUISetState()

    _GDIPlus_Startup ()
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND ($hWnd)
    $hBrush = _GDIPlus_BrushCreateSolid (0x7F00007F)
    $hFormat = _GDIPlus_StringFormatCreate ()
    $hFamily = _GDIPlus_FontFamilyCreate ("Arial")
    $hFont = _GDIPlus_FontCreate ($hFamily, $font_size, 2)
    
    _GDIPlus_GraphicsDrawStringEx ($hGraphic, $text[$x], $hFont, $tLayout, $hFormat, $hBrush)
    
    $hImage = _GDIPlus_ImageLoadFromFile($ShowPic)
    
    For $x = 0x000000 To 0xFCFCFC Step 0x111111
        GUISetBkColor ($x)
        Sleep(60)
    Next
    
    Do
    $stRegion = DllStructCreate($tagRECT)
        DllStructSetData($stRegion, 1, $xpos)
        DllStructSetData($stRegion, 2, $ypos)
        DllStructSetData($stRegion, 3, $xsize)
        DllStructSetData($stRegion, 4, $ysize)
        _WinAPI_InvalidateRect($hGui, $stRegion, True)
        _GDIPLus_GraphicsDrawImageRect($hGraphic, $hImage, 0, 0, $xsize, $ysize)
    
        $c = 0
        For $x = 1 To UBound($text) - 1
            $tLayout = _GDIPlus_RectFCreate ($xpos, $ypos + $i + $c * 2 * $font_size, 0, 0)
            _GDIPlus_GraphicsDrawStringEx ($hGraphic, $text[$x], $hFont, $tLayout, $hFormat, $hBrush)
            $c = $c + 1
        Next
        
        $i = $i - 1
        If $i = 0 - ($font_size * UBound($text) * 2) Then $i = $ysize + $font_size
        Sleep(60)
        
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    
    For $x = 0xFCFCFC To 0x000000 Step -0x111111
        GUISetBkColor ($x)
        Sleep(60)
    Next

    _GDIPlus_FontDispose ($hFont)
    _GDIPlus_FontFamilyDispose ($hFamily)
    _GDIPlus_StringFormatDispose ($hFormat)
    _GDIPlus_BrushDispose ($hBrush)
    _GDIPlus_GraphicsDispose ($hGraphic)
    _GDIPlus_Shutdown ()
EndFunc

Func _GDIPLus_GraphicsDrawImageRect($hGraphics, $hImage, $iX, $iY, $iW, $iH)
    Local $aResult
    $aResult = DllCall($ghGDIPDll, "int", "GdipDrawImageRectI", "hwnd", $hGraphics, "hwnd", $hImage, "int", $iX, "int", $iY, "int", $iW, "int", $iH)
    Return SetError($aResult[0], 0, $aResult[0] = 0)
EndFunc

And I wanted to embed the image to avoid any seprate image file.

By the way, any idea why the window with the scroller is flickering sometime? Is the GDI+ routine too slow?

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

By the way, any idea why the window with the scroller is flickering sometime? Is the GDI+ routine too slow?

Look at BlackJack

There is used antiflicker method:

Complicated drawing is done on hidden memory bitmap first and finished whole image is drawn on visible window by quick BitBlt API from this memory bitmap.

Link to comment
Share on other sites

Look here

Core of solution is to use:

CreateStreamOnHGlobal
GdipLoadImageFromStream
_GDIP_BitmapCreateHBITMAPFromBitmap

But I haven't so much time to play with this now.

If you are interested take this my unfinished raw concept and help me finish it.

I can be cooperative with this.

Sounds very interesting but I think I don't have enough coding skills at the moment. :)

I cannot compile Blackjack because of the em: ...Blackjack_zedna.au3(73,32) : ERROR: $WM_PAINT previously declared as a 'Const'.

Any idea?

Anyway, I will try to understand the routine in Blackjack how to fix the flickering but it will take some time :P

THANX

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Sounds very interesting but I think I don't have enough coding skills at the moment. :)

I cannot compile Blackjack because of the em: ...Blackjack_zedna.au3(73,32) : ERROR: $WM_PAINT previously declared as a 'Const'.

Any idea?

Anyway, I will try to understand the routine in Blackjack how to fix the flickering but it will take some time :P

THANX

You can run BlackJack from first post. Author incorporated my antiflicker method into it.

Error aredue to different constants declarations inside standard AutoIt include files in older AutoIt versions.

Just comment (or delete) constants declarations on error lines.

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