views:

48

answers:

2

I have a program, where I need to disable a specific button on toolbar. "Save" on the Adobe Reader control.

I know it's possible to hide a control by locating its window handle.

Using Spy++, I found the required toolbar. It has buttons and text fields. Although text fields are child windows of the toolbar, buttons aren't windows at all!

How to proceed in that case? Is there a way to hide such buttons? I tried locating them using relative position from the toolbar and displaying something on top, but it's sections can be repositioned manually by user.

+1  A: 

You should send a TB_ENABLEBUTTON to the toolbar

Lior Kogan
Lior, thanks for your answer. I can see wParam is a "Command identifier", where can I find it?
Sphynx
The value is assigned when adding the button to the toolbar. To discover this value, spy for toolbar notifications (NM_CLICK i presume).
Lior Kogan
See http://msdn.microsoft.com/en-us/library/bb760435(v=VS.85).aspx for a list of all toolbar notifications.
Lior Kogan
@Sphynx: see my answer
Cătălin Pitiș
+1  A: 

Supposing you have the hwindow of the toolbar, you could iterate through all the buttons of the toolbar (position based, use TB_BUTTONCOUNT for number of buttons), use TB_GETBUTTON message to get the current command ID, then TB_GETBUTTONTEXT (with the command id) to get the caption of the button. Then use TB_ENABLEBUTTON for the button with the caption you search.

Cătălin Pitiș
The buttons have icons and no captions. Maybe I can find it by the number? And how to iterate through buttons of the toolbar? Which function should I use?
Sphynx
It doesn't work, I tried Dim count As IntPtr = SendMessage(toolbarHandle, TB_BUTTONCOUNT, IntPtr.Zero, IntPtr.Zero) with a handler obtained from Spy++, and the result is always "Invalid Windows Handle"
Sphynx