Retrieve Toolbar Button Text

C

Christopher McKay

Does anyone know if it's possible to retrieve a string from a toolbar
button created in another process? I'm trying to write a program that
will enumerate all of the toolbar elements from another program in a
list. So far, using TB_GETBUTTONINFO, I am only able to retrieve the
index of the string, but not any information about where it is.

Thanks in advance.
 
J

John Phillips

What do you mean by the "index of the string"? I don't see anything like
that in the TBBUTTONINFO structure...
 
C

Christopher McKay

I'm sorry, I meant to say that I was using the TB_GETBUTTON message.
However, you just made me look at the TB_GETBUTTONINFO message. I did a
little test to see if I could retrieve the button text through the
pszText member of the TBBUTTONINFO structure and it seems to return a
NULL string.

Do I have to do something special to get the caption of a toolbar button?

Thanks.
 
J

John Phillips

Well, as with all structures of this type, you must provide the memory into
which the string will be copied. You then put the pointer to the memory
location in the pszText member, and ensure that the dwMask member includes
TBIF_TEXT. For example:

TCHAR szButtonText[1000];
TBBUTTONINFO info;
info.cbSize = sizeof(info);
info.dwMask = TBIF_TEXT;
info.pszText = szButtonText;
info.cchText = 1000;
SendMessage(hwndToolbar, TB_GETBUTTONINFO, iMyButtonIndex, (LPARAM)info);

And voila, text will appear in szButtonText.

However, since you are doing this from another process, you'll have to
ensure that the memory is accessible to the process being queried, by either
allocating it into the remote process' memory space with VirtualAllocEx() or
by using GlobalAlloc().
 
C

Christopher McKay

Thank you. That worked perfectly. Now, that I know about the
VirtualAllocEx routine the rest of my work should be made easier.

Thanks again.

Chris McKay

John said:
Well, as with all structures of this type, you must provide the memory into
which the string will be copied. You then put the pointer to the memory
location in the pszText member, and ensure that the dwMask member includes
TBIF_TEXT. For example:

TCHAR szButtonText[1000];
TBBUTTONINFO info;
info.cbSize = sizeof(info);
info.dwMask = TBIF_TEXT;
info.pszText = szButtonText;
info.cchText = 1000;
SendMessage(hwndToolbar, TB_GETBUTTONINFO, iMyButtonIndex, (LPARAM)info);

And voila, text will appear in szButtonText.

However, since you are doing this from another process, you'll have to
ensure that the memory is accessible to the process being queried, by either
allocating it into the remote process' memory space with VirtualAllocEx() or
by using GlobalAlloc().


--
John Phillips
MVP - Windows SDK


I'm sorry, I meant to say that I was using the TB_GETBUTTON message.
However, you just made me look at the TB_GETBUTTONINFO message. I did a
little test to see if I could retrieve the button text through the
pszText member of the TBBUTTONINFO structure and it seems to return a
NULL string.

Do I have to do something special to get the caption of a toolbar button?

Thanks.

John Phillips wrote:


like

message
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top