Dynamic menu of windows, error on when title has : or *

Creating macros. Working with QM.

Dynamic menu of windows, error on when title has : or *

Postby r0n on Thu Aug 17, 2017 1:36 am

I have 3 problems (propably related to eachother?)

Macro Menu of windows, with icons     ?
;Shows dynamically created menu of currently open windows.

str titles exe ico
ARRAY(int) handles
GetWindowList &titles "" 1|2|4 0 0 handles
ARRAY(str) arr = titles
ARRAY(int) hicons.create(handles.len)
int i

for(i 0 arr.len)
,hicons[i]=GetWindowIcon(handles[i])
,arr[i].findreplace(":" "[91[58]") ;;escape :
,arr[i].escape(1) ;;escape "
,arr[i].formata(" : * %i" hicons[i])
,
titles=arr

int p=DynamicMenu(titles "" 1)



for(i 0 arr.len) DestroyIcon(hicons[i])

if(p)act handles[p-1]



The above code is from the archive.

Problem 1
The : is not correctly replaced (or this was done purposely?)

Should this line

arr[i].findreplace(":" "[91[58]") ;;escape :



be like this (?):

arr[i].findreplace(":" "[58]") ;;escape :



It then replaces the : properly.
But the problem is, when I modify it like above then when selecting a window that has a path (eg. c:\test) in the window title, then I get an error.
"Windows can not find..."
After you press "Ok" on the error pop-up it properly activates the correct window.

I think it has to do with

for(i 0 arr.len) DestroyIcon(hicons[i])



Problem 2
Another problem is with windows titles that begin with a *
Example, in notepad++ you can set the window title to show path.
When you edit an document, notepad++ adds a * in the window title (in the beginning) to indicate the document has been changed.
Example, you end up with the following in the title:
* c:\test.txt

When you run the above example script, the popup contains greyed out items which has those troublesome window titles (example: * c:\test.txt).

(Question) Possible problem 3
Do pipes in windows titles also cause problems with this script?


When I leave the script like above, problem 1 is resolved. Problem 2 persists.
r0n
Active Member
 
Posts: 498
Joined: Tue Jul 24, 2012 5:47 am

Re: Dynamic menu of windows, error on when title has : or *

Postby Gintaras on Thu Aug 17, 2017 4:27 am

Need more string processing.

Macro Menu of windows, with icons     ?
;Shows dynamically created menu of currently open windows.

str titles
ARRAY(int) handles
GetWindowList &titles "" 1|2|4 0 0 handles
ARRAY(str) arr = titles
ARRAY(__Hicon) hicons.create(handles.len)
int i

for(i 0 arr.len)
,hicons[i]=GetWindowIcon(handles[i])
,str& r=arr[i]
,if(!r.len) r="<no name>"; continue
,r.findreplace("[9]" " ") ;;escape tab
,r.escape(1) ;;escape " etc
,if(r[0]!='[') r.replace(F"[{r[0]}]" 0 1) ;;escape first character. It can be a special character: space, tab, -, |, *.
,r.findreplace(":" "[91]58]") ;;escape :
,r.findreplace("&" "&&") ;;escape &
,r.formata(" : * %i" hicons[i])

titles=arr

int p=DynamicMenu(titles "" 1)
if(p) act handles[p-1]

Gintaras
Site Admin
 
Posts: 10385
Joined: Thu Dec 19, 2002 7:36 pm
Location: Lithuania

Re: Dynamic menu of windows, error on when title has : or *

Postby r0n on Thu Aug 17, 2017 2:00 pm

Works perfectly, thank you!!!
r0n
Active Member
 
Posts: 498
Joined: Tue Jul 24, 2012 5:47 am


Return to General

Who is online

Users browsing this forum: No registered users and 2 guests

cron