Jump to content

Lock GUI Windows


 Share

Recommended Posts

Is there anything simple than that?

I have a Menu and when the user select "Lock", I want that the selected window to be locked. That mean the user cannot move it around until he unlock it. Im looking for something simple as GuiSetState.

Edited by Dieuz
Link to comment
Share on other sites

I think fear1313's suggestion would do close to what your after.

I just tried an example using his advice and it works ok.

#include <GUIConstants.au3>

Global $State[3]

$gui = GUICreate('Window Unlocked',220, 70 -1, -1 )
$Button = GUICtrlCreateButton('Lock Window', 64, 10, 88, 50)
GUISetState(@SW_SHOW, $gui)

While 1
    If $State[0] = 1 Then
        $winpos = WinGetPos($gui)
        If $winpos[0] <> $State[1] Or $winpos[1] <> $State[2] Then
            WinMove($gui,'', $State[1], $State[2])
        EndIf
    EndIf
    $msg = GUIGetMsg()
    Select
        Case $msg = $Button
            If $State[0] = 0 Then
                $State[0] = 1
                $pos = WinGetPos($gui)
                $State[1] = $Pos[0]
                $State[2] = $Pos[1]
                GUICtrlSetData($Button, 'Unlock Window')
                WinSetTitle($gui, '', 'Window Locked')
            Else
                $State[0] = 0
                GUICtrlSetData($Button, 'Lock Window')
                WinSetTitle($gui, '', 'Window Unlocked')
            EndIf
        Case $msg = $GUI_EVENT_CLOSE
            Exit
    EndSelect
WEnd

Cheers.

Edited by smashly
Link to comment
Share on other sites

@Volly: I dont wanna do anything suspicious. I just want the user to decide if he want to lock thee Gui window or not

@Smashly: Thx! The only problem is that you can move the window but it bring it back to it original place after you move it.

Is there a way to make the window impossible to move?

I got an idea.

In GUICreation, you can choose style $WS_POPUP or $WS_POPUPWINDOW

That makes GUI a pop up and unable to move.

Maybe when user click Lock

GUIDelete orginal one,

Create new GUI exactly like that but have $WS_POPUP or $WS_POPUPWINDOW

Along assigning all the events.

Hope that helped.

Edited by Generator
Link to comment
Share on other sites

Learned!

Can't you just change the styles rather than delete and recreate?
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

@Volly: I dont wanna do anything suspicious. I just want the user to decide if he want to lock thee Gui window or not

@Smashly: Thx! The only problem is that you can move the window but it bring it back to it original place after you move it.

Is there a way to make the window impossible to move?

If I use $WS_POPUP, it delete the title bar so that wont work

Link to comment
Share on other sites

If you are giving the user a choice, then why make it so they can't move it? If the user doesn't want to move it, they won't. If you give them a button, an they don't click it, the GUI can be moved.

So, what's the point?

I just want the user to decide if he want to lock thee Gui window or not

Dude, your answer still sounds weird. no offense.

Link to comment
Share on other sites

Perhaps you could do away with the title bar completely and draw your own "look-alike" in its place.

Then you could easily enable/disable the drag functionality.

gsb

"Did you ever stop to think? ...and forget to restart!"
Link to comment
Share on other sites

$pos = WinGetPos

If $pos[0] <> $desiredx or $pos[1] <> $desiredy Then WinMove( $desiredx, $desiredy )

You could try making AutoIt find the coordinates of the window upon locking, then resetting it to those coordinates every millisecond.

You are repeating his idea.

Use AdibeEnable to check the WinPos every 100 ms, or use my way.

Delete GUI when select lock and recreate 1 with popup style, just try to get your menu back in.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...