On 20 Nov 2002 20:16:07 -0800, <vb.@127.0.0.1> wrote:
>
>thank for your quick reply again ,but there have no way to get ID of the selected
>button on toolbar by use of API? how does SPY++ check out the ID
>with codes? i just need the code!! i want to realize a program when mouse
>points to the button on toolbar,the caption of the corresponding button can
>be retrieved ,whether the button is in my application or in other one. for
>exmaple ,when mouse move to IE's toolbar,the corresponding button caption
>can be shown in my statusbar.this program have two key problem:
>(1) retrieve the buttonID with VB codes ;i need the VB codes
>(2)GPF will be aroused when tring to send message directly to toolbar in
>another application . This involves the problem in communicating with external
>process. ALLOC external memory can realize in window NT with API ¡°VirtualAllocX¡±
>,however in windowX is difficult¡£


Spy++ does it by hooking the WM_COMMAND message that's sent to the
toolbar's parent when a button is clicked. When the message is
received, the ID is delivered in wParam, but that's really irrelevant
for what you want to do, which BTW is ~not~ going to be particularly
easy <g>.
The only way to fetch the button info by position (i.e. mouse
position), is to obtain the toolbar hwnd and enumerate it's buttons by
their ~index~, which fortunately (unlike their ID) is always
zero-based. That's done by sending (SendMessage) the toolbar a
TB_GETBUTTON message. On return it populates a TBBUTTON data structure
(which you supply) with various bits of info, including it's position
RECT and text. However the BIG PROBLEM here is that Windows does not
marshall the data across processes for you with messages in the
WM_USER+ range (which of course includes TB_GETBUTTON). That means
it's up to you to manage a shared memory block and pass a pointer to
it along with the message. ...And just in case you're thinking it
can't get ~more~ difficult <g>, the exact technique for handling the
shared mem is different for NT/XP and Win9x. I'm pretty sure Brad
Martinez has a sample of handling cross-process SendMessage with
commoncontrols. I don't have the exact page url, but the site is:
http://www.mvps.org/btmtz/



-Tom
MVP - Visual Basic
(please post replies to the newsgroup)