legend Posted June 30, 2019 Share Posted June 30, 2019 (edited) I have a transparent label on a picture, I have a function that changes the picture when you hover the mouse over the picture, but that does not work when it's hovering over the label, anyway to sort of deactivate the label? i tried disabling it, but that won't do it, or put it behind the background, and still show it? I added the script and the 2 pictures expandcollapse popup#include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <WinApi.au3> Global $RBOX_EVENT_CLOSE = 1 Global $ROUNDES = 20, $LastHwnd = 0 Global $GUIBKCOLOR = 0x222222 Global $ARRAY_COLOR_TOP_MIN[3] = [300 ,200 ,300] , $ARRAY_COLOR_TOP_MAX[3] = [300 ,250 ,300] Local $hGui = RBoxCreate("",800,600) $Pic1 = GUICtrlCreatePic("bmp1.bmp", 25, 50, 290, 292) $Pic2 = GUICtrlCreatePic("bmp1.bmp", 350, 50, 290, 292) $Label = GUICtrlCreateLabel("Optimize", 127, 185, 100, 24) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) GUICtrlSetFont(-1, 17, 400, 0, "Trench") GUICtrlSetColor(-1, 0x00FF00) While 1 CheckX($hGui,$RBOX_EVENT_CLOSE,"GuiCtrlSetColor("&$RBOX_EVENT_CLOSE&",0xA3A3A3)","GuiCtrlSetColor("&$RBOX_EVENT_CLOSE&",0x555555)") $gMsg = GUIGetMsg() Switch $gMsg Case $RBOX_EVENT_CLOSE, $GUI_EVENT_CLOSE Exit Case $GUI_EVENT_MOUSEMOVE Local $aCursor = GUIGetCursorInfo() _ImageHover($Pic1, "bmp2.bmp", "bmp1.bmp", $aCursor) _ImageHover($Pic2, "bmp2.bmp", "bmp1.bmp", $aCursor) case $Pic1 GUICtrlSetImage($Pic1, "bmp1.bmp") sleep(100) GUICtrlSetImage($Pic1, "bmp2.bmp") case $Pic2 GUICtrlSetImage($Pic2, "bmp1.bmp") sleep(100) GUICtrlSetImage($Pic2, "bmp2.bmp") EndSwitch WEnd Func _ImageHover($iCtrl, $iIMG_1, $i_IMG2, ByRef $aCursor) If ($aCursor[4] = $iCtrl) Then GUICtrlSetImage($iCtrl, $iIMG_1) ElseIf ($aCursor[4] <> $iCtrl) Then GUICtrlSetImage($iCtrl, $i_IMG2) EndIf EndFunc ;==>_ImageHover Func RBoxCreate($Title,$width, $height ,$left=-1 ,$top=-1 ,$show=1) Local $GUI = GUICreate($Title,$width,$height,$left,$top,$WS_POPUP) GUISetBkColor($GUIBKCOLOR,$GUI) _GuiRoundCorners($GUI,0,0,$ROUNDES,$ROUNDES) $RBOX_EVENT_CLOSE = GUICtrlCreateLabel('x',$width-20,3,25,25) GUICtrlSetCursor($RBOX_EVENT_CLOSE,0) GUICtrlSetBkColor($RBOX_EVENT_CLOSE,-2) GUICtrlSetFont($RBOX_EVENT_CLOSE,15,800) GUICtrlSetColor($RBOX_EVENT_CLOSE,0x555555) $Title &= " " Local $hTitle = GUICtrlCreateLabel($Title,0,0,$width-20,26,$SS_CENTER,$GUI_WS_EX_PARENTDRAG) GUICtrlSetFont($hTitle,17,400,0,"Consolas") GUICtrlSetBkColor($hTitle,-2) Local $Graphic = GUICtrlCreateGraphic (0,0, $width, 25) GUICtrlSetState($Graphic,$Gui_DISABLE) GradientFill($Graphic, 0, 0, $width, 25, $ARRAY_COLOR_TOP_MIN, $ARRAY_COLOR_TOP_MAX) If $show = 1 Then GUISetState(@SW_SHOW,$GUI) Return $GUI EndFunc Func CheckX($hGui, $CtrlID, $sCMD, $eCMD) Local $cGui = GUIGetCursorInfo($hGui) If Not IsArray($cGui) Then Return 0 if $LastHwnd <> $cGui[4] And $cGui[4] = $CtrlID Then Return Execute($sCMD) + Assign("LastHwnd",$cGui[4]) if $LastHwnd <> $cGui[4] Then Return Execute($eCMD) + Assign("LastHwnd",$cGui[4]) EndFunc Func _GuiRoundCorners($h_win, $i_x1, $i_y1, $i_x3, $i_y3) Dim $pos, $ret, $ret2 $pos = WinGetPos($h_win) $ret = DllCall("gdi32.dll", "long", "CreateRoundRectRgn", "long", $i_x1, "long", $i_y1, "long", $pos[2], "long", $pos[3], "long", $i_x3, "long", $i_y3) If $ret[0] Then $ret2 = DllCall("user32.dll", "long", "SetWindowRgn", "hwnd", $h_win, "long", $ret[0], "int", 1) If $ret2[0] Then Return 1 Else Return 0 EndIf Else Return 0 EndIf EndFunc Func GradientFill($im, $x1, $y1, $width, $height, $left_color, $right_color) Local $color0=($left_color[0]-$right_color[0])/$height Local $color1=($left_color[1]-$right_color[1])/$height $color2=($left_color[2]-$right_color[2])/$height For $Y=0 to $height-1 $red=$left_color[0]-floor($Y*$color0) $green=$left_color[1]-floor($Y*$color1) $blue=$left_color[2]-floor($Y*$color2) $col = Dec(Hex($blue,2) & Hex($green,2) & Hex($red,2)) GUICtrlSetGraphic($im,$GUI_GR_COLOR, $col) GUICtrlSetGraphic($im,$GUI_GR_MOVE,0,$Y) GUICtrlSetGraphic($im,$GUI_GR_LINE,$width,$Y) Next GUICtrlSetGraphic($im,$GUI_GR_COLOR, 0x000000) GUICtrlSetGraphic($im,$GUI_GR_MOVE,0,$height) GUICtrlSetGraphic($im,$GUI_GR_LINE,$width,$height) GUICtrlSetGraphic($im,$GUI_GR_REFRESH) EndFunc bmp1.bmp bmp2.bmp Edited June 30, 2019 by legend Link to comment Share on other sites More sharing options...
Subz Posted July 1, 2019 Share Posted July 1, 2019 You could try the following: Add to top of your script: Global $aCursor, $iCursor = 0 Change $GUI_EVENT_MOUSEMOVE Case $GUI_EVENT_MOUSEMOVE $aCursor = GUIGetCursorInfo() _ImageHover("bmp2.bmp", "bmp1.bmp", $aCursor[4]) _ImageHover("bmp2.bmp", "bmp1.bmp", $aCursor[4]) Change _ImageHover Func _ImageHover($iIMG_1, $i_IMG2, $_iCursor = 0) If $_iCursor = $iCursor Then Return ;~ Stops flickering Switch $_iCursor Case $Pic1, $Label GUICtrlSetImage($Pic1, $iIMG_1) GUICtrlSetImage($Pic2, $i_IMG2) Case $Pic2 GUICtrlSetImage($Pic2, $iIMG_1) GUICtrlSetImage($Pic1, $i_IMG2) Case Else GUICtrlSetImage($Pic1, $i_IMG2) GUICtrlSetImage($Pic2, $i_IMG2) EndSwitch $iCursor = $_iCursor EndFunc ;==>_ImageHover Link to comment Share on other sites More sharing options...
legend Posted July 1, 2019 Author Share Posted July 1, 2019 1 hour ago, Subz said: You could try the following: Add to top of your script: Global $aCursor, $iCursor = 0 Change $GUI_EVENT_MOUSEMOVE Case $GUI_EVENT_MOUSEMOVE $aCursor = GUIGetCursorInfo() _ImageHover("bmp2.bmp", "bmp1.bmp", $aCursor[4]) _ImageHover("bmp2.bmp", "bmp1.bmp", $aCursor[4]) Change _ImageHover Func _ImageHover($iIMG_1, $i_IMG2, $_iCursor = 0) If $_iCursor = $iCursor Then Return ;~ Stops flickering Switch $_iCursor Case $Pic1, $Label GUICtrlSetImage($Pic1, $iIMG_1) GUICtrlSetImage($Pic2, $i_IMG2) Case $Pic2 GUICtrlSetImage($Pic2, $iIMG_1) GUICtrlSetImage($Pic1, $i_IMG2) Case Else GUICtrlSetImage($Pic1, $i_IMG2) GUICtrlSetImage($Pic2, $i_IMG2) EndSwitch $iCursor = $_iCursor EndFunc ;==>_ImageHover that won't do it, no more hover effect if you use case Link to comment Share on other sites More sharing options...
Subz Posted July 1, 2019 Share Posted July 1, 2019 Works fine for me, full code: expandcollapse popup#include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <WinApi.au3> Global $aCursor, $iCursor = 0 Global $RBOX_EVENT_CLOSE = 1 Global $ROUNDES = 20, $LastHwnd = 0 Global $GUIBKCOLOR = 0x222222 Global $ARRAY_COLOR_TOP_MIN[3] = [300 ,200 ,300] , $ARRAY_COLOR_TOP_MAX[3] = [300 ,250 ,300] Local $hGui = RBoxCreate("",800,600) $Pic1 = GUICtrlCreatePic("bmp1.bmp", 25, 50, 290, 292) $Pic2 = GUICtrlCreatePic("bmp1.bmp", 350, 50, 290, 292) $Label = GUICtrlCreateLabel("Optimize", 127, 185, 100, 24) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) GUICtrlSetFont(-1, 17, 400, 0, "Trench") GUICtrlSetColor(-1, 0x00FF00) While 1 CheckX($hGui,$RBOX_EVENT_CLOSE,"GuiCtrlSetColor("&$RBOX_EVENT_CLOSE&",0xA3A3A3)","GuiCtrlSetColor("&$RBOX_EVENT_CLOSE&",0x555555)") $gMsg = GUIGetMsg() Switch $gMsg Case $RBOX_EVENT_CLOSE, $GUI_EVENT_CLOSE Exit Case $GUI_EVENT_MOUSEMOVE $aCursor = GUIGetCursorInfo() _ImageHover("bmp2.bmp", "bmp1.bmp", $aCursor[4]) _ImageHover("bmp2.bmp", "bmp1.bmp", $aCursor[4]) EndSwitch WEnd Func _ImageHover($iIMG_1, $i_IMG2, $_iCursor = 0) If $_iCursor = $iCursor Then Return ;~ Stops flickering Switch $_iCursor Case $Pic1, $Label GUICtrlSetImage($Pic1, $iIMG_1) GUICtrlSetImage($Pic2, $i_IMG2) Case $Pic2 GUICtrlSetImage($Pic2, $iIMG_1) GUICtrlSetImage($Pic1, $i_IMG2) Case Else GUICtrlSetImage($Pic1, $i_IMG2) GUICtrlSetImage($Pic2, $i_IMG2) EndSwitch $iCursor = $_iCursor EndFunc ;==>_ImageHover Func RBoxCreate($Title,$width, $height ,$left=-1 ,$top=-1 ,$show=1) Local $GUI = GUICreate($Title,$width,$height,$left,$top,$WS_POPUP) GUISetBkColor($GUIBKCOLOR,$GUI) _GuiRoundCorners($GUI,0,0,$ROUNDES,$ROUNDES) $RBOX_EVENT_CLOSE = GUICtrlCreateLabel('x',$width-20,3,25,25) GUICtrlSetCursor($RBOX_EVENT_CLOSE,0) GUICtrlSetBkColor($RBOX_EVENT_CLOSE,-2) GUICtrlSetFont($RBOX_EVENT_CLOSE,15,800) GUICtrlSetColor($RBOX_EVENT_CLOSE,0x555555) $Title &= " " Local $hTitle = GUICtrlCreateLabel($Title,0,0,$width-20,26,$SS_CENTER,$GUI_WS_EX_PARENTDRAG) GUICtrlSetFont($hTitle,17,400,0,"Consolas") GUICtrlSetBkColor($hTitle,-2) Local $Graphic = GUICtrlCreateGraphic (0,0, $width, 25) GUICtrlSetState($Graphic,$Gui_DISABLE) GradientFill($Graphic, 0, 0, $width, 25, $ARRAY_COLOR_TOP_MIN, $ARRAY_COLOR_TOP_MAX) If $show = 1 Then GUISetState(@SW_SHOW,$GUI) Return $GUI EndFunc Func CheckX($hGui, $CtrlID, $sCMD, $eCMD) Local $cGui = GUIGetCursorInfo($hGui) If Not IsArray($cGui) Then Return 0 if $LastHwnd <> $cGui[4] And $cGui[4] = $CtrlID Then Return Execute($sCMD) + Assign("LastHwnd",$cGui[4]) if $LastHwnd <> $cGui[4] Then Return Execute($eCMD) + Assign("LastHwnd",$cGui[4]) EndFunc Func _GuiRoundCorners($h_win, $i_x1, $i_y1, $i_x3, $i_y3) Dim $pos, $ret, $ret2 $pos = WinGetPos($h_win) $ret = DllCall("gdi32.dll", "long", "CreateRoundRectRgn", "long", $i_x1, "long", $i_y1, "long", $pos[2], "long", $pos[3], "long", $i_x3, "long", $i_y3) If $ret[0] Then $ret2 = DllCall("user32.dll", "long", "SetWindowRgn", "hwnd", $h_win, "long", $ret[0], "int", 1) If $ret2[0] Then Return 1 Else Return 0 EndIf Else Return 0 EndIf EndFunc Func GradientFill($im, $x1, $y1, $width, $height, $left_color, $right_color) Local $color0=($left_color[0]-$right_color[0])/$height Local $color1=($left_color[1]-$right_color[1])/$height $color2=($left_color[2]-$right_color[2])/$height For $Y=0 to $height-1 $red=$left_color[0]-floor($Y*$color0) $green=$left_color[1]-floor($Y*$color1) $blue=$left_color[2]-floor($Y*$color2) $col = Dec(Hex($blue,2) & Hex($green,2) & Hex($red,2)) GUICtrlSetGraphic($im,$GUI_GR_COLOR, $col) GUICtrlSetGraphic($im,$GUI_GR_MOVE,0,$Y) GUICtrlSetGraphic($im,$GUI_GR_LINE,$width,$Y) Next GUICtrlSetGraphic($im,$GUI_GR_COLOR, 0x000000) GUICtrlSetGraphic($im,$GUI_GR_MOVE,0,$height) GUICtrlSetGraphic($im,$GUI_GR_LINE,$width,$height) GUICtrlSetGraphic($im,$GUI_GR_REFRESH) EndFunc 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