Notice: This forum has been recovered from an old backup, so some content, links, and dates may be outdated. The forum is currently read-only while we restore sign-in and registration functionality. Details

If you find this forum valuable and would like to help keep it online, donations to help cover hosting and domain costs are greatly appreciated, but never expected. You can support the forum through Buy Me a Coffee or Ko-fi. Thank you for helping preserve the EventGhost community.

Toggle window states?

If you have a question or need help, this is the place to be.
Post Reply
molitar
Experienced User
Posts: 209
Joined: Fri Sep 11, 2009 6:44 am

Toggle window states?

Post by molitar »

Ok here is what I have a macro that does...

Image

What I would like is a cleaner method that would check state of the window than take the appropriate action because this method is really dirty and if the windows has been modified by mouse than the call is going to be incorrect. Can anyone help me out with this?
User avatar
jinxdone
Plugin Developer
Posts: 443
Joined: Tue Jan 02, 2007 4:08 pm

Re: Toggle window states?

Post by jinxdone »

Here's a quick way to do it with a python script. Target the window you want to toggle Minimize/Restore with the 'Find Window' action, and then put the script directly after that. I targeted ultraedit (uedit32.exe) as an example. You can remove the print -lines from the code, they are there just to make it clarify how it works. If you want to toggle between Minimized and Maximized replace the SW_RESTORE with SW_MAXIMIZE in the code.

Code: Select all

<?xml version="1.0" encoding="UTF-8" ?>
<EventGhost Version="918">
    <Macro Name="Find Window: uedit32.exe" Expanded="True">
        <Action>
            Window.FindWindow(u'uedit32.exe', None, None, None, None, None, False, 0.0, 0)
        </Action>
        <Action>
            EventGhost.PythonScript(u'from eg.WinApi.Dynamic import GetWindowLong, ShowWindow, SW_RESTORE, SW_MAXIMIZE, SW_MINIMIZE\n    \n# Check that we have a window to try to minimize/restore\n# Use Find Window action before this script!\nif len(result) > 0:\n    # Check if WS_MINIMIZE bit is set\n    if(GetWindowLong(result[0], -16) & 0x20000000):\n        print "Minimized!"\n        ShowWindow(result[0], SW_RESTORE)\n    else:\n        print "Not Minimized."\n        ShowWindow(result[0], SW_MINIMIZE)\n')
        </Action>
    </Macro>
</EventGhost>
I think the equivalent code needs to be added to the Window plugin, but before that happens I think we need to brainstorm a bit what will be the best way to add it so it will be as easy and intuitive to use as possible.

ps. I know I should update the EG installation on this computer, but it should be work the same with the newer builds as well.

-jinxdone
molitar
Experienced User
Posts: 209
Joined: Fri Sep 11, 2009 6:44 am

Re: Toggle window states?

Post by molitar »

Ok thanks for the code.. though I did not realize I had to type that directly in the xml file so had all sorts of errors but by doing a search discovered that is direct xml code. Showing actual script would of been a bit easier like..

Code: Select all

from eg.WinApi.Dynamic import GetWindowLong, ShowWindow, SW_RESTORE, SW_MAXIMIZE, SW_MINIMIZE
    
# Check that we have a window to try to minimize/restore
# Use Find Window action before this script!
if len(result) > 0:
    # Check if WS_MINIMIZE bit is set
    if(GetWindowLong(result[0], -16) & 0x20000000):
        print "Minimized!"
        ShowWindow(result[0], SW_RESTORE)
    else:
        print "Not Minimized."
        ShowWindow(result[0], SW_MINIMIZE)
Now I understand what that code is doing and why. I'm sure glad EventGhost shows the actual python script code.
Last edited by molitar on Mon Sep 14, 2009 5:29 pm, edited 2 times in total.
User avatar
jinxdone
Plugin Developer
Posts: 443
Joined: Tue Jan 02, 2007 4:08 pm

Re: Toggle window states?

Post by jinxdone »

You do not need to edit the xml file by hand, simply copy & paste everything from the code box it into EG. EventGhost will recognize the snipplet and paste it seamlessly into your config tree.

The same works the other way as well, just select something in your config tree and use 'copy', it will be stored as an xml snipplet in your clipboard.

-jinxdone
molitar
Experienced User
Posts: 209
Joined: Fri Sep 11, 2009 6:44 am

Re: Toggle window states?

Post by molitar »

jinxdone wrote:You do not need to edit the xml file by hand, simply copy & paste everything from the code box it into EG. EventGhost will recognize the snipplet and paste it seamlessly into your config tree.

The same works the other way as well, just select something in your config tree and use 'copy', it will be stored as an xml snipplet in your clipboard.

-jinxdone
now that is cool I did not realize that.. just tested that created a folder and pasted on it. BTW works great thanks. Another question for you.. Made the change to Maximize with the Maximize value of 0x10000000 and it works perfectly but how could I add the print command to print the actual result[0] and the hwnd name?
User avatar
jinxdone
Plugin Developer
Posts: 443
Joined: Tue Jan 02, 2007 4:08 pm

Re: Toggle window states?

Post by jinxdone »

You could get the title of the window with eg.WinApi.GetWindowText(result[0]). I don't see how printing out the result[0] itself would be useful as it just contains a window handle (a number).
If you want instead of printing to the log you could show the name of the minimized window with the ShowOSD action. example:

Code: Select all

from eg.WinApi.Dynamic import GetWindowLong, ShowWindow, SW_RESTORE, SW_MAXIMIZE, SW_MINIMIZE
    
# Check that we have a window to try to minimize/restore
# Use Find Window action before this script!
if len(result) > 0:
    # Check if WS_MINIMIZE bit is set
    if(GetWindowLong(result[0], -16) & 0x20000000):
        eg.plugins.EventGhost.ShowOSD('Minimized ' + eg.WinApi.GetWindowText(eg.result[0]), None, (255, 255, 255), (0, 0, 0), 0, (0, 0), 0, 3.0, None)
        ShowWindow(result[0], SW_RESTORE)
    else:
        eg.plugins.EventGhost.ShowOSD('Maximized ' + eg.WinApi.GetWindowText(eg.result[0]), None, (255, 255, 255), (0, 0, 0), 0, (0, 0), 0, 3.0, None)
        ShowWindow(result[0], SW_MINIMIZE)
Sorry I did not quite get what you wanted to do with the printing but I hope the above example is useful.

-jinxdone
molitar
Experienced User
Posts: 209
Joined: Fri Sep 11, 2009 6:44 am

Re: Toggle window states?

Post by molitar »

Thanks.. mainly for log tracing it helps to show what the program is showing.. but the modification is very useful that you showed their.
Post Reply