I'm new in python and I needed a messagebox. I used ctypes but it opens the message box under all other programs. how can I make it to be above all programs??
import ctypes
def run(x=0):
STOP = False
x += 5
MessageBox = ctypes.windll.user32.MessageBoxA
reply = MessageBox(None, 'text', 'title', 1)
if reply == 1 and not STOP:
threading.Timer(3, run).start()
else:
STOP = True;
You are passing NULL for the hWnd parameter of MessageBox. From the documentation:
A handle to the owner window of the message box to be created. If this parameter is NULL, the message box has no owner window.
So, the message box has no owner window. Which means that it may well appear behind other windows. Ideally you should pass the window handle of an appropriate owner window in your application. Owned windows always appear above their owners. That's far and away the most normal way to control which windows appear on top of other windows.
However, I suspect that you may find it hard to come up with such a window handle. In which case you may find that including the MB_TOPMOST flag in the uType parameter, parameter number 4, meets your needs.
It's hard to be quite sure what you exact needs are though, because what you ask for is demonstrably impossible to achieve. You asked that the window
be above all programs
Well, that's clearly impossible, as can be proved by demonstrating a contradiction. Suppose that your window showed itself above all other windows. If your window could do that, so could another window. And clearly you cannot have two different windows that show above all other windows.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With