Announcement

Collapse
No announcement yet.

using the right windows handle ?

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

  • using the right windows handle ?

    Hello,

    what´s wrong on this code ??? The application "Classic PhoneTools" does not stop and close.

    Code:
    #COMPILE EXE
    #DIM ALL
    
    #INCLUDE "WIN32API.INC"
    
    FUNCTION PBMAIN () AS LONG
         LOCAL winindex AS DWORD
         winindex=FindWindow("","Classic PhoneTools"+CHR$(0))
                       IF winindex THEN
                                 ? "Classic is open"
                                ?STR$(Destroywindow (winindex))
                       ELSE
                            ?"Classic is closed"
    
                       END IF
                                                                                                
    
    END FUNCTION
    Thanks for help.

    Regards

    Matthias Kuhn

  • #2

    Remarks

    A thread cannot use DestroyWindow to destroy a window created by a different thread
    MCM
    Michael Mattias
    Tal Systems (retired)
    Port Washington WI USA
    [email protected]
    http://www.talsystems.com

    Comment


    • #3
      Don't mess with that manual! Ask your friends instead.

      Try changing your code to do something like this..
      Code:
           ? "Classic is open"                
           PostMessage winindex, %WM_SYSCOMMAND, %SC_CLOSE, 0
      Rgds, Dave

      Comment


      • #4
        He didn't ask how to do it, he asked what was wrong with his code.

        BTW, sending WM_SYSCOMMAND/SC_CLOSE does not guarantee either the window will be destroyed or that the target application will end, as that can be pre-empted in the window procedure for window 'winindex.'
        Michael Mattias
        Tal Systems (retired)
        Port Washington WI USA
        [email protected]
        http://www.talsystems.com

        Comment


        • #5
          Matthias also said "Thanks for help"

          Code:
          #COMPILE EXE
          #DIM ALL
           
          #INCLUDE "WIN32API.INC"
           
          Function ErrorMsg (ByVal ErrorCode As Dword) As String
           Local szMsg As Asciiz * 255
              FormatMessage %FORMAT_MESSAGE_FROM_SYSTEM, ByVal 0, ErrorCode, 0, szMsg, SIZEOF(szMsg), ByVal 0
           Function = Str$(ErrorCode) +" "+ szMsg
          End Function 
          '------------------/
           
          FUNCTION PBMAIN () AS LONG
           LOCAL winindex AS DWORD, Res As Long
             winindex=FindWindow("","Classic PhoneTools"+CHR$(0))
               IF winindex THEN
                   ? "Classic is open" + str$(winindex)
                   '?STR$(Destroywindow (winindex))
                   If DestroyWindow (winindex) = 0 Then
                      Res = GetLastError
                      ? ErrorMsg (Res), ,"DestroyWindow() error"
                   End If
                   SendMessage winindex, %WM_SYSCOMMAND, %SC_CLOSE, 0
                   If IsWindow(winindex) Then
                      ? "Try something else", , "WM_SYSCOMMAND/SC_CLOSE didn't work!"
                   Else 
                      ? "Taddaaa !!"
                   End If
               ELSE
                    ? "Classic is closed"
               END IF
           
          END FUNCTION 
          '------------------/
          BTW Tested - works in this case.
          Rgds, Dave

          Comment


          • #6
            Hello Dave and Michael,

            first> thanks for response and advice

            second> Dave i'll reach "Taddaaa !!" so it works !

            third> thinking about buying of the "Pezold-Book" to understand it better.:coffee3: and hope to to find the translated c++ examplecode
            here in the forum.

            fourth> Best regards !!!

            Matthias Kuhn

            Comment


            • #7
              The translated samples from Programming Windows by Petzold can be found on the PowerBASIC Downloads page.
              Sincerely,

              Steve Rossell
              PowerBASIC Staff

              Comment

              Working...
              X