Jump to content

Recommended Posts

Posted (edited)

Hello community !
 
to keep it short...
 
Problem: If I minimize my GUI incl. the brushed pngs and restore the windows again the brushed pngs disappear.
 
Tested:
I allraedy searched for solutions in this and other forums, but the examples doon't work.
For example

<some code>
GUIRegisterMsg($WM_PAINT, "MY_WM_PAINT")

While 1
<some codes>
WEnd

Func MY_WM_PAINT($hWnd, $Msg, $wParam, $lParam)
    _WinAPI_RedrawWindow($hGUI, 0, 0, $RDW_UPDATENOW)
    _GDIPlus_GraphicsFillRect($hBackbuffer, 0, 0, 470, $iY, $hBrush)
    _GDIPlus_GraphicsDrawImage($hBackbuffer, $hImage, 10, -40)
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 0, 0, $w, $h)
    _WinAPI_RedrawWindow($hGUI, 0, 0, $RDW_VALIDATE)
    Return $GUI_RUNDEFMSG
EndFunc   ;==>MY_WM_PAINT

Goal: I want a GUI with several transparent pngs.
The pngs should be visible after minimize a window or move a window over the pngs.
If this works fine I want to draw png buttons, with a hover function.
When hover png then delete old png and draw new png.
Of course that is not all ... but first I want to fix the mentioned problem above.
 
HERE MY AU3 CODE:

#include <GDIPlus.au3>
#include <GuiConstantsEx.au3>
#Include <Misc.au3>

Opt("MustDeclareVars", 1)

; ===============================================================================================================================
; Description ...: Shows how to display a PNG image
; Author ........: Andreas Klein
; Notes .........:
; ===============================================================================================================================

; ===============================================================================================================================
; Global variables
; ===============================================================================================================================
Global $hGUI, $hImage1, $hImage2, $hGraphic, $label_cursorinfo, $cursorinfo, $mousepos, $WM_PAINT

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

$label_cursorinfo = GUICtrlCreateLabel(" ",10,10,290,290)
GUICtrlSetState($label_cursorinfo,@SW_HIDE)

;069380767265
;2178post
;michael102
GUISetState()

; Load PNG image
_GDIPlus_StartUp()
$hImage1   = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\win7.png")
$hImage2  = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\Rainbow_trout_transparent.png")

; Draw PNG image
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)

;Local $hMatrix = _GDIPlus_MatrixCreate()
; Scale the matrix by 2 (everything will get 2x larger)
;_GDIPlus_MatrixScale($hMatrix, 0.1, 0.1)
;_GDIPlus_GraphicsSetTransform($hGraphic,$hMatrix)

;_GDIPlus_GraphicsDrawImage($hGraphic, $hImage2, 0, 0)
;_GDIPlus_GraphicsDrawImage($hGraphic, $hImage1,5, 5)

_GDIPlus_GraphicsDrawImageRect($hGraphic,$hImage2,0,0,300,300)
_GDIPlus_GraphicsDrawImageRect($hGraphic,$hImage1,10,10,200,200)
; Loop until user exits

GUIRegisterMsg($WM_PAINT, "WM_PAINT")
While 1

    GUICtrlSetState($label_cursorinfo,@SW_HIDE)
    $cursorinfo = GUIGetCursorInfo($hGUI)
    $mousepos = MouseGetPos()
    ;GUICtrlSetData($label_cursorinfo,$cursorinfo[0] & @CRLF & $cursorinfo[1] & @CRLF & $cursorinfo[2] & @CRLF & $cursorinfo[3] & @CRLF & $cursorinfo[4])

    If $cursorinfo[4] = $hImage1 Then
        ToolTip("Button Start erreicht!" & @CRLF & "ID: " & $hImage1,$mousepos[0],$mousepos[1])
    Else
        ToolTip("X: " & $cursorinfo[0] & @CRLF & "Y: " & $cursorinfo[1] & @CRLF & "Gesucht: " & $hImage1,$mousepos[0],$mousepos[1])
    EndIf
    Sleep(50)

    Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
    EndSwitch
WEnd


Func WM_PAINT($hWnd, $Msg, $wParam, $lParam)
    _GDIPlus_GraphicsDrawImageRect($hGraphic,$hImage1,10,10,200,200)
EndFunc   ;==>WM_PAINT

; Clean up resources
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_ImageDispose($hImage1)
_GDIPlus_ImageDispose($hImage2)
_GDIPlus_ShutDown()

HERE ARE THE PNGs & THE AU3 FILE:

post-82646-0-15178300-1401451420_thumb.p

post-82646-0-60884800-1401451420_thumb.p

GDI_png_draw.au3

Edited by AndroidZero
Posted (edited)

Your problem is the declaration $WM_PAINT. Thus WM_PAINT will never called. Remove it and it should work.

#include <GDIPlus.au3>
#include <GuiConstantsEx.au3>
#Include <Misc.au3>
#include <WindowsConstants.au3>


Opt("MustDeclareVars", 1)

; ===============================================================================================================================
; Description ...: Shows how to display a PNG image
; Author ........: Andreas Klein
; Notes .........:
; ===============================================================================================================================

; ===============================================================================================================================
; Global variables
; ===============================================================================================================================
Global $hGUI, $hImage1, $hImage2, $hGraphic, $label_cursorinfo, $cursorinfo, $mousepos

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

$label_cursorinfo = GUICtrlCreateLabel(" ",10,10,290,290)
GUICtrlSetState($label_cursorinfo,@SW_HIDE)

;069380767265
;2178post
;michael102
GUISetState()

; Load PNG image
_GDIPlus_StartUp()
$hImage1   = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\win7.png")
$hImage2  = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\Rainbow_trout_transparent.png")

; Draw PNG image
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)

;Local $hMatrix = _GDIPlus_MatrixCreate()
; Scale the matrix by 2 (everything will get 2x larger)
;_GDIPlus_MatrixScale($hMatrix, 0.1, 0.1)
;_GDIPlus_GraphicsSetTransform($hGraphic,$hMatrix)

;_GDIPlus_GraphicsDrawImage($hGraphic, $hImage2, 0, 0)
;_GDIPlus_GraphicsDrawImage($hGraphic, $hImage1,5, 5)


; Loop until user exits
WM_PAINT()
GUIRegisterMsg($WM_PAINT, "WM_PAINT")

While 1

;~     GUICtrlSetState($label_cursorinfo,@SW_HIDE)
;~     $cursorinfo = GUIGetCursorInfo($hGUI)
;~     $mousepos = MouseGetPos()
;~     ;GUICtrlSetData($label_cursorinfo,$cursorinfo[0] & @CRLF & $cursorinfo[1] & @CRLF & $cursorinfo[2] & @CRLF & $cursorinfo[3] & @CRLF & $cursorinfo[4])

;~     If $cursorinfo[4] = $hImage1 Then
;~         ToolTip("Button Start erreicht!" & @CRLF & "ID: " & $hImage1,$mousepos[0],$mousepos[1])
;~     Else
;~         ToolTip("X: " & $cursorinfo[0] & @CRLF & "Y: " & $cursorinfo[1] & @CRLF & "Gesucht: " & $hImage1,$mousepos[0],$mousepos[1])
;~     EndIf
;~     Sleep(50)

    Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
    EndSwitch
WEnd


Func WM_PAINT()
    _WinAPI_RedrawWindow($hGUI, "", "", BitOR($RDW_INVALIDATE, $RDW_UPDATENOW, $RDW_FRAME));
    _GDIPlus_GraphicsDrawImageRect($hGraphic,$hImage2,0,0,300,300)
    _GDIPlus_GraphicsDrawImageRect($hGraphic,$hImage1,10,10,200,200)
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_PAINT

; Clean up resources
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_ImageDispose($hImage1)
_GDIPlus_ImageDispose($hImage2)
_GDIPlus_ShutDown()

Btw, are you from Frankfurt am Main?

Br,

UEZ

Edited by UEZ

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Posted

A big THANKS !!

Now i can continue with my other functions.

 

Btw, are you from Frankfurt am Main?

I'm from germany but not from Frankfurt.

For more questions pm me.

Btw, a few minutes ago I checked out your AutoIt SysInfo Clock and it works really good.

I also tryed to build something like that 1-2 month ago but it doesn't looks good without GDI+ functions.

That's why I try to learn it now.

Ahh before I forget, I read something about multi threading with autoit.

Is it possible with autoit execute and complete several functions in 1 au3 file while moving the GUI or clicking on the TrayIcon etc. ?

Posted

Ahh before I forget, I read something about multi threading with autoit.

Is it possible with autoit execute and complete several functions in 1 au3 file while moving the GUI or clicking on the TrayIcon etc. ?

 

You can use the timer function for something called "multi tasking" but with AutoIt real "multi tasking / multi threading" is not possible.

Br,

UEZ

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Posted

I wasn't sure if I should open new Topic for my next question/problem so I place here first.

PROBLEM:

I want detect with Switch Case if cursor is hovering image png.

I tryed with this:

While 1
$aCtrlHover = GUIGetCursorInfo($hGUI)

Switch $aCtrlHover[4]
   Case $label_cursorinfo
       ToolTip("Label hovered!" & @CRLF & "ID: " & $label_cursorinfo)
   Case $handle_image1
       ToolTip("Image1 hovered!" & @CRLF & "ID: " & $handle_image1)
   Case $handle_image2
       ToolTip("Image2 hovered!" & @CRLF & "ID: " & $handle_image2)
   Case 0
       ToolTip("No Control hovered" & @CRLF & $aCtrlHover[4])
EndSwitch

Sleep(50)

Switch GUIGetMsg()
   Case $GUI_EVENT_CLOSE
       ExitLoop
EndSwitch
WEnd

The Cursor can't track any ID if I hover the images.

Additional to this problem I figured out that the Handle ID of both GDI images changes at every restart of the script.

What function I need to get everytime the right ID with my cursor when I hover the images ?

Here the full Script:

#include <GDIPlus.au3>
#include <GuiConstantsEx.au3>
#Include <Misc.au3>
#include <WindowsConstants.au3>

;Opt("MustDeclareVars", 1)

; ===============================================================================================================================
; Description ...: Shows how to display a PNG image
; Author ........: Andreas Klein
; Notes .........:
; ===============================================================================================================================

; ===============================================================================================================================
; Global variables
; ===============================================================================================================================
Global $hGUI, $hImage1, $hImage2, $hGraphic, $label_cursorinfo, $cursorinfo, $mousepos

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

$label_cursorinfo = GUICtrlCreateLabel(" ",10,300,50,50)
GUICtrlSetState($label_cursorinfo,@SW_HIDE)

GUISetState()

; Load PNG image
_GDIPlus_StartUp()
$hImage1   = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\win7.png")
$hImage2  = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\Rainbow_trout_transparent.png")

; Draw PNG image
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)

; Loop until user exits
WM_PAINT()
GUIRegisterMsg($WM_PAINT, "WM_PAINT")

$handle_image1 = _GDIPlus_ImageGetGraphicsContext($hImage1)
$handle_image2 = _GDIPlus_ImageGetGraphicsContext($hImage2)

While 1
$aCtrlHover = GUIGetCursorInfo($hGUI)
Switch $aCtrlHover[4]
Case $label_cursorinfo
    ToolTip("Label hovered!" & @CRLF & "ID: " & $label_cursorinfo)
Case $handle_image1
    ToolTip("Image1 hovered!" & @CRLF & "ID: " & $handle_image1)
Case $handle_image2
    ToolTip("Image2 hovered!" & @CRLF & "ID: " & $handle_image2)
Case 0
    ToolTip("No Control hovered" & @CRLF & $aCtrlHover[4])
EndSwitch

Sleep(50)
    Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
    EndSwitch
WEnd



Func WM_PAINT()
    _WinAPI_RedrawWindow($hGUI, "", "", BitOR($RDW_INVALIDATE, $RDW_UPDATENOW, $RDW_FRAME));
    _GDIPlus_GraphicsDrawImageRect($hGraphic,$hImage2,0,0,300,300)
    _GDIPlus_GraphicsDrawImageRect($hGraphic,$hImage1,10,10,200,200)
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_PAINT

; Clean up resources
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_ImageDispose($hImage1)
_GDIPlus_ImageDispose($hImage2)
_GDIPlus_ShutDown()
Posted (edited)

GUIGetCursorInfo can get only information about GUI controls but GDI+ graphic handles are not GUI controls and thus GUIGetCursorInfo will not work.

You can create dummy label controls where you have placed your images but have in mind the z order of the controls! GUIGetCursorInfo will catch those labels.

#include <GDIPlus.au3>
#include <GuiConstantsEx.au3>
#Include <Misc.au3>
#include <WindowsConstants.au3>

;Opt("MustDeclareVars", 1)

; ===============================================================================================================================
; Description ...: Shows how to display a PNG image
; Author ........: Andreas Klein
; Notes .........:
; ===============================================================================================================================

; ===============================================================================================================================
; Global variables
; ===============================================================================================================================
Global $hGUI, $hImage1, $hImage2, $hGraphic, $label_cursorinfo, $cursorinfo, $mousepos

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

$label_cursorinfo = GUICtrlCreateLabel(" ",10,300,50,50)
$label_bgimage = GUICtrlCreateLabel("", 0, 0, 300, 300)
$label_fgimage = GUICtrlCreateLabel("", 10, 10, 200, 200)
GUICtrlSetState($label_cursorinfo,@SW_HIDE)

GUISetState()

; Load PNG image
_GDIPlus_StartUp()
$hImage1   = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\win7.png")
$hImage2  = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\Rainbow_trout_transparent.png")

; Draw PNG image
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)

; Loop until user exits
WM_PAINT()
GUIRegisterMsg($WM_PAINT, "WM_PAINT")

$handle_image1 = _GDIPlus_ImageGetGraphicsContext($hImage1)
$handle_image2 = _GDIPlus_ImageGetGraphicsContext($hImage2)

While 1
    $aCtrlHover = GUIGetCursorInfo($hGUI)
    Switch $aCtrlHover[4]
    Case $label_cursorinfo
        ToolTip("Label hovered!" & @CRLF & "ID: " & $label_cursorinfo)
    Case $label_bgimage
        ToolTip("Image1 hovered!" & @CRLF & "ID: " & $handle_image1)
    Case $label_fgimage
        ToolTip("Image2 hovered!" & @CRLF & "ID: " & $handle_image2)
    Case 0
        ToolTip("No Control hovered" & @CRLF & $aCtrlHover[4])
    EndSwitch

    Sleep(50)
    Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
    EndSwitch
WEnd

Func WM_PAINT()
    _WinAPI_RedrawWindow($hGUI, "", "", BitOR($RDW_INVALIDATE, $RDW_UPDATENOW, $RDW_FRAME));
    _GDIPlus_GraphicsDrawImageRect($hGraphic,$hImage2,0,0,300,300)
    _GDIPlus_GraphicsDrawImageRect($hGraphic,$hImage1,10,10,200,200)
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_PAINT

; Clean up resources
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_ImageDispose($hImage1)
_GDIPlus_ImageDispose($hImage2)
_GDIPlus_ShutDown() 

Br,

UEZ

Edited by UEZ

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...