Board index » cppbuilder » Re: InsertMenu, kind helpk, please. - to GAMBIT !

Re: InsertMenu, kind helpk, please. - to GAMBIT !


2003-09-20 05:31:17 AM
cppbuilder8
Sorry, but I HAD found a much easier solution. The code I had made just by
trying out all possibilities, IT IS WORKS GREAT !!!!!!!!!!!!
Look :
HWND hwnd = FindWindow("Notepad",NULL);
HMENU hMenu = GetSystemMenu(hwnd,FALSE);
if (hwnd!=NULL)
{
InsertMenu (hMenu, 0, MF_BYPOSITION, 0, "EXTRA");
}
Can you help me, how can I get, weather this menu had been clicked ?
THANK YOUA LOT IN ADVANCE,
Moore
 
 

Re:Re: InsertMenu, kind helpk, please. - to GAMBIT !

"D.Moore" < XXXX@XXXXX.COM >wrote in message
Quote
Can you help me, how can I get, weather this menu had been clicked ?
I already explained how to do that - install a message hook via
SetWindowsHookEx() in a DLL.
Gambit
 

Re:Re: InsertMenu, kind helpk, please. - to GAMBIT !

"Rick" < XXXX@XXXXX.COM >wrote in message
Quote
I just took this from one of my published papers
for an example. See if you can follow along.
I think you missed the original question. D.Moore does not want to add new
items to his own application's menu, as your code is doing. He wants to add
new items to the menus of other applications. Your code does not apply for
that goal. Although it can be adapted easily enough to call GetSystemMenu()
using a different HWND (which D.Moore has already gotten working), your
message handling code will not work, as it is handling messages only for
your own application, not other applications. You cannot process other
applications' messages without using a hook, and such a hook cannot be
installed into another process (which is required in this case) without
making a DLL for it.
Gambit
 

{smallsort}

Re:Re: InsertMenu, kind helpk, please. - to GAMBIT !

I just took this from one of my published papers for an example. See if
you can follow along.
form's header
private: // User declarations
HMENU DefSysMenu;
void __fastcall MySysMenu(TMsg &Msg, bool &Handled);
void __fastcall ShowAbout(void);
void __fastcall StayOnTop(void);
bool Is_on_top;
form's OnCreate event
void __fastcall TForm1::FormCreate(TObject *Sender)
{
HMENU DefSysMenu;
Is_on_top = false;
Application->OnMessage = MySysMenu;
InsertMenu(GetSystemMenu(Form1->Handle, false), 5, MF_BYPOSITION,
MF_SEPARATOR, NULL);
InsertMenu(GetSystemMenu(Form1->Handle, false),6, MF_BYPOSITION |
MF_UNCHECKED, IDM_STAYONTOP, "Stay On &Top");
InsertMenu(GetSystemMenu(Form1->Handle, false),7, MF_BYPOSITION,
IDM_ABOUTME, "&About");
//This next thing is done twice. Once to copy the original, and once to
modify it.
DefSysMenu = GetSystemMenu(Application->Handle, true);
DefSysMenu = GetSystemMenu(Application->Handle, false);
InsertMenu(DefSysMenu, 5, MF_BYPOSITION , MF_SEPARATOR, NULL);
InsertMenu(DefSysMenu, 6, MF_BYPOSITION | MF_UNCHECKED, IDM_STAYONTOP,
"Stay On &Top");
InsertMenu(DefSysMenu, 7, MF_BYPOSITION, IDM_ABOUTME, "&About");
}
Next we'll write our message handler. (This seemed easier than using
BEGIN_MESSY_MESSAGE_MAPS)
void __fastcall TForm1::MySysMenu(TMsg &Msg, bool &Handled)
{
if (Msg.message == WM_SYSCOMMAND)
{
switch (Msg.wParam)
{
case IDM_STAYONTOP :
StayOnTop();
Handled = true;
break;
case IDM_ABOUTME :
AboutForm->Show();
Handled = true;
break;
}
}
}
next we toggle the checkmark next to the "Stay on Top" item
void __fastcall TForm1::StayOnTop(void)
{
if(Is_on_top)
{
Form1->FormStyle = fsNormal;
InsertMenu(GetSystemMenu(Form1->Handle, false), 5, MF_BYPOSITION ,
MF_SEPARATOR, NULL);
InsertMenu(GetSystemMenu(Form1->Handle, false),6, MF_BYPOSITION |
MF_UNCHECKED, IDM_STAYONTOP, "Stay On &Top");
InsertMenu(GetSystemMenu(Form1->Handle, false),7, MF_BYPOSITION,
IDM_ABOUTME, "&About");
DefSysMenu = GetSystemMenu(Application->Handle, true);
DefSysMenu = GetSystemMenu(Application->Handle, false);
InsertMenu(DefSysMenu, 5, MF_BYPOSITION , MF_SEPARATOR, NULL);
InsertMenu(DefSysMenu, 6, MF_BYPOSITION | MF_UNCHECKED, IDM_STAYONTOP,
"Stay On &Top");
InsertMenu(DefSysMenu, 7, MF_BYPOSITION, IDM_ABOUTME, "&About");
Is_on_top = false;
}
else if (!Is_on_top)
{
Form1->FormStyle = fsStayOnTop;
InsertMenu(GetSystemMenu(Form1->Handle, false), 5, MF_BYPOSITION ,
MF_SEPARATOR, NULL);
InsertMenu(GetSystemMenu(Form1->Handle, false),6, MF_BYPOSITION |
MF_CHECKED, IDM_STAYONTOP, "Stay On &Top");
InsertMenu(GetSystemMenu(Form1->Handle, false),7, MF_BYPOSITION,
IDM_ABOUTME, "&About");
DefSysMenu = GetSystemMenu(Application->Handle, true);
DefSysMenu = GetSystemMenu(Application->Handle, false);
InsertMenu(DefSysMenu, 5, MF_BYPOSITION , MF_SEPARATOR, NULL);
InsertMenu(DefSysMenu, 6, MF_BYPOSITION | MF_CHECKED, IDM_STAYONTOP,
"Stay On &Top");
InsertMenu(DefSysMenu, 7, MF_BYPOSITION, IDM_ABOUTME, "&About");
Is_on_top = true;
}
}
 

Re:Re: InsertMenu, kind helpk, please. - to GAMBIT !

I see. Thank you a lot,
Moore