Monday, January 29, 2018

moving citrix windows on Windows

When using Nihon Kohden NeuroWorkbench via Citrix, I occasionally lose the ability to see the video display window.

This seems to be due to using it on different display configurations: sometimes I use it on on a dual display computer sometimes on a single display computer. The video window appears to be displaying "off screen"

I wanted to find a way to fix this. It looks like this is possible. For example, from python, I can find all the windows with "Video" in the title and move them to the (0,0) position with code like this:


from pprint import pprint

import win32gui
import win32con # constants

VERBOSE = 1
windowlist = []
global videowinlist

def callback(hwnd, extra):
    rect = win32gui.GetWindowRect(hwnd)
    x = rect[0]
    y = rect[1]
    w = rect[2] - x
    h = rect[3] - y
    if VERBOSE > 1:
        print("Window %s:" % win32gui.GetWindowText(hwnd))
        print("\tLocation: (%d, %d)" % (x, y))
        print("\t    Size: (%d, %d)" % (w, h))
    windowlist.append({'text':win32gui.GetWindowText(hwnd),
                       'hwnd':hwnd,
                       'xy': (x,y),
                       'w': w,
                       'h': h})
                                                     
win32gui.EnumWindows(callback, None)

if VERBOSE >=2:
    print("global list of windows in 'windowlist'")
    pprint(windowlist)
    
videowinlist = [win for win in windowlist if win['text'].find('Video') >= 0]
if VERBOSE > 0:
    print("video windows")
    pprint(videowinlist)

for win in videowinlist:
    r=win32gui.SendMessage(win['hwnd'], win32con.WM_ENTERSIZEMOVE)
    if VERBOSE: 
        print("result of SendMessage")
        pprint(r)
    win32gui.SetWindowPos(win['hwnd'], 0, 0,0,win['w'], win['h'],
                          win32con.SWP_NOOWNERZORDER | win32con.SWP_SHOWWINDOW)

Tested so far on Windows 10, but should work on Windows 7 and other versions