Jump to content

Resources UDF


Zedna
 Share

Recommended Posts

Hi Guys,

Zedna, super UDF. It's making life a lot easier muttley

Hope you guys can help me with the following:

I am making this GUI and combined the use of the resources UDF with the tranparent GUI loader of Lod3n from this posting:

Lod3n loader

I manage to get the Main GUI on screen, bij loading it from a .png embedded in the .exe it even fades in, so that part is working, then there has to loaded a .gif with the transparancy color, that one is loaded from embeded resource too. That part seems to be working too, because the main GUI on the screen is transparent.

Then i am trying to put all the controls on the GUI, but that part seems to fail, i only see the main GUI with none of the controls on screen. I tried different approaches but i cannot seem to get it right, i hope you guys can help me out here...

First the Lod3en code for transparent GUI:

#NoTrayIcon
#include <WindowsConstants.au3>
#include <StructureConstants.au3>
#include <GUIConstantsEx.au3>
#Include <GDIPlus.au3>; this is where the magic happens, people
;#include <GuiComboBox.au3>
#Include <File.au3>
#include <Array.au3>
#include <ButtonConstants.au3>
;Opt("MustDeclareVars", 0)

Global Const $AC_SRC_ALPHA = 1
;Global Const $ULW_ALPHA = 2
Global $old_string = "", $runthis = ""
Global $launchDir = @DesktopDir

; Load PNG file as GDI bitmap
_GDIPlus_Startup()
$pngSrc = @ScriptDir & "\test.png"
$hImage = _GDIPlus_ImageLoadFromFile($pngSrc)

; Extract image width and height from PNG
$width = _GDIPlus_ImageGetWidth($hImage)
$height = _GDIPlus_ImageGetHeight($hImage)

; Create layered window
$GUI = GUICreate("lod3n launcher", $width, $height, -1, -1, $WS_POPUP, $WS_EX_LAYERED)
SetBitmap($GUI, $hImage, 0)
; Register notification messages
GUIRegisterMsg($WM_NCHITTEST, "WM_NCHITTEST")
GUISetState()
WinSetOnTop($GUI, "", 1)
;fade in png background
For $i = 0 To 255 Step 1        ; The higher the Step the faster the fade in
    SetBitmap($GUI, $hImage, $i)
Next


; create child MDI gui window to hold controls
; this part could use some work - there is some flicker sometimes...
$controlGui = GUICreate("ControlGUI", $width, $height, 0, 0, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $GUI)

; child window transparency is required to accomplish the full effect, so $WS_EX_LAYERED above, and
; I think the way this works is the transparent window color is based on the image you set here:
GUICtrlCreatePic(@ScriptDir & "\grey.gif", 0, 0, $width, $height)
GUICtrlSetState(-1, $GUI_DISABLE)

; just a text label
GUICtrlCreateLabel("Test press escape to quit...", 100, 112, 240, 150)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetColor(-1, 0x808080)

GUISetState()

;Loop that keeps the GUI running until pressed ESC
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop

    EndSelect
WEnd
AdlibDisable()

GUIDelete($controlGui)
;fade out png background
For $i = 255 To 0 Step - 1          ; The higher the Step, the faster the fade out
    SetBitmap($GUI, $hImage, $i)
Next

; Release resources
_GDIPlus_ImageDispose($hImage)
_GDIPlus_Shutdown()

;===================================================================================================


; Handle the WM_NCHITTEST for the layered window so it can be dragged by clicking anywhere on the image.
;===================================================================================================



Func WM_NCHITTEST($hWnd, $iMsg, $iwParam, $ilParam)
    If ($hWnd = $GUI) And ($iMsg = $WM_NCHITTEST) Then Return $HTCAPTION
EndFunc  ;==>WM_NCHITTEST

;===================================================================================================


; SetBitMap
;===================================================================================================



Func SetBitmap($hGUI, $hImage, $iOpacity)
    Local $hScrDC, $hMemDC, $hBitmap, $hOld, $pSize, $tSize, $pSource, $tSource, $pBlend, $tBlend

    $hScrDC = _WinAPI_GetDC(0)
    $hMemDC = _WinAPI_CreateCompatibleDC($hScrDC)
    $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
    $hOld = _WinAPI_SelectObject($hMemDC, $hBitmap)
    $tSize = DllStructCreate($tagSIZE)
    $pSize = DllStructGetPtr($tSize)
    DllStructSetData($tSize, "X", _GDIPlus_ImageGetWidth($hImage))
    DllStructSetData($tSize, "Y", _GDIPlus_ImageGetHeight($hImage))
    $tSource = DllStructCreate($tagPOINT)
    $pSource = DllStructGetPtr($tSource)
    $tBlend = DllStructCreate($tagBLENDFUNCTION)
    $pBlend = DllStructGetPtr($tBlend)
    DllStructSetData($tBlend, "Alpha", $iOpacity)
    DllStructSetData($tBlend, "Format", $AC_SRC_ALPHA)
    _WinAPI_UpdateLayeredWindow($hGUI, $hScrDC, 0, $pSize, $hMemDC, $pSource, 0, $pBlend, $ULW_ALPHA)
    _WinAPI_ReleaseDC(0, $hScrDC)
    _WinAPI_SelectObject($hMemDC, $hOld)
    _WinAPI_DeleteObject($hBitmap)
    _WinAPI_DeleteDC($hMemDC)
EndFunc  ;==>SetBitmap

; I don't like AutoIt's built in ShellExec. I'd rather do the DLL call myself.
Func _ShellExecute($sCmd, $sArg = "", $sFolder = "", $rState = @SW_SHOWNORMAL)
    $aRet = DllCall("shell32.dll", "long", "ShellExecute", _
            "hwnd", 0, _
            "string", "", _
            "string", $sCmd, _
            "string", $sArg, _
            "string", $sFolder, _
            "int", $rState)
    If @error Then Return 0

    $RetVal = $aRet[0]
    If $RetVal > 32 Then
        Return 1
    Else
        Return 0
    EndIf
EndFunc  ;==>_ShellExecute

Now my code:

$GUIpic1 = GUICtrlCreatePic("",0,0,900,300)
$GUIpic2 = GUICtrlCreatePic("",0,0,900,300)
_ResourceSetImageToCtrl($GUIpic1, "KABOOKIE_PIC_1")
_ResourceSetImageToCtrl($GUIpic2, "GREY_1")
;$size1 = _ResourceGetImageSize("KABOOKIE_PIC_1")
$hImage = _ResourceGetAsImage("KABOOKIE_PIC_1", 10)
$TransPic = _ResourceGetAsImage("GREY_1", 10)

;==================== Transparent GUI Loading =============
_GDIPlus_Startup()
;$pngSrc = @ScriptDir & "\Kabookie IM.png"
;$hImage = _GDIPlus_ImageLoadFromFile($pngSrc)

; Extract image width and height from PNG
$width = _GDIPlus_ImageGetWidth($hImage)
$height = _GDIPlus_ImageGetHeight($hImage)
;==================== Transparent GUI Loading End =========

;==================== Build Up GUI ========================
$MainGUI = GUICreate("Kabookie - Intra Messaging V 0.10b  -  Levix Edition", $width, $height, -1, -1, BitOr($WS_POPUP,$WS_MINIMIZEBOX), $WS_EX_LAYERED)

SetBitmap($MainGUI, $hImage, 0)

; Register notification messages
GUIRegisterMsg($WM_NCHITTEST, "WM_NCHITTEST")
GUISetState()
;WinSetOnTop($MainGUI, "", 1)
;fade in png background
For $i = 0 To 255 Step 1        ; The higher the Step the faster the fade in
    SetBitmap($MainGUI, $hImage, $i)
Next

; create child MDI gui window to hold controls
; this part could use some work - there is some flicker sometimes...
$controlGui = GUICreate("ControlGUI", $width, $height, 0, 0, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $MainGUI)

; child window transparency is required to accomplish the full effect, so $WS_EX_LAYERED above, and
; I think the way this works is the transparent window color is based on the image you set here:
GUICtrlCreatePic($GUIpic2, 0, 0, $width, $height)
GUICtrlSetState(-1, $GUI_DISABLE)

$ConIPGroup = GUICtrlCreateGroup("", 650, 178, 205, 362)
GUICtrlSetFont(-1, 8.5,"Times New Roman")
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetColor(-1, 0xFFFFFF)
$ConnectedIP = GUICtrlCreateListView("", 668, 196, 175, 292, BitOR($LVS_SORTASCENDING,$LVS_LIST,$LVS_SINGLESEL,$LVS_SHOWSELALWAYS,$WS_VSCROLL,$WS_BORDER))
_GUICtrlListView_SetColumnWidth($ConnectedIP, 0, 175)
GUICtrlSetFont(-1, 9,"Times New Roman")
GUICtrlSetColor(-1, 0x000000)
$EditIPBut = GUICtrlCreateButton("Edit", 782, 514, 61, 19)
GUICtrlSetState(-1, $GUI_DISABLE)

..........more controls added here...

GUISetState(@SW_SHOW)

Hope you guys can see why my controls are never put to screen..

Link to comment
Share on other sites

...

1) you can't use GUICtrlCreatePic() before GUICreate()

2)

instead of

GUICtrlCreatePic($GUIpic2, 0, 0, $width, $height)

use

$GUIpic2 = GUICtrlCreatePic("", 0, 0, $width, $height)

_ResourceSetImageToCtrl($GUIpic2, "KABOOKIE_PIC_1")

Here is code (not tested):

;~ $GUIpic1 = GUICtrlCreatePic("",0,0,900,300)
;~ $GUIpic2 = GUICtrlCreatePic("",0,0,900,300)
;~ _ResourceSetImageToCtrl($GUIpic1, "KABOOKIE_PIC_1")
;~ _ResourceSetImageToCtrl($GUIpic2, "GREY_1")
;$size1 = _ResourceGetImageSize("KABOOKIE_PIC_1")
$hImage = _ResourceGetAsImage("KABOOKIE_PIC_1", 10)
$TransPic = _ResourceGetAsImage("GREY_1", 10)

;==================== Transparent GUI Loading =============
_GDIPlus_Startup()
;$pngSrc = @ScriptDir & "\Kabookie IM.png"
;$hImage = _GDIPlus_ImageLoadFromFile($pngSrc)

; Extract image width and height from PNG
$width = _GDIPlus_ImageGetWidth($hImage)
$height = _GDIPlus_ImageGetHeight($hImage)
;==================== Transparent GUI Loading End =========

;==================== Build Up GUI ========================
$MainGUI = GUICreate("Kabookie - Intra Messaging V 0.10b  -  Levix Edition", $width, $height, -1, -1, BitOr($WS_POPUP,$WS_MINIMIZEBOX), $WS_EX_LAYERED)

SetBitmap($MainGUI, $hImage, 0)

; Register notification messages
GUIRegisterMsg($WM_NCHITTEST, "WM_NCHITTEST")
GUISetState()
;WinSetOnTop($MainGUI, "", 1)
;fade in png background
For $i = 0 To 255 Step 1        ; The higher the Step the faster the fade in
    SetBitmap($MainGUI, $hImage, $i)
Next

; create child MDI gui window to hold controls
; this part could use some work - there is some flicker sometimes...
$controlGui = GUICreate("ControlGUI", $width, $height, 0, 0, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $MainGUI)

; child window transparency is required to accomplish the full effect, so $WS_EX_LAYERED above, and
; I think the way this works is the transparent window color is based on the image you set here:
$GUIpic2 = GUICtrlCreatePic("", 0, 0, $width, $height)
;~ _ResourceSetImageToCtrl($GUIpic2, "GREY_1")
_ResourceSetImageToCtrl($GUIpic2, "KABOOKIE_PIC_1")
GUICtrlSetState(-1, $GUI_DISABLE)

$ConIPGroup = GUICtrlCreateGroup("", 650, 178, 205, 362)
GUICtrlSetFont(-1, 8.5,"Times New Roman")
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetColor(-1, 0xFFFFFF)
$ConnectedIP = GUICtrlCreateListView("", 668, 196, 175, 292, BitOR($LVS_SORTASCENDING,$LVS_LIST,$LVS_SINGLESEL,$LVS_SHOWSELALWAYS,$WS_VSCROLL,$WS_BORDER))
_GUICtrlListView_SetColumnWidth($ConnectedIP, 0, 175)
GUICtrlSetFont(-1, 9,"Times New Roman")
GUICtrlSetColor(-1, 0x000000)
$EditIPBut = GUICtrlCreateButton("Edit", 782, 514, 61, 19)
GUICtrlSetState(-1, $GUI_DISABLE)

;~ ..........more controls added here...

GUISetState(@SW_SHOW)
Edited by Zedna
Link to comment
Share on other sites

Hmmm that did not work, i get a window the size of grey.gif, so my guess is that the pic's get mixed up.

Fading is not being done anymore too..

Edited by inet
Link to comment
Share on other sites

  • 2 weeks later...

Anyone has another solution or idea??

I had the same idea as you and tried to use Lod3n Launcher with resources.

For me the fading works, but the GUI on top with the Controls on it, is not transparent. (see attachment)

I couldn't find a quick fix and am now also hoping for help from Zedna.

As a work around we could include both pix as resources and filesave the grey.gif to temp folder before usage.

@ Zedna:

I'm wondering if _GDIPlus_ImageDispose($hImage) is still necessary if we use your function to get the handle, like this...

$hImage = _ResourceGetAsImage("PICTURE_BG_1") ??

thx

post-32823-1217257407_thumb.jpg

You can fool some of the people all of the time, and all of the people some of the time, but you can not fool all of the people all of the time. Abraham Lincoln - http://www.ae911truth.org/ - http://www.freedocumentaries.org/
Link to comment
Share on other sites

To make the Top GUI transparent, use just this:

http://www.autoitscript.com/forum/index.ph...indowattributes

#include "WinAPI_SetLayered.au3"
GUISetBkColor(0x121314)
_WinAPI_SetLayeredWindowAttributes($transparent_gui, 0x121314)

-> No image needed

//Edit: And yes, you have to call _GDIPlus_ImageDispose :P

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

I have a correction for _ResourceGetAsImage, but still doesn't work with animated gifs

; returned hImage can be used in many GDI+ functions:
; $width =  _GDIPlus_ImageGetWidth ($hImage)
; $height = _GDIPlus_ImageGetHeight($hImage)
Func _ResourceGetAsImage($ResName, $ResType = 10, $DLL = -1) ; $RT_RCDATA = 10
    Local $ResData, $nSize, $hData, $pData, $pStream, $pBitmap, $hBitmap

    $ResData = _ResourceGet($ResName, $ResType, 0, $DLL)
    If @error Then Return SetError(1, 0, 0)
    $nSize = @extended

    _GDIPlus_Startup()

    If $ResType = $RT_BITMAP Then
        ; $ResData is hBitmap type
        $hImage = _GDIPlus_BitmapCreateFromHBITMAP($ResData)
    Else
        ; $ResData is memory pointer
        ; thanks ProgAndy
        $hData = _MemGlobalAlloc($nSize, 2)
        $pData = _MemGlobalLock($hData)
        _MemMoveMemory($ResData, $pData, $nSize)
        _MemGlobalUnlock($hData)
        $pStream = DllCall("ole32.dll", "int", "CreateStreamOnHGlobal", "int", $hData, "long", 1, "Int*", 0)
        $pStream = $pStream[3]
;~        _GDIPlus_Startup()
        $hImage = DllCall($ghGDIPDll, "int", "GdipCreateBitmapFromStream", "ptr", $pStream, "int*", 0)
        $hImage = $hImage[2]
        $hTempImg = DllCall($ghGDIPDll, "int", "GdipCloneImage","hwnd",$hImage,"int*",0)
        $hTempImg = $hTempImg[2]
        DllCall($ghGDIPDll, "int", "GdipImageForceValidation","hwnd",$hTempImg)
        _GDIPlus_BitmapDispose($hImage)
        $hImage = $hTempImg
;~          _GDIPlus_Shutdown()
        _WinAPI_DeleteObject($pStream)
        _MemGlobalFree($hData)
    EndIf

    Return $hImage ; hImage type
EndFunc   ;==>_ResourceGetAsImageoÝ÷ Ø   Ý#
.ØZ½æ§{^ȨÊ-«r¢çhm«Þ¶Þjw±µêçjPË-ú+y§!­ë(º·jëh×6Func _ResourceLoadDLL($DLL)
    Local $hInstance = DllCall("kernel32.dll", "int", "LoadLibraryEx", "str", $DLL,"hwnd",0,"dword",BitOR(0x00000020,0x00000002))
    If @error Or $hInstance[0] = 0 Then Return SetError(1,0,0)
    Return HWnd($hInstance[0])
EndFunc
Func _ResourceFreeDLL($DLLHandle)
    Local $aResult = DllCall("Kernel32.dll", "hwnd", "FreeLibrary", "hwnd", $DLLHandle)
    If @error Or $aResult[0] = 0 Then Return SetError(1,0,0)
    Return HWnd($aResult[0])
EndFuncoÝ÷ Ú)ÑzÊ.­ÇzÛaxÛ$Â+aÓ~,

in _ResourcePlaySound make similar additions :P

*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

I have a correction for _ResourceGetAsImage, but still doesn't work with animated gifs

I think your addition with $hTempImg is not neccessary. Animated GIFs from resources works fine when you comment this line at end of _ResourceGetAsImage()

_MemGlobalFree($hData)

But when I stop animation then Left/Right doesn't work and also unPause will not start animation again.

EDIT:  more clarification. Pause/unPause/Left/Right now works fine when I comment only this one line _MemGlobalFree($hData)

EDIT2: Here is link about using animated GIF images from resources: http://www.autoitscript.com/forum/index.ph...st&p=559985

Edited by Zedna
Link to comment
Share on other sites

I think your addition with $hTempImg is not neccessary. Animated GIFs from resources works fine when you comment this line at end of _ResourceGetAsImage()

_MemGlobalFree($hData)
OK :P I hope, that then all is cleaned up correctly. And what do you think about my other sugestion, the pre-loading of the DLLs?

//Edit: And, i cchenged from loadlibrary to loadlibraryEx, so that you can load as resourceFile, not as normal DLL,whose Functions are used (should be faster :P )

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

OK :P I hope, that then all is cleaned up correctly. And what do you think about my other sugestion, the pre-loading of the DLLs?

I'm afraid that this will cause memory leak but I will remove it (comment) in the next version though.

//Edit: And, i cchenged from loadlibrary to loadlibraryEx, so that you can load as resourceFile, not as normal DLL,whose Functions are used (should be faster :P )

It looks good as for optimizations.

I will look into it more deeply later. As obvious thanks for your neverending cooperation ProgAndy  :o

Edited by Zedna
Link to comment
Share on other sites

It looks good as for optimizations.

I will look into it more deeply later. As obvious thanks for your neverending cooperation ProgAndy  :P

Thanks :P But why should I write my own reource UDf, when this is great. ( I would only have stolen you code :o )

*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

I found a bug :P You should remove _GDIPlus_Startup() from the Image-Functions, or at least add _GDIPlus_Shutdown(), because GDIPlus only can be shut down correctly, if _GDIPlus_Shutdown() is called as often as _GDIPlus_Startup()

*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

I found a bug :P You should remove _GDIPlus_Startup() from the Image-Functions, or at least add _GDIPlus_Shutdown(), because GDIPlus only can be shut down correctly, if _GDIPlus_Shutdown() is called as often as _GDIPlus_Startup()

As I said in my first post (known problems) I did it but then some things stopped working :-(

Now I think I will add  _GDIPlus_Startup() at begin of my whole UDF so it will start GDI+ once at begin of script which will be including my resources UDF and no _GDIPlus_Shutdown() will be done at all.

Link to comment
Share on other sites

  • 2 weeks later...

New version. See first post.

TODO list:

- add _ResourceLoadDLL(),_ResourceFreeDLL() - thanks ProgAndy

2008-08-14

- change: _GDIPlus_Startup() is called once at start of whole include --> no _GDIPlus_Shutdown() is called

- fixed support for animated GIFs in _ResourceGetAsImage() --> removed _MemGlobalFree($hData)

- used simpler UDF syntax (from WinAPI) instead of DllCall() where possible

- added new example for animated GIF image

Link to comment
Share on other sites

  • 2 weeks later...

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