Windows+Python: Why is the first opened window not shown active?
Tim Golden
mail at timgolden.me.uk
Wed Dec 18 04:05:42 EST 2013
On 18/12/2013 06:35, asmwarrior wrote:
> 1. start a Python command line prompt(this is usually to hit the Start
> Menu->Python 2.7->Python(command line).
> 2.
>
> type the following text, and hit Enter key.
>
> |import ctypes|
>
> 3.
>
> type the following text, and hit Enter key.
>
> |ctypes.windll.user32.MessageBoxA(0, "Your text", "Your title", 1)|
>
> 4. You will see a message box opened, but this message box window is
> not activated.
> 5. Use the mouse to click on the icon of the message box in task bar to
> activate the message box
> 6. Close the message box
> 7.
>
> type the text again in the Python prompt shell
>
> |ctypes.windll.user32.MessageBoxA(0, "Your text", "Your title", 1)|
>
> 8. Now, the message box is showed activated (the expected behavior)
This isn't related to Python specifically: ctypes is just handing the
values you pass straight on to the underlying DLL (here: user32.dll).
If you check the MSDN page for the MessageBox function:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms645505(v=vs.85).aspx
you can see there's a MB_SETFOREGROUND flag with value 0x00010000L which
seems to do what you want.
Why the Message box is activated the second time when it isn't the
first, I have no idea. But it's Windows which is deciding what to do
there, not Python.
TJG
More information about the Python-list
mailing list