window api question - DestroyWindow()
Posted: Thu Nov 28, 2024 2:25 pm
Hi,
I would like to use runprogram() to open a chrome window and then later close it (not minimize )
Below is my attempt using examples from other experienced member (thanks for their contribution).
The API Closewindow (line 44) work as expected but when I use DestroyWindow (line 43) it failed. Please advise.
Thanks
Allen
I would like to use runprogram() to open a chrome window and then later close it (not minimize )
Below is my attempt using examples from other experienced member (thanks for their contribution).
The API Closewindow (line 44) work as expected but when I use DestroyWindow (line 43) it failed. Please advise.
Code: Select all
Structure ChromeWin_Structure
FullTitle$
WinTitlePart$
TitleFrontPart$
hWnd.i
EndStructure
Global ChromeWin.ChromeWin_Structure
Procedure.i ChromeWinsCallback(hWnd.i, *lParam.ChromeWin_Structure)
Protected *Buffer, Result
Result = #True
If IsWindowVisible_(hWnd)
*Buffer = AllocateMemory(1024)
If *Buffer
If GetWindowText_(hWnd, *Buffer, MemorySize(*Buffer))
*lParam\FullTitle$ = PeekS(*Buffer)
If *lParam\FullTitle$ <> ""
If *lParam <> #Null
If *lParam\WinTitlePart$ <> ""
If FindString(*lParam\FullTitle$, *lparam\WinTitlePart$)
*lParam\hWnd = hWnd
Debug hWnd
Result = #False
EndIf
EndIf
EndIf
EndIf
EndIf
FreeMemory(*Buffer)
EndIf
EndIf
ProcedureReturn Result
EndProcedure
Procedure.i FindVisibleWindowByTitlePart(WinTitlePart$)
ChromeWin\hWnd = 0
ChromeWin\WinTitlePart$ = WinTitlePart$
EnumWindows_(@ChromeWinsCallback(), @ChromeWin)
EndProcedure
Procedure CloseChrome()
If IsWindow_(ChromeWin\hWnd)
;If DestroyWindow_(ChromeWin\hWnd)
If CloseWindow_(ChromeWin\hWnd)
Debug "OK"
Else
Debug "Fail"
EndIf
EndIf
EndProcedure
RunProgram("Chrome.exe")
Delay(7000)
FindVisibleWindowByTitlePart("Google Chrome")
Delay(1000)
CloseChrome()
Allen