ctypes.windll.user32.SetWindowPos no longer works in Rhino 8

All,

I’m working through some older python scripts written for earlier versions of Rhino that do not work in Rhino 8. Can someone tell me why the block of python code pasted below will work in Rhino 7 but not in Rhino 8?

Sorry for not posting the code example as preformatted text. My window would freeze when attempting to do this for some reason.

Also attached .py file.

Thanks,

Eric

import rhinoscriptsyntax as rs
import ctypes

def SetRhinoWindowPosition(x, y, w, h):
“”"
Sets the position and size of the Rhino main window.
“”"
hwnd = rs.WindowHandle()

# SWP_SHOWWINDOW = 0x0040

ctypes.windll.user32.SetWindowPos(hwnd, 0, x, y, w, h, 0x0040)

# Example: Move the window to (100, 100) with a size of 800x600

SetRhinoWindowPosition(100, 100, 800, 600)

SetWindowPos.py (408 Bytes)

Doesn’t like the Window Handle. I believe this is where it’s throwing the error.

Eric

All,

I’ve discovered that the number that is pulled by hwnd = rs.WindowHandle() is of the type: <class ‘System.IntPtr’>

If you convert this number to an integer the code works to reposition Rhino. Still more testing to do to make sure this works. I’ll mark as a solution when I’m sure.

hwnd = int(str(rs.WindowHandle()))

Can someone tell me the best way to convert an IntPtr to an integer? I tried using the python function int() but it would fail. I changed it to int(str(hwnd)) and that worked. Must be a simple way?

Eric