Jump to content

PNG as GUI, drop shadows, curved edges, you name it


lod3n
 Share

Recommended Posts

You should create a third GUI specifically and only for the picture control. Using this stuff is different from normal GUI methodology, to say the least.

Lod3n.. thanks very much that worked great for me :)

Its a very nice include you've got. And no doupt I'll be using it a lot in the future :)

Thanks again

Welcome to the internet :) where men are men! Women are men! and 16 year old women are FBI agents!

Link to comment
Share on other sites

  • Replies 148
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Posted Images

I have the same error and I can`t get it work :)...

HELP :)

Based on what Lod3n said

for the second graphic I used..

CODE

$minon=guicreate("minon", 38,28,532,-19,$WS_POPUP,BitOR($WS_EX_LAYERED,$WS_EX_MDICHILD),$Gui)

GUICtrlCreatePic(@ScriptDir &"\minon.jpg",0, 0, 38,28)

GUISetState()

This creates a very small gui the size of my new graphic at the coords that I wanted my second graphic to appear at (overlayed on the first gui)

then created a pic at 0,0 of this second gui

So basically you create your fisrt background gui..

then create a new gui the size and shape of the graphic you want to create and then finally put a picture into the new gui.

hope this sorta makes sence.

Welcome to the internet :) where men are men! Women are men! and 16 year old women are FBI agents!

Link to comment
Share on other sites

  • 2 months later...
  • 3 weeks later...

Ah never mind, I got it working myself...

CODE

;Updated to support latest autoit by spyrorocks

#NoTrayIcon

#Include <GDIPlus.au3> ; this is where the magic happens, people

#include <GuiCombo.au3>

#Include <File.au3>

#include <Array.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&"\LaunchySkin.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 10

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("Type the name of a file on your desktop and press Enter",50,12,140,50)

GUICtrlSetBkColor(-1,$GUI_BKCOLOR_TRANSPARENT)

GUICtrlSetColor(-1,0xFFFFFF)

; combo box listing all items on desktop

$Combo = GuiCtrlCreateCombo("", 210, 12,250,-1)

GUICtrlSetFont ($Combo, 12)

; set default button for Enter key activation - renders outside GUI window

$goButton = GUICtrlCreateButton ( "Go",$width,$height,10,10,$BS_DEFPUSHBUTTON)

GUISetState()

; get list of files on desktop, show in combobox

$aFileList=_FileListToArray($launchDir)

_ArraySort($aFileList,0,1)

$FileList = _ArrayToString ( $aFileList, "|", 1)

GUICtrlSetData($Combo,$FileList)

AdlibEnable ( "GoAutoComplete", 1000 ) ; combo autocomplete every message loop = often incorrect

While 1

$msg = GUIGetMsg()

Select

Case $msg = $GUI_EVENT_CLOSE

ExitLoop

Case $msg = $goButton

$runthis = GUICtrlRead($Combo)

ExitLoop

EndSelect

WEnd

AdlibDisable ()

if $runthis <> "" then

if fileexists($launchDir & "\" & $runthis) then

beep(1000,50)

beep(2000,50)

_ShellExecute($runthis, "", $launchDir)

EndIf

EndIf

GUIDelete($controlGui)

;fade out png background

for $i = 255 to 0 step -10

SetBitMap($GUI, $hImage, $i)

next

; Release resources

_GDIPlus_ImageDispose($hImage)

_GDIPlus_Shutdown()

func GoAutoComplete()

_GUICtrlComboAutoComplete ($Combo, $old_string)

EndFunc

;

====================================================================================================

=====

======================

; 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

;

====================================================================================================

=====

======================

; 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

; 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

one problem, there is a bug in the guicomb.au3 file... execute the code and you will see what I mean. I tested it using autoit v3.2.10.0.

Link to comment
Share on other sites

@ SpyroRocks: Im haveing trouble using the updated script. It throws me all these errors:

C:\Users\Draygoes\Desktop\lod3n_launcher\lod3n launcher.au3(4,10) : ERROR: can't open include file <GuiCombo.au3>

#include <GuiCombo.au3>

~~~~~~~~~^

C:\Users\Draygoes\Desktop\lod3n_launcher\lod3n launcher.au3(38,55) : ERROR: syntax error

$controlGui = GUICreate("ControlGUI", $width, $height,

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\Users\Draygoes\Desktop\lod3n_launcher\lod3n launcher.au3(109,1) : ERROR: syntax error

==

^

C:\Users\Draygoes\Desktop\lod3n_launcher\lod3n launcher.au3(25,27) : ERROR: SetBitMap(): undefined function.

SetBitMap($GUI, $hImage, 0)

~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\Users\Draygoes\Desktop\lod3n_launcher\lod3n launcher.au3(27,45) : ERROR: WM_NCHITTEST(): undefined function.

GUIRegisterMsg($WM_NCHITTEST, "WM_NCHITTEST")

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\Users\Draygoes\Desktop\lod3n_launcher\lod3n launcher.au3(87,39) : ERROR: _ShellExecute(): undefined function.

_ShellExecute($runthis, "", $launchDir)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\Users\Draygoes\Desktop\lod3n_launcher\lod3n launcher.au3(104,47) : ERROR: _GUICtrlComboAutoComplete(): undefined function.

_GUICtrlComboAutoComplete ($Combo, $old_string)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\Users\Draygoes\Desktop\lod3n_launcher\lod3n launcher.au3 - 7 error(s), 0 warning(s)

I have no idea whats wrong. Im using the latest version of autoit.

Spoiler

 

"If a vegetarian eats vegetables,What the heck does a humanitarian eat?"

"I hear voices in my head, but I ignore them and continue on killing."

"You have forced me to raise the indifference warning to beige, it's a beige alert people. As with all beige alerts please prepare to think about the possibility of caring."

An optimist says that giving someone power DOESN'T immediately turn them into a sadist. A pessimist says that giving someone power doesn't IMMEDIATELY turn them into a sadist.

 

 
Link to comment
Share on other sites

Clean the script up... When you copy it, lines are added... :)

And this works for me ^_^

;Updated to support latest autoit by spyrorocks, then re-updated by Bert... =]
#NoTrayIcon
#Include <GDIPlus.au3> ; this is where the magic happens, people
#include <GuiComboBox.au3>
#Include <File.au3>
#include <Array.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 & "\LaunchySkin.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 10
    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("Type the name of a file on your desktop and press Enter", 50, 12, 140, 50)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetColor(-1, 0xFFFFFF)

; combo box listing all items on desktop
$Combo = GUICtrlCreateCombo("", 210, 12, 250, -1)
GUICtrlSetFont($Combo, 12)


; set default button for Enter key activation - renders outside GUI window
$goButton = GUICtrlCreateButton("Go", $width, $height, 10, 10, $BS_DEFPUSHBUTTON)

GUISetState()

; get list of files on desktop, show in combobox
$aFileList = _FileListToArray($launchDir)
_ArraySort($aFileList, 0, 1)
$FileList = _ArrayToString($aFileList, "|", 1)
GUICtrlSetData($Combo, $FileList)

AdlibEnable("GoAutoComplete", 1000) ; combo autocomplete every message loop = often incorrect
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $goButton
            $runthis = GUICtrlRead($Combo)
            ExitLoop
    EndSelect
WEnd
AdlibDisable()



If $runthis <> "" Then
    If FileExists($launchDir & "\" & $runthis) Then
        Beep(1000, 50)
        Beep(2000, 50)
        _ShellExecute($runthis, "", $launchDir)
    EndIf
EndIf

GUIDelete($controlGui)
;fade out png background
For $i = 255 To 0 Step - 10
    SetBitmap($GUI, $hImage, $i)
Next

; Release resources
_GDIPlus_ImageDispose($hImage)
_GDIPlus_Shutdown()



Func GoAutoComplete()
    _GUICtrlComboBox_AutoComplete($Combo)
EndFunc   ;==>GoAutoComplete

;===============================================================================================================================
; 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
Edited by Bert
Link to comment
Share on other sites

  • 2 weeks later...

Hi,

I've solved this problem doing like this...

If @OSVersion = "WIN_VISTA" Then

$controlGui = GUICreate("ControlGUI", $width, $hight, -4,-22,$WS_POPUP,BitOR($WS_EX_LAYERED,$WS_EX_MDICHILD),$GUI)

ElseIf @OSVersion = "WIN_2003" Then

$controlGui = GUICreate("ControlGUI", $width, $hight, -4,-22,$WS_POPUP,BitOR($WS_EX_LAYERED,$WS_EX_MDICHILD),$GUI)

Else

$controlGui = GUICreate("ControlGUI", $width, $hight, -4,-28,$WS_POPUP,BitOR($WS_EX_LAYERED,$WS_EX_MDICHILD),$GUI)

EndIf

Maybe not the right way but...

I'm having a little difficulty determining where the GUICtrlCreateLabel gets it's initial placement values from. When I set it to (10, 0) it offsets it correctly from the left side, but not from the top.

I disabled the GUICtrlSetBkColor to show where the label is actually placed.

Posted Image

#NoTrayIcon
#include <A3LGDIPlus.au3> ; this is where the magic happens, people
#include <GuiCombo.au3>
#Include <File.au3>
#include <Array.au3>
Opt("MustDeclareVars", 0)

Global Const $AC_SRC_ALPHA      = 1
Global Const $ULW_ALPHA         = 2

; Load PNG file as GDI bitmap
_GDIP_Startup()
$pngSrc = @scriptdir&"\Sample.png"
$hImage = _GDIP_ImageLoadFromFile($pngSrc)

; Extract image width and height from PNG
$width =  _GDIP_ImageGetWidth ($hImage)
$height = _GDIP_ImageGetHeight($hImage)

; Create layered window
$GUI = GUICreate("Sample", $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 10
    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("Sample PNG GUI",10,0,110,30)
;GUICtrlSetBkColor(-1,$GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetColor(-1,0xf000000)

GUISetState()

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
;       Case $msg = $goButton
;           
            ExitLoop
    EndSelect
WEnd
AdlibDisable ()



GUIDelete($controlGui)
;fade out png background
for $i = 255 to 0 step -10
    SetBitMap($GUI, $hImage, $i)
next

; Release resources
_API_DeleteObject($hImage)
_GDIP_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

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

  $hScrDC  = _API_GetDC(0)
  $hMemDC  = _API_CreateCompatibleDC($hScrDC)
  $hBitmap = _GDIP_BitmapCreateHBITMAPFromBitmap($hImage)
  $hOld    = _API_SelectObject($hMemDC, $hBitmap)
  $tSize   = DllStructCreate($tagSIZE)
  $pSize   = DllStructGetPtr($tSize  )
  DllStructSetData($tSize, "X", _GDIP_ImageGetWidth ($hImage))
  DllStructSetData($tSize, "Y", _GDIP_ImageGetHeight($hImage))
  $tSource = DllStructCreate($tagPOINT)
  $pSource = DllStructGetPtr($tSource)
  $tBlend  = DllStructCreate($tagBLENDFUNCTION)
  $pBlend  = DllStructGetPtr($tBlend)
  DllStructSetData($tBlend, "Alpha" , $iOpacity    )
  DllStructSetData($tBlend, "Format", $AC_SRC_ALPHA)
  _API_UpdateLayeredWindow($hGUI, $hScrDC, 0, $pSize, $hMemDC, $pSource, 0, $pBlend, $ULW_ALPHA)
  _API_ReleaseDC   (0, $hScrDC)
  _API_SelectObject($hMemDC, $hOld)
  _API_DeleteObject($hBitmap)
  _API_DeleteDC    ($hMemDC)
EndFunc
Link to comment
Share on other sites

Hi,

I've solved this problem doing like this...

If @OSVersion = "WIN_VISTA" Then

$controlGui = GUICreate("ControlGUI", $width, $hight, -4,-22,$WS_POPUP,BitOR($WS_EX_LAYERED,$WS_EX_MDICHILD),$GUI)

ElseIf @OSVersion = "WIN_2003" Then

$controlGui = GUICreate("ControlGUI", $width, $hight, -4,-22,$WS_POPUP,BitOR($WS_EX_LAYERED,$WS_EX_MDICHILD),$GUI)

Else

$controlGui = GUICreate("ControlGUI", $width, $hight, -4,-28,$WS_POPUP,BitOR($WS_EX_LAYERED,$WS_EX_MDICHILD),$GUI)

EndIf

Maybe not the right way but...

Hmmmmmmmmmmmmm. Maybe it's just me but I see no difference between your @OSVersion = "WIN_VISTA" and your @OSVersion = "WIN_2003". Are you sure you got that right?

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

  • 1 month later...
  • 2 months later...

Here is the script cleand up for A3.

#NoTrayIcon
#include <GDIPlus.au3>; this is where the magic happens, people
#include <GuiComboBox.au3>
#Include <File.au3>
#include <Array.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&"\LaunchySkin.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 10
    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("Type the name of a file on your desktop and press Enter",50,12,140,50)
GUICtrlSetBkColor(-1,$GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetColor(-1,0xFFFFFF)

; combo box listing all items on desktop
$Combo = GuiCtrlCreateCombo("", 210, 12,250,-1)
GUICtrlSetFont ($Combo, 12)


; set default button for Enter key activation - renders outside GUI window
$goButton = GUICtrlCreateButton ( "Go",$width,$height,10,10,$BS_DEFPUSHBUTTON)

GUISetState()

; get list of files on desktop, show in combobox
$aFileList=_FileListToArray($launchDir)
_ArraySort($aFileList,0,1)
$FileList = _ArrayToString ( $aFileList, "|", 1)
GUICtrlSetData($Combo,$FileList)

AdlibEnable ( "GoAutoComplete", 1000 ); combo autocomplete every message loop = often incorrect
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $goButton
            $runthis = GUICtrlRead($Combo)
            ExitLoop
    EndSelect
WEnd
AdlibDisable ()



if $runthis <> "" then 
    if fileexists($launchDir & "\" & $runthis) then 
        beep(1000,50)
        beep(2000,50)
        _ShellExecute($runthis, "", $launchDir)
    EndIf
EndIf

GUIDelete($controlGui)
;fade out png background
for $i = 255 to 0 step -10
    SetBitMap($GUI, $hImage, $i)
next

; Release resources
_WinAPI_DeleteObject($hImage)
_GDIPlus_Shutdown()



func GoAutoComplete()
    _GUICtrlComboBox_AutoComplete ($Combo)
EndFunc

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


===========================
; 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

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


===========================
; 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


; 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

Download the original zip file and replace the content of lod3n_launcher with above and enjoy.

Cheers.

Stevo

Edited by Stevo
Link to comment
Share on other sites

  • 1 month later...

Here is the script cleand up for A3.

#NoTrayIcon
#include <GDIPlus.au3>; this is where the magic happens, people
#include <GuiComboBox.au3>
#Include <File.au3>
#include <Array.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&"\LaunchySkin.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 10
    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("Type the name of a file on your desktop and press Enter",50,12,140,50)
GUICtrlSetBkColor(-1,$GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetColor(-1,0xFFFFFF)

; combo box listing all items on desktop
$Combo = GuiCtrlCreateCombo("", 210, 12,250,-1)
GUICtrlSetFont ($Combo, 12)


; set default button for Enter key activation - renders outside GUI window
$goButton = GUICtrlCreateButton ( "Go",$width,$height,10,10,$BS_DEFPUSHBUTTON)

GUISetState()

; get list of files on desktop, show in combobox
$aFileList=_FileListToArray($launchDir)
_ArraySort($aFileList,0,1)
$FileList = _ArrayToString ( $aFileList, "|", 1)
GUICtrlSetData($Combo,$FileList)

AdlibEnable ( "GoAutoComplete", 1000 ); combo autocomplete every message loop = often incorrect
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $goButton
            $runthis = GUICtrlRead($Combo)
            ExitLoop
    EndSelect
WEnd
AdlibDisable ()



if $runthis <> "" then 
    if fileexists($launchDir & "\" & $runthis) then 
        beep(1000,50)
        beep(2000,50)
        _ShellExecute($runthis, "", $launchDir)
    EndIf
EndIf

GUIDelete($controlGui)
;fade out png background
for $i = 255 to 0 step -10
    SetBitMap($GUI, $hImage, $i)
next

; Release resources
_WinAPI_DeleteObject($hImage)
_GDIPlus_Shutdown()



func GoAutoComplete()
    _GUICtrlComboBox_AutoComplete ($Combo)
EndFunc

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



===========================
; 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

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



===========================
; 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


; 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

Download the original zip file and replace the content of lod3n_launcher with above and enjoy.

Cheers.

Stevo

I'm using AutoIt v3.2.12.0. This cleaned up code throws many errors in my system. Could you please help me out.
Link to comment
Share on other sites

I'm using AutoIt v3.2.12.0. This cleaned up code throws many errors in my system. Could you please help me out.

#NoTrayIcon
#include <GDIPlus.au3>; this is where the magic happens, people
#include <GuiComboBox.au3>
#include <File.au3>
#include <Array.au3>
#include <WindowsConstants.au3>
#include <GuiConstantsEx.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 & "\LaunchySkin.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 10
    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("Type the name of a file on your desktop and press Enter", 50, 12, 140, 50)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetColor(-1, 0xFFFFFF)

; combo box listing all items on desktop
$Combo = GUICtrlCreateCombo("", 210, 12, 250, -1)
GUICtrlSetFont($Combo, 12)


; set default button for Enter key activation - renders outside GUI window
$goButton = GUICtrlCreateButton("Go", $width, $height, 10, 10, $BS_DEFPUSHBUTTON)

GUISetState()

; get list of files on desktop, show in combobox
$aFileList = _FileListToArray($launchDir)
_ArraySort($aFileList, 0, 1)
$FileList = _ArrayToString($aFileList, "|", 1)
GUICtrlSetData($Combo, $FileList)

AdlibEnable("GoAutoComplete", 1000); combo autocomplete every message loop = often incorrect
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $goButton
            $runthis = GUICtrlRead($Combo)
            ExitLoop
    EndSelect
WEnd
AdlibDisable()



If $runthis <> "" Then
    If FileExists($launchDir & "\" & $runthis) Then
        Beep(1000, 50)
        Beep(2000, 50)
        _ShellExecute($runthis, "", $launchDir)
    EndIf
EndIf

GUIDelete($controlGui)
;fade out png background
For $i = 255 To 0 Step -10
    SetBitmap($GUI, $hImage, $i)
Next

; Release resources
_WinAPI_DeleteObject($hImage)
_GDIPlus_Shutdown()



Func GoAutoComplete()
    _GUICtrlComboBox_AutoComplete($Combo)
EndFunc   ;==>GoAutoComplete

; ====================================================================================================
; 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

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

Hi guys,

I had an older version of this script which was "Updated to support latest autoit by spyrorocks, then re-updated by Bert".

It worked fine, but now I compared it to the script posted by Gary Frost, and I noticed one (?important?) change there...

In Gary's Version the following line (#98) ...

_GDIPlus_ImageDispose($hImage)

is replaced with this one...

_WinAPI_DeleteObject($hImage)

Are those two functions doing the same thing, or which version is "cleaner" from a programming perspective?

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

Perhaps you guys will be interested in what we are doing in autohotkey on the same front as this...?

You might be interested as we are a lot further along so you might be able to get ideas. I'd be happy to help try and convert it for autoit. I can show a demonstration if you wish...

Link to comment
Share on other sites

Perhaps you guys will be interested in what we are doing in autohotkey on the same front as this...?

You might be interested as we are a lot further along so you might be able to get ideas. I'd be happy to help try and convert it for autoit. I can show a demonstration if you wish...

Sure, why not give us a conversion? And maybe a link to an example of what has been done with AHK.
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Sure, why not give us a conversion? And maybe a link to an example of what has been done with AHK.

Sure buddy. Here's a very simple example that I just wrote just to demonstrate 2 wrapper functions I have created, namely Gdip_TextToGraphics and Gdip_BlurBitmap. I have made much more insane things than this :) but just give this example a try and tell me what you think. I have included it compiled and the source in case you dont feel like installing ahk (http://www.autohotkey.com/download/)

Hover buttons example

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