AppTux Posted November 19, 2010 Share Posted November 19, 2010 (edited) First of all, sorry for the strange topic name. I've got a GUI window with my own buttons en close buttons. Control $bCLO = GUICtrlCreatePic("Data\wrun-close-n.bmp",320,1,25,25) Script expandcollapse popupWhile 1 $hMSG = GUIGetCursorInfo($MGUI) Switch $hMSG[4] Case $bCLO _HoverClose() EndSwitch WEnd Func _HoverClose() GUICtrlSetImage($bCLO,"Data\wrun-close-h.bmp");set the hover pic $hMSG = GUIGetCursorInfo($MGUI);get again the cursorinfo While $hMSG[4] = $bCLO;while cursor is over the control $hMSG = GUIGetCursorInfo($MGUI);continuely get cursor info Sleep(10);Be nice to your CPU!! If $hMSG[2]=1 Then;If the primary button is pressed, but not released GUICtrlSetImage($bCLO,"Data\wrun-close-p.bmp");set the press pic $hMSG = GUIGetCursorInfo($MGUI);get again the cursor info While $hMSG[2] = 1;while the primary button is pressed $hMSG = GUIGetCursorInfo($MGUI);get again cursor info Sleep(10);Be nice to you CPU!! If $hMSG[4] <> $bCLO Then;If cursor isn't again on control $El = 1;Exitloop variable is 1 ExitLoop;Exit the while Else $El = 0;exitloop is 0 EndIf WEnd;end of while If $El = 0 Then;if exitloop is 0, so if the cursor isn't again on control GUICtrlSetImage($bCLO,"Data\wrun-close-h.bmp");set the hover pic exit;close the program ElseIf $El = 1 Then;or exitloop =1 ExitLoop;exit the while and then is the normal pic again set EndIf EndIf WEnd;end of while GUICtrlSetImage($bCLO,"Data\wrun-close-n.bmp");set normal pic EndFunc ;==> HoverClose() Yes, I know, it's a pretty stupid code, but it works; and I hope I explained it good enough. The question: If I have a window that's in front of the window; if I then go over the area where the close button is, click and release, the program exits!! How can I prevent this?? AppTux EDIT: now I used GUIGetMSG() before it's checking if the primary button is pressed. Look at the edited code: expandcollapse popupWhile 1 $hMSG = GUIGetCursorInfo($MGUI) Switch $hMSG[4] Case $bCLO _HoverClose() EndSwitch WEnd Func _HoverClose() GUICtrlSetImage($bCLO,"Data\wrun-close-h.bmp");set the hover pic $hMSG = GUIGetCursorInfo($MGUI);get again the cursorinfo While $hMSG[4] = $bCLO;while cursor is over the control $hMSG = GUIGetCursorInfo($MGUI);continuely get cursor info $MSG = GUIGetMSG() Sleep(10);Be nice to your CPU!! If $MSG = $bCLO Then If $hMSG[2]=1 Then;If the primary button is pressed, but not released GUICtrlSetImage($bCLO,"Data\wrun-close-p.bmp");set the press pic $hMSG = GUIGetCursorInfo($MGUI);get again the cursor info While $hMSG[2] = 1;while the primary button is pressed $hMSG = GUIGetCursorInfo($MGUI);get again cursor info Sleep(10);Be nice to you CPU!! If $hMSG[4] <> $bCLO Then;If cursor isn't again on control $El = 1;Exitloop variable is 1 ExitLoop;Exit the while Else $El = 0;exitloop is 0 EndIf WEnd;end of while If $El = 0 Then;if exitloop is 0, so if the cursor isn't again on control GUICtrlSetImage($bCLO,"Data\wrun-close-h.bmp");set the hover pic exit;close the program ElseIf $El = 1 Then;or exitloop =1 ExitLoop;exit the while and then is the normal pic again set EndIf EndIf EndIf WEnd;end of while GUICtrlSetImage($bCLO,"Data\wrun-close-n.bmp");set normal pic EndFunc ;==> HoverClose() Edited November 19, 2010 by AppTux PowerSlide2UnlockiPhone look-a-like program you can use to lock your pc, you can't access your desktop again until the password is entered and the slider slided to the right. (really proud of it)-- After a time AutoIt and Windows, I switched to Mac. Don't expect me to answer anymore. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 19, 2010 Moderators Share Posted November 19, 2010 AppTux,I would suggest checking to see if your app is the active window. If it is not then return immediately from the _HoverClose() function:If BitAND(WinGetState($MGUI), 8) Then ;Run the function here Else Return ; Your GUI is not active EndIfTry that and see if it works. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
AppTux Posted November 19, 2010 Author Share Posted November 19, 2010 Well, I think that's not a very useful for a close button (like a button with "X" in windows). It also have to close when the window isn't active, but there's no window in top of that (like the window beside of a active window). I think I have to do something with GUIGetMSG before the "If $hMSG[2] = 1 Then". But I don't think how I have to process that in the script... PowerSlide2UnlockiPhone look-a-like program you can use to lock your pc, you can't access your desktop again until the password is entered and the slider slided to the right. (really proud of it)-- After a time AutoIt and Windows, I switched to Mac. Don't expect me to answer anymore. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 19, 2010 Moderators Share Posted November 19, 2010 AppTux,Then I suggest you use a WindowFromPoint API call to check if you are over the picture and it is visible. This script shows how it works using a label - you will see it only works if the label is visible when you pass over it: expandcollapse popup#include <GUIConstantsEx.au3> #include <WinAPI.au3> Global $tPoint = DllStructCreate($tagPoint) $hGUI = GUICreate("Test", 500, 500) $hLabel = GUICtrlCreateLabel("", 10, 10, 100, 100) GUICtrlSetBkColor(-1, 0xFF0000) $hLabel_Handle = GUICtrlGetHandle(-1) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch $aCurInfo = GUIGetCursorInfo($hGUI) Switch $aCurInfo[4] Case $hLabel If @AutoItX64 Then Local $tPoint = DllStructCreate("int X;int Y") DllStructSetData ( $tPoint, "X", MouseGetPos(0)) DllStructSetData ( $tPoint, "Y", MouseGetPos(1)) Local $tPoint64 = DllStructCreate("int64", DllStructGetPtr($tPoint)) Local $aHwnd = DllCall("user32.dll", "hwnd", "WindowFromPoint", "int64", DllStructGetData($tPoint64, 1)) Else Local $aHwnd = DllCall("user32.dll", "hwnd", "WindowFromPoint", "uint", MouseGetPos(0), "uint", MouseGetPos(1)) EndIf If $aHwnd[0] = $hLabel_Handle Then ConsoleWrite("Hit" & @CRLF) Do Sleep(10) $aCurInfo = GUIGetCursorInfo($hGUI) Until $aCurInfo[4] <> $hLabel EndIf EndSwitch WEndAs you can see, we have to adjust the API call for x64 Windows - if you only use x86 then you can use _WinAPI_WindowFromPoint without problem: DllStructSetData($tPoint, "x", MouseGetPos(0)) DllStructSetData($tPoint, "y", MouseGetPos(1)) If _WinAPI_WindowFromPoint($tPoint) = $hLabel_Handle ThenHow is that? M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
AppTux Posted November 19, 2010 Author Share Posted November 19, 2010 Thanks for the answer, but because of homework I can't try it now. I'll try it as fast as possible. PowerSlide2UnlockiPhone look-a-like program you can use to lock your pc, you can't access your desktop again until the password is entered and the slider slided to the right. (really proud of it)-- After a time AutoIt and Windows, I switched to Mac. Don't expect me to answer anymore. Link to comment Share on other sites More sharing options...
taietel Posted November 21, 2010 Share Posted November 21, 2010 Melba, THANK YOU! I've struggled with this issue for quite some time... Things you should know first...In the beginning there was only ONE! And zero... Progs: Create PDF(TXT2PDF,IMG2PDF) 3D Bar Graph DeskGadget Menu INI Photo Mosaic 3D Text 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