1

I'm trying to disable or hide a button in another application

I get the hndl of button but when I call SendMessage

[DllImport("user32.dll", SetLastError = true)]
public static extern bool SendMessage(IntPtr hWnd, uint Msg, int wParam,
   bool lParam);

bool x = SendMessage(hndl, TB_HIDEBUTTON, 0, false);

nothing happens and x always returns false. I have also tried TB_DELETEBUTTON

1
  • Just to mention something here. Unless the program expresses an API to disable or hide that button, it's generally a very bad idea to mess with it. If you're lucky, the program will work okay, but if you're unlucky, it could crash... or worse. Commented Nov 27, 2010 at 4:14

3 Answers 3

3

You're sending the wrong message. Get a handle to the button, and call EnableWindow(hndl, FALSE); instead (or if you want to hide it, try ShowWindow(hndl, SW_HIDE);).

Sign up to request clarification or add additional context in comments.

1 Comment

What did you do to make it work? If my suggestion is correct, then can you please accept the answer?
0

TB_HIDEBUTTON is a window message that used to hide the button in a toolbar. If you want to do this, there is something wrong with your code, you must provide the button identifer as the third parameter of SendMessage, go to link text for reference.

Comments

0

Here's an example for Internet Explorer 11 (called from dll injected into iexplore):

HWND Suchleiste = FindWindowEx(GetActiveWindow(), NULL, NULL, "Navigationsleiste"); // WorkerW

Suchleiste = FindWindowEx(Suchleiste, NULL, "ReBarWindow32", NULL);

AddressbarRight = FindWindowEx(Suchleiste, NULL, "ControlBandClass", NULL);

AddressbarRight = FindWindowEx(AddressbarRight, NULL, "ToolbarWindow32", NULL);

TBBUTTON tButton;

SendMessage(AddressbarRight, TB_GETBUTTON, 0, (LPARAM)&tButton); // 0 == Home button

SendMessage(AddressbarRight, TB_HIDEBUTTON, tButton.idCommand, (LPARAM)MAKELONG(TRUE, 0)); // idCommand == 1

//SendMessage(AddressbarRight, TB_ENABLEBUTTON, tButton.idCommand, (LPARAM)MAKELONG(FALSE, 0)); // makes it inactive

Everybody says to use "DestroyWindow" or "EnableWindow" or whatever. These buttons are not windows, if I interpret "inspect" and "spyxx_amd64" output correctly.

Events:

https://learn.microsoft.com/en-us/windows/win32/controls/toolbar-control-reference

Functions:

https://learn.microsoft.com/en-us/windows/win32/api/commctrl

The ImageList_ functions don't work correctly though. Like I call "ImageList_Remove":

HIMAGELIST mlist=(HIMAGELIST)::SendMessage(AddressbarRight, TB_GETIMAGELIST, 0, 0);

ImageList_Remove(mlist, 0);

but the button is still visible when I hover over it, looks broken though. But the event:

SendMessage(AddressbarRight, TB_DELETEBUTTON, 0, 0);

removes the icon completely. forever. Besides, if you use events, you don't need to link to "comctl32".

Beware when deleting buttons! The index decreases, so you delete index 0, index 1 takes its index (becoming 0). So when deleting several buttons, go backwards, starting with the highest index.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.