Jump to content

Problem while hovering a PNG image


Iuli
 Share

Recommended Posts

Hi,

I'm writing a script that will change the an image when the mouse if over. But it seems it doesn't work. I'm attaching the code below

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include "setimage.au3"
#include "hover.au3"
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 625, 467, 192, 124)
$Pic1 = GUICtrlCreatePic("options_logo.jpg", 0, 0, 196, 466)
$Pic2 = GUICtrlCreatePic("", 32, 112, 162, 59)
;Yashied UDF
_SetImage($Pic2,"performance.png")
GUICtrlSetOnHover($Pic2, "HoverPic", "LeaveHoverPic")

GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd


Func HoverPic ($CtrlID)
    Select
        Case $CtrlID=$Pic2
            ConsoleWrite("1")
            ;Yashied UDF
            _SetImage($Pic2,"performance_over.png")
    EndSelect
EndFunc

Func LeaveHoverPic ($CtrlID)
    Select
        Case $CtrlID=$Pic2
            ConsoleWrite("2")
            ;Yashied UDF
            _SetImage($Pic2,"performance.png")
    EndSelect
EndFunc

What did i do wrong ?

gfx.zip

Edited by Iuli
[size="2"]SFXMaker[/size] - The most complete switchless installer creator software[indent][/indent]
Link to comment
Share on other sites

Icons.au3 primarily designed for static images. But I made a few changes for you:

  • I changed MrCreatoR's UDF for such tasks. _WinAPI_WindowFromPoint() function not quite suited for this.
  • I wrote the _SetImageHover() function and change your code to avoid flicker when changing images. You do not need Icons.au3.
#Include <GUICtrlSetOnHover.au3>
#Include <GUIConstantsEx.au3>
#Include <GDIPlus.au3>

Opt('MustDeclareVars', 1)

Global $hForm, $Pic1, $hPic1, $Pic2, $hPic2, $nMsg

_GDIPlus_Startup()

$hForm = GUICreate('Form1', 625, 467, 192, 124)
$Pic1 = GUICtrlCreatePic(@ScriptDir & '\options_logo.jpg', 0, 0, 196, 466)
$hPic1 = GUICtrlGetHandle($Pic1)
GUICtrlSetState(-1, $GUI_DISABLE)
$Pic2 = GUICtrlCreatePic('', 32, 112, 162, 59)
$hPic2 = GUICtrlGetHandle($Pic2)
_SetImageHover($Pic2, @ScriptDir & '\performance.png')
GUICtrlSetOnHover($Pic2, 'HoverPic', 'LeaveHoverPic')
GUISetState()

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func HoverPic($CtrlID)
    Select
        Case $CtrlID = $Pic2
            _WinAPI_InvalidateRect($hPic1, _ControlGetRect($hPic2))
            _SetImageHover($Pic2, @ScriptDir & '\performance_over.png')
            _WinAPI_InvalidateRect($hPic2)
    EndSelect
EndFunc   ;==>HoverPic

Func LeaveHoverPic($CtrlID)
    Select
        Case $CtrlID = $Pic2
            _WinAPI_InvalidateRect($hPic1, _ControlGetRect($hPic2))
            _SetImageHover($Pic2, @ScriptDir & '\performance.png')
            _WinAPI_InvalidateRect($hPic2)
    EndSelect
EndFunc   ;==>LeaveHoverPic

Func _ControlGetRect($hWnd)

    Local $Pos = ControlGetPos($hWnd, '', '')
    Local $tRect = DllStructCreate('int;int;int;int')

    DllStructSetData($tRect, 1, $Pos[0])
    DllStructSetData($tRect, 2, $Pos[1])
    DllStructSetData($tRect, 3, $Pos[0] + $Pos[2])
    DllStructSetData($tRect, 4, $Pos[1] + $Pos[3])
    Return $tRect
EndFunc   ;==>_ControlGetRect

Func _SetImageHover($ControlID, $sImage)

    Local $hWnd = GUICtrlGetHandle($ControlID)
    Local $hImage, $hBitmap

;    _GDIPlus_Startup()
    $hImage = _GDIPlus_BitmapCreateFromFile($sImage)
    $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
    _GDIPlus_ImageDispose($hImage)
;    _GDIPlus_Shutdown()
    _WinAPI_DeleteObject(_SendMessage($hWnd, 0x0173))
    _SendMessage($hWnd, 0x0172, 0, $hBitmap)
    $hImage = _SendMessage($hWnd, 0x0173)
    If $hImage <> $hBitmap Then
        _WinAPI_DeleteObject($hBitmap)
    EndIf
EndFunc   ;==>_SetImageHover

GUICtrlSetOnHover.au3 (Modified)

EDIT:

Nice GUI you do it.

Edited by Yashied
Link to comment
Share on other sites

Link to comment
Share on other sites

Bad news. When I compiled your scripts into a program (the edited version by Yashied), my Avira marked it as VIRUS!!! I think if you continued without changing anything, anti-viruses will continue to mark it as viruses...

Then...

People won't trust your software...

Not joke. No offense.

Edited by Crash

JPGRARMouse Lock | My website | Thanks so much for your help! ❤️

Link to comment
Share on other sites

Bad news. When I compiled your scripts into a program (the edited version by Yashied), my Avira marked it as VIRUS!!! I think if you continued without changing anything, anti-viruses will continue to mark it as viruses...

Then...

People won't trust your software...

Not joke. No offense.

Try compiling it without compression.

We know all about false positives from AV tools.

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

Bad news. When I compiled your scripts into a program (the edited version by Yashied), my Avira marked it as VIRUS!!! I think if you continued without changing anything, anti-viruses will continue to mark it as viruses...

Then...

People won't trust your software...

Not joke. No offense.

I just gave you the source code. Do you really think that I wrote a virus? :D

I suggest you update your antivirus and not ask again the stupid questions.

Link to comment
Share on other sites

I just gave you the source code. Do you really think that I wrote a virus? :D

I suggest you update your antivirus and not ask again the stupid questions.

I do not mean something like that, OK?

Like I said, NO OFFENSE. I, too, know this is a false positive. I just want to tell him about it. It's fine if you want me to shut up.

***Mouth Zipped***

Edited by Crash

JPGRARMouse Lock | My website | Thanks so much for your 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...