Announcement

Collapse
No announcement yet.

Messagebox in separate thread

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    #41
    Mike, thank you for the example, but i think this is not the equivalent of the WinApi Messagebox.
    The concerns that were brought forward were not about forwarding a string to the screen,
    but rather about properly reading the return value by the main program when one of the buttons is clicked.

    Michael, thanks for your reply.
    It is clear to me that any operation that involves more than one instruction may be interrupted
    by thread switching. From Pauls reply i learned that the operation A=B involves also two instructions.

    Edwin, thanks. I will try that.

    Paul, thanks. Your reply is very clear: the alignment issue is not present in PB.
    But on the downside, the operation A = B does not involve one instruction, as i supposed, but two,
    and may therefore be interrupted by thread switching.

    Therefore it may be concluded that a 32 bit variable is not guaranteed put in place in one single
    operation, as i supposed. This implies that synchronisation techniques are required at all times.

    Arie Verheul

    Comment


      #42
      Mike, thank you for the example, but i think this is not the equivalent of the WinApi Messagebox.
      Just change the line with ? to whatever you want.

      Comment


        #43
        Win32 Message box in the background

        Code:
        DECLARE FUNCTION MessageBox LIB "USER32.DLL" ALIAS "MessageBoxA" _
                       (BYVAL hWnd           AS DWORD,     _
                            lpText           AS ASCIIZ,    _
                            lpCaption        AS ASCIIZ, _
                            BYVAL dwType     AS DWORD) AS LONG
        TYPE MyUDT
          hWnd       AS DWORD
          lpText     AS ASCIIZ * 128
          lpCaption  AS ASCIIZ * 128
          dwType     AS DWORD
        END TYPE
        FUNCTION PBMAIN&
          mb 0,"How now brown cow","Title", %MB_ICONERROR
          ? "Click to exit"
        END FUNCTION
        SUB MB(hWnd AS DWORD, lpText AS ASCIIZ,lpCaption AS ASCIIZ,dwType AS DWORD)
          LOCAL x AS MyUDT, hThread AS DWORD
          x.hWnd       = hWnd
          x.lpText     = lpText
          x.lpCaption  = lpCaption
          x.dwType     = dwType
          THREAD CREATE MessageBoxThread(VARPTR(x)) TO hThread???
          SLEEP 50
          THREAD CLOSE hThread??? TO hThread???
        END SUB
        THREAD FUNCTION MessageBoxThread(BYVAL y AS DWORD) AS DWORD
          LOCAL x  AS MyUDT POINTER
          LOCAL hWnd       AS DWORD
          LOCAL lpText     AS ASCIIZ * 128
          LOCAL lpCaption  AS ASCIIZ * 128
          LOCAL dwType     AS DWORD
          x = y
          MessageBox @x.hWnd,@x.lpText,@x.lpCaption,@x.dwType
        END FUNCTION
        Last edited by Mike Doty; 19 Oct 2009, 05:05 PM.

        Comment


          #44
          This implies that synchronisation techniques are required at all times [in multi-thread programs]
          You know, it really does 'make my day' when one or more persons 'see the light' on one of these otherwise esoteric things about which I often post.

          Thank you for letting me know.

          MCM
          Michael Mattias
          Tal Systems (retired)
          Port Washington WI USA
          [email protected]
          http://www.talsystems.com

          Comment

          Working...
          X
          😀
          🥰
          🤢
          😎
          😡
          👍
          👎