 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Lexikos
Joined: 17 Oct 2006 Posts: 4467 Location: Qld, Australia
|
Posted: Wed Apr 08, 2009 12:11 pm Post subject: Re: Hotkey If [, Expression ] version for #If [, Expression |
|
|
| tinku99 wrote: | | can it be possible to use arbitrary if expressions to create dynamic hotkey variants as follows? | It seems I've neglected to mention a feature which has been present since the initial revision. I've added the following to the documentation:
| Quote: | To create context-sensitive hotkeys with the Hotkey command, select an existing #If expression with Hotkey, If, Expression. Expression must exactly match the text of an existing #If expression, excluding "#If". The comma following "If" is required.
...
| Code: | ; Example 4: Dynamic hotkeys.
NumpadAdd::
Hotkey, If, MouseIsOver("ahk_class Shell_TrayWnd")
if (doubleup := !doubleup)
Hotkey, WheelUp, DoubleUp
else
Hotkey, WheelUp, WheelUp
return
DoubleUp:
Send {Volume_Up 2}
return
|
| To answer the question, the Hotkey command may be used to create dynamic hotkey variants under existing #If expressions, but it cannot create new expressions.
| emmanuel d wrote: | | menu icon not working for menuitems with subitems | It appears to be a problem with the owner-drawn menu code, so should not affect Windows Vista or later. Thanks for reporting it - I'll see if it can be fixed.
| Quote: | | sugestion, if no icon is specified can you make it give no error so if my var is empty it can continue without my checking that first? | What you describe fits the current behaviour: if the icon parameter is blank, the icon is removed. No error is given unless an icon is specified but cannot be loaded, in which case the following allows you to handle the error:
| Code: | | Menu, Tray, UseErrorLevel |
|
|
| Back to top |
|
 |
emmanuel d
Joined: 29 Jan 2009 Posts: 77 Location: Belgium
|
Posted: Wed Apr 08, 2009 4:59 pm Post subject: |
|
|
| Quote: | | It appears to be a problem with the owner-drawn menu code |
weird in the normal version of ahk i use owner-drawn menu for these and it works fine.
| Quote: |
// v1.0.43.03: Load via LoadPicture() vs. ExtractIcon() because ExtractIcon harms the quality
// of 16x16 icons inside .ico files by first scaling them to 32x32 (which then has to be scaled
// back to 16x16 for the tray and for the SysMenu icon). I've visually confirmed that the
// distortion occurs at least when a 16x16 icon is loaded by ExtractIcon() then put into the
// tray. It might not be the scaling itself that distorts the icon: the pixels are all in the
// right places, it's just that some are the wrong color/shade. This implies that some kind of
// unwanted interpolation or color tweaking is being done by ExtractIcon (and probably LoadIcon),
// but not by LoadImage.
|
but instead of LoadPicture() or ExtractIcon() i use ExtractIconEx()
and i dont need biger icons for the menu then 32 so hence the ;;;; in the code, dont need it for a menu
| Code: |
MI_ExtractIcon(Filename, IconNumber, IconSize)
{
; LoadImage is not used..
; ..with exe/dll files because:
; it only works with modules loaded by the current process,
; it needs the resource ordinal (which is not the same as an icon index), and
; ..with ico files because:
; it can only load the first icon (of size %IconSize%) from an .ico file.
; If possible, use PrivateExtractIcons, which supports any size of icon.
; if A_OSVersion in WIN_VISTA,WIN_2003,WIN_XP,WIN_2000
; {
; r:=DllCall("PrivateExtractIcons"
; ,"str",Filename,"int",IconNumber-1,"int",IconSize,"int",IconSize
; ,"uint*",h_icon,"uint*",0,"uint",1,"uint",0,"int")
; StdOut("icon: " h_icon ", size: " IconSize ", num: " IconNumber ", file: " Filename)
; if !ErrorLevel
; {
; if !h_icon || r>1
; {
; Clipboard:=Filename
; ListVars
; Pause
; }
; return h_icon
; }
; }
; Use ExtractIconEx, which only returns 16x16 or 32x32 icons.
if DllCall("shell32.dll\ExtractIconExA","str",Filename,"int",IconNumber-1,"uint*",h_icon,"uint*",h_icon_small,"uint",1)
{
SysGet, SmallIconSize, 49
; Use the best-fit size; delete the other. Defaults to small icon.
if (IconSize <= SmallIconSize) {
DllCall("DestroyIcon","uint",h_icon)
h_icon := h_icon_small
} else DllCall("DestroyIcon","uint",h_icon_small)
; I think PrivateExtractIcons resizes icons automatically,
; so resize icons returned by ExtractIconEx for consistency.
if (h_icon && IconSize)
h_icon := DllCall("CopyImage","uint",h_icon,"uint",1,"int",IconSize,"int",IconSize,"uint",4|8)
}
return h_icon ? h_icon : 0
}
|
| Quote: | | What you describe fits the current behaviour |
my mistake ill do this:
| Code: |
menu,x,add,%somevar%,%somesub% ;this is loaded from ini and menuname can be blank for a sepporator no need to check errors here,so
menu,x,icon,%somevar%,%somicon%,%someindex%,%somesize% ; here i get error in the menuname i gues
|
Can you fix that if you have no menuname you abbort the iconcreationprocess?
another question, i am creating a browser with menu's only
is there a limit for how many menus i make?
i create main , delete main, create main ......
if i do that are the icons keeped in memmory or what
because after a couple menus it stops with no error
and sommetimes the script blocks.
this is in ahk_L and ahk
[/quote] |
|
| Back to top |
|
 |
Lexikos
Joined: 17 Oct 2006 Posts: 4467 Location: Qld, Australia
|
Posted: Wed Apr 08, 2009 10:22 pm Post subject: |
|
|
| emmanuel d wrote: | | Quote: | | It appears to be a problem with the owner-drawn menu code |
weird in the normal version of ahk i use owner-drawn menu for these and it works fine. | Obviously you aren't using the same "owner-drawn menu code".
| Quote: | | Can you fix that if you have no menuname you abbort the iconcreationprocess? | There's nothing to fix. Omitting the menu name or menu item name is an error - if you don't want to abort, use Menu, Tray, UseErrorLevel.
| Quote: | | another question, i am creating a browser with menu's only is there a limit for how many menus i make? | Not that I know of.
| Quote: | | i create main , delete main, create main ...... if i do that are the icons keeped in memmory or what | No, the icons are deleted when appropriate.
| Quote: | | because after a couple menus it stops with no error and sommetimes the script blocks. this is in ahk_L and ahk | I'm not sure what the cause, but there appears to be a memory leak when repeatedly recreating menus with icons. In my test, it would fail every time after recreating the menu 9981 times, but only if the Icon sub-command was used. It does not seem to matter how many icons the menu has. |
|
| Back to top |
|
 |
Lexikos
Joined: 17 Oct 2006 Posts: 4467 Location: Qld, Australia
|
Posted: Sat Apr 11, 2009 6:30 am Post subject: |
|
|
| Lexikos wrote: | | Quote: | | i create main , delete main, create main ...... if i do that are the icons keeped in memmory or what | No, the icons are deleted when appropriate. | Uh, now they are.
| Quote: | Revision 26 - April 11, 2009
- Fixed: Menu icons were not drawn on items which have sub-menus if owner-drawing was in use.
- Fixed: Menu icons were not freed if all menu items were deleted at once.
- Changed (Source): Renamed AutoHotkey.sln to AutoHotkey_L.sln to allow VS window to be identified more easily.
|
|
|
| Back to top |
|
 |
emmanuel d
Joined: 29 Jan 2009 Posts: 77 Location: Belgium
|
Posted: Sat Apr 11, 2009 11:07 am Post subject: |
|
|
| Quote: | | Fixed: Menu icons were not drawn on items which have sub-menus if owner-drawing was in use. |
Sweet
it will shrink my code and make it more readable and understandable (for me)
Thx |
|
| Back to top |
|
 |
emmanuel d
Joined: 29 Jan 2009 Posts: 77 Location: Belgium
|
Posted: Sun Apr 12, 2009 11:05 am Post subject: functions and more in Menu items |
|
|
Here commes a wishlist:
| Code: |
Menu,Tray,Add,someName,gosub,test ;=Menu,Tray,Add,someName,test
Menu,Tray,Add,someName,Func,test(%someVar%) ;This one i miss the most, to be able tu use a function in a menu directly
Menu,Tray,Add,someName,Run,%aCommand%,,,PId ; would be nace if it would work
Menu,Tray,HIcon,someName,%Hicon% ;used in:
;SendMessage, 0x7F, 2, 0,, ahk_id %this_id%
;h_icon := ErrorLevel
|
But i am handling fine as is so no pressure.
| Quote: | | Fixed: Menu icons were not freed if all menu items were deleted at once. |
Are you sure? becous my menu still stops after 10 times not 9981
I see it comming, sommetimes before it stops my menu has no icons next click it dies.
i am working on making it independent of my icons and stuf from my main script, and then ill post my MenuBrowser.
And thanks for pointig out "Menu, Tray, UseErrorLevel" , did not know how to use it, but i gues it supresses all errors en continues, witch is exelent in case of "menu,tray,icon,...".
in case of my using owner draw i have to specifie witch item, so if menu add fails the icons are out of place. so no UseErrorLevel there.
my code shrinkt with 500 lines
if i could do it in 1 line i would
Gues my inglish sucs, sorry for that  |
|
| Back to top |
|
 |
Lexikos
Joined: 17 Oct 2006 Posts: 4467 Location: Qld, Australia
|
Posted: Sun Apr 12, 2009 12:04 pm Post subject: Re: functions and more in Menu items |
|
|
| emmanuel d wrote: | | Here commes a wishlist: | I'd prefer wishes be posted in the Wish List forum, unless they are specifically related to AutoHotkey_L features. There are at least two related topics already:
call functions in HotKey, SetTimer (toralf, 2006)
Allow Functions in Addition to Labels for Timers, Etc. (Piz, 2008)
| Quote: | | Quote: | | Fixed: Menu icons were not freed if all menu items were deleted at once. |
Are you sure? | There are only two places that I can see where menu items are deleted: UserMenu::DeleteItem and UserMenu::DeleteAllItems. Before revision 26, DeleteItem called UserMenu::RemoveItemIcon, but DeleteAllItems did not. Now both do.
I tested with a simple loop: add an item, set its icon, remove all items (Delete or DeleteAll). The menu can also be shown on request, to ensure it hasn't broken. Needless to say, the test (which failed previously) passed.
| Code: | KeyWait, Ctrl
KeyWait, Ctrl, D ; Press Ctrl to begin.
KeyWait, Ctrl
SetBatchLines, -1
Loop
{
Menu, M, Add, Test
Menu, M, Icon, Test, AutoHotkey.exe
if GetKeyState("Ctrl")
Menu, M, Show
Menu, M, Delete
}
Test:
ExitApp
|
Interestingly, while testing I observed that running AutoHotkey in XP compatibility mode (under Windows 7) causes an odd (but not inexplicable) memory usage pattern:
- Working Set begins about 2.5 MB higher, Private Working Set about 1 MB. (As in: before the script does anything.)
- With the loop running, memory usage increases rapidly (or slowly if you add Sleep 10) up to the initial usage plus 5 MB, and sits at that level.
I had been using compatibility mode as a way to force AutoHotkey to use owner-drawing. Testing without compatibility mode enabled but with owner-drawing (in a separate build) shows memory usage is roughly the same for either method.
| Quote: | becous my menu still stops after 10 times not 9981 ...
i am working on making it independent of my icons and stuf from my main script, and then ill post my MenuBrowser. | Until you do, I can't help. |
|
| Back to top |
|
 |
emmanuel d
Joined: 29 Jan 2009 Posts: 77 Location: Belgium
|
Posted: Sun Apr 12, 2009 12:32 pm Post subject: Menu Browse Browser FileBrowse FileBrowser AutoHotkey_L |
|
|
Here it is, some icons wont work, but it works
| Code: |
#SingleInstance,Force
CoordMode,Menu,Screen ;show the menu at screen position
Menu,Tray,UseErrorLevel ;to continue on errors
msgbox,Use Win+Space to activate the menu
return
#space::CreateMenuSingleFolder() ;createmore of these like, !#P::CreateMenuSingleFolder(A_ProgramFiles "\")
CreateMenuSingleFolder(Foldername = "") {
global
if (Foldername = "")
{
Browse1:=A_ScriptDir "\"
Foldername:=A_ScriptDir "\"
}
Menu,Browse,add ; Add the menu to avoid error when deleting a nonexisting one
menu,Browse,delete
StringGetPos, l, Foldername,\,R,1
if (StrLen(Foldername)=3)
Menu,Browse,add,DezeComputer ..\,BrowseBack
else if l>"1"
{
Menu,Browse,add,% SubStr(Foldername,1,l+1) " ..\",BrowseBack
Menu,Browse,Icon,% SubStr(Foldername,1,l+1) " ..\",Icons\up.ico,1,24
}
else { ;if we are here somethings wrong wont you think
Menu,Browse,add,?????? ..\,BrowseBack
Menu,Browse,Icon,?????? ..\,Icons\up.ico,1,24
}
Loop %Foldername%*.* ,1
{
; msgbox A_LoopFileAttrib-%A_LoopFileAttrib%
ItemName:=A_LoopFileName
Browse0:=A_Index+1
Browse%Browse0%:=A_LoopFileName
Menu,Browse,Add,%A_LoopFileName%,BrowseMenuClicked
if InStr(A_LoopFileAttrib, "D") ;if it is a directory
{
IniRead,FolderIcon,%A_LoopFileLongPath%\Desktop.ini,.ShellClassInfo,IconFile,0 ;read the Foldericon if posible
if FolderIcon ; if there was a icon specified
{
if (SubStr(FolderIcon, 1 , 1)="\") ;if 1 char = \ set the var from the root
FolderIcon:=SubStr(A_LoopFileLongPath, 1 , 2) FolderIcon
else if (SubStr(FolderIcon, 1 , 2)=".\")
StringReplace,FolderIcon,FolderIcon,.\,%A_LoopFileLongPath%\,1
else if (SubStr(FolderIcon, 1 , 3)="..\")
FolderIcon:=GetFullName( A_LoopFileLongPath "\" FolderIcon ) IconFile=%FolderIcon%
else IfExist,% A_LoopFileLongPath "\" FolderIcon
FolderIcon:=A_LoopFileLongPath "\" FolderIcon
IfExist,%FolderIcon% ;if the foldericon exist,
Menu,Browse,Icon,%A_LoopFileName%,%FolderIcon%,1,24 ; use it
else Menu,Browse,Icon,%A_LoopFileName%,shell32.dll,4,24 ;if Foldericon failed , use default
}
else Menu,Browse,Icon,%A_LoopFileName%,shell32.dll,4,24 ;there is no Foldericon, use default
}
else if A_LoopFileName contains .
{
if A_LoopFileExt in exe,ico
Menu,Browse,Icon,%A_LoopFileName%,%A_LoopFileLongPath%,1,24
else {
RegRead,Assoc,HKEY_CLASSES_ROOT,% "." A_LoopFileExt
if ! errorlevel
{
RegRead,Icon,HKEY_CLASSES_ROOT,%Assoc%\DefaultIcon
if ! errorlevel
{
StringSplit, icon,Icon,`,
if ! icon2
icon2:="1"
GetFullName( icon1 )
Menu,Browse,Icon,%A_LoopFileName%,%icon1%,%icon2%,24
; msgbox,%icon%
}
}
}
}
else Menu,Browse,Icon,%A_LoopFileName%,Icons\files.ico,1,24
}
SetTimer,ShowMenuBrowse,-1 ; Show the menu in a new thread and let this thread finish, to avoid #MaxThreads limit.
return
}
BrowseBack:
StringGetPos, l, Browse1,\,R,1 ;get previous directory
; msgbox 1 %l%-%browse1%
if ! errorlevel ; if no error the previous directory is posible
Browse1:=SubStr(Browse1,1,l+1),CreateMenuSingleFolder(Browse1) ;go 1 level back, Recreate themenu
else { ;if there was a error it meens we are at root eg c:
; msgbox %Browse1%
Menu,Browse,add ; Add the menu to avoid error when deleting a nonexisting one
menu,Browse,delete ; Delete the previous menu
Menu,Browse,add,Deze Computer,FakeSub ; Add the item for this computer
Menu,Browse,Disable,Deze Computer ; and make it unklikkable
browse0=1
browse1=
Loop 26 ;loop all drives
{
drv:=Chr(A_Index+64) ":"
ifExist,% drv "\" ;check if the drive exists
{
browse0+=1
browse%browse0%:=drv
Menu,Browse,Add,%drv%,BrowseMenuClicked
IniRead,DriveIcon,% drv "\autorun.inf",autorun,Icon,0 ;Read the driveIcon if posible
if DriveIcon
{
if (SubStr(DriveIcon, 1 , 1)="\") ;if 1 char = \ set the var from the root
DriveIcon:=drv DriveIcon
else if (SubStr(DriveIcon, 1 , 2)=".\") ; if first 2 chars are .\ , replace .\ with X:\ where X is the drive
StringReplace,DriveIcon,DriveIcon,.\,%drv%\,1
else if (SubStr(DriveIcon, 1 , 3)="..\") ; if first 2 chars are ..\ , thats imposible for a drive
msgbox,..\???? not Posible for %A_LoopFileLongPath%\Desktop.ini .ShellClassInfo IconFile=%DriveIcon%
else ifExist,% drv "\" DriveIcon ; if given disk.ico , check if exist X:\disk.ico
DriveIcon:=drv "\" DriveIcon
ifExist,%DriveIcon% ; Final check to see all is ok
Menu,Browse,Icon,%drv%,%DriveIcon%,,32 ;add the icon to the menu
else Menu,Browse,Icon,%drv%,icons\Default.ico,,32 ;if driveicon failed , use default
}
else Menu,Browse,Icon,%drv%,icons\Default.ico,,32 ;if there is no driveicon, use default
}
}
SetTimer,ShowMenuBrowse,-1 ; Show the menu in a new thread and let this thread finish, to avoid #MaxThreads limit.
}
return
FakeSub:
return
BrowseMenuClicked:
if !InStr(FileExist(Browse1 Browse%A_ThisMenuItemPos%), "D") ;check if you clicked a file
run % Browse1 Browse%A_ThisMenuItemPos%
else {
Browse1:=Browse1 Browse%A_ThisMenuItemPos% "\"
CreateMenuSingleFolder(Browse1)
}
; msgbox %Cdir%%A_ThisMenuItem%
return
BrowseMenu:
Browse1:= exedrive "\"
CreateMenuSingleFolder(Browse1)
return
GetFullName( fn ) {
static buf, i
if !i
i := VarSetCapacity(buf, 512)
DllCall("GetFullPathNameA", "str", fn, "uint", 512, "str", buf, "str*", 0)
return buf
}
ShowMenuBrowse:
Menu,Browse,Show,0,0
return
|
anny comments please, thx
hope someone can use this.
todo:
still working on comments,
and retrieving fileicons from the registry (done)
dont know if this is the place to post it.
is there a place for ahk_L scripts?
ps: is there a way to scroll in a menu?
edit: fixed menufailure,thx Lexikos
Last edited by emmanuel d on Mon Apr 13, 2009 2:25 pm; edited 1 time in total |
|
| Back to top |
|
 |
Lexikos
Joined: 17 Oct 2006 Posts: 4467 Location: Qld, Australia
|
Posted: Sun Apr 12, 2009 2:21 pm Post subject: Re: Menu Browse Browser FileBrowse FileBrowser AutoHotkey_L |
|
|
| emmanuel d wrote: | | Here it is, some icons wont work, but it works | You are right - it works, even if I re-open the menu 50+ times. It certainly doesn't stop after 10 times. If you're still having problems, please verify that the following reports "1.0.48.00.L26":
| Code: | | MsgBox % A_AhkVersion |
|
|
| Back to top |
|
 |
emmanuel d
Joined: 29 Jan 2009 Posts: 77 Location: Belgium
|
Posted: Sun Apr 12, 2009 7:30 pm Post subject: |
|
|
| Quote: | | reports "1.0.48.00.L26": |
its the same, it had to be for the menus to show icons but thanks.
still working on it. hopefuly i find it, because if it works, i don't have to mess with fileassociations. |
|
| Back to top |
|
 |
emmanuel d
Joined: 29 Jan 2009 Posts: 77 Location: Belgium
|
Posted: Sun Apr 12, 2009 8:40 pm Post subject: |
|
|
| Quote: | | You are right - it works, even if I re-open the menu 50+ times. |
oh i see, but that is not what i meen.
re-open allways works. it is browsing itself that is the problem.
like klik folder, klik folder, go up, go up,klik folder,go up...
then it just stops phuuu
but atleast its a start, so i make less folders, with less files
so the menu does not die, and i don'thave to arrow down  |
|
| Back to top |
|
 |
Lexikos
Joined: 17 Oct 2006 Posts: 4467 Location: Qld, Australia
|
Posted: Mon Apr 13, 2009 1:15 am Post subject: |
|
|
I also tried browsing about 20 times, but didn't know what I was looking for. Trying again, I see that occasionally clicking the menu item fails to re-open the menu. At no point did the menu open without icons. Additionally, after disabling the icons and testing in official v1.0.48, I still see the same problem.
Unless you can find a more specific way to reproduce the problem, I don't think I can help.
Edit: I was mistaken. Your script is reaching the #MaxThreads limit. Here's what I did:
- When a subroutine is called, log >%A_ThisLabel%.
- When a subroutine returns, log -%A_ThisLabel%.
- Open the menu and .., browse into a folder, repeat.
Each time I click .., >BrowseBack is logged. Each time I click a folder, >BrowseMenuClicked is logged. This repeats until 10 subroutines/threads have been logged, then it fails and logs -BrowseBack, -BrowseMenuClicked, -BrowseBack, -BrowseMenuClicked, etc. demonstrating that only then are the subroutines returning/threads finishing.
Since you previously said your menu stops after 10 times, I assume this is indeed the problem. There is an easy solution:
| Code: | ShowMenu:
Menu,Browse,Show,0,0
return |
| Code: | ; Show the menu in a new thread and let this thread finish.
SetTimer,ShowMenu,-1
return | A delay of -1 seems to be long enough for the current thread to finish, if setting the timer is the last thing it does. |
|
| Back to top |
|
 |
emmanuel d
Joined: 29 Jan 2009 Posts: 77 Location: Belgium
|
Posted: Mon Apr 13, 2009 2:16 pm Post subject: |
|
|
| Quote: | | Edit: I was mistaken. Wink Your script is reaching the #MaxThreads limit. |
you might be mistaken, but you are a genious.
im just doing ahk for 3 months so i don't know about #MaxThreads
but shure, i will never forget now.  |
|
| Back to top |
|
 |
Guest
|
Posted: Wed Apr 15, 2009 6:58 am Post subject: |
|
|
This is great!
But I am a little confused. I am not sure which version I should use?
Is it safe to use the Lexikos build? Or are there any problems with this build so that it is better to use the original build? What did Chris recommend
Thanks,
Peter |
|
| Back to top |
|
 |
Lexikos
Joined: 17 Oct 2006 Posts: 4467 Location: Qld, Australia
|
Posted: Wed Apr 15, 2009 9:10 am Post subject: |
|
|
| Quote: | | I am not sure which version I should use? | If you don't see any clear benefit in using AutoHotkey_L, you should use the official release. The most likely reasons to use AutoHotkey_L would be #if, debugging features and built-in support for menu icons.
| Quote: | | Is it safe to use the Lexikos build? | I use it on an every-day basis, but the answer to your question is subjective. If you intend to release your script in source code form, you must keep in mind which features of AutoHotkey_L are not supported by the official release.
| Quote: | | Or are there any problems with this build so that it is better to use the original build? | If you look in the version history, you'll see a few instances where changes I have made have broken things, and later been fixed. You have to decide for yourself whether the features on offer are worth the perceived risk. I suppose similar concerns are present when deciding whether to use a beta version of AutoHotkey.
I do not know of any problems with the current build (that aren't present in AutoHotkey v1.0.48), or I would be working on fixing them. |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|