Announcement
Collapse
No announcement yet.
using the right windows handle ?
Collapse
X
-
The translated samples from Programming Windows by Petzold can be found on the PowerBASIC Downloads page.
-
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:
-
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 '------------------/
Leave a comment:
-
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:
-
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:
-
Remarks
A thread cannot use DestroyWindow to destroy a window created by a different thread
Leave a comment:
-
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
Regards
Matthias KuhnTags: None
Leave a comment: