Re: MoveWindow with Windows API
Michael C <[email protected]> Fri, 21 Apr 2017 16:21:09 -0700
| Newsgroups | gmane.comp.python.ctypes |
|---|---|
| Message-ID | <CANyKM1g0voNOzOixceFzao7AAP4vq_npJP1KQ+tfzsRBfwdejw@mail.gmail.com> |
--===============5530282253351500544== Content-Type: multipart/alternative; boundary=001a11c025ec41d2f4054db583ac --001a11c025ec41d2f4054db583ac Content-Type: text/plain; charset=UTF-8 Oh and the error code from print(Kernel32.GetLastError()) was "5" On Fri, Apr 21, 2017 at 4:19 PM, Michael C <[email protected]> wrote: > 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 > --001a11c025ec41d2f4054db583ac Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr">Oh and the error code from=C2=A0<span style=3D"font-size:1= 2.8px">print(Kernel32.GetLastError()) =C2=A0was "5"</span></div><= div class=3D"gmail_extra"><br><div class=3D"gmail_quote">On Fri, Apr 21, 20= 17 at 4:19 PM, Michael C <span dir=3D"ltr"><<a href=3D"mailto:mysecretro= [email protected]" target=3D"_blank">[email protected]</a>&= gt;</span> wrote:<br><blockquote class=3D"gmail_quote" style=3D"margin:0 0 = 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><div>H= i all,</div><div><br></div><div>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 m= ove it to the specified location and size. Since it works on notepad, but n= ot my game window, i used Kernel32.GetLastError() to find out what went wro= ng.=C2=A0</div><div><br></div><div>Now, I am still a 1st year CS student, s= o my school hasn't taught me what exceptions are yet, any pointers on w= hat to read up?</div><div><br></div><div>Thanks!</div><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><div>User32 =3D ctypes.Win= DLL('User32', use_last_error=3DTrue)</div><div>Kernel32 =3D ctypes.= WinDLL('Kernel32', use_last_error=3DTrue)</div><div><br></div><div>= handle =3D User32.GetForegroundWindow()</div><div><br></div><div>print(User= 32.MoveWindow(<wbr>handle, 50, 50, 500, 500, False))</div><div>print(Kernel= 32.GetLastError())</div><div><br></div><div>#<a href=3D"https://msdn.micros= oft.com/en-us/library/windows/desktop/ms633534(v=3Dvs.85).aspx" target=3D"_= blank">https://msdn.microsoft.com/<wbr>en-us/library/windows/desktop/<wbr>m= s633534(v=3Dvs.85).aspx</a></div></div> </blockquote></div><br></div> --001a11c025ec41d2f4054db583ac-- --===============5530282253351500544== 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 --===============5530282253351500544== 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 --===============5530282253351500544==--