Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Dynamic menu of windows, error on when title has : or *
#1
I have 3 problems (propably related to eachother?)

Macro Menu of windows, with icons
Code:
Select All      Help
;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
Code:
Select All      Help
arr[i].findreplace(":" "[91[58]") ;;escape :

be like this (?):
Code:
Select All      Help
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
Code:
Select All      Help
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.
Reply
#2
Need more string processing.

Macro Menu of windows, with icons
Code:
Select All      Help
;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]
Reply
#3
Works perfectly, thank you!!!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)