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;
}

CodePudding user response:

reference 1st floor zgl7903 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;
}



I just tried to the font into a member variable, but doesn't work, the cursor is in character! How be to return a responsibility excuse me?

CodePudding user response:

Void CDisDsp568View: : OnInitialUpdate ()
{
CEditView: : OnInitialUpdate ();
//TODO: Add your specialized code here and/or call the base class
the SetFont (m_pFont);//Fixed


Not in CtlColor

CodePudding user response:

The
reference 3 floor schlafenhamster response:
void CDisDsp568View: : OnInitialUpdate ()
{
CEditView: : OnInitialUpdate ();
//TODO: Add your specialized code here and/or call the base class
the SetFont (m_pFont);//Fixed


Not in CtlColor


Use this method to solve the problem, thank you!

CodePudding user response:

Ladies and gentlemen, I want to ask, how to implement like vs editor in a view to change certain strings the function of the font color, thank you!

CodePudding user response:

In RichEditVire view

CodePudding user response:

I am using is CEditView, could you tell the specific steps?
Is needed in the virtual functions that news, or your own?

CodePudding user response:

CEditView change a single character color difficult
CRichEditView, but must be familiar with

CodePudding user response:

Another problem, dynamically generated menu, I created four pop-up menu, each pop-up menu under several sub menu, the four sub menu under the popup menu ids begins WM_USER + 200, generated a total of 23 menu, but the last two are grey??????? This is what circumstance?
Which can help to solve, thank you!
  • Related