C++ Win32 How to Create a “toggle” Pushbutton

China☆狼群 提交于 2019-12-08 06:33:31

问题


I was originally thinking this would be extremely easy to do. Google searches returned results for everything but this.

I am trying to have a normal button that I can click, and it stays down, click again, and it rises back up.

I found one function that did what I wanted, but only worked if the button retained focus, click anywhere else and it rises again.

Button_SetState(GetDlgItem(hwnd, IDC_BTN_SLEEPCLICK), TRUE);

Is there any real way to do this? Or am I gonna need to do this kind of thing by hand?

Thanks.


回答1:


Create a check box, then set the "push like" property for that check box to true.




回答2:


You want a checkbox with BS_PUSHLIKE style. To toggle it programmatically, use Button_SetCheck




回答3:


The "staying down" and "rising back up" are a matter of how you draw the button.

You could create your own button class by using the Paint and Redraw methods.



来源:https://stackoverflow.com/questions/18369721/c-win32-how-to-create-a-toggle-pushbutton

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!