Announcement

Collapse
No announcement yet.

using the right windows handle ?

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

  • Steve Rossell
    replied
    The translated samples from Programming Windows by Petzold can be found on the PowerBASIC Downloads page.

    Leave a comment:


  • Matthias Kuhn
    replied
    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. and hope to to find the translated c++ examplecode
    here in the forum.

    fourth> Best regards !!!

    Matthias Kuhn

    Leave a comment:


  • Dave Biggs
    replied
    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.

    Leave a comment:


  • Michael Mattias
    replied
    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.'

    Leave a comment:


  • Dave Biggs
    replied
    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

    Leave a comment:


  • Michael Mattias
    replied

    Remarks

    A thread cannot use DestroyWindow to destroy a window created by a different thread
    MCM

    Leave a comment:


  • Matthias Kuhn
    started a topic using the right windows handle ?

    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
Working...
X