Auto-painted button control property self-painted attribute hold

xiaoxiao2021-03-06  56

Since the standard button control is monotonous on the style, we need to self-drawn to meet the standard button controls in many times to meet specific needs. In order to allow the button control to support the self-drawn, you need to set the button's BS_OWNERDRAW style. In general, we can set in PresubClassWindow: Class CxxxButton: Public CButton {...}; void cxxxButton :: PRESUBCLASSWINDOW () {modifystyle (0, BS_OWNERDRAW); CButton :: PRESUBCLASSWINDOW ();} This can override the DrawItem, so you can self-draw up the button in accordance with your own will. However, in a practical environment, we often find such bugs: We clearly have submitted a new button control, and the button is indeed self-drawn, which can meet the current needs. However, after some other operations, it was found that the button has changed to the standard button, and the self-painting attribute is not flying! This is not what we hope. So, how to keep the button after any operation, can you still keep your own style? Methods of resolving from MSDN: Intercepted BM_SETSTYLE. From MSDN, you can understand that when the application changes the button's style, the button will send the button message. We intercepted it before the button handled this message, and then modified the message parameters to meet the style of your own demand, so it is not afraid that the application is in the dark. Part of the code as follows: 1, message states: afx_msg LRESULT OnSetStyle (WPARAM wParam, LPARAM lParam); 2, mapping message: ON_MESSAGE (BM_SETSTYLE, OnSetStyle) 3, modified to achieve Style: LRESULT CxxxButton :: OnSetStyle (WPARAM wParam, LPARAM lParam) { return DefWindowProc (BM_SETSTYLE, (wParam & ~ BS_TYPEMASK) | BS_OWNERDRAW, lParam);} If the compiler does not define when prompted BS_TYPEMASK, you can add the macro manually: #ifndef BS_TYPEMASK # define BS_TYPEMASK SS_TYPEMASK # endif

转载请注明原文地址:https://www.9cbs.com/read-83489.html

New Post(0)