Jump to content

Recommended Posts

Posted (edited)

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

Posted

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.

Posted

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 

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

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

Posted

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

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

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

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
  • Recently Browsing   0 members

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