Find Window With No Title and Variable Class Name

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
jsnyder2k
Newbie
Posts: 1
Joined: Sun Jul 27, 2014 8:31 pm

Find Window With No Title and Variable Class Name

Post by jsnyder2k » Fri Feb 11, 2022 9:59 pm

I'm having trouble focusing and closing a window with no window title and a class name that changes. I reviewed this post... viewtopic.php?t=2451 and it is very helpful and works great when the class name for the window does not change, but I'm wondering if I can find a window where the class name can have wildcards in it? I have a window that looks like this:

Code: Select all

3938112 - Afx:37830000:b:00010003:00000006:1283158F ""
where the window handle, 3938112 changes and the last section, 1283158F changes. The beginning of the class name seems to be constant, Afx:3783000. Is there a way to grab the window and close it using just this information?

Any help would be great!

User avatar
JRL
Automation Wizard
Posts: 3497
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: Find Window With No Title and Variable Class Name

Post by JRL » Wed Feb 16, 2022 9:46 pm

Try this. I took it from my "Enumerate All Windows" post.

You would set the portion of the class name you want to discover to the "vPartClass" variable (Line one). As written the vPartClass variable value will be case sensitive. If found the "DetectPortion" Subroutine will display the Window Handle, Title and Class of the window. Instead of MDL> (Line Seven) you would use that space to focus or close your window using the handle.

Code: Select all

Let>vPartClass=Afx:3783000

SRT>DetectPortion
  Position>vPartClass,Class,1,vPos,0
  If>vPos<>0
    //GWres is the window handle
    MDL>%GWres%%crlf%%title%%crlf%%class%
    Exit>
  EndIf
END>DetectPortion

Let>WindowCount=0
Let>Level=0
Let>WIN_USEHANDLE=1

//Get and write data for top window
LibFunc>user32,GetDesktopWindow,hwnd
GetWindowNames>hwnd,title,class

//Initial jump down to first top level child window.
Let>Level=1
LibFunc>user32,GetWindow,GWres,hwnd,5
GetWindowNames>GWres,title,class
GoSub>DetectPortion
Let>Window_%Level%=GWres
Let>DoNextFlag=0

Label>StepDown
  If>DoNextFlag=0
    GoSub>GetChild,GWres
    If>{(%GWChildRes%<>0)or(%DoNextFlag%=1)}
      GoTo>StepDown
    Else>
      Sub>Level,1
      Let>LastWindow=Window_%Level%
      GoSub>GetNext,LastWindow
      Goto>StepDown
    EndIf
  Else>
    GoSub>GetNext,GWres
    GoTo>StepDown
  EndIf

SRT>GetChild
  LibFunc>user32,GetWindow,GWChildRes,GetChild_var_1,5
  If>GWChildRes<>0
    Add>Level,1
    Let>Window_%Level%=GWChildRes
    GetWindowNames>GWChildRes,title,class
    GoSub>DetectPortion
    Let>GWRes=GWChildRes
  Else
      GoSub>GetNext,GetChild_var_1
  EndIf
END>GetChild

SRT>GetNext
  LibFunc>user32,GetWindow,GWRes,GetNext_var_1,2
  If>GWres<>0
    Let>Window_%Level%=GWRes
    Let>GWChildRes=1
    GetWindowNames>GWRes,title,class
    GoSub>DetectPortion
    Let>DoNextFlag=0
  Else
    Sub>Level,1
    Let>GWRes=Window_%Level%
    Let>DoNextFlag=1
  EndIf
  If>Level=0
    MDL>%vPartClass%%crlf%Not found
    Wait>0.2
    Exit>0
  EndIf
END>GetNext

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts