mbob61 Posted June 1, 2015 Posted June 1, 2015 Morning everyone!Does anyone know a way to get the name of an icon that gets clicked on the windows taskbar?I need to perform a certain action when I open a certain program / click on a certain icon.I've had a look but can't find anything beyond the height/width/position etc of the taskbar. It seems like something which can be possible.Cheers,Mike
l3ill Posted June 1, 2015 Posted June 1, 2015 (edited) Have a look at WinGetTitle and use the active parameter to get the name of the window that you just activated.Another possibility is to use the script to start the program and get the Handle from the git-go... edit: getting the "Icons" name seems irrelevant to me, if this is what you are going for you may need to elaborate. Edited June 1, 2015 by l3ill additional info My Contributions... Reveal hidden contents SnippetBrowser NewSciTE PathFinder Text File Manipulation FTP Connection Tester / INI File - Read, Write, Save & Load Example
mbob61 Posted June 1, 2015 Author Posted June 1, 2015 Hi, cheers for the reply,I'll expand a little, my request was a little vague without all the facts. I have an application that is stealing focus when it completes certain events.I only want the application to be opened when I click the icon, when I see the activation message from the app in question, I wish to open whatever I had open before.I've got the last part working, I just need some way to detect when I have manually opened the application, rather than it stealing focus back.Is this even possible?Mike
l3ill Posted June 1, 2015 Posted June 1, 2015 (edited) If I understand correctly you may be able to keep the application minimized with WinSetState.Might help if you post your code and elaborate where it is failing you. Edited June 1, 2015 by l3ill added clarification My Contributions... Reveal hidden contents SnippetBrowser NewSciTE PathFinder Text File Manipulation FTP Connection Tester / INI File - Read, Write, Save & Load Example
mbob61 Posted June 1, 2015 Author Posted June 1, 2015 ;If MY_APP wants focus but is not open, do not give it. Func CheckForActivatedWindow($hWnd, $Msg, $wParam, $lParam) ;Get the current active window, and put it in "old" if $new <> "" and $new <> $old Then $old = $new ;Grab the title of the newly activated window Switch $wParam Case $HSHELL_WINDOWACTIVATED MsgPrint("Window activated: " & $lParam & " (" & WinGetTitle($lParam) & ")") $new = WinGetTitle($lParam) EndSwitch ;Only activate FLY if the cursor is in the correct position if $new = 'MY_APP' and $old <> 'MY_APP' and $old <> $new and $correctPositionFlag = 'N' then WinActivate($old) EndFuncThe core part is there. At the moment, its only allowed to be opened when $correctPositionFlag = 'Y'.That is currently just worked out by querying whether or not the mouse is within the height of the task bar on the screen. if $mousePositionHeight < $iFullDesktopHeight and $mousePositionHeight > ($iFullDesktopHeight - $taskbarHeight) then $correctPositionFlag = "Y" Else $correctPositionFlag = "N" EndIfThat last statement should, hopefully, be some sort of "... and I haven't clicked the icon named MY_APP"I'm not sure if the mouse ever has an context of what it is clicking. The ideal scenario would be to get back the icon name from the task bar when it is clicked.Cheers for the interest Mike
l3ill Posted June 1, 2015 Posted June 1, 2015 Well that does get hard to follow... :-)Just stabbing in the dark here but to get a more exact position in the taskbar you could use the PixelSearch function if the icon has a color that the others don't.I am sorry but I don't entirely understand the end game. I have to assume there are other ways to get there without getting the name of the icon. Thinking out loud (typing)You want to be able to open a program and if you open the same program again (from the taskbar) you want it "not to open" or "not steal focus"?? My Contributions... Reveal hidden contents SnippetBrowser NewSciTE PathFinder Text File Manipulation FTP Connection Tester / INI File - Read, Write, Save & Load Example
mbob61 Posted June 2, 2015 Author Posted June 2, 2015 (edited) Its a bit of a mess isn't it We have a Java app, which, while completing certain tasks, steals the focus back from the user. Therefore, if you ask it to do something, then alt-tab back into Notepad for example, when its job has finished, it will pop back to the top, taking keyboard focus. This gets very irritating for people who don't touch type, as they spend as long time looking at their keyboard, only to realise they have typed half their sentence in the wrong window.What we want is to effective "suppress" this focus stealing while the application is minimized or not the active application. However, it obviously still needs to be opened when the user needs it The code above minimizes it when it is not active, and doesn't let it open if it tries to when it is not the active app e.g. If you are typing in notepad, it cannot take focus over the top of it. However, the problem comes when you try to open it manually. Because it is not the active application when you click the icon, the logic forces it closed again. I either need a change of logic, or a couple of override conditions (clicking the icon and ALT-Tabbing into it).Hopefully this clears it up Mike Edited June 2, 2015 by mbob61
l3ill Posted June 2, 2015 Posted June 2, 2015 How about a HotKeySet or even a little GUI that Activates/Deactivates or Hide/Unhide the Java App when needed/Not needed.Using one of the Window Functions, seems a little more robust to me. Build a little app that starts the App and a HKS and give the user F7 and F8 (for instance) as keys to Hide or Unhide as neededThat is if they work with your app...For instance:WinSetOnTopWinSetStateWinActivateHotKeySetAre we getting closer? My Contributions... Reveal hidden contents SnippetBrowser NewSciTE PathFinder Text File Manipulation FTP Connection Tester / INI File - Read, Write, Save & Load Example
mbob61 Posted June 2, 2015 Author Posted June 2, 2015 Getting users to work with new things is tricky, but I will see what I can do on that one I have got it working, using isPressed and a mouseLocation part to allow the users back in via either clicking the icon or ALT-Tabbing back in.Its a little dirty, but it should be ok for a first try I think. Cheers for your help so far. If I find something more elegant, I will come back, if you are interested Mike
l3ill Posted June 2, 2015 Posted June 2, 2015 n.p.. And yes, post your final solution. Future searchers with similar issues will be interested to see how you finally solved it.good luck !Bill My Contributions... Reveal hidden contents SnippetBrowser NewSciTE PathFinder Text File Manipulation FTP Connection Tester / INI File - Read, Write, Save & Load Example
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now