Highlight button

In macOS you can force a button to highlight (read: fake it has been clicked on) with this declare

declare sub highlight lib “AppKit” selector “highlight:” (id As integer, h As Boolean)

Is there a way to do this within Windows?

MyPushButton.setfocus ?

https://msdn.microsoft.com/en-us/library/system.windows.controls.button(v=vs.110).aspx

Or use a BevelButton and change its color …

No, that doesn’t work to get it highlighted/pushed.

Its not really a done thing in windows UI. The Focus pretty much tells the user what they clicked on last. What do you aim to achieve with this, maybe we can think of a different method of achieving the same end result if you explain what you’re using it do denote?

https://msdn.microsoft.com/en-us/library/windows/desktop/bb761823(v=vs.85).aspx

Soft Declare Function SendMessage Lib "user32" Alias "SendMessageA" (hWnd As Integer, msg As Int32, wParam As Int32, lParam As Int32) As Integer Const BM_SETSTATE = &HF3 DIM moo As Integer = SendMessage(self.oink.Handle, BM_SETSTATE, 1, 0)

Edited my post to link to the correct article as well as adding code

Are you wanting to perform the “action” that would occur if the user pressed a particular button, but under control of the app?

If so, the answer is simple, requires no fancy declares, or message trapping

in the ACTION event of the button

Sub Action
 my_action_method()
End Sub

in a global Module

sub my_action_methd
... whatever code needs to be executed
end sub

where ever you want to “fake” the button press

my_action_method()

I think he wanted to change the look of the button…

DIM moo As Integer = SendMessage(self.oink.Handle, BM_SETSTATE, 1, 0) To highlight the button

DIM moo As Integer = SendMessage(self.oink.Handle, BM_SETSTATE, 0, 0) To remove the hilite

Thanks Shao ! That’s exactly what I needed. Works prefect.

This way I can control the state of the button when I use .drawinto to draw it into a canvas.

[quote=329543:@shao sean]https://msdn.microsoft.com/en-us/library/windows/desktop/bb761823(v=vs.85).aspx

Soft Declare Function SendMessage Lib "user32" Alias "SendMessageA" (hWnd As Integer, msg As Int32, wParam As Int32, lParam As Int32) As Integer Const BM_SETSTATE = &HF3 DIM moo As Integer = SendMessage(self.oink.Handle, BM_SETSTATE, 1, 0)[/quote]

Just asking. Where did you found &HF3 in the docs?

http://docs.embarcadero.com/products/rad_studio/delphiAndcpp2009/HelpUpdate2/EN/html/delphivclwin32/Messages_BM_SETSTATE.html

Oh now that is clever.

[quote=329599:@Tim Parnell]Oh now that is clever.
[/quote]

Yeah, I use this technique a lot for macOS.
When done correctly, you can fake native controls (and how they behave) into a Canvas or Listbox Cell. :slight_smile: