Window Handles and Finding Windows...

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
User avatar
Phil Pendlebury
Automation Wizard
Posts: 518
Joined: Tue Jan 16, 2007 9:00 am
Contact:

Window Handles and Finding Windows...

Post by Phil Pendlebury » Fri Jul 08, 2022 7:00 pm

An example:

Code: Select all

Let>hWndParent=0
Let>cubpat=Cubase .+
Let>nuepat=Nuendo .+
Let>WIN_REGEX=1
GetWindowHandle>%cubpat%,hWndParent
The actual code will first look for window that starts with Cubase and if it is not found it will look for a window that starts with Nuendo. At least that is what is supposed to happen.

The window I am looking for is actually open and is called:
"Nuendo Project by Phil Pendlebury"

But using the above regex is picking up a completely separate window that is actually part of Dopus Browser named:

"C:\Users\Phil\AppData\Roaming\Steinberg\Cubase 12_64\Presets" (if I close this the code works fine).

I have struggled with this for years to be honest. I used to use various permutations with and without asterisk etc. Forcing window into focus then getting active window handle. So many things. And just ended up having to make sure that no other windows were ever open that have any part of the name in them, even if not at the start.

But now, realising that regex is possible I thought this would solve it. But no.

Why is "Cubase .+" pattern being allowed to pick up that word that is actually 6 words into the string?

Full code (WIP) for info:

Code: Select all

Let>hWndParent=0
Let>cubpat=Cubase .+
Let>nuepat=Nuendo .+
Let>WIN_REGEX=1
GetWindowHandle>%cubpat%,hWndParent
IF>%hWndParent%<>0
  Let>memomsg=Cubase Found...%CRLF%%CRLF%Good to go!
  SetDialogProperty>Dialog1,MSMemo1,Text,%memomsg%
  SetDialogProperty>Dialog1,Panel69,Color,Green
  GOTO>FOUNDYOU
ENDIF
IF>%hWndParent%=0
  GetWindowHandle>%nuepat%,hWndParent
  IF>%hWndParent%<>0
    Let>memomsg=Nuendo Found...%CRLF%%CRLF%Good to go!
    SetDialogProperty>Dialog1,MSMemo1,Text,%memomsg%
    SetDialogProperty>Dialog1,Panel69,Color,Green
  GOTO>FOUNDYOU
  ENDIF
ENDIF
IF>%hWndParent%=0
  Let>memomsg=No active DAW Host (Cubase or Nuendo) found...%CRLF%%CRLF%Please start your DAW Host and either restart this application or go to the Menu Tab and click DAW to rescan.
  SetDialogProperty>Dialog1,MSMemo1,Text,%memomsg%
  SetDialogProperty>Dialog1,Panel69,Color,Red
  // MSG>No active DAW Host found! (Cubase or Nuendo)...%CRLF%%CRLF%Please start your DAW Host and either restart this application or go to the Menu Tab and click DAW to rescan.
ENDIF
Phil Pendlebury - Linktree

hagchr
Automation Wizard
Posts: 314
Joined: Mon Jul 05, 2010 7:53 am
Location: Stockholm, Sweden

Re: Window Handles and Finding Windows...

Post by hagchr » Fri Jul 08, 2022 9:35 pm

Hi, your RegEx patterns will look search the whole string. If you want the string to start with the pattern then you need to anchor it with a ^ (start of string), ie

Let>cubpat=^Cubase .+
Let>nuepat=^Nuendo .+

(Look for a start of string character (^) followed by Cubase / Nuendo etc).

If the names should be in the beginning I guess you can remove the " .+"

Let me know if I misunderstood your question.

Code: Select all

LabelToVar>test,test

Let>cubpat=^Cubase
Let>nuepat=^Nuendo

RegEx>cubpat,test,0,m1,nm1,0
RegEx>nuepat,test,0,m2,nm2,0


/*
test:
Nuendo Project by Phil Pendlebury
C:\Users\Phil\AppData\Roaming\Steinberg\Cubase 12_64\Presets" (if I close this the code works fine).
*/

User avatar
Phil Pendlebury
Automation Wizard
Posts: 518
Joined: Tue Jan 16, 2007 9:00 am
Contact:

Re: Window Handles and Finding Windows...

Post by Phil Pendlebury » Fri Jul 08, 2022 9:50 pm

Hi hagchr,

Thanks ever so much for taking the time to check this and for spotting that.

I had used one of the online Regcheckers to build the Regex (I am generally pretty good with Regex but usually use the online tools in order to check my work, like this one):

https://regex101.com/

Of course I had omitted to copy the ^ character from my final working regex. Doh!

Great stuff. Thanks once again. :-)
Phil Pendlebury - Linktree

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