Posts: 81
Threads: 37
Joined: Jun 2008
Anyone know of a way to launch macros from the system menu (e.g., the right click menu of window titlebars), kinda like QM shell menu triggers but with the system menu instead? If a programatic way is too hard, anyone know any software that lets you add things to those menus? For example, before shell menu triggers I used software called "FileMenu Tools" to add shell menu command line entries that would launch macros.
Posts: 12,071
Threads: 140
Joined: Dec 2002
With QM you can add system menu items but cannot receive notifications when clicked. For it would need to create dll.
Posts: 12,071
Threads: 140
Joined: Dec 2002
Instead you can create menu and assign right click or middle click trigger that works only if on window icon.
This is one menu for all windows.
Menu
Trigger #Rh3
Macro650 :mac "Macro650"
Macro652 :mac "Macro652"
This is for one window (Notepad).
Menu
Trigger #Rh3 //FF_Menu22
Macro650 :mac "Macro650"
Macro652 :mac "Macro652"
Function FF_Menu22
;/
function# iid FILTER&f
if(wintest(f.hwnd "Notepad" "Notepad")) ret iid
Posts: 81
Threads: 37
Joined: Jun 2008
Thanks, I've been using something like this in explorer and it's working well. The only problem with right-click menus is that if I use a QM menu the system one disappears, probably not possible to present both at the same time.
Posts: 81
Threads: 37
Joined: Jun 2008
I found a way to add QM macros to a window's "system menu" (the menu that pops up when you right-click on a window's titlebar).
SysMenu & SysMenuCreate functions are basically tweaked versions of PopupMenu & PopupMenuCreate .
I also added an option to return a more practical value upon menu item selection (the MenuItemNum function does this).
See example macro at end.
Function SysMenu
;/
function# $items [x] [y] [!*flags] [accel] [hwndowner] [return_val]
;Adds items to & shows the system menu (the menu that pops up when you right-click on a window's titlebar).
;Allows you to launch QM macros from system menu.
;Returns: see return_val below
;items - list of [] delimited strings. You can add separators and submenus in the same way as in <help "::/QM_Help/IDH_POPUP.html">QM popup menus</help>.
;x y - menu position. Default: 0 0 (mouse position).
;flags - byte array, where each element can be combination of the following flags:
;;;1 disabled
;;;2 checked
;;;4 item type is radiocheck
;accel - if 1, you can use accelerator keys (characters, preceded by &). Also can contain TPM_ flags (documented in MSDN, look for TrackPopupMenuEx).
;hwndowner - owner window. Must belong to current thread.
;return val - 0 return TPM_RETURNCMD return value, 1 return item number
;See SysMenuExample for an example.
;These flags can be used in accel:
;def TPM_RIGHTBUTTON 0x0002
;def TPM_CENTERALIGN 0x0004
;def TPM_RIGHTALIGN 0x0008
;def TPM_VCENTERALIGN 0x0010
;def TPM_BOTTOMALIGN 0x0020
;def TPM_VERTICAL 0x0040
str s=items
if(s.end("[]")) s.fix(s.len-2)
if(!s.len) ret
int hwnd hf hm r
if(hwndowner) hwnd=hwndowner
else
,hf=win
,hwnd=CreateWindowEx(WS_EX_TOOLWINDOW|WS_EX_NOPARENTNOTIFY +32770 0 WS_POPUP 0 0 0 0 hf 0 _hinst 0)
,SetForegroundWindow hf;; hf=0
if(x=0 and y=0) GetCursorPos(+&x)
if(accel&1)
,if(!hwndowner) hf=win
,SetForegroundWindow(hwnd)
hm=SysMenuCreate(_i s flags hf)
r=TrackPopupMenuEx(hm accel~1|TPM_RETURNCMD x y hwnd 0)
GetSystemMenu(hf 1)
DestroyMenu(hm)
if(!hwndowner) DestroyWindow(hwnd)
0
if(hf) act hf
if(return_val) ret MenuItemNum(r items)
ret r
Function SysMenuCreate
;/
function# &i str&items lpstr'fa hf [FINDWORDN*getlstate]
str ss.flags=1
lpstr s
int vert hm=GetSystemMenu(hf 0)
MENUITEMINFOW mii.cbSize=sizeof(MENUITEMINFOW)
if(getlstate) _getl=*getlstate
for i i 1000000
,vert=0
,;g2
,if(ss.getl(items -i)<0) break
,for(s ss s+ss.len) if(s[0]!9) break ;;skip tabs
,mii.fMask=MIIM_TYPE|MIIM_ID|MIIM_STATE
,mii.fState=0; mii.dwTypeData=0; mii.fType=MF_STRING|vert
,sel s[0]
,,case '-' mii.fType=MF_SEPARATOR|vert
,,case '|' vert=MF_MENUBARBREAK; i+1; goto g2
,,case '>'
,,,mii.fMask=MIIM_TYPE|MIIM_SUBMENU|MIIM_STATE
,,,mii.dwTypeData=@(s+1)
,,,i+1
,,,mii.hSubMenu=PopupMenuCreate(&i &items fa &_getl)
,,,goto g1
,,case '<' i-1; goto gr
,,case else
,,mii.dwTypeData=@s
,,;g1
,,if(fa)
,,,int flags=fa[i]
,,,if(flags&1) mii.fState|MF_DISABLED|MF_GRAYED
,,,if(flags&2) mii.fState|MF_CHECKED
,,,if(flags&4) mii.fType|MFT_RADIOCHECK
,mii.wID=i+1
,InsertMenuItemW(hm 65000 0 &mii)
;gr
if(getlstate) *getlstate=_getl
ret hm
Function MenuItemNum
;/
function #tpm_return $items
int i0 i1
if(!tpm_return) ret 0
rep
,if(_s.getl(items)<0) break
,if(_s!="<") i0+1
,,if(_s!="-" and _s[0]!=62) i1+1
,,if(tpm_return=i0) ret i1
ret 0
Macro SysMenuExample
Trigger #Rh2
;Adds items to the system menu of all windows
sel SysMenu("-[]Item 1[]>SubA[]Item 2[]Item 3[]<[]>SubB[]>SubC[]Item 4[]Item 5[]<[]Item 6[]<[]-[]Item 7" 0 0 0 0 0 1)
,case 1: out "Item 1";; mac "mac1"
,case 2: out "Item 2";; mac "mac2"
,case 3: out "Item 3";; mac "mac3"
,case 4: out "Item 4";; mac "mac4"
,case 5: out "Item 5";; mac "mac5"
,case 6: out "Item 6";; mac "mac6"
,case 7: out "Item 7";; mac "mac7"
,case SC_RESTORE : SendMessage(win WM_SYSCOMMAND SC_RESTORE 0)
,case SC_CLOSE : SendMessage(win WM_SYSCOMMAND SC_CLOSE 0)
,case SC_MINIMIZE : SendMessage(win WM_SYSCOMMAND SC_MINIMIZE 0)
,case SC_MAXIMIZE : SendMessage(win WM_SYSCOMMAND SC_MAXIMIZE 0)
,case SC_MOVE : SendMessage(win WM_SYSCOMMAND SC_MOVE 0)
,case SC_SIZE : SendMessage(win WM_SYSCOMMAND SC_SIZE 0)
,case else ret
Posts: 1,000
Threads: 253
Joined: Feb 2008
None of the system commands are working with this example...I'll double check I have the names of the functions right
|