Page 1 of 2
Checks to see if a specified window exists?
Posted: Thu Apr 20, 2023 8:08 am
by RK_aus_S
Hi
I'm new with PureBasic and wonder, if there exists a fuction (or a simple solution) which
checks to see if a specified window exists?
In the past years, I worked a lot with
AutoIt Script. But I was impressed of PureBasic and want to give it a try. I don't want to compare AutoIt with PureBasic, but simply as an example, in AutoIt, there exists a function for that:
Thanks for any tipps.
Regards
Roman
Re: Checks to see if a specified window exists?
Posted: Thu Apr 20, 2023 8:17 am
by Caronte3D
Hi, you can use something like that:
Code: Select all
Procedure FindPartialWindow(part$)
r=GetWindow_(GetDesktopWindow_(),#GW_CHILD)
Repeat
t$=Space(999) : GetWindowText_(r,t$,999)
If FindString(t$,part$,1)<>0
w=r
Else
r=GetWindow_(r,#GW_HWNDNEXT)
EndIf
Until r=0 Or w<>0
ProcedureReturn w
EndProcedure
Debug FindPartialWindow("PartOfWindowName")
Re: Checks to see if a specified window exists?
Posted: Thu Apr 20, 2023 8:31 am
by RASHAD
Welcome to PB
Code: Select all
If FindWindow_(0,"Title Text")
Debug "The Window exist"
Else
Debug "Not found"
EndIf
Re: Checks to see if a specified window exists?
Posted: Thu Apr 20, 2023 8:44 am
by RK_aus_S
Wow. Thanks to RASHAD and Caronte3D
Now, I have a solution for partial as well as for full window title string.
That's an enjoyable start to PureBasic.
Regards
Re: Checks to see if a specified window exists?
Posted: Thu Apr 20, 2023 8:45 am
by BarryG
PureBasic > AutoIt. Anything AutoIt can do, so can PureBasic; and more. Welcome to the forum!
Re: Checks to see if a specified window exists?
Posted: Thu Apr 20, 2023 9:23 am
by RK_aus_S
Caronte3D wrote: Thu Apr 20, 2023 8:17 am
Hi, you can use something like that:
Code: Select all
Procedure FindPartialWindow(part$)
r=GetWindow_(GetDesktopWindow_(),#GW_CHILD)
Repeat
t$=Space(999) : GetWindowText_(r,t$,999)
If FindString(t$,part$,1)<>0
w=r
Else
r=GetWindow_(r,#GW_HWNDNEXT)
EndIf
Until r=0 Or w<>0
ProcedureReturn w
EndProcedure
Debug FindPartialWindow("PartOfWindowName")
But I can see I'm still at the very beginning of the learning curve; How can I bring the found window permanently to the foreground? The found window doesn't seem to be "initialized"?
Code: Select all
StickyWindow(FindPartialWindow("myWindow"), #True)
I assume, "StickyWindows()" expects that this window is created (and initialised) by PureBasic itself? But it isn't, I wanted to find a windows from another application.
Re: Checks to see if a specified window exists?
Posted: Thu Apr 20, 2023 9:31 am
by Caronte3D
Use:
Code: Select all
SetWindowPos_(FindPartialWindow("myWindow"),#HWND_TOPMOST,0,0,0,0,#SWP_NOMOVE|#SWP_NOSIZE)
Re: Checks to see if a specified window exists?
Posted: Thu Apr 20, 2023 9:35 am
by Caronte3D
You should understand The PureBasic window number isn't the same as Window Handle.
Re: Checks to see if a specified window exists?
Posted: Thu Apr 20, 2023 9:37 am
by RK_aus_S
Caronte3D wrote: Thu Apr 20, 2023 9:31 am
Use:
Code: Select all
SetWindowPos_(FindPartialWindow("myWindow"),#HWND_TOPMOST,0,0,0,0,#SWP_NOMOVE|#SWP_NOSIZE)
Thanks, that worked!
By the way; why can I not find some functions in the help (*.chm) file? For example, I can't find this functions in the help:
- GetWindow_()
GetDesktopWindow_()
SetWindowPos_()
Are the "_"-underscore functions somehow external or public work?
Re: Checks to see if a specified window exists?
Posted: Thu Apr 20, 2023 9:40 am
by Caronte3D
The underscore means Windows functions, you can search on the windows API:
https://learn.microsoft.com/en-us/windo ... -getwindow
Re: Checks to see if a specified window exists?
Posted: Thu Apr 20, 2023 9:42 am
by RK_aus_S
Thanks a lot. I appreciate the valuable help from all of you.
Re: Checks to see if a specified window exists?
Posted: Thu Apr 20, 2023 9:44 am
by Caronte3D
This forum is very helpful, you will get comfortably instantly with PB

Re: Checks to see if a specified window exists?
Posted: Thu Apr 20, 2023 9:50 am
by RK_aus_S
BarryG wrote: Thu Apr 20, 2023 8:45 am
PureBasic > AutoIt. Anything AutoIt can do, so can PureBasic; and more. Welcome to the forum!
I hope that!
I can't expect that PureBasic will deliver all the comparable functions of AutoIt, there will certainly be "only" a more or less big overlap (and vica-versa).
But AutoIt also has pretty strong functions and features and strengths. Since I don't know PureBasic, I don't know where PureBasic is "superior" to AutoIt?
(One of them probably speed...?)
Re: Checks to see if a specified window exists?
Posted: Thu Apr 20, 2023 10:07 am
by Caronte3D
Autoit! is more "High level" a tool, but PureBasic is a general purpose languaje, more "Low level", so you have more freedom to do anything.
Re: Checks to see if a specified window exists?
Posted: Thu Apr 20, 2023 11:44 am
by AZJIO