Home > Software engineering > MFC document view with more CtlColor cursor changed after change font
MFC document view with more CtlColor cursor changed after change font
Time:09-30
HBRUSH CMyCaretView: : CtlColor (CDC * pDC, UINT nCtlColor) { //TODO: any features in this change DC PDC - & gt; SetTextColor (RGB (255, 0, 0));//set the text foreground PDC - & gt; SetBkColor (RGB (255, 255, 255));//set the text background color PDC - & gt; SetBkMode (TRANSPARENT);//TRANSPARENT or OPAQUE CFont font; The font. CreatePointFont (120, L "tahoma"); PDC - & gt; SelectObject (& amp; The font); DeleteObject (font);//release resources
Return (HBRUSH) : : GetStockObject (WHITE_BRUSH); //TODO: if the parent should not call the handler, it returns a null brush Return NULL; }
After I use this code to change the font, font is changed, but the cursor is not normal, the cursor is always on the character, to solve
CodePudding user response:
CFont font; Instead of a class member, local in scope to a stack variable will be clean up
The class MyCaretView: { CFont font; };
HBRUSH CMyCaretView: : CtlColor (CDC * pDC, UINT nCtlColor) { //TODO: any features in this change DC PDC - & gt; SetTextColor (RGB (255, 0, 0));//set the text foreground PDC - & gt; SetBkColor (RGB (255, 255, 255));//set the text background color PDC - & gt; SetBkMode (TRANSPARENT);//TRANSPARENT or OPAQUE If (the font. M_hObject==NULL) The font. CreatePointFont (120, L "tahoma"); PDC - & gt; SelectObject (& amp; The font); //DeleteObject (font);//release resources
Return (HBRUSH) : : GetStockObject (WHITE_BRUSH); //TODO: if the parent should not call the handler, it returns a null brush Return NULL; }