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.
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.
Determine window status (fullscreen, maximized, minimized)
Determine window status (fullscreen, maximized, minimized)
Greetings,
I wonder if there's a way to determine in phyton script whether the current window is maximized, minimized or in fullscreen.
Thanks,
johny
I wonder if there's a way to determine in phyton script whether the current window is maximized, minimized or in fullscreen.
Thanks,
johny
- Pako
- Plugin Developer
- Posts: 2294
- Joined: Sat Nov 11, 2006 1:31 pm
- Location: Czech Republic
- Contact:
Re: Determine window status (fullscreen, maximized, minimized)
You can try this script (You must know the handle (hwnd) of window):spm_jhn wrote:I wonder if there's a way to determine in phyton script whether the current window is maximized, minimized or in fullscreen.
Code: Select all
from win32gui import GetWindowPlacement
#SW_SHOWNORMAL = 1
#SW_SHOWMINIMIZED = 2
#SW_SHOWMAXIMIZED = 3
def GetWindowStatus(hwnd):
showList = (None, "Normal", "Minimized", "Maximized")
placement = GetWindowPlacement(hwnd)
if placement[2] == (-1, -1):
return "Fullscreen"
else:
return showList[placement[1]]Pako
Re: Determine window status (fullscreen, maximized, minimized)
Well, in case of fullscreen, I still get the status Maximized. No matter, I accually just wanted the maximized status, and it works perfectly. Thanks a lot.
Btw, great software. I'm seriously considering of finishing my igorUsb project.
Btw, great software. I'm seriously considering of finishing my igorUsb project.
Re: Determine window status (fullscreen, maximized, minimized)
Is there anyone that can give me a hand in trying to get this script working?
I'm trying to use eg.WindowMatcher to get the window handle (hwnd) to pass to this script to get the window state of Media Center. It seems to get the handle ok (I think) but it doesn't properly get the window state.
I'm trying to display a volume OSD when Media Center is minimzed because Media Center has it's own volume OSD and I don't want my OSD displayed when Media Center is windowed or maximized, (hope that sounds clear).
Can one of the code gurus work this out?
Andy
I'm trying to use eg.WindowMatcher to get the window handle (hwnd) to pass to this script to get the window state of Media Center. It seems to get the handle ok (I think) but it doesn't properly get the window state.
Code: Select all
from win32gui import GetWindowPlacement
#SW_SHOWNORMAL = 1
#SW_SHOWMINIMIZED = 2
#SW_SHOWMAXIMIZED = 3
FindWin = eg.WindowMatcher(u'ehshell.exe', None, None, None, None, None, False, 0.0, 0)
hwnd = FindWin()
def GetWindowStatus(hwnd):
showList = (None, "Normal", "Minimized", "Maximized")
placement = GetWindowPlacement(hwnd)
if placement[2] == (-1, -1):
return "Fullscreen"
else:
return showList[placement[1]]Can one of the code gurus work this out?
Andy
- Pako
- Plugin Developer
- Posts: 2294
- Joined: Sat Nov 11, 2006 1:31 pm
- Location: Czech Republic
- Contact:
Re: Determine window status (fullscreen, maximized, minimized)
Code: Select all
from win32gui import GetWindowPlacement
#SW_SHOWNORMAL = 1
#SW_SHOWMINIMIZED = 2
#SW_SHOWMAXIMIZED = 3
FindWin = eg.WindowMatcher(u'ehshell.exe', None, None, None, None, None, True, 0.0, 0)
hwnd = FindWin()
def GetWindowStatus(hwnd):
showList = (None, "Normal", "Minimized", "Maximized")
placement = GetWindowPlacement(hwnd)
if placement[2] == (-1, -1):
return "Fullscreen"
else:
return showList[placement[1]]
print GetWindowStatus(hwnd[0])Re: Determine window status (fullscreen, maximized, minimized)
Okay I finally got this working to some extent with the help of Pako's code, I've also simplified it a bit:
The only problem I am having with the script is if Media Center isn't running at all, then I would get the following error:
...which isn't a big deal because I can just do a find window but was hoping to keep it in the script.
Thanks,
Andy
Code: Select all
from win32gui import GetWindowPlacement
#SW_SHOWNORMAL = 1
#SW_SHOWMINIMIZED = 2
#SW_SHOWMAXIMIZED = 3
FindWin = eg.WindowMatcher(u'ehshell.exe', None, None, None, None, None, False, 0.0, 0)
hwnd = FindWin()
def GetWindowStatus(hwnd):
showList = (None, "Normal", "Minimized", "Maximized")
placement = GetWindowPlacement(hwnd)
return showList[placement[1]]
print 'mceWindow.' + GetWindowStatus(hwnd[0])Code: Select all
Traceback (most recent call last):
Python script "131", line 11, in <module>
print 'mceWindow.' + GetWindowStatus(hwnd[0])
IndexError: list index out of rangeThanks,
Andy
- Pako
- Plugin Developer
- Posts: 2294
- Joined: Sat Nov 11, 2006 1:31 pm
- Location: Czech Republic
- Contact:
Re: Determine window status (fullscreen, maximized, minimized)
Code: Select all
if len(hwnd) > 0:
print 'mceWindow.' + GetWindowStatus(hwnd[0])
else:
print 'mceWindow.is_not_running'Re: Determine window status (fullscreen, maximized, minimized)
Thanks Pako, worked perfectly!!!
Andy
Andy
Re: Determine window status (fullscreen, maximized, minimized)
Here's a window minimize/restore toggle example I posted in another thread. It does basically the same thing detecting window state with the GetWindowLong and comparing it's result to the bitmask (0x20000000 = WS_MINIMIZE, you could check for other bits too).
-jinxdone
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)Re: Determine window status (fullscreen, maximized, minimized)
Yeah jinxdone script works great but I also do a jump to call a windows restore before I change maximize or minimize of the window. This way if I am in full screen before calling it my normal window view does not get messed up. If you have mpc remember window size like I do I don't like it auto resizing than minimizing window when it's full screen will easily mess up the normal window view. I tried just adding it to the code but it would not work maybe a wait statement needed to be put in the code itself to give time to do the restore before doing the minimize of screen so I just did a jump event to call the window restore, but I am curious on if a wait is what I needed to make the script work or something else?
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)
print "Minimized!"
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)
print "Not Minimized."
ShowWindow(result[0], SW_RESTORE)
ShowWindow(result[0], SW_MINIMIZE)