2

Hi I have a simple code showing a message box using ctypes but my problem is its not appending or overlapping of messagebox after i've add MB_TOPMOST?

def msgbox(self,msg):
        MB_OK = 0x0
        MB_OKCXL = 0x01
        MB_YESNOCXL = 0x03
        MB_YESNO = 0x04
        MB_HELP = 0x4000
        ICON_EXLAIM=0x30
        ICON_INFO = 0x40
        ICON_STOP = 0x10
        MB_TOPMOST=0x40000
        """
                HEX VALUE LINK
        https://www.autoitscript.com/autoit3/docs/functions/MsgBox.htm
        """
        writeLogs = WriteLogs(
                    pathLog = app_config['path_logs'] +"\\"+strftime("%Y_%m_%d")+".log",
                    timedate = time.strftime("%m/%d/%Y %I:%M:%S %p")
                    )
        writeLogs.appendLogA(msg)
        ctypes.windll.user32.MessageBoxA(None, msg+str(operatorMessage), "[Error]", MB_OK | ICON_STOP | MB_TOPMOST)

1 Answer 1

5

I tried to change the MB_TOPMOST into MB_SYSTEMMODAL and my desired output with topmost and overlapping message error boxes.

you can refer to this link: https://msdn.microsoft.com/en-us/library/windows/desktop/ms645505%28v=vs.85%29.aspx

and also this post on stackoverflow gives me an idea: Have Win32 MessageBox appear over other programs

def msgbox(self,msg):
        MB_OK = 0x0
        MB_OKCXL = 0x01
        MB_YESNOCXL = 0x03
        MB_YESNO = 0x04
        MB_HELP = 0x4000
        ICON_EXLAIM=0x30
        ICON_INFO = 0x40
        ICON_STOP = 0x10
        MB_TOPMOST=0x40000
        MB_SYSTEMMODAL=0x1000
        """
                HEX VALUE LINK
        https://www.autoitscript.com/autoit3/docs/functions/MsgBox.htm
        """
        writeLogs = WriteLogs(
                    pathLog = app_config['path_logs'] +"\\"+strftime("%Y_%m_%d")+".log",
                    timedate = time.strftime("%m/%d/%Y %I:%M:%S %p")
                    )
        writeLogs.appendLogA(msg)
        ctypes.windll.user32.MessageBoxA(None, msg+str(operatorMessage), "[Error]", MB_OK | ICON_STOP | MB_SYSTEMMODAL)
Sign up to request clarification or add additional context in comments.

4 Comments

In your class body you should set _user32 = ctypes.WinDLL('user32'). Then reference self._user32.MessageBoxA. The problem is ctypes.windll.user32.MessageBoxA is shared by all modules, so any module could set the argtypes or errcheck attributes in ways that break your code.
hi sir thanks for your comment, but could you have a sample code you talk about?
msgbox is a method of some class, since the first argument is self. I suggested to define _user32 = ctypes.WinDLL('user32') in the class body, as a class attribute that you can reference from the instance as self._user32. This will be your private copy of ctypes.WinDLL('user32') instead of using the shared ctypes.windll.user32. Note that ctypes.windll.user32 is implemented by calling ctypes.WinDLL('user32') and caching the result on the ctypes.windll loader. This cached instance is shared by all modules that use ctypes.windll, which should be avoided.
thank you for fast reply sir...I think i get what you telling about. another thing now that the piece of code is capable of of multiple pop of messagebox when calling. Is there a way to kill/close all messageboxes generated at one time??

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.