Jump to content
Sign in to follow this  
Alexxander

Make a button visible when Notepad is opened

Recommended Posts

Alexxander

Hi all

i want to make a script :

while notepad is running a button is visible and when Notepad is not running the button is not visible

and when i press the button try.exe is opened

#include <WindowsConstants.au3>
#include <GuiConstantsEx.au3>

$GUI = GUICreate("MY GUI", -1,-1,-1,-1, $WS_POPUP , $WS_EX_TOPMOST)
$but = GUICtrlCreateButton("", -1, -1, 100, 100)

guisetstate()



While 1
    $nMsg = GUIGetMsg()
        WinSetOnTop($GUI, "", 1)
    $menu = WinExists("[CLASS:Notepad]")
    if $menu = 1 then GUICtrlSetState($but, $GUI_SHOW)
    if $menu = 0 then GUICtrlSetState($but, $GUI_HIDE)
    If $nMsg = $but Then ShellExecute("C:\auto\try.exe")
WEnd

it is working but the button is flashing when start menu is opened and it is not exciting the try.exe when the button is pressed any ideas ?

PS: i'm using win 7

Edited by Alexxander

Share this post


Link to post
Share on other sites
FireFox

Hi,

The button is flickering because you change its state constantly, I would add a boolean to toggle the state only when needed.

it is not exciting the try.exe when the button is pressed any ideas ?

Where is the exit code?

Br, FireFox.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
Alexxander

Hi,

The button is flickering because you change its state constantly, I would add a boolean to toggle the state only when needed.

Where is the exit code?

Br, FireFox.

 

bro what does boolean  means ?

sorry i meant executing not exciting 


Share this post


Link to post
Share on other sites
FireFox

what does boolean  means ?

http://lmgtfy.com/?q=what+is+boolean

In other terms:

Local $fMyBool = True
;or
Local $fMyBool = False

sorry i meant executing not exciting

It should work.

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
Mat
Generally you don't want to set a state in a tight loop. That's just asking for flashing and other graphical glitches.
 
WinExists is not quite what you want either. When you close notepad it hides the window, and only deletes it later (there shouldn't be a huge delay, but I'm using a pretty old computer so it's noticeable).
 
Anyway, I changed the code a bit and it works now. No idea what issue it was stopping your code from working, possibly NOTEPAD wasn't matching any windows, and was matching the start menu somehow. Can't reproduce here on xp.
 
#include <WindowsConstants.au3>
#include <GuiConstantsEx.au3>

$GUI = GUICreate("MY GUI", 100, 100, 500, 500, $WS_POPUP, $WS_EX_TOPMOST)
$but = GUICtrlCreateButton("", -1, -1, 500, 500)
GUISetState()


Local $fShown = True, $h
While 1
    $nMsg = GUIGetMsg()

    $h = WinGetHandle("[CLASS:Notepad]")
    $menu = Not @error And BitAND(WinGetState($h), @SW_SHOW)

    If $menu <> $fShown Then
        GUICtrlSetState($but, $menu ? $GUI_SHOW : $GUI_HIDE)
        ConsoleWrite($menu & @LF)
        $fShown = $menu
    EndIf

    If $nMsg = $but Then ShellExecute("C:\auto\try.exe")
WEnd
  • Like 1

Share this post


Link to post
Share on other sites
Alexxander
Mat

 

thank you bro but i'm getting error at this line

GUICtrlSetState($but, $menu ? $GUI_SHOW : $GUI_HIDE)

maybe the "?" mark ?


Share this post


Link to post
Share on other sites
FireFox

The ternary operator is implemented in the beta version.

If $menu Then
    GUICtrlSetState($but, $GUI_SHOW)
Else
    GUICtrlSetState($but, $GUI_HIDE)
EndIf
Br, FireFox.

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
Mat

My bad. I'm getting so used to using the new features that I forget they aren't present in the latest stable.

The stable version still has a function called _Iif in Misc.au3 that is nearly an equivalent to the ternary operator (no difference in this case).

Share this post


Link to post
Share on other sites
TheSaint

Personally I would use - If ProcessExists("Notepad.exe") Then

But there could be reasons you may not want that method.


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

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

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  

×