Jump to content

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


lod3n
 Share

Recommended Posts

Hello

Yes, i know this Example! And i've written it so, that the png resize with the GUI. But not "Live". While i rezising there is a Grey Screen :).

#include <A3LGDIPlus.au3>

;~ Opt("MustDeclareVars", 1)

; ====================================================================================================
;~ ===========================
; Description ...: Shows how to display a PNG image
; Author ........: Paul Campbell (PaulIA)
; Notes .........:
; ====================================================================================================
;~ ===========================

; ====================================================================================================
;~ ===========================
; Global variables
; ====================================================================================================
;~ ===========================
Global $hGUI, $hImage, $hGraphic,$h,$w

; Create GUI
$hGUI = GUICreate("Show PNG", 600, 600,0,0,$WS_SIZEBOX)

GUISetState()

; Load PNG image
_GDIP_StartUp()
$hImage   = _GDIP_ImageLoadFromFile(_Lib_AutoItDir() & "\Auto3Lib\Images\Torus.png")
$h = _GDIP_ImageGetWidth($hImage)
$w = _GDIP_ImageGetHeight($hImage)

; Draw PNG image
$hGraphic = _GDIP_GraphicsCreateFromHWND($hGUI)
_GDIP_GraphicsDrawImageRectRect($hGraphic, $hImage, 0, 0, $w, $h, 0,0, 590, 590)

; Loop until user exits
do
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    If $msg = $GUI_EVENT_RESIZED Then
        $hGraphic = _GDIP_GraphicsCreateFromHWND($hGUI)
        $wgcs = WinGetClientSize($hGUI)
        _GDIP_GraphicsDrawImageRectRect($hGraphic, $hImage, 0, 0, $w, $h, 0,0, $wgcs[0]-10, $wgcs[1]-10)
    EndIf
until 1<>1

; Clean up resources
_GDIP_GraphicsDispose($hGraphic)
_GDIP_ImageDispose($hImage)
_GDIP_ShutDown()

Mfg Spider

www.AutoIt.de - Moderator of the German AutoIt Forum

 

Link to comment
Share on other sites

  • 3 weeks later...
  • Replies 148
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Posted Images

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

Agreement is not necessary - thinking for one's self is!

My-Colors.jpg

cuniform2.gif

Link to comment
Share on other sites

@Fossil Rock

You know, I've noticed that too. I think it has to do with the way AutoIt "simulates" MDI parents and children. I think it's padding the top, presuming there will be a titlebar, even if there isn't one. In any case, an easy workaround is to simply add some transparent padding at the top edge of your PNG.

[font="Fixedsys"][list][*]All of my AutoIt Example Scripts[*]http://saneasylum.com[/list][/font]

Link to comment
Share on other sites

@Fossil Rock

You know, I've noticed that too. I think it has to do with the way AutoIt "simulates" MDI parents and children. I think it's padding the top, presuming there will be a titlebar, even if there isn't one. In any case, an easy workaround is to simply add some transparent padding at the top edge of your PNG.

Yeah, I though of padding the top, but wanted to see if there was a fix first.

Thanks for the reply.

Agreement is not necessary - thinking for one's self is!

My-Colors.jpg

cuniform2.gif

Link to comment
Share on other sites

is there a way to make buttons using .png

for excample a round blue button...

I'm probably wrong on this, but I think I saw a discussion about buttons along this line somewhere in the forums. Like I said though I'm probably totally wrong.

A decision is a powerful thing
Link to comment
Share on other sites

^^Use some png button pictures and the mouse hover udf

ok thanks

I'm probably wrong on this, but I think I saw a discussion about buttons along this line somewhere in the forums. Like I said though I'm probably totally wrong.

ill look that up...

But what i ment was is there a way that i can be done useing this...

or maybe in next version it could be added...

Link to comment
Share on other sites

  • 3 weeks later...

This is some really great stuff!

The only issue that I am having (this is in the samples too) is after the screensaver runs and then you come back to the desktop, the control child window is grey and does not refresh. Only closing the window will refresh it.

Does any one have an idea about this and how to fix it?

The only idea that I have been able to come up with so far is to monitor for the screensaver to start, close the windows, and then open them again when the screensaver quits. admittedly, this is not the best solution.

Link to comment
Share on other sites

I'm not really sure why that happens. That's worth investigating further. However, your other idea of checking to see if the screen saver is running isn't a bad one. Turns out good old PaulIA showed us the way there too:

#344733

Here's how I would use in your scenario:

#include <GUIConstants.au3>
#include <A3LWinAPI.au3>

$tBool = DllStructCreate("int Result")
$pBool = DllStructGetPtr($tBool)
$lastState = false

$hGUI = GUICreate("Screensaver Detector")
GUISetState()


AdlibEnable ( "CheckForSaver",1000)
func CheckForSaver()
  _API_SystemParametersInfo($SPI_GETSCREENSAVERRUNNING, 0, $pBool)
  $running = DllStructGetData($tBool, "Result")
  if $laststate <> $running then 
      $laststate = $running
      if $running Then
          ConsoleWrite("Screensaver started!" & @crlf)
          Beep(100,100)
          Winsetstate($hGUI,"",@SW_HIDE)
      Else
          ConsoleWrite("Screensaver ended!" & @crlf)
          Winsetstate($hGUI,"",@SW_SHOW)
      EndIf
  EndIf
EndFunc


While 1
    $GUIMsg = GUIGetMsg()
    
    Switch $GUIMsg
        Case $GUI_EVENT_CLOSE
            ExitLoop
            
    EndSwitch
WEnd

Exit
Edited by lod3n

[font="Fixedsys"][list][*]All of my AutoIt Example Scripts[*]http://saneasylum.com[/list][/font]

Link to comment
Share on other sites

lod3n: thanks for the function for checking the screen saver, that is what I was thinking. I just haven't taken it that far yet, because my application is a desktop note type and has the potential to have several windows open that would need to be hidden.

Link to comment
Share on other sites

Oh, well then replace the WinSetState functions above with _WinSetMyWindowStates(@SW_HIDE) / _WinSetMyWindowStates(@SW_SHOW)

Func _WinSetMyWindowStates($state)
    Local $aWindows = WinList()
    For $i = 1 to $aWindows[0][0]
        If WinGetProcess($aWindows[$i][1]) = @AutoItPID Then
            WinSetState($aWindows[$i][1],"",$state)
        EndIf
    Next
EndFunc

Hey, post your application when you're done with it; I am anxious to see projects that use the method. :)

[font="Fixedsys"][list][*]All of my AutoIt Example Scripts[*]http://saneasylum.com[/list][/font]

Link to comment
Share on other sites

This is the function that I am using and found to work best so far:

Func _CheckForSaver()
    Local $cnt, $running, $ret
    _API_SystemParametersInfo ($SPI_GETSCREENSAVERRUNNING, 0, $pBool)
    $running = DllStructGetData($tBool, "Result")
;I am not sure that the $SSCheck is needed, but it is to eliminate a recursion
    If $lastState <> $running And $SSCheck = False Then
        $lastState = $running
        If $running Then
            _ReduceMemory(@AutoItPID)
        Else
        ;this is set to false at program start
            $SSCheck = True
        ;screen saver is no longer running so show the notes again
        ;once the user clicks anywhere to activate a window
            $ret = WinGetTitle('')
            While $ret = ''
                Sleep(1000)
                $ret = WinGetTitle('')
            WEnd
        ;go through the notes and redraw
            For $cnt = 1 To UBound($RSNotesHwnd) - 1
                _API_RedrawWindow ($RSNotesCTRLHwnd[$cnt])
            Next
        ;reset back to false
            $SSCheck = False
        EndIf
    EndIf
EndFunc

I am not redrawing until the user clicks on the desktop or another window so that the notes don't try to redraw before the user logs back in (QuickSwitch enabled)

I don't see any way to add a zip file for the application- but it is still a work in progress anyway.

Link to comment
Share on other sites

This forum limits what you can do until your status is more well established. I'm not sure what the parameters are, but eventually you will be able to add attachments to your posts, as well as create a topic in Example Scripts for your script - which is where it should go. Do post a link to that topic here though, I'd appreciate it.

A good way to increase your status is to help random people over on General Help - you obviously know enough to help people over there. Just ignore the game cheaters and script kiddies, and it's kind of fun. I was like you, having used AutoIt for quite awhile before ever posting anything out of fear of ridicule. :)

[font="Fixedsys"][list][*]All of my AutoIt Example Scripts[*]http://saneasylum.com[/list][/font]

Link to comment
Share on other sites

Ive been playing with the A3LGDIPlus.au3 to create a vista type looking interface.

My problem is that now I have a png for a background I'm unable to create a picture item above that without either

having the script quit.. not showing the new picture or killing the transparency mask on the $controlGui.

CODE
#NoTrayIcon

#include <A3LGDIPlus.au3> ; this is where the magic happens, people

#include <GUIConstants.au3>

Opt("MustDeclareVars", 0)

Global Const $AC_SRC_ALPHA = 1

Global Const $ULW_ALPHA = 2

Global $old_string = "", $runthis = ""

Global $launchDir = @DesktopDir

global Const $title="WhoAmi"

; Load PNG file as GDI bitmap

global $tempdir= @tempdir & "\test1"

DirCreate ($tempdir)

fileinstall("backdrop.png",$tempdir & "\backdrop.png",1)

_GDIP_Startup()

$pngSrc = $tempdir & "\backdrop.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($title, $width, $height, -1, -1, $WS_POPUP, $WS_EX_LAYERED)

SetBitMap($GUI, $hImage, 0)

; Register notification messages

GUIRegisterMsg($WM_NCHITTEST, "WM_NCHITTEST")

WinSetOnTop($gui,"",1)

;fade in png background

for $i = 0 to 255 step 20

SetBitMap($GUI, $hImage, $i)

next

SetBitMap($GUI, $hImage, 255)

GUISetState()

$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)

GUISetState()

CREATEGUI()

While 1

$msg = GUIGetMsg()

Select

Case $msg = $GUI_EVENT_CLOSE

ExitLoop

EndSelect

WEnd

#ce

;fade gui then png background

DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $controlGui, "int", 1000, "long", 0x00090000);fade-out

for $i = 255 to 0 step -10

SetBitMap($GUI, $hImage, $i)

next

; Release resources

_API_DeleteObject($hImage)

_GDIP_Shutdown()

Exit

Func CREATEGUI()

; Error HERE !!! ! $minon= GUICtrlCreatePic(@ScriptDir &"\minon.jpg", 200, 100, 38,28)

$Group_2 = GUICtrlCreateGroup("Machine Details", 10, 30, 260, 170)

GUISetBkColor($Group_2,)

EndFunc ;==>CREATEGUI

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

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

; 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

; 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

Any help would be greatly appreciated. :)

Ta

logo_ps.zip

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

Ive been playing with the A3LGDIPlus.au3 to create a vista type looking interface.

My problem is that now I have a png for a background I'm unable to create a picture item above that without either

having the script quit.. not showing the new picture or killing the transparency mask on the $controlGui.

CODE
#NoTrayIcon

#include <A3LGDIPlus.au3> ; this is where the magic happens, people

#include <GUIConstants.au3>

Opt("MustDeclareVars", 0)

Global Const $AC_SRC_ALPHA = 1

Global Const $ULW_ALPHA = 2

Global $old_string = "", $runthis = ""

Global $launchDir = @DesktopDir

global Const $title="WhoAmi"

; Load PNG file as GDI bitmap

global $tempdir= @tempdir & "\test1"

DirCreate ($tempdir)

fileinstall("backdrop.png",$tempdir & "\backdrop.png",1)

_GDIP_Startup()

$pngSrc = $tempdir & "\backdrop.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($title, $width, $height, -1, -1, $WS_POPUP, $WS_EX_LAYERED)

SetBitMap($GUI, $hImage, 0)

; Register notification messages

GUIRegisterMsg($WM_NCHITTEST, "WM_NCHITTEST")

WinSetOnTop($gui,"",1)

;fade in png background

for $i = 0 to 255 step 20

SetBitMap($GUI, $hImage, $i)

next

SetBitMap($GUI, $hImage, 255)

GUISetState()

$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)

GUISetState()

CREATEGUI()

While 1

$msg = GUIGetMsg()

Select

Case $msg = $GUI_EVENT_CLOSE

ExitLoop

EndSelect

WEnd

#ce

;fade gui then png background

DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $controlGui, "int", 1000, "long", 0x00090000);fade-out

for $i = 255 to 0 step -10

SetBitMap($GUI, $hImage, $i)

next

; Release resources

_API_DeleteObject($hImage)

_GDIP_Shutdown()

Exit

Func CREATEGUI()

; Error HERE !!! ! $minon= GUICtrlCreatePic(@ScriptDir &"\minon.jpg", 200, 100, 38,28)

$Group_2 = GUICtrlCreateGroup("Machine Details", 10, 30, 260, 170)

GUISetBkColor($Group_2,)

EndFunc ;==>CREATEGUI

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

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

; 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

; 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

Any help would be greatly appreciated. :P

Ta

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

HELP :)

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