Sign in to follow this  
Followers 0
Iuli

Problem while hovering a PNG image

19 posts in this topic

#1 ·  Posted (edited)

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]

Share this post


Link to post
Share on other sites



Please attach the all images that uses this code.

Attached them to the first post :D


[size="2"]SFXMaker[/size] - The most complete switchless installer creator software[indent][/indent]

Share this post


Link to post
Share on other sites

Can you give me the link to the _SetImage function because I couldn't find it


mfg. SimonMany of my answers are translated of google, because I'am from Germany

Share this post


Link to post
Share on other sites

Can you give me the link to the _SetImage function because I couldn't find it

Here :D


[size="2"]SFXMaker[/size] - The most complete switchless installer creator software[indent][/indent]

Share this post


Link to post
Share on other sites

Sorry, but I don't have the file setimage.au3 and hover.au3.

Can you please attach the files?


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

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Why is it that I don't have the au3 files? This line doesn't work for me:

#Include <GUICtrlSetOnHover.au3>
:D

EDIT:

WHERE DID YOU ALL GET THE FILES???

Edited by Crash

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

Share this post


Link to post
Share on other sites

Luli, where did you get the file? I am using the beta version too.. WHERE!?!?! :D


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

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

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! ❤️

Share this post


Link to post
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]

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Rather than edit my own post, just above; I'll make another one and increase my post count.

Hint. Hint.

http://www.autoitscript.com/forum/index.php?showtopic=34658


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

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

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! ❤️

Share this post


Link to post
Share on other sites

Thank you Yashied !


[size="2"]SFXMaker[/size] - The most complete switchless installer creator software[indent][/indent]

Share this post


Link to post
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
Sign in to follow this  
Followers 0