Click to See Complete Forum and Search --> : PopupmenuHandle of a Window (Notepad)


venusridhar
September 20th, 2005, 08:25 AM
Hello everyone,

Is it possible to get the popupmenu handle of window eg., notepad. The problem is i am intercepting the windows app. thru subclassing using windows procedure and i have tried to block the messages WM_CONTEXTMENU,WM_INITMENUPOPUP,WM_RMBUTTONDOWN but no message is actually giving the popupmenu handle.

Why i need popup menu handle because i need to extend the exisiting menu by adding my own context menu.

I have managed to block the context menu and can put my own custom menu, but that is not i want i actually want to append to the existing menu. i know that there is a APPENDMENU option available in windows.h but that actually requires a windows handle.

I tried a lot in getting a popup menu handle but yet to figure out the dump.

Thanks in advance,

Regards,

Venu.

PeejAvery
September 20th, 2005, 05:01 PM
I have done it in Visual Basic following an example at Planet Source Code. The trick is that it cannot catch every applications menu. I can't find it right now but I can look for it later. The following should help for now.

http://www.mentalis.org/apilist/GetMenu.shtml

venusridhar
September 21st, 2005, 12:05 AM
Thanks for the Reply.

The Solution which you have posted won't help me out because, it actually an application hooking and we have to write a global hook thru VC++ or a windows dll which would run for all the processes commonly.

And thru my analysis and coding i achieved at writing a global hook. But the problem is not nowhere i am getting the popup menu handle using windows process. WNdProc

I can copy the code for the procedure which will be fired automatically during every action made by windows process.

extern "C" __declspec(dllexport) LRESULT CALLBACK GetMsgProc(INT nCode, WPARAM wParam, LPARAM lParam)
{
CLogger *oCLogger = new CLogger();
// bSubclass was added to this procedure to ensure that we only subclass the window
// once. Otherwise bad things can happen

MSG* pCwp = (MSG*)lParam;
static bool bSubclass = false;
//hEdit = FindWindowEx( FindWindow("WordPadClass", NULL), 0, "RichEdit20W", NULL );
hEdit = FindWindowEx( FindWindow("Notepad", NULL), 0, "Edit", NULL );
if (hEdit)
{

if( (pCwp->message == WM_RBUTTONDOWN ) && (pCwp->hwnd==hEdit) && (bSubclass == false) )
{

initMenus();
lPrevProc = (WNDPROC)GetWindowLong(hEdit, GWL_WNDPROC );
SetWindowLong( hEdit, GWL_WNDPROC, (LONG)WinProc);
bSubclass = true;

}
return CallNextHookEx( hHook, nCode, wParam, lParam );
}
}



The above procedure is automatically called by the windows procedure, since it is subclassed.

Here we have to block the WM_CONTEXTMENU and should get the handle of the menu.

But i am not getting it at any means.

Please throw a light on this.

Thanks and regards,

Venu.

PeejAvery
September 21st, 2005, 12:30 AM
The Solution which you have posted won't help me out because, it actually an application hooking and we have to write a global hook thru VC++ or a windows dll which would run for all the processes commonly.
First, since this is a general Windows forum it would be better off posted in C++ forum for better results. Plus you should only post this once so if you already posted it there, you should as a moderator to erase this one.

Secondly, Visual Basic can compile a DLL. If you wanted to write this in Visual Basic you could then call it from C++.

Lastly, getting the handle of a window's menu will only work on standard set applications. This means that no matter how inclusively you write this, there are still applications which will have a menu that is non-hookable.