Jump to content

How to disable/enable GUI application - (Moved)


Recommended Posts

Hello Experts,

I'm new to the forum and I'm a real Autoit enthusiast. Searching a lot for this question (disable an application GUI), I found several arguments, but since I'm at the beginning with Autoit programming, I can't figure out why the following lines don't work. The project I'm realizing is more complex, but my necessity is to obtain that a specific application GUI (MSWord) doesn't receive the user input commands (for example ENTER pressure), but only for a particular moment during the flow of script. I report a semplified example.

My question is: in the five seconds afte the instruction " GUISetState(@SW_DISABLE, $hWnd)" if I interact with the instance of Notepad yet opened, the GUI receive all my inputs (as ENTER pressure, letters pressure, etc.). Probably I'm using the function GUISetState() as a real newbie. How to obtain the "freezing" of Notepad GUI?

Any suggestion will be greatly appreciated.

#include <AutoItConstants.au3>
;#include <GUIConstants.au3>

    ; Run Notepad
    Run("notepad.exe")

    ; Wait 10 seconds for the Notepad window to appear.
    Local $hWnd = WinWait("[CLASS:Notepad]", "", 10)

    ; Disable Notepad GUI.
    GUISetState(@SW_DISABLE, $hWnd)
    
    ; Wait for 5 seconds. - (If I press keys in this five seconds, the GUI doesn't appear as disable!)
    Sleep(5000)

    ; Enable Notepad GUI.
    GUISetState(@SW_ENABLE, $hWnd)

    ; Send the 'F5' key to the edit control of Notepad to display the date and time. The handle returned by WinWait is used for the "title" parameter of ControlSend.
    ControlSend($hWnd, "", "Edit1", "{F5}")

   ; Wait for 2 seconds.
    Sleep(2000)

    ; Close the Notepad window using the handle returned by WinWait.
    WinClose($hWnd)

    ; Now a screen will pop up and ask to save the changes, the classname of the window is called
    ; "#32770" and simulating the "TAB" key to move to the second button in which the "ENTER" is simulated to not "save the file"
    WinWaitActive("[CLASS:#32770]")
    Sleep(500)
    Send("{TAB}{ENTER}")

 

Link to comment
Share on other sites

  • Moderators

Moved to the appropriate forum, as the Developer General Discussion forum very clearly states:

Quote

General development and scripting discussions. If it's super geeky and you don't know where to put it - it's probably here.


Do not create AutoIt-related topics here, use the AutoIt General Help and Support or AutoIt Technical Discussion forums.

Moderation Team

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 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

 

Link to comment
Share on other sites

Hello, 

From what i understand you're just trying to block user's inputs at a specified moment. 

 

You can check in the help file. This macro :

Blockinput (1)

Be carefull you need admin rights for this. 

Help file : 

#RequireAdmin

#include <AutoItConstants.au3>

Example()

Func Example()
    ; Run Notepad
    Run("notepad.exe")

    ; Wait 10 seconds for the Notepad window to appear.
    Local $hWnd = WinWait("[CLASS:Notepad]", "", 10)

    ; Disable user input from the mouse and keyboard.
    BlockInput($BI_DISABLE)

    ; Wait for 2 seconds.
    Sleep(2000)

    ; Send the 'F5' key to the edit control of Notepad to display the date and time. The handle returned by WinWait is used for the "title" parameter of ControlSend.
    ControlSend($hWnd, "", "Edit1", "{F5}")

    ; Enable user input from the mouse and keyboard.
    BlockInput($BI_ENABLE)

    ; Wait for 2 seconds.
    Sleep(2000)

    ; Close the Notepad window using the handle returned by WinWait.
    WinClose($hWnd)

    ; Now a screen will pop up and ask to save the changes, the classname of the window is called
    ; "#32770" and simulating the "TAB" key to move to the second button in which the "ENTER" is simulated to not "save the file"
    WinWaitActive("[CLASS:#32770]")
    Sleep(500)
    Send("{TAB}{ENTER}")
EndFunc   ;==>Example

To answer to the primary question: 

Your first script is not working becose you're not using the correct flag

Try this one :

#include <AutoItConstants.au3>


    ; Run Notepad
    Run("notepad.exe")

    ; Wait 10 seconds for the Notepad window to appear.
    Local $hWnd = WinWait("[CLASS:Notepad]", "", 10)

    ; Get GUI actual stat.
    $State = WinGetState($hWnd)
    ; Msg Actual stat
    MsgBox (0,'','OK:'&$State)
    
    Sleep (1500)

    ; Hide GUI
    WinSetState($hWnd, "", @SW_HIDE)

    ; Get GUI actual stat.
    $State = WinGetState($hWnd)
    ; Msg Actual stat
    MsgBox (0,'','OK:'&$State)

    Sleep (1500)

    ; Show Gui
    WinSetState($hWnd, "", @SW_SHOW)
    
    
    ;If $Stat = 13 Then
    ;
    ;EndIF

To be familiar with all these flag and macro i recommand you to make some simple GUI and play with them.

#include <AutoItConstants.au3>
#include <GuiConstants.au3>


$MyGui = GUICreate("test",300,300)
$Button1 = GUICtrlCreateButton ( "Hit me!" , 100 ,100 )
$Button2 = GUICtrlCreateButton ( "Hit me!" , 100 ,130 )
GUICtrlSetState ($Button1 , $GUI_DISABLE )
GUISetState ( @SW_SHOW , $MyGui )

While (1)
Sleep (10) ; Avoid CPU usage

$GuiMsg = GUIGetMsg () ; Checking what is hapenning to $MyGui

    Switch $GuiMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1 ;Button1
                GUICtrlSetState ($MyGui , @SW_DISABLE ) ; = Nothing
        Case $Button2
                _MyFirstFunction () ; Enable Button1
    EndSwitch
    
WEnd

Func _MyFirstFunction ()
    GUICtrlSetState ($Button1 , @SW_ENABLE )
EndFunc

Regards,

Edited by caramen

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Link to comment
Share on other sites

Hello Caramen!

First of all, thank you very much for your very appreciated support.
Yes, you fully understood my need. Reading the help, I tried the solution that you propose (even if you have a much superior style of writing the code). My problem is due to the fact that every time I call the Blockinput () function, a message rightly due to the #RequiredAdmin directive appears.
My need to disable for an extremely short amount of time MSWord recurs many times during a working session of the Autoit script.
In case it is useful I'll try to explain briefly what kind of work the script does.

Perfect for your tip on the use of flags: in this aspect I'm particulary weak. Now I have to study and try your examples and follow the excellent advices. I'll update on the results.

Thank you so much for your time and your expertise!
Link to comment
Share on other sites

You're welcome. 

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Link to comment
Share on other sites

Hello Caramen and to all,

I studied and tried your three useful examples and I think I undestood how they work: very interesting.
The "@SW_HIDE" flag work very well and hiding the GUI, the same doesn't receive commands.

Now, since the appetite grow with eating, I would have a new question that rise in my mind. I would have the necessity that the MSWord GUI remain displayed on the screen, also in the short period of time when it became disable. This is possible in your opinion? Another solution come in my mind looking at your third script: I could disable and "freeze" all controls of MSWord and the text field where normally start a document (in my case a document is already present)

Thank you for any suggestion

Regards

S_A

 

Link to comment
Share on other sites

So if you dont got admin rights you cannot use BlockInput() that's all.

But this is the only way for me to do what you want.

 

An other simple way to disable a windows without block anyinput is a brain thing. You can move the windows out of the screen but it wont be displayed. 

Somthing like :

WinMove ( $hWND , "" , -1000 , -1000 ) 

An other way ( Advanced skill ) would be to use : 

#include <WinAPI.au3>

With some others macro. But unfortunatly we 're not learning this on the forum since it can make malicius things.

Edited by caramen

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Link to comment
Share on other sites

Hello Caramen,

thank you one more time for your hints.

I started the week working quite hard so I reply you only this evening. But I kept in mind your suggestions and applied myself.

Experimenting with Autoit Help file and following your suggestions, I solved.

I believe that the function "GUISetState(@SW_DISABLE, $hwnd)" work only if the GUI is created with function $hwnd = GUICreate("title").

Instead seems me that this function doesn't work with the GUI of an already open MSWord instance. So I thought to try to open an embedded Notepad instance inside an Autoit GUI and try to disable it.

And it work. It's possible to disable the interface... (of course mine are not statements, cause I always talk about my experiments, that are experiments of a real Autoit newbie!).

This method already imply the "#include <WinAPI.au3>". And is not the better method since, when I try to embed the MS Word instance inside AutoIt GUI, all disappears.

So I decided to try another way: keeping  in mind your suggestion on "#include <WinAPI.au3>", and searching inside Autoit Help file, I found a one-instruction solution that work perfectly and directly on the MSWord GUI, without involving embedding or other complications.

So thank you very much for your support!

See you soon,

Regards

S_A 

 

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