Jump to content

Hide image created by _GDIPlus_GraphicsDrawImageRect


Recommended Posts

Hello,

I am making a program where the button is an image that "changes" when specific conditions are fullfilled. Problem is that these images have different dimensions and when a smaller picture is displayed over a bigger one both will be seen, therefore i would like the images to be hidden, invincible or, alternatively, deleted.

I have tried using _GDIPlus_GraphicsClear() with no luck

However that might just be me not using it right as im quite new to autoit :(

Here is the code if you want to test run it:

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


Global $hGUI, $hImage, $hGraphic, $label_cursorinfo, $cursorinfo, $mousepos, $i1, $aDim, $iPID, $i12, $handle_image1, $handle_image2, $handle_image3, $handle_image4, $handle_image5, $label_bgimage
Global $i1 = 1
Global $i2 = 4
Global $i3 = 0

_GDIPlus_StartUp()
Global $hImage1 = _GDIPlus_ImageLoadFromFile("C:\Users\Heimd\Downloads\Start.png")
Global $hImage2 = _GDIPlus_ImageLoadFromFile("C:\Users\Heimd\Downloads\Run.png")
Global $hImage3 = _GDIPlus_ImageLoadFromFile("C:\Users\Heimd\Downloads\Start_no_select.png")
Global $hImage4 = _GDIPlus_ImageLoadFromFile("C:\Users\Heimd\Downloads\Run_no_select.png")
Global $hImage5 = _GDIPlus_ImageLoadFromFile("C:\Users\Heimd\Downloads\test" & $i2 & ".png")
Global $aDim1 = _GDIPlus_ImageGetDimension($hImage1)
Global $aDim2 = _GDIPlus_ImageGetDimension($hImage2)
Global $aDim3 = _GDIPlus_ImageGetDimension($hImage3)
Global $aDim4 = _GDIPlus_ImageGetDimension($hImage4)
Global $aDim5 = _GDIPlus_ImageGetDimension($hImage5)


HotKeySet("{F5}","Esc")
Func Esc()
   Exit
EndFunc

$hGUI = GUICreate("Mr.Helper", 700, 350,-1,-1,$WS_POPUP)

GUISetState()



WM_PAINT()
GUIRegisterMsg($WM_PAINT, "WM_PAINT")

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

While 1
   $aCtrlHover = GUIGetCursorInfo($hGUI)
   If WinActive("Mr.Helper") Then
      If $aCtrlHover[4] <> $label_bgimage Then
         If WinExists( 'Firefox' ) Then
               If $i3 = 1 Then
                     If $i12 <> $i1 Then
                        $file_loc = "C:\Users\Heimd\Desktop\auManager.au3"
                        $file_au3 = FileGetShortName($file_loc)
                        Global $iPID = Run(@AutoItExe & " " & $file_au3, "", @SW_HIDE)
                        $i1 = 5
                        Call("waiting")
                     EndIf
               Else
                     $i1 = 1
                     If $i12 <> $i1 Then
                        Call("WM_PAINT")
                     EndIf
               EndIf
         Else
               If $i3 = 1 Then
                     $i1 = 5
                     If $i12 <> $i1 Then
                        Global $iPID = Run("C:\Program Files\Mozilla Firefox\firefox.exe")
                        Call("waiting")
                     EndIf
                  Else
                     $i1 = 2
                     If $i12 <> $i1 Then
                        Call("WM_PAINT")
                     EndIf
               EndIf
         EndIf
      Else
         If WinExists( 'Firefox' ) Then
            $i1 = 3
            If $i12 <> $i1 Then
               Call("WM_PAINT")
            EndIf
         Else
            $i1 = 4
            If $i12 <> $i1 Then
               Call("WM_PAINT")
            EndIf
         EndIf
      EndIf
   EndIf
   $i12 = $i1
   $i3 = 0
   Sleep(50)
   Switch GUIGetMsg()
      case $GUI_EVENT_CLOSE
         Exit
      Case $GUI_EVENT_PRIMARYDOWN
         $i3 = 1
   EndSwitch
WEnd

Func waiting()
   Do
   Global $hImage5 = _GDIPlus_ImageLoadFromFile("C:\Users\Heimd\Downloads\test" & $i2 & ".png")
   Call("WM_PAINT")
   Sleep(500)
   If $i2 = 1 Then
      $i2 = 4
   Else
      $i2 -= 1
   EndIf
   Until ProcessExists($iPID) And WinExists( 'Firefox' )
EndFunc

Func WM_PAINT()
   $hGraphic = '$handle_image' & $i12
 if _GDIPlus_GraphicsClear($hGraphic, 0x00FF00) == True Then
    MsgBox(0,'test','test')
    EndIf
   If $i1 = 1 Then
      $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
      $aDim = _GDIPlus_ImageGetDimension($hImage1)
      _WinAPI_RedrawWindow($hGUI, "", "", BitOR($RDW_INVALIDATE, $RDW_UPDATENOW, $RDW_FRAME));
      _GDIPlus_GraphicsDrawImageRect($hGraphic,$hImage1,60,85,$aDim1[0],$aDim1[1])
      $handle_image1 = _GDIPlus_ImageGetGraphicsContext($hImage1)
      $label_bgimage = GUICtrlCreateLabel("", 60, 85, $aDim1[0],$aDim1[1])
   ElseIf $i1 = 2 Then
      $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
      $aDim = _GDIPlus_ImageGetDimension($hImage2)
      _WinAPI_RedrawWindow($hGUI, "", "", BitOR($RDW_INVALIDATE, $RDW_UPDATENOW, $RDW_FRAME));
      _GDIPlus_GraphicsDrawImageRect($hGraphic,$hImage2,60,85,$aDim2[0],$aDim2[1])
      $handle_image2 = _GDIPlus_ImageGetGraphicsContext($hImage2)
      $label_bgimage = GUICtrlCreateLabel("", 60, 85, $aDim2[0],$aDim2[1])
   ElseIf $i1 = 3 Then
      $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
      $aDim = _GDIPlus_ImageGetDimension($hImage3)
      _WinAPI_RedrawWindow($hGUI, "", "", BitOR($RDW_INVALIDATE, $RDW_UPDATENOW, $RDW_FRAME));
      _GDIPlus_GraphicsDrawImageRect($hGraphic,$hImage3,60,85,$aDim3[0],$aDim3[1])
      $handle_image3 = _GDIPlus_ImageGetGraphicsContext($hImage3)
      $label_bgimage = GUICtrlCreateLabel("", 60, 85, $aDim3[0],$aDim3[1])
   ElseIf $i1 = 4 Then
      $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
      $aDim = _GDIPlus_ImageGetDimension($hImage4)
      _WinAPI_RedrawWindow($hGUI, "", "", BitOR($RDW_INVALIDATE, $RDW_UPDATENOW, $RDW_FRAME));
      _GDIPlus_GraphicsDrawImageRect($hGraphic,$hImage4,60,85,$aDim4[0],$aDim4[1])
      $handle_image4 = _GDIPlus_ImageGetGraphicsContext($hImage4)
      $label_bgimage = GUICtrlCreateLabel("", 60, 85, $aDim4[0],$aDim4[1])
   ElseIf $i1 = 5 Then
      $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
      $aDim = _GDIPlus_ImageGetDimension($hImage5)
      _WinAPI_RedrawWindow($hGUI, "", "", BitOR($RDW_INVALIDATE, $RDW_UPDATENOW, $RDW_FRAME));
      _GDIPlus_GraphicsDrawImageRect($hGraphic,$hImage5,60,85,$aDim5[0],$aDim5[1])
      $handle_image5 = _GDIPlus_ImageGetGraphicsContext($hImage5)
      $label_bgimage = GUICtrlCreateLabel("", 60, 85, $aDim5[0],$aDim5[1])
   EndIf
      GUISetState(@SW_SHOW, $hImage5)
      Return $GUI_RUNDEFMSG
EndFunc

_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_ImageDispose($hImage)
_GDIPlus_ShutDown()

 

Thanks to everyone helping! :)

Edited by Pricehacker
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

×
×
  • Create New...