<html><head><meta content="text/html; charset=UTF-8" http-equiv="Content-Type"></head><body bgcolor="#FFFFFF" text="#000000"><div class="moz-cite-prefix">On 2013-12-18 14:35, asmwarrior wrote:<br></div><blockquote cite="mid:52B14248.2010303@gmail.com" type="cite">
<meta http-equiv="content-type" content="text/html; charset=UTF-8"><tt>Hello, Python community.<br><br></tt>I have found a very strange problem about using the python 
scripts under Python Windows command line prompt, to reproduce this 
issue, you can simply do those steps:

<div class="post-text" itemprop="description"><ol><li>start a Python command line prompt(this is usually to hit the Start Menu->Python 2.7->Python(command line).  </li><li><p>type the following text, and hit Enter key.</p>

<pre style="" class="lang-py prettyprint prettyprinted"><code><span class="kwd">import</span><span class="pln"> ctypes</span></code></pre></li><li><p>type the following text, and hit Enter key.</p>

<pre style="" class="lang-py prettyprint prettyprinted"><code><span class="pln">ctypes</span><span class="pun">.</span><span class="pln">windll</span><span class="pun">.</span><span class="pln">user32</span><span class="pun">.</span><span class="typ">MessageBoxA</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="str">"Your text"</span><span class="pun">,</span><span class="pln"> </span><span class="str">"Your title"</span><span class="pun">,</span><span class="pln"> </span><span class="lit">1</span><span class="pun">)</span></code></pre></li><li>You will see a message box opened, but this message box window is not activated.  </li><li>Use the mouse to click on the icon of the message box in task bar to activate the message box  </li><li>Close the message box  </li><li><p>type the text again in the Python prompt shell</p>

<pre style="" class="lang-py prettyprint prettyprinted"><code><span class="pln">ctypes</span><span class="pun">.</span><span class="pln">windll</span><span class="pun">.</span><span class="pln">user32</span><span class="pun">.</span><span class="typ">MessageBoxA</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="str">"Your text"</span><span class="pun">,</span><span class="pln"> </span><span class="str">"Your title"</span><span class="pun">,</span><span class="pln"> </span><span class="lit">1</span><span class="pun">)</span></code></pre></li><li>Now, the message box is showed activated (the expected behavior) </li></ol>

<p>So, my question is, why the first message box(window) is not shown 
active? I originally find this issue when I run a Python pretty printer 
under GDB command line, because I want to use some python pretty printer
 to visual the data, like this <a moz-do-not-send="true" href="http://stackoverflow.com/questions/16227166/gdb-cvmat-python-object-issue-when-debugging-a-c-program">GDB cv::Mat python object issue when debugging a c++ program</a>, I need to show the OpenCV Image window immediately after I type the plot command.</p>

<p>But later I found that this is an issue related to Python itself.<br></p><p><br>Thanks.<br></p><p>Yuanhui Zhang<br></p><p>BTW: I post the same question in StackOverflow: <a moz-do-not-send="true" class="moz-txt-link-freetext" href="http://stackoverflow.com/questions/20614249/windowspython-why-is-the-first-opened-window-not-shown-active">http://stackoverflow.com/questions/20614249/windowspython-why-is-the-first-opened-window-not-shown-active</a><br></p><p><br></p>

    </div>

</blockquote><tt>FYI:<br><br>I get the an answer in stackoverflow in the above link which solve my problem. (<a class="moz-txt-link-freetext" href="http://stackoverflow.com/a/20651708/154911">http://stackoverflow.com/a/20651708/154911</a>)<br><br>It looks like the Windows OS system block a console window to create/pop-up a window, so I need some opitons like:<br></tt><br> <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms645505%28v=vs.85%29.aspx" rel="nofollow">MB_SETFOREGROUNDWINDOW</a><br><br>Thanks.<br><br>Yuanhui Zhang<br></body></html>