wisem2540

Disable or hide a control in another application

11 posts in this topic

#1 ·  Posted (edited)

Hi all,

Is it possible to disable a button or control in an app I did not create?  For example, just a random EXIT button in a windows app like office, or adobe?  I just want to prevent a user from clicking it

Edited by wisem2540

Share this post


Link to post
Share on other sites



#2 ·  Posted

In theory, yes...but it also depends on the application and the control.

To illustrate, here's a crude example that disables the = button on the windows calculator:
 

If Not ProcessExists("calc.exe") Then Run(@SystemDir & "\calc.exe")
ProcessWait("calc.exe")

$hWnd = WinGetHandle("Calculator")
If Not IsHWnd($hWnd) Then Exit

ControlDisable($hWnd, "", "Button28")

 

Share this post


Link to post
Share on other sites

#3 ·  Posted

Hi.

My "="-Button is "Button30". And code above is only working on english speaking systems because of "calculator". But it works.

But if I try ControlHide($hWnd, "", "Button30") instead of ControlDisable() it's not working (but returns 1 - meaning success). So your right - in theory.

Regards, Conrad

Share this post


Link to post
Share on other sites

#4 ·  Posted

And I am curious

On 8/3/2017 at 11:57 AM, wisem2540 said:

Hi all,

Is it possible to disable a button or control in an app I did not create?  For example, just a random EXIT button in a windows app like office, or adobe?  I just want to prevent a user from clicking it

I am actually curious about this too.

 

On 8/3/2017 at 8:31 PM, spudw2k said:

In theory, yes...but it also depends on the application and the control.

To illustrate, here's a crude example that disables the = button on the windows calculator:
 

If Not ProcessExists("calc.exe") Then Run(@SystemDir & "\calc.exe")
ProcessWait("calc.exe")

$hWnd = WinGetHandle("Calculator")
If Not IsHWnd($hWnd) Then Exit

ControlDisable($hWnd, "", "Button28")

 

@spudw2k, do you think you could go into a bit more detail as what kinds of control items autoit is able to manipulate (change the state of) like you did with the calculator example and which controls autoit is unable to modify.

Share this post


Link to post
Share on other sites

#5 ·  Posted

Natively, AutoIt can interact with most "Standard Microsoft Controls".  

This note in on the Controls help file page.
"Note: AutoIt only works with standard Microsoft controls. Some applications write their own custom controls which may look like a standard MS control but may resist automation.  Experiment!"

There are libraries to interact and UDFs to interact with non-standard controls (.Net for example), but I have little to no experience automating/interacting-with those.

Share this post


Link to post
Share on other sites

#6 ·  Posted

On 5/8/2017 at 0:09 AM, Simpel said:

But if I try ControlHide($hWnd, "", "Button30") instead of ControlDisable() it's not working (but returns 1 - meaning success). So your right - in theory.

It works for me:

ba3AuLn.png

And here is my code:

If Not ProcessExists("calc.exe") Then Run(@SystemDir & "\calc.exe")
ProcessWait("calc.exe")

$hWnd = WinGetHandle("Calculator")
If Not IsHWnd($hWnd) Then Exit

ControlHide($hWnd, "", "Button28")

 


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Spoiler

My contributions to the AutoIt Community

Some messages & Apologizes:

If I hurt you, Please accept my apologies, I never (regardless of the situation) mean to hurt anybody!!!

Also, I am very busy with my project so I will appear in the last row of the online list, if you want to contact me: Email@TheDcoder.xyz

Or you can have a nice chat with me in freenode, I use the same nick on freenode too!

3fHNZJ.gif

PLEASE JOIN ##AutoIt AND HELP THE IRC AUTOIT COMMUNITY!

Share this post


Link to post
Share on other sites

#7 ·  Posted

Funny. It's not working for me.

I definitely have to use "Button30" to disable "=" (Win 7). But anyway ControlHide() isn't working. Maybe you need admin privilege? I'm a standard user.

Regards, Conrad

Share this post


Link to post
Share on other sites

#8 ·  Posted

Maybe it depends on the version of Windows, what version are you using? and what edition?

18 minutes ago, Simpel said:

Maybe you need admin privilege? I'm a standard user.

I ran the script as a standard user too.


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Spoiler

My contributions to the AutoIt Community

Some messages & Apologizes:

If I hurt you, Please accept my apologies, I never (regardless of the situation) mean to hurt anybody!!!

Also, I am very busy with my project so I will appear in the last row of the online list, if you want to contact me: Email@TheDcoder.xyz

Or you can have a nice chat with me in freenode, I use the same nick on freenode too!

3fHNZJ.gif

PLEASE JOIN ##AutoIt AND HELP THE IRC AUTOIT COMMUNITY!

Share this post


Link to post
Share on other sites

#10 ·  Posted

I am using Windows 8... something must have been changed in the way the APIs work between Win 7 and Win 8


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Spoiler

My contributions to the AutoIt Community

Some messages & Apologizes:

If I hurt you, Please accept my apologies, I never (regardless of the situation) mean to hurt anybody!!!

Also, I am very busy with my project so I will appear in the last row of the online list, if you want to contact me: Email@TheDcoder.xyz

Or you can have a nice chat with me in freenode, I use the same nick on freenode too!

3fHNZJ.gif

PLEASE JOIN ##AutoIt AND HELP THE IRC AUTOIT COMMUNITY!

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

It's working for me also on Win10.

Win7, 8 and 10 have the same OS core so it should work for you as well.

 

Edited by Neutro

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