MoveWindow with Windows API

Michael C <[email protected]> Fri, 21 Apr 2017 16:19:39 -0700
Newsgroups gmane.comp.python.ctypes
Message-ID <CANyKM1joFOJhcH8=69BK0y4ZvtRNt4V0n-rrs5VwFWQbKQmQzg@mail.gmail.com>
--===============6012706676915875935==
Content-Type: multipart/alternative; boundary=001a113f6a20e59498054db57d8b

--001a113f6a20e59498054db57d8b
Content-Type: text/plain; charset=UTF-8

Hi all,

I am trying to move and resize a window of a video game, but the following
code doesn't work for some reason. How it works is that it acquire the
handle to the foreground window, and then move it to the specified location
and size. Since it works on notepad, but not my game window, i used
Kernel32.GetLastError() to find out what went wrong.

Now, I am still a 1st year CS student, so my school hasn't taught me what
exceptions are yet, any pointers on what to read up?

Thanks!



import ctypes
import time

time.sleep(2)

User32 = ctypes.WinDLL('User32', use_last_error=True)
Kernel32 = ctypes.WinDLL('Kernel32', use_last_error=True)

handle = User32.GetForegroundWindow()

print(User32.MoveWindow(handle, 50, 50, 500, 500, False))
print(Kernel32.GetLastError())

#
https://msdn.microsoft.com/en-us/library/windows/desktop/ms633534(v=vs.85).aspx

--001a113f6a20e59498054db57d8b
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>Hi all,</div><div><br></div><div>I am trying to move =
and resize a window of a video game, but the following code doesn&#39;t wor=
k for some reason. How it works is that it acquire the handle to the foregr=
ound window, and then move it to the specified location and size. Since it =
works on notepad, but not my game window, i used Kernel32.GetLastError() to=
 find out what went wrong.=C2=A0</div><div><br></div><div>Now, I am still a=
 1st year CS student, so my school hasn&#39;t taught me what exceptions are=
 yet, any pointers on what to read up?</div><div><br></div><div>Thanks!</di=
v><div><br></div><div><br></div><div><br></div><div>import ctypes</div><div=
>import time</div><div><br></div><div>time.sleep(2)</div><div><br></div><di=
v>User32 =3D ctypes.WinDLL(&#39;User32&#39;, use_last_error=3DTrue)</div><d=
iv>Kernel32 =3D ctypes.WinDLL(&#39;Kernel32&#39;, use_last_error=3DTrue)</d=
iv><div><br></div><div>handle =3D User32.GetForegroundWindow()</div><div><b=
r></div><div>print(User32.MoveWindow(handle, 50, 50, 500, 500, False))</div=
><div>print(Kernel32.GetLastError())</div><div><br></div><div>#<a href=3D"h=
ttps://msdn.microsoft.com/en-us/library/windows/desktop/ms633534(v=3Dvs.85)=
.aspx">https://msdn.microsoft.com/en-us/library/windows/desktop/ms633534(v=
=3Dvs.85).aspx</a></div></div>

--001a113f6a20e59498054db57d8b--


--===============6012706676915875935==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
--===============6012706676915875935==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
ctypes-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ctypes-users

--===============6012706676915875935==--