Jump to content

close app gracefully


Recommended Posts

Melba,

I get "Icon Not Found in System Tray" when i use this:

#Include <GuiToolBar.au3>


Global $hSysTray_Handle, $iSystray_ButtonNumber


Global $FlingFileTransfer = "" ; <<<<<<<<<<<<<<<< Enter some tooltip text for the icon you want here <<<<<<<<<<<<<<<<<<<<<<<<<<<


$iSystray_ButtonNumber = Get_Systray_Index($FlingFileTransfer)


If $iSystray_ButtonNumber = 0 Then
    MsgBox(16, "Error", "Icon not found in system tray")
    Exit
Else
    Sleep(500)
    _GUICtrlToolbar_ClickButton($hSysTray_Handle, $iSystray_ButtonNumber, "right")
EndIf


Exit


;............


Func Get_Systray_Index($sToolTipTitle)


    ; Find systray handle
    $hSysTray_Handle = ControlGetHandle('[Class:Shell_TrayWnd]', '', '[Class:ToolbarWindow32;Instance:1]')
    If @error Then
        MsgBox(16, "Error", "System tray not found")
        Exit
    EndIf


    ; Get systray item count
    Local $iSystray_ButCount = _GUICtrlToolbar_ButtonCount($hSysTray_Handle)
    If $iSystray_ButCount = 0 Then
        MsgBox(16, "Error", "No items found in system tray")
        Exit
    EndIf


    ; Look for wanted tooltip
    For $iSystray_ButtonNumber = 0 To $iSystray_ButCount - 1
        If StringInStr(_GUICtrlToolbar_GetButtonText($hSysTray_Handle, $iSystray_ButtonNumber), $sToolTipTitle) <> 0 Then ExitLoop
    Next


    If $iSystray_ButtonNumber = $iSystray_ButCount Then
        Return 0 ; Not found
    Else
        Return $iSystray_ButtonNumber ; Found
    EndIf


EndFunc

The actual tooltip is  "Fling File Transfer", so i assume i use:  FlingFileTranfer  (with no spaces).  Right?

Link to comment
Share on other sites

Jev,

Delete or comment the WinActivate($win[1]) line for now.

Does _ArrayDisplay($win) display something? what is that?

Michael,

i commented out the WinActivate and just ran with the _Array..............

The script completes with no errors, but nothing shows up at all anywhere.

jev

Link to comment
Share on other sites

  • Moderators

jevbrowser,

No, you use it just as it appears while leaving the variable name as it was:

Global $sToolTipTitle = "Fling File Transfer"
Try that and see how you get on. :)

As you are such a complete beginner, I strongly recommend reading the Help file (at least the first few sections - Using AutoIt, Tutorials and the first couple of References). You should also look at this excellent tutorial - you will find other tutorials in the Wiki (the link is at the top of the page). That will give you a good grounding in AutoIt syntax and structure and make the code look a little less like (Chinese|Cyrillic|Greek|insert non-latin alphabet of choice). :D

M23

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

Thanks M23!  I will read more Help files!  :thumbsup:   For now, i have this and i still get the "Icon not found in system tray"

#Include <GuiToolBar.au3>


Global $hSysTray_Handle, $iSystray_ButtonNumber


Global $sToolTipTitle = "Fling File Tranfer" ; <<<<<<<<<<<<<<<< Enter some tooltip text for the icon you want here <<<<<<<<<<<<<<<<<<<<<<<<<<<


$iSystray_ButtonNumber = Get_Systray_Index($sToolTipTitle)


If $iSystray_ButtonNumber = 0 Then
    MsgBox(16, "Error", "Icon not found in system tray")
    Exit
Else
    Sleep(500)
    _GUICtrlToolbar_ClickButton($hSysTray_Handle, $iSystray_ButtonNumber, "right")
EndIf


Exit


;............


Func Get_Systray_Index($sToolTipTitle)


    ; Find systray handle
    $hSysTray_Handle = ControlGetHandle('[Class:Shell_TrayWnd]', '', '[Class:ToolbarWindow32;Instance:1]')
    If @error Then
        MsgBox(16, "Error", "System tray not found")
        Exit
    EndIf


    ; Get systray item count
    Local $iSystray_ButCount = _GUICtrlToolbar_ButtonCount($hSysTray_Handle)
    If $iSystray_ButCount = 0 Then
        MsgBox(16, "Error", "No items found in system tray")
        Exit
    EndIf


    ; Look for wanted tooltip
    For $iSystray_ButtonNumber = 0 To $iSystray_ButCount - 1
        If StringInStr(_GUICtrlToolbar_GetButtonText($hSysTray_Handle, $iSystray_ButtonNumber), $sToolTipTitle) <> 0 Then ExitLoop
    Next


    If $iSystray_ButtonNumber = $iSystray_ButCount Then
        Return 0 ; Not found
    Else
        Return $iSystray_ButtonNumber ; Found
    EndIf


EndFunc
Link to comment
Share on other sites

  • Moderators

jevbrowser,

Try spelling "Transfer" correctly. ;)

M23

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

  • Moderators

jevbrowser,

 

guess what..........it worked!

Why so surprised? My examples usually do what they are supposed to do. :D

Anyway, glad I could help. But please do read the tutorial to which I linked and those early Help file sections - that really will help you get to grips with AutoIt. ;)

M23

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

Hey Melba!,

Still have a small problem.  Your code works perfectly to shut down my app gracefully, which is::

#Include <GuiToolBar.au3>




Global $hSysTray_Handle, $iSystray_ButtonNumber




Global $sToolTipTitle = "Fling File Transfer" ; <<<<<<<<<<<<<<<< Enter some tooltip text for the icon you want here <<<<<<<<<<<<<<<<<<<<<<<<<<<




$iSystray_ButtonNumber = Get_Systray_Index($sToolTipTitle)




If $iSystray_ButtonNumber = 0 Then
    MsgBox(16, "Error", "Icon not found in system tray")
    Exit
Else
    Sleep(500)
    _GUICtrlToolbar_ClickButton($hSysTray_Handle, $iSystray_ButtonNumber, "right")
EndIf




Exit




;............




Func Get_Systray_Index($sToolTipTitle)




    ; Find systray handle
    $hSysTray_Handle = ControlGetHandle('[Class:Shell_TrayWnd]', '', '[Class:ToolbarWindow32;Instance:1]')
    If @error Then
        MsgBox(16, "Error", "System tray not found")
        Exit
    EndIf




    ; Get systray item count
    Local $iSystray_ButCount = _GUICtrlToolbar_ButtonCount($hSysTray_Handle)
    If $iSystray_ButCount = 0 Then
        MsgBox(16, "Error", "No items found in system tray")
        Exit
    EndIf




    ; Look for wanted tooltip
    For $iSystray_ButtonNumber = 0 To $iSystray_ButCount - 1
        If StringInStr(_GUICtrlToolbar_GetButtonText($hSysTray_Handle, $iSystray_ButtonNumber), $sToolTipTitle) <> 0 Then ExitLoop
    Next




    If $iSystray_ButtonNumber = $iSystray_ButCount Then
        Return 0 ; Not found
    Else
        Return $iSystray_ButtonNumber ; Found
    EndIf




EndFunc

Your code above brings up the app menu from the system tray and then i add just a couple of mouse clicks to EXIT the app, and then i relaunch the app right away and it seems to launch ok to the system tray.   That code is:

MouseClick("left",1386,865,1) ;click EXIT
MouseClick("left",1256,639,1) ;click STOP
Run("C:\Program Files (x86)\NCH Software\Fling\fling.exe", "", @SW_SHOWMINIMIZED)

The problem is that all of the above (your code, followed by my mouse clicks and the relaunch) only works ONCE.  After that, I MUST reboot in order for your script to work again.  If I do not reboot my Win7 pc, then I get the error:   "Icon not found in system tray".  EVERYTIME i reboot, the whole process works perfectly.  The problem may be in how I am LAUNCHING the app after i run your script to shut it down.  So, the steps in the process are:  1.run your script plus my mouse clicks to shut down the app, 2. relaunch the app with my RUN line above. I am trying to launch the app to mimick how win7 launchs it during reboot, which is that it loads and runs at STARTUP and it runs ONLY in the system tray, not in the TASKBAR at all.

I think the way that i am launching the app may be the problem, but I am not sure how to launch the app to mimick the way win7 launchs it at reboot.

Do you think you could help me out here?

thanks,

jev

 
Link to comment
Share on other sites

ok Inverted.  So, what i have now is this:

Run("C:\Program Files (x86)\NCH Software\Fling\fling.exe", "", @SW_SHOWMINIMIZED)

What is in msconfig is exactly this:

"C:Program Files (x86)NCH SoftwareFlingfling.exe" -logon

So, what exactly should my code line be?

thanks,

jev

Link to comment
Share on other sites

ShellExecute("C:Program Files (x86)NCH SoftwareFlingfling.exe", "-logon","C:Program Files (x86)NCH SoftwareFling")

You generally should be using ShellExecute instead of Run, unless there is a specific reason.

I don't think you need  @SW_SHOWMINIMIZED at all since the program will acknowledge the -logon parameter and go in the tray by itself. If it still doesn't work , please post your exact code, all of it.

Edited by Inverted
Link to comment
Share on other sites

The Run command has been mostly superseded by ShellExecute now that ShellExecute returns a PID since the latest version. Prior to 3.3.10.x it didn't return the PID which made things harder when trying to interact with the programs you started.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Inverted,

Here is what i have total:

#Include <GuiToolBar.au3>


Global $hSysTray_Handle, $iSystray_ButtonNumber


Global $sToolTipTitle = "Fling File Transfer" ; <<<<<<<<<<<<<<<< Enter some tooltip text for the icon you want here <<<<<<<<<<<<<<<<<<<<<<<<<<<


$iSystray_ButtonNumber = Get_Systray_Index($sToolTipTitle)


If $iSystray_ButtonNumber = 0 Then
    MsgBox(16, "Error", "Icon not found in system tray")
    Exit
Else
    Sleep(500)
    _GUICtrlToolbar_ClickButton($hSysTray_Handle, $iSystray_ButtonNumber, "right")
EndIf


Exit


;............


Func Get_Systray_Index($sToolTipTitle)


    ; Find systray handle
    $hSysTray_Handle = ControlGetHandle('[Class:Shell_TrayWnd]', '', '[Class:ToolbarWindow32;Instance:1]')
    If @error Then
        MsgBox(16, "Error", "System tray not found")
        Exit
    EndIf


    ; Get systray item count
    Local $iSystray_ButCount = _GUICtrlToolbar_ButtonCount($hSysTray_Handle)
    If $iSystray_ButCount = 0 Then
        MsgBox(16, "Error", "No items found in system tray")
        Exit
    EndIf


    ; Look for wanted tooltip
    For $iSystray_ButtonNumber = 0 To $iSystray_ButCount - 1
        If StringInStr(_GUICtrlToolbar_GetButtonText($hSysTray_Handle, $iSystray_ButtonNumber), $sToolTipTitle) <> 0 Then ExitLoop
    Next


    If $iSystray_ButtonNumber = $iSystray_ButCount Then
        Return 0 ; Not found
    Else
        Return $iSystray_ButtonNumber ; Found
    EndIf


EndFunc


Func _WinWaitActivate($title,$text,$timeout=0)
WinWait($title,$text,$timeout)
If Not WinActive($title,$text) Then WinActivate($title,$text)
WinWaitActive($title,$text,$timeout)
;_WinWaitActivate("Fling File Transfer","")
MouseClick("left",1388,864,1)
;_WinWaitActivate("Confirm Exit","Background")
MouseClick("left",1270,634,1)


EndFunc

The last _WinWaitActivate Func is all messed up i am sure.  I can get the systray app menu to come up, but i can't click on the EXIT menu selection, followed by the STOP window selection in order to make the app close.

Not sure what to do next.  Thanks for your help

jev

Link to comment
Share on other sites

I installed the program on a VM to check it out. It seems when you exit/stop the program it stops the service, too. What happens if you do a

ShellExecute("C:\Program Files (x86)\NCH Software\Fling\fling.exe", "-scanall","C:\Program Files (x86)\NCH Software\Fling")

while the program is already running ? Isn't it doing a forced scan of your stuff ?

Adjust your paths properly of course.

Check the program's Help section for the command line options, you can update/upload/download etc with the cmdline.

Edited by Inverted
Link to comment
Share on other sites

I have tried to run the -scanall swich in the past with the RUN command, and it did not cause the Fling program to SCAN.  I will try it with ShellExecute and let you know.  You are right in that it would obviously be preferable not to have to stop and start the app everytime i wanted to force a SCAN.

thanks,

jev

Link to comment
Share on other sites

Yes, i have it setup to auto-monitor.  But i was turning my nic off after work hours, then auto-turning it back on at midnight to run my scripts unattended.  i think that was (and still is) causing the auto-monitor to break.  Therefore, i have to run the -scanall.

Anyway, you will be glad to know that your ShellExecute line FIXED it.  It runs good now!!!  So, i don't have to RESTART the app.  Just run the -scanall via ShellExecute.

Thanks a lot for your help!!!

jev

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