<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
span.EmailStyle17
{mso-style-type:personal-compose;
font-family:"Calibri","sans-serif";
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
font-family:"Calibri","sans-serif";}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal">I am occasionally getting back negative HWND values from EnumChildWindows. They appear to round trip properly, for example win32gui.GetClassName(-1901131990) appears to function properly. Not exactly a bug but is somewhat unexpected.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I had grabbed this code from the net somewhere to get the currently focused window which returns HWND as an unsigned long:<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in">class GUITHREADINFO(ctypes.Structure):<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in"> _fields_ = [<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in"> ("cbSize", ctypes.c_ulong),<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in"> ("flags", ctypes.c_ulong),<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in"> ("hwndActive", ctypes.c_ulong),<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in"> ("hwndFocus", ctypes.c_ulong),<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in"> ("hwndCapture", ctypes.c_ulong),<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in"> ("hwndMenuOwner", ctypes.c_ulong),<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in"> ("hwndMoveSize", ctypes.c_ulong),<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in"> ("hwndCaret", ctypes.c_ulong),<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in"> ("rcCaret", RECT)<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in"> ]<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in"><o:p> </o:p></p>
<p class="MsoNormal" style="margin-left:.5in">def getFocusedWindow():<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in"> guiThreadInfo = GUITHREADINFO(cbSize=ctypes.sizeof(GUITHREADINFO))<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in"> user32.GetGUIThreadInfo(0, ctypes.byref(guiThreadInfo))<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in"> return guiThreadInfo.hwndFocus<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">My code would fail occasionally and I’d wonder why but never got into debugging it until one day it was failing constantly. After much head scratching the simple fix for me was to change the focus-finding-code to use ctypes.c_long so the
result is not unsigned from both HWND sources.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Not sure it is worth trying to fix in Pythonwin but figured I should post about it.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">This is on pywin32 build 217 on Python 2.7.2, Windows 7 32bit.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Kelly Kranabetter<o:p></o:p></p>
<p class="MsoNormal">Programmer/Support Analyst<o:p></o:p></p>
<p class="MsoNormal">Tolko Industries<o:p></o:p></p>
<p class="MsoNormal">(250)398-3980<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</body>
</html>