Jump to content

Referencing window with Variable Title/Class


Recommended Posts

I'm having problems with referencing window with variable Title and Class in my script.

The window I want to interact with is the main window of application.

As far as application could be in the state when document is open it's title could be something more then just name of app.

Window Class is every time new - it is almost same but last 6 characters are different when app is restarted and looks like:

Afx:0000000140000000:8:0000000000010005:0000000000000000:0000000000XXXXXX

I guess I should use regular expression, but not sure.

Any ideas how to reference windows like this?

Tanks in advance.

Link to comment
Share on other sites

  • Moderators

MaxU77,

You could use "[REGEXPCLASS:]" instead of "Title" to identify the window. In your case I would try:

("[REGEXPCLASS:Afx:0000000140000000:8:0000000000010005:0000000000000000:0000000000.{4}]")

Let us know how you get on. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

MaxU77,

You could use "[REGEXPCLASS:]" instead of "Title" to identify the window. In your case I would try:

("[REGEXPCLASS:Afx:0000000140000000:8:0000000000010005:0000000000000000:0000000000.{4}]")

Let us know how you get on. :)

M23

Thanks a lot.

I can't say I clearly understand why ".{4}" makes sence, but it works. Could you, please, comment why 4?

Anyway my script now has another issue.

Before trying to switch to REGEX script contained lines:

$WinPos = WinGetPos("[CLASS:Afx:0000000140000000:8:0000000000010005:0000000000000000:0000000000150589]","")

MsgBox(0, "Window Stats:", "POS: " & $WinPos[0] & "," & $WinPos[1] & "SIZE: " & $WinPos[2] & "," & $WinPos[3] )

and there was a message

Now lines:

$WinPos = WinGetPos("[REGEXPCCLASS:Afx:0000000140000000:8:0000000000010005:0000000000000000:0000000000.{4}]","")

MsgBox(0, "Window Stats:", "POS: " & $WinPos[0] & "," & $WinPos[1] & "SIZE: " & $WinPos[2] & "," & $WinPos[3] )

Return error "Subscript used with non-Array variable."

Could you, please, give some hint on how to debug this?

Thank in advance.

Link to comment
Share on other sites

  • Moderators

MaxU77,

A whole tutorial on SREs is a bit much to ask! Suffice to say that .{4} means exactly 4 characters of any sort. You can find a lot more about SRE syntax in the Help file under StringRegExp - and that page is just touching the surface of the wide and wacky world of SREs. :D

As to the error, it means just what it says - $WinPos is not an array. This is undoubtedly because the window you are using did not exist when you called the function. You need to add some error checking to confirm that you have an array in the variable before trying to address it. :)

All clear. :)

M23

Edit: Looking more carefully at your first post I now see 6 Xs - so perhaps you could try using .{6} instead. :P

Edited by Melba23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

MaxU77,

As to the error, it means just what it says - $WinPos is not an array. This is undoubtedly because the window you are using did not exist when you called the function. You need to add some error checking to confirm that you have an array in the variable before trying to address it. :)

All clear. :)

M23

Edit: Looking more carefully at your first post I now see 6 Xs - so perhaps you could try using .{6} instead. :P

Indeed when I reported that it works I was judjing by

WinActivate ("[REGEXPCLASS:Afx:0000000140000000:8:0000000000010005:0000000000000000:0000000000.{4}]")

But in fact that line works for all from .{1} to .{6}

Im right now browse help subclause you are referencing.

Any single character repeated {x} times is now clear for me. I swear without your hint I would never understand the syntax (One more thanks).

But I still dont understand how using REGEX (the only change) spoiled that variable array.

Link to comment
Share on other sites

  • Moderators

MaxU77,

in fact that line works for all from .{1} to .{6}

Which of course it will as it matches with 1-6 additional characters - it just ignores those that are left over. :)

As to your problem, I do not think it is the REGEX that is the problem - if it activates the GUI it can certainly find it to get its position. Normally WinGetPos fails because the GUI does not exist - are you sure that it does when you call the function? :)

I would also suggest using the GUI handle rather than the REGEX once the window is created. Use:

$hGUI = WinGetHandle(("[REGEXPCLASS:Afx:0000000140000000:8:0000000000010005:0000000000000000:0000000000.{6}]")

to get the handle and then use that in other cases where you want to identify that particulr window - like this:

WinGetPos($hWin)

Saves a lot of wear and tear on the typing fingers. :P

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Wow! WinActivate ("[REGEXPCLASS:Afx:0000000140000000:8:0000000000010005:0000000000000000:0000000000]") works as well (who could think) thus I need no count those character just trim works fine

Thanks for advice regarding handle I'll try it.

Error is solved - there was a misprint. doulble C.

That was wery kind of you to help me.

Edited by MaxU77
Link to comment
Share on other sites

Excuse me, Just couple more tiny-little questions:

1. Regarding REGEXP:

Could REGEXP be used alike leading wildcard?

You know "*book"

to find all of:

Ebook

Notebook

Facebook etc.

?

2. If my script interacts with window control which is drop-down list of options..does that mean there is no way to do it on locked workstation?

Edited by MaxU77
Link to comment
Share on other sites

  • Moderators

MaxU77,

You really want that tutorial! :)

The short answer is "Yes".

The longer answer is - look at this website and get ready for a very long journey. :)

As I have often said, SREs are the hardest thing I have ever tried to learn in computing terms (they make my brain bleed sometimes), but also among the most useful.

Good luck! :P

M23

Edit: Sneaky edit on your part there! Search on the forum for "+locked +workstation" topics - I seem to remember that the answer is that you cannot do anything, but I am not altogether sure.

Edited by Melba23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...