Sign in to follow this  
Followers 0
AppTux

Strange buttons

6 posts in this topic

#1 ·  Posted (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

While 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:

While 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 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.

Share this post


Link to post
Share on other sites



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
EndIf

Try that and see if it works. :graduated:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

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... :graduated:


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.

Share this post


Link to post
Share on other sites

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: :graduated:

#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

WEnd

As 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: :D

DllStructSetData($tPoint, "x", MouseGetPos(0))
DllStructSetData($tPoint, "y", MouseGetPos(1))
If _WinAPI_WindowFromPoint($tPoint) = $hLabel_Handle Then

How 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._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

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.

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