Posts: 1,058
Threads: 367
Joined: Oct 2007
Is there any way to add a button to the system menu of an existing window, which it will be associated with this window? Let me clarify that I do not mean a toolbar to be attached to this window.
Any advice will be much appreciated.
Posts: 12,073
Threads: 140
Joined: Dec 2002
The link is incorrect.
System menu items can be added. Buttons probably not.
Posts: 1,058
Threads: 367
Joined: Oct 2007
Thank you very much for your answer. I am sorry that the link was mistaken. The correct link is :
http://www.quickmacros.com/forum/showthr...6#pid19766
Could you please explain or give a hint or link about adding system menu items ?
Posts: 1,058
Threads: 367
Joined: Oct 2007
Thank you again. I found the information previously requested in QM documentation, starting from link :
http://www.quickmacros.com/forum/showthr...1#pid13701
Best regards
Posts: 12,073
Threads: 140
Joined: Dec 2002
Macro
Add system menu items to any window
;Adds two menu items to the system menu of Notepad.
int hwnd=win("" "Notepad")
int hmenu=GetSystemMenu(hwnd 0)
if(!hmenu) ret
AppendMenu hmenu MF_DISABLED 0xA001 "test"
AppendMenu hmenu MF_DISABLED 0xA002 "test2"
SetProp hwnd "symt_hmenu" hmenu
Filter-function. Runs on mouse left button up. If clicked a system menu item added with the above macro, shows its id. You can use mac to run a macro. This function must be as fast as possible.
Function
FF_on_system_menu_click
Trigger
#Lh1 0x1 //FF_on_system_menu_click
;/
function# iid FILTER&f
if(GetClassLong(f.hwnd GCW_ATOM)!=32768) ret -2 ;;is popup menu?
int hwnd=GetWindow(f.hwnd GW_OWNER)
if(!hwnd) ret -2 ;;context menu; else system or window menu
int hmenu=GetProp(hwnd "symt_hmenu"); if(!hmenu) ret -2 ;;has QM-added submenus?
if(hmenu!=SendMessage(f.hwnd MN_GETHMENU 0 0)) ret -2 ;;is system menu?
;int hmenu=GetSystemMenu(hwnd 0)
POINT p; xm p
int itemIndex=MenuItemFromPoint(hwnd hmenu p) ;;note: will not work with DPI-scaled windows
int itemId=GetMenuItemID(hmenu itemIndex)
if(!(itemId>=0xA000 and itemId<=0xAFFF)) ret -2 ;;assume we always add menu items with id in this range
str s1.getwinclass(hwnd) s2.getwintext(hwnd) s3.format("%s[]%s" s1 s2)
sel s3 3
,case "Notepad[]*"
,out "itemIndex=%i itemId=%i" itemIndex itemId
ret -1
Posts: 1,058
Threads: 367
Joined: Oct 2007
Many thanks for this code example. I will use it immediately.