mage123 Posted October 2, 2010 Share Posted October 2, 2010 I have a gui that uses gdi+ with a transparent png in it. I also made a blank pic control behind the png so that I could use GUIGetCursorInfo to see if you are hovering over it, and if so draw a different image on top (hover over image). It works fine, except that the png isn't square, so it displays the hover over image even when you're not hovering over it. Also, I use GUICtrlSetCursor to make a hand cursor show whenever you hover over it, and it has the same problem- displaying the hand even when you aren't hovering over the image. Anybody know how to fix this? Link to comment Share on other sites More sharing options...
martin Posted October 3, 2010 Share Posted October 3, 2010 I have a gui that uses gdi+ with a transparent png in it. I also made a blank pic control behind the png so that I could use GUIGetCursorInfo to see if you are hovering over it, and if so draw a different image on top (hover over image). It works fine, except that the png isn't square, so it displays the hover over image even when you're not hovering over it. Also, I use GUICtrlSetCursor to make a hand cursor show whenever you hover over it, and it has the same problem- displaying the hand even when you aren't hovering over the image. Anybody know how to fix this?Malkey has some functions in example scripts that allow you to decide if a point, the cursor in your case, is inside a shape. So instaed of deciding if you are over the image you could decide if you were inside a certain area of the image. You'll have to search for the functions because I don't have a link. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted October 5, 2010 Share Posted October 5, 2010 You'll have to search for the functions because I don't have a link.Link. .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
mage123 Posted October 5, 2010 Author Share Posted October 5, 2010 I would rather not make a shape to see if the cursor is in it... Do you know if there's a function to read the pixel of an image or graphics object? Link to comment Share on other sites More sharing options...
Yashied Posted October 5, 2010 Share Posted October 5, 2010 (edited) Try to determine a transparent areas in PNG.#Include <GDIP.au3> If BitAND(_GDIPlus_BitmapGetPixel($hImage, $iX, $iY), 0xFF000000) Then ; Set over image EndIfGDIP UDF Edited October 5, 2010 by Yashied My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More... Link to comment Share on other sites More sharing options...
Yashied Posted October 5, 2010 Share Posted October 5, 2010 (edited) expandcollapse popup#Include <GDIPlus.au3> #Include <WinAPIEx.au3> #Include <WindowsConstants.au3> _GDIPlus_Startup() $hBackground = _GDIPlus_ImageLoadFromFile(@ScriptDir & '\bg_440x440.png') $hReg = _GDIPlus_ImageLoadFromFile(@ScriptDir & '\Red.png') $hYellow = _GDIPlus_ImageLoadFromFile(@ScriptDir & '\Yellow.png') $State = Default $hForm = GUICreate('', 440, 440, -1, -1, $WS_POPUPWINDOW, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST)) _Update(0) GUISetState() While 1 $Info = GUIGetCursorInfo($hForm) If @error Then _Update(0) Else If ($Info[0] >=120) And ($Info[0] <=320) And ($Info[1] >=120) And ($Info[1] <=320) And (BitAND(_GDIPlus_BitmapGetPixel($hReg, $Info[0] - 120, $Info[1] - 120), 0xFF000000) = 0xFF000000) Then _Update(1) If $Info[2] Then ExitLoop EndIf Else _Update(0) EndIf EndIf $Msg = GUIGetMsg() Switch $Msg Case -3 ExitLoop EndSwitch WEnd _GDIPlus_Shutdown() Func _Update($iState) If $iState = $State Then Return EndIf Local $hGraphic, $hImage $hImage = _GDIPlus_ImageClone($hBackground) $hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage) Switch $iState Case 0 _GDIPlus_GraphicsDrawImageRect($hGraphic, $hYellow, 120, 120, 200, 200) Case 1 _GDIPlus_GraphicsDrawImageRect($hGraphic, $hReg, 120, 120, 200, 200) EndSwitch _WinAPI_UpdateLayeredWindowEx($hForm, _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage), 255, 1) _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_ImageDispose($hImage) $State = $iState EndFunc ;==>_Update Func _GDIPlus_BitmapGetPixel($hBitmap, $iX, $iY) Local $aResult = DllCall($ghGDIPDll, 'uint', 'GdipBitmapGetPixel', 'ptr', $hBitmap, 'int', $iX, 'int', $iY, 'ptr*', 0) If @error Then Return SetError(1, 0, 0) Else If $aResult[0] Then Return SetError($aResult[0], 0, 0) EndIf EndIf Return $aResult[4] EndFunc ;==>_GDIPlus_BitmapGetPixel Func _GDIPlus_ImageClone($hImage) Local $aResult = DllCall($ghGDIPDll, 'uint', 'GdipCloneImage', 'ptr', $hImage, 'ptr*', 0) If @error Then Return SetError(1, 0, 0) Else If $aResult[0] Then Return SetError($aResult[0], 0, 0) EndIf EndIf Return $aResult[2] EndFunc ;==>_GDIPlus_ImageClone WinAPIEx.au3 Edited October 5, 2010 by Yashied My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More... Link to comment Share on other sites More sharing options...
UEZ Posted October 5, 2010 Share Posted October 5, 2010 (edited) Another possibility: instead checking for transparency you can calculate the distance from the middle of the buttom to its border. In this case (round objects with same diameter) it is the radius. That means when the mouse distance to the middle of the buttom is less then the radius then change the image. Example (images used from pevious post by Yashied): expandcollapse popup#include <GDIPlus.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <WinAPIEx.au3> Opt("MustDeclareVars", 1) Opt("GUIOnEventMode", 1) _GDIPlus_Startup() Local $hBackground = _GDIPlus_ImageLoadFromFile("bg_440x440.png") Local $Width = _GDIPlus_ImageGetWidth($hBackground) Local $Height = _GDIPlus_ImageGetHeight($hBackground) Local $center_w = $Width / 2 Local $center_h = $Height / 2 Local $hRed = _GDIPlus_ImageLoadFromFile("Red.png") Local $hRed_w = _GDIPlus_ImageGetWidth($hRed) Local $hRed_h = _GDIPlus_ImageGetHeight($hRed) Local $hYellow = _GDIPlus_ImageLoadFromFile("Yellow.png") Local $hYellow_w = _GDIPlus_ImageGetWidth($hYellow) Local $hYellow_h = _GDIPlus_ImageGetHeight($hYellow) Local $hGUI = GUICreate("GDI+ Mouse Hover by UEZ", $Width, $Height, -1, -1, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST)) GUISetState() Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI) Local $hBitmap = _GDIPlus_BitmapCreateFromGraphics($Width, $Height, $hGraphics) Local $hBackbuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap) GUIRegisterMsg($WM_NCHITTEST, "WM_NCHITTEST") GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") Local $mpos, $pd, $radius = ($hYellow_w - 22) / 2 While Sleep(30) _GDIPlus_GraphicsClear($hBackbuffer, 0x00000000) _GDIPlus_GraphicsDrawImageRect($hBackbuffer, $hBackground, 0, 0, $Width, $Height) $mpos = GUIGetCursorInfo($hGUI) $pd = Pixel_Distance($mpos[0], $mpos[1], $center_w, $center_h) If $mpos[2] And $pd < $radius Then _Exit() If $pd < $radius Then _GDIPlus_GraphicsDrawImage($hBackbuffer, $hRed, $Width / 2 - $hRed_w / 1.5, $Height / 2 - $hRed_w / 1.5) Else _GDIPlus_GraphicsDrawImage($hBackbuffer, $hYellow, $Width / 2 - $hYellow_w / 1.5, $Height / 2 - $hYellow_w / 1.5) EndIf _GDIPlus_GraphicsDrawImageRect($hGraphics, $hBitmap, 0, 0, $Width, $Height) _WinAPI_UpdateLayeredWindowEx($hGUI, _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap), 255, 0) WEnd Func Pixel_Distance($x1, $y1, $x2, $y2) ;Pythagoras theorem Local $a, $b, $c If $x2 = $x1 And $y2 = $y1 Then Return 0 $a = $y2 - $y1 $b = $x2 - $x1 $c = Sqrt($a * $a + $b * $b) Return $c EndFunc ;==>Pixel_Distance Func _Exit() _GDIPlus_BitmapDispose($hBitmap) _GDIPlus_GraphicsDispose($hBackbuffer) _GDIPlus_GraphicsDispose($hGraphics) _GDIPlus_Shutdown() GUIDelete($hGUI) Exit EndFunc Func WM_NCHITTEST($hWnd, $iMsg, $iwParam, $ilParam) If ($hWnd = $hGui) And ($iMsg = $WM_NCHITTEST) Then Return $HTCAPTION EndFunc ;==>WM_NCHITTEST Thanks to Yasied for WinAPIEx.au3 and the images! Br, UEZ Edited March 22, 2011 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!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
mage123 Posted October 6, 2010 Author Share Posted October 6, 2010 Thanks Yashied exactly what I was looking for and worked great Link to comment Share on other sites More sharing options...
bub Posted March 23, 2011 Share Posted March 23, 2011 (edited) I downloaded the images of the original code, however, the GUI is still not view. I tried to remove $ WS_EX_LAYERED, the GUI is show, but not pictures. The same thing happens with the GDI version of UEZ It may be that I downloaded an older version of WinAPIEx? Edited March 23, 2011 by bub Link to comment Share on other sites More sharing options...
UEZ Posted March 23, 2011 Share Posted March 23, 2011 I downloaded the images of the original code, however, the GUI is still not view.I tried to remove $ WS_EX_LAYERED, the GUI is show, but not pictures.The same thing happens with the GDI version of UEZIt may be that I downloaded an older version of WinAPIEx?For me it is still working with the latest WinAPIEx version - tested yesterday!Probably the images cannot be loaded properly. Try @scriptdir & "\image.jpg"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!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now