Article View: borland.public.cppbuilder.nativeapi
Article #6358Re: "use" menu item in another app?
From: Remy Lebeau (TeamB)
Date: Thu, 19 May 2005 10:49
Date: Thu, 19 May 2005 10:49
81 lines
3857 bytes
3857 bytes
"Segal" <none@none.spam.sucks.balls> wrote in message
news:428c2e72@newsgroups.borland.com...
> Than kfor all the repsonses, but neither of those seem to work:
Then you are not using it properly, because WM_COMMAND *is* the proper way
that menu item clicks are issued.
> hwnd = FindWindowEx(NULL, hwnd, NULL, "Target App");
You are not verifying that hwnd is not NULL before using it.
> HMENU hmenu = GetMenu(hwnd); // Main menu
You are not verifying that hmenu is not NULL before using it.
> menuinfo.fMask = MIIM_STRING;
MIIM_STRING is not a valid entry for the fMask member. It is used with the
fType member instead. You should be specifying the MIIM_TYPE mask instead.
Also, you are trying to retrieve the menu item's ID, but you did not specify
the MIIM_ID mask at all.
> menuinfo.dwTypeData = NULL;
To retreive the menu item text, you need to provide your own buffer for the
text to be stored into. NULL is not valid, and you must also fill in the
cch member as well so the menu knows how large the buffer is.
> GetMenuItemInfo(hmenu, 2, true, &menuinfo);
> menuinfo.dwTypeData = buff;
> if (GetMenuItemInfo(hmenu, 2, true, &menuinfo)) {
Why are you calling GetMenuItemInfo() twice?
> SendMessage(hwnd, WM_COMMAND, MAKEWPARAM(menuinfo.wID, 0), 0);
> PostMessage( hwnd, WM_COMMAND, menuinfo.wID, 0);
Why are you issuing the WM_COMMAND message twice?
> Either method doesn't seem to do anything.
That is because you are not retreiving the menu item ID properly in the
first place.
With all of that said, you need to use the following code instead:
HWND hwnd = NULL;
char buff[101] = {0};
// App with Menu
hwnd = FindWindowEx(NULL, hwnd, NULL, "Target App");
if( hwnd )
{
HMENU hmenu = GetMenu(hwnd); // Main menu
if( hmenu )
{
MENUITEMINFO menuinfo = {sizeof(MENUITEMINFO), 0};
menuinfo.fMask = MIIM_ID | MIIM_TYPE;
menuinfo.dwTypeData = buff;
menuinfo.cch = 100;
if( GetMenuItemInfo(hmenu, 2, TRUE, &menuinfo) )
{
ShowMessage(buff);
SendMessage(hwnd, WM_COMMAND, MAKEWPARAM(menuinfo.wID, 0),
0);
}
}
}
> As a little side question, I noticed the String I get (the Menu-item
> caption) always is short a caracter on the end when it has an underlined
> (shortcut) char. Is this a known bug (looks like it doesn't count the
> hidden '&' when counting how many chars and ends up 1 char short in
> length, hence lopping the last one off. Such as above getting "Option"
> with underlined 'O' instead of "Options".)
Gambit
Technical Details
Message-ID:
<428c6ef5$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!border1.nntp.dca.giganews.com!nntp.giganews.com!feed5.newsreader.com!newsreader.com!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mailReferences:
<4289b235@newsgroups.borland.com> <v54k81lu0gb49sp76ri3ecjhb37gfbcatq@4ax.com> <428a1917$3@newsgroups.borland.com> <o2ck8151hqea0h667513g8lh0h8149n6aq@4ax.com> <428c2e72@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,de4107a245e3b3a8 X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <4289b235@newsgroups.borland.com> <v54k81lu0gb49sp76ri3ecjhb37gfbcatq@4ax.com> <428a1917$3@newsgroups.borland.com> <o2ck8151hqea0h667513g8lh0h8149n6aq@4ax.com> <428c2e72@newsgroups.borland.com> Subject: Re: "use" menu item in another app? Date: Thu, 19 May 2005 03:49:28 -0700 Lines: 83 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1409 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409 NNTP-Posting-Host: 68.69.17.41 Message-ID: <428c6ef5$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1116499701 68.69.17.41 (19 May 2005 03:48:21 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!border1.nntp.dca.giganews.com!nntp.giganews.com!feed5.newsreader.com!newsreader.com!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail