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:
- start a Python command line prompt(this is usually to hit the Start Menu->Python 2.7->Python(command line).
type the following text, and hit Enter key.
import ctypestype the following text, and hit Enter key.
ctypes.windll.user32.MessageBoxA(0, "Your text", "Your title", 1)- You will see a message box opened, but this message box window is not activated.
- Use the mouse to click on the icon of the message box in task bar to activate the message box
- Close the message box
type the text again in the Python prompt shell
ctypes.windll.user32.MessageBoxA(0, "Your text", "Your title", 1)- Now, the message box is showed activated (the expected behavior)
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 GDB cv::Mat python object issue when debugging a c++ program, I need to show the OpenCV Image window immediately after I type the plot command.
But later I found that this is an issue related to Python itself.
MB_SETFOREGROUNDthat explicitly sets the dialog to be active. If it weren't modal, you could do it directly withctypes.windll.user32.SetForegroundWindow(hwnd). I think theMB_SETFOREGROUNDdoes exactly that internally. This page might help with figuring out how to set the option.