Checks to see if a specified window exists?

Just starting out? Need help? Post your questions and find answers here.
User avatar
RK_aus_S
User
User
Posts: 11
Joined: Thu Apr 20, 2023 7:29 am
Contact:

Checks to see if a specified window exists?

Post 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:

Code: Select all

WinExists ( "title" [, "text"] )
Image

Thanks for any tipps.
Regards
Roman
User avatar
Caronte3D
Addict
Addict
Posts: 1371
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: Checks to see if a specified window exists?

Post 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")
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4991
Joined: Sun Apr 12, 2009 6:27 am

Re: Checks to see if a specified window exists?

Post by RASHAD »

Welcome to PB

Code: Select all

If FindWindow_(0,"Title Text")
  Debug "The Window exist"
Else
  Debug "Not found"
EndIf
Egypt my love
User avatar
RK_aus_S
User
User
Posts: 11
Joined: Thu Apr 20, 2023 7:29 am
Contact:

Re: Checks to see if a specified window exists?

Post 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
BarryG
Addict
Addict
Posts: 4219
Joined: Thu Apr 18, 2019 8:17 am

Re: Checks to see if a specified window exists?

Post by BarryG »

PureBasic > AutoIt. Anything AutoIt can do, so can PureBasic; and more. Welcome to the forum!
User avatar
RK_aus_S
User
User
Posts: 11
Joined: Thu Apr 20, 2023 7:29 am
Contact:

Re: Checks to see if a specified window exists?

Post 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.
Last edited by RK_aus_S on Thu Apr 20, 2023 9:32 am, edited 1 time in total.
User avatar
Caronte3D
Addict
Addict
Posts: 1371
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: Checks to see if a specified window exists?

Post by Caronte3D »

Use:

Code: Select all

SetWindowPos_(FindPartialWindow("myWindow"),#HWND_TOPMOST,0,0,0,0,#SWP_NOMOVE|#SWP_NOSIZE)
User avatar
Caronte3D
Addict
Addict
Posts: 1371
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: Checks to see if a specified window exists?

Post by Caronte3D »

You should understand The PureBasic window number isn't the same as Window Handle.
User avatar
RK_aus_S
User
User
Posts: 11
Joined: Thu Apr 20, 2023 7:29 am
Contact:

Re: Checks to see if a specified window exists?

Post 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?
User avatar
Caronte3D
Addict
Addict
Posts: 1371
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: Checks to see if a specified window exists?

Post by Caronte3D »

The underscore means Windows functions, you can search on the windows API:

https://learn.microsoft.com/en-us/windo ... -getwindow
User avatar
RK_aus_S
User
User
Posts: 11
Joined: Thu Apr 20, 2023 7:29 am
Contact:

Re: Checks to see if a specified window exists?

Post by RK_aus_S »

Caronte3D wrote: Thu Apr 20, 2023 9:40 am You should understand The PureBasic window number isn't the same as Window Handle.

The underscore means Windows functions, you can search on the windows API:

https://learn.microsoft.com/en-us/windo ... -getwindow
Thanks a lot. I appreciate the valuable help from all of you.
User avatar
Caronte3D
Addict
Addict
Posts: 1371
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: Checks to see if a specified window exists?

Post by Caronte3D »

This forum is very helpful, you will get comfortably instantly with PB :wink:
User avatar
RK_aus_S
User
User
Posts: 11
Joined: Thu Apr 20, 2023 7:29 am
Contact:

Re: Checks to see if a specified window exists?

Post 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...?)
User avatar
Caronte3D
Addict
Addict
Posts: 1371
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: Checks to see if a specified window exists?

Post 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.
Post Reply