findwindow with wildcards

Share your advanced PureBasic knowledge/code with the community.
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

findwindow with wildcards

Post by blueznl »

Code updated for 5.20+

Code: Select all

Procedure x_findwindow(pattern.s,ulcase)
  Protected n
  Global x_window_name.s, x_window_h
  ;
  ; in:     pattern.s     - see x_matchpattern()
  ;         ulcase        - 1 don't check case 0 check case
  ; retval: #true         - found
  ; out:    x_window_name - name of the window found
  ;         x_window_h    - handle of the window found
  ;
  n = 0
  x_window_h = 0
  h = GetTopWindow_(0)
  While h <> 0
    x_window_name = Space(513)
    GetWindowText_(h,@x_window_name,512)
    n = n+1
    If n > 5000                                                     ; on tinman's request :-)
      h = 0
    ElseIf x_matchpattern(x_window_name,pattern,ulcase) = #True
      x_window_h = h
      h = 0
    Else
      h = GetWindow_(h,#GW_HWNDNEXT)
    EndIf
  Wend
  ;
  If x_window_h <> 0
    ProcedureReturn #True
  Else
    ProcedureReturn #False
  EndIf
EndProcedure
using the x_lib.pb include file from the purebasic survival guide
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )