There's no way to make an invisible button that still functions. Imagine all of the ways that could be abused if it were possible! Not to mention how confusing to have invisible, yet functional, UI.
What Mark Ransom posted is exactly right: you need to get your existing control to respond to mouse click events, just like a button does. Then you can do whatever you want in response to clicks. You don't need a button just to be clickable.
You say that you have a "static text box", but I'm not really sure what that is. There are text boxes (which are not static), and then there are static controls (which can display text). I'm going to assume that you have the latter.
In that case, you don't need to handle the WM_LBUTTONDOWN
and WM_LBUTTONUP
messages directly, which would require that you subclass the control. Although that's probably the best approach design-wise (separation of responsibilities and all that), it's also a lot more trouble.
Instead, you can handle the click events from the parent's window procedure by setting the SS_NOTIFY
style for your static control (you can do this either in the Dialog Editor or in your call to CreateWindow
, depending on how you create the control). This causes the control to notify its parent in four cases: when it is clicked (STN_CLICKED
), when it is double-clicked (STN_DBLCLK
), when it is enabled (STN_ENABLE
), and when it is disabled (STN_DISABLE
).
So at the parent, you need to process WM_COMMAND
messages. The message you're looking for will have a HIWORD(wParam)
of STN_CLICKED
(indicating that a static control with the SS_NOTIFY
style has been clicked), a LOWORD(wParam)
corresponding to your static control's ID (set either in the Dialog Editor or specified as the hMenu
parameter in your call to CreateWindow
), and an lParam
containing a handle to your static control.