yingkit
asked on
Add Menuitem.
Hi,
How can I add a custom menuitem to OTHER program's menu, such as Notepad's FileMenu? Examples expected.
(D2)
How can I add a custom menuitem to OTHER program's menu, such as Notepad's FileMenu? Examples expected.
(D2)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I've tried the function insertmenu, but I can't control the position where the menuitem appears.
If possible, could you please also tell me how can I execute an EXE file with some parameters when the added menuitem is clicked by the user? Of course, I will offer more points for the answers.
Thanks!
If possible, could you please also tell me how can I execute an EXE file with some parameters when the added menuitem is clicked by the user? Of course, I will offer more points for the answers.
Thanks!
Hi
InsertMenu works like this :
procedure TForm1.Button1Click(Sender : TObject);
var
TheWindowHandle, MenuHandle : THandle;
begin
TheWindowHandle := FindAWindow('Untitled - Notepad', '');
if TheWindowHandle = 0 then
ShowMessage('Window Not Found!') else
begin
MenuHandle := GetMenu(TheWindowHandle);
MenuHandle := GetSubMenu(MenuHandle, 0);
InsertMenu(MenuHandle,
3,
MF_STRING + MF_BYPOSITION,
$EFF0,
'Menu at place 4');
end;
end;
I don't know directly how to intercept the click of the menu. I'll look into it.
Zif.
InsertMenu works like this :
procedure TForm1.Button1Click(Sender
var
TheWindowHandle, MenuHandle : THandle;
begin
TheWindowHandle := FindAWindow('Untitled - Notepad', '');
if TheWindowHandle = 0 then
ShowMessage('Window Not Found!') else
begin
MenuHandle := GetMenu(TheWindowHandle);
MenuHandle := GetSubMenu(MenuHandle, 0);
InsertMenu(MenuHandle,
3,
MF_STRING + MF_BYPOSITION,
$EFF0,
'Menu at place 4');
end;
end;
I don't know directly how to intercept the click of the menu. I'll look into it.
Zif.
yuck, it's not so easy as I thought... here is what I have so far... perhaps it should work when using dll. But I don't have time to test it in a dll.
const
WM_NotePad = WM_USER + 100;
procedure MenuIsClicked;
begin
showmessage('hello');
end;
procedure TForm1.Button1Click(Sender : TObject);
var
TheWindowHandle, MenuHandle : THandle;
POldWndProc : Pointer;
begin
TheWindowHandle := FindAWindow('Untitled - Notepad', '');
if TheWindowHandle = 0 then
ShowMessage('Window Not Found!') else
begin
MenuHandle := GetMenu(TheWindowHandle);
MenuHandle := GetSubMenu(MenuHandle, 0);
InsertMenu(MenuHandle,
3,
MF_STRING + MF_BYPOSITION,
WM_NotePad,
'Menu at place 4');
POldWndProc := Pointer(SetWindowLong(Menu Handle, GWL_WNDPROC, LongInt(@MenuIsClicked)));
end;
end;
Regards, zif
const
WM_NotePad = WM_USER + 100;
procedure MenuIsClicked;
begin
showmessage('hello');
end;
procedure TForm1.Button1Click(Sender
var
TheWindowHandle, MenuHandle : THandle;
POldWndProc : Pointer;
begin
TheWindowHandle := FindAWindow('Untitled - Notepad', '');
if TheWindowHandle = 0 then
ShowMessage('Window Not Found!') else
begin
MenuHandle := GetMenu(TheWindowHandle);
MenuHandle := GetSubMenu(MenuHandle, 0);
InsertMenu(MenuHandle,
3,
MF_STRING + MF_BYPOSITION,
WM_NotePad,
'Menu at place 4');
POldWndProc := Pointer(SetWindowLong(Menu
end;
end;
Regards, zif
Hi,
Reading this :
Processes run in different memory spaces on Win32 and you cannot directly call a function in another memory space.
and we know that we've to create a dll if we want to get it to work :-(
Reading this :
Processes run in different memory spaces on Win32 and you cannot directly call a function in another memory space.
and we know that we've to create a dll if we want to get it to work :-(
listening...
ASKER
Adjusted points to 200
ASKER
Is it possible to test it in a DLL for me and show me how I can make the DLL and get everything worked??
yuck, tried it with DLL and I get an error about not a correct window handler, when using the menu handle :-(
ASKER
Actually, is it impossible to interfere other programs' menus, just like my question? Very difficult??
Hi, I don't know, it should be possible, because we can add a menu to it... only problem is that we don't find a way to attach a function/procedure to this menu :-(. Nevertheless, it looks like it is really hard.
Zif.
Zif.
mmm, perhaps a global messages hook can work...
Zif.
Zif.
ASKER
Hook? Can you give me some examples? I don't really care what method is used. I just want to have a new menuitem appeared in other program with my own procedures.
ASKER
Thanks ZifNab.
If you find a way to attach a procedure to a menuitem in the future, please post it here. Thank you very much!
If you find a way to attach a procedure to a menuitem in the future, please post it here. Thank you very much!
yingkit, I'll certainly do!
ASKER
The code worked quite well. But if I don't want to create a new menu, but just want to add a menuitem under the "File" menu, how should I modify the code?
Thanks in advance.