Solved

Forcing a specific menu to show (no listed in process)

Posted on 2006-06-18
15
239 Views
Last Modified: 2013-12-03
Hi guys, I found a interest program that alow me to see some resources of another programs.

normaly, the resources are listed in a process viewer like WinSight32 and others but in this specific program, there is a menu (popup menu) that I can see in the resource program but when it is running, it is not listed in the process viewer (not even hidden).


The menu, in the resource program is listed as:

+Cursor
+Icon
-Menu
    |__109
    |    |__0 <-- this is the menu i want to show* (code listed below)
    |__227
    |    |__0
    |__1315
         |__0
+Dialog
+...
+...

*
109 MENU
LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
{
   POPUP "Check"
   {
        MENUITEM "Check the Rendered Equip Image...",  110
        MENUITEM " Check Frame.",  32772
        MENUITEM "Change Color",  32775
        MENUITEM "Chage Font( \"font.ini\" )",  32889
        MENUITEM SEPARATOR
        MENUITEM "Check the Wrong Tile Attr.",  32807
        MENUITEM "Right Mouse Button",  32811
   }
   POPUP "Event"
   {
        MENUITEM "Event View",  32773
        MENUITEM SEPARATOR
   }
... And so on
}

I was wondering if there is a chance to locate this resource and then force it to show like using a sendmessage or whatever.


ty in advance
0
Comment
Question by:furmiga
  • 6
  • 6
  • 2
15 Comments
 
LVL 7

Author Comment

by:furmiga
ID: 16930220
I already deleted the Delphi one. increassed this one. Srry about breaking the rules.
0
 
LVL 86

Expert Comment

by:jkr
ID: 16930499
No problem. Thanks for fixing that yourself. BTW, there's nothing wrong with posting a 20pts pointer question in the Delphi TA with a link to this one here.
0
 
LVL 7

Author Comment

by:furmiga
ID: 16930560
thanks for the tip man !

btw, don't you have any idea how do i open this "in code" menu ?
0
 
LVL 86

Expert Comment

by:jkr
ID: 16931514
Well, I do have an idea about displaying/inserting such a menu using the usual Win32 paths, but: Why? If the target app does not have command handlers that are responsible for executing the commands bound to the menu entries, that keeps me scratching my head...
0
 
LVL 7

Author Comment

by:furmiga
ID: 16934974
All i want is activate the menu, using  another program or injecting a code to force it to open. The menu is a normal menu "file - etc - etc - about" but this menu only exists inside the EXE. It never shows. When you use some resource app you can see the menu inside it but, again, it never really shows. The app don't allocate handlers for the menu either. I'm just wondering if there is a possibility to show this menu (or inject a code to force it to open). There is no possibility to change the code in the app since all i have is it's executable.
0
 
LVL 3

Expert Comment

by:griffin36
ID: 16940743
In C++, you can do the following to show the menu as a popup menu:

HMENU menu = LoadMenu(hInstance, MAKEINTRESOURCE(109));

TrackPopupMenuEx(menu, TPM_RIGHTBUTTON, 100, 100, hwnd, NULL);

Let hwnd be the handle to the window that you want to own the window, and let hInstance be the handle to the module (dll or exe) that contains the menu resource.

This will create the menu at 100 pixels down and the the right of the top left (I think).
0
 
LVL 7

Author Comment

by:furmiga
ID: 16943207
I guess we are almost there griffin, but its not happening when I change hwnd to anything diferent then my own handle.

here the code:

var
  Form1: TForm1;
  menu1 : HMENU;
  wnd  : HWND;
implementation

{$R *.dfm}
{$R Menu_109.res}

procedure TForm1.Button1Click(Sender: TObject);

begin
  wnd := FindWindow('TheProgram',nil);
  menu1 := LoadMenu(HInstance,MAKEINTRESOURCE(109));
  showmessage(inttostr(wnd));
  TrackPopupMenuEx(menu1, TPM_RIGHTBUTTON, 100, 100, wnd, nil); // if I change "wnd" to "application.handle", that means, my own handle, the menu works fine.
end;
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 3

Expert Comment

by:griffin36
ID: 16944475
When the TrackPopupMenuEx fails, could you call GetLastError() and post the return value here to see what the problem is?

Also, try adding TPM_NONOTIFY to the flags, which will prevent the menu from sending messages to its owner, and that might be worth a shot is the application is intentionally not showing it.
0
 
LVL 7

Author Comment

by:furmiga
ID: 16946847
TPM_NONOTIFY didn't change anything

GetLastError returns only 0 :( well, if I turn the program off and try to open the menu, it return 1401 guess it's working lol.

Another thing. The menu shows like a little vertival bar with no names. only when you pass the mouse over this little bar the itens come.
0
 
LVL 3

Expert Comment

by:griffin36
ID: 16947736
That's strange behavior. It's possible the program is altering that particular menu resource, which would explain why it doesn't show up in the process viewer.

One final thing I'd try if you're really trying to coax out that menu is to use LoadLibrary to manually load the program into memory without executing it, then load the menu from there. Again, in C++:

HMODULE hModule = LoadLibrary(progname); // progname should be the string specifying the program's location

HMENU menu = LoadMenu(hModule, MAKEINTRESOURCE(109));

Also, FreeLibrary(hModule) when you're done.
0
 
LVL 3

Expert Comment

by:griffin36
ID: 16947752
I just was reviewing a program where I used TrackPopupMenuEx and I noticed that I called

SetForegroundWindow(hwnd);

before TrackPopupMenuEx and

PostMessage(hwnd, WM_NULL, 0, 0);

afterwards, where hwnd is the owner window for the menu. That might be necessary for a properly functioning popup menu.
0
 
LVL 7

Author Comment

by:furmiga
ID: 16953274
damn... not working... and in my program it just blinks.

Lemmi ask you something:

Is it possible to:

program1 - mine
program2 - the one I want to change

1 - copy the menu I want from program2 by loadLibrary or just adding a .res
2 - make a normal TmainMenu in program 1 and load the menu to it (from the resource)
3 - Load the program2 inside program1 (like a frame in HTML) - Both will be working
4 - Try to send menu messages to the program2

Is it possible ?
0
 
LVL 3

Accepted Solution

by:
griffin36 earned 500 total points
ID: 16957644
I'll answer this number by number.

1 - This should be no problem at all if you just use a .res file, but make sure that you won't have any overlapping in the menu id's. Using loadLibrary would be more complicated.
2 - Again, shouldn't be a problem (remember there can't be overlapping id's).
3 - For this one, you need to do a few things:
Get the window handle for program2's main window.
Call SetParent(program2hwnd, program1hwnd).
Then, add WS_CHILD style to program2's window:
SetWindowLong(program2hwnd, GWL_STYLE, GetWindowLong(program2hwnd, GWL_STYLE) | WS_CHILD);
Finally, adjust program2's position using SetWindowPos and maybe show the window using the SWP_SHOWWINDOW flag so it is visible in program1.
4 - I would say, when you process the WM_COMMAND message, then if (HIWORD(wParam) == 0) you should PostMessage to program2's window with the exact same message.

Note: According to MSDN Library, SetParent will not work if the two windows do not belong to the same application. It might work anyway, I seem to remember it working for someone before. Otherwise, another option would be to call LoadLibrary on program2, then creating a new thread and launching program2 in the thread by calling it's WinMain function, effectively turning the other program into a part of your program. This last bit is all speculation, though; I don't know if it's actually possible to launch a program in a thread like that.
0
 
LVL 3

Expert Comment

by:griffin36
ID: 16957721
I have just verified that indeed, SetParent does work on windows from different applications, so my note of warning at the bottom of the last message is unnecessary.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

This article describes how to programmatically preset the "Pages per Sheet" option that's available with most printer drivers.   This setting lets you do "n-Up" printing, where two, four, or more pages are printed on each sheet of paper. If your …
This article describes how to add a user-defined command button to the Windows 7 Explorer toolbar.  In the previous article (http://www.experts-exchange.com/A_2172.html), we saw how to put the Delete button back there where it belongs.  "Delete" is …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now