How to make a derived CEdit more perfect?
-
Hi all! I meet a problem when I derive a class from CEdit. I want to use a font specficed by myself in it. Now I use the font in the message function of WM_CTLCOLOR in parent window of CEdit. The new font can be shown in CEdit. But when I double click the left-button or drag the mouse to select more than one character, the position of caret is wrong. I don't know how to fix it. Plz help me! Thx! whiteclouds
There is some white cloud floating on the blue sky. That's the landscape I like.
-
Hi all! I meet a problem when I derive a class from CEdit. I want to use a font specficed by myself in it. Now I use the font in the message function of WM_CTLCOLOR in parent window of CEdit. The new font can be shown in CEdit. But when I double click the left-button or drag the mouse to select more than one character, the position of caret is wrong. I don't know how to fix it. Plz help me! Thx! whiteclouds
There is some white cloud floating on the blue sky. That's the landscape I like.
Have you already tried to set a font at the
WM_CREATE
reaction ? :)virtual void BeHappy() = 0;
-
Have you already tried to set a font at the
WM_CREATE
reaction ? :)virtual void BeHappy() = 0;
In WM_CREATE of CEdit? What difference between this and the action I take?
There is some white cloud floating on the blue sky. That's the landscape I like.
-
In WM_CREATE of CEdit? What difference between this and the action I take?
There is some white cloud floating on the blue sky. That's the landscape I like.
I think, the difference is the settings purpose: - your choice: the drawing (I guess, not in the edit mode) - my choice: system assignment (I guess, for drawing and editing as well) When you will want to use the class for a dialog item, you could place the setting in your
OnInitDialog()
function :) :...
m_cYourEdit.SetFont(..); // the font could be a static member in your class
...virtual void BeHappy() = 0;
-
I think, the difference is the settings purpose: - your choice: the drawing (I guess, not in the edit mode) - my choice: system assignment (I guess, for drawing and editing as well) When you will want to use the class for a dialog item, you could place the setting in your
OnInitDialog()
function :) :...
m_cYourEdit.SetFont(..); // the font could be a static member in your class
...virtual void BeHappy() = 0;
I had test your method. I add some codes into OnInitDialog() of parent window as below:
CColorEdit \*pEdit = (CColorEdit\*)GetDlgItem(IDC\_ED\_COLOR); if(pEdit) { CDC \*pDC = pEdit->GetDC(); if(pDC) { pDC->SelectObject(m\_fnt); } }
Then m_fnt can't be shown. And when I select some characters, the caret isn't in correct position. :(
There is some white cloud floating on the blue sky. That's the landscape I like.
-
I had test your method. I add some codes into OnInitDialog() of parent window as below:
CColorEdit \*pEdit = (CColorEdit\*)GetDlgItem(IDC\_ED\_COLOR); if(pEdit) { CDC \*pDC = pEdit->GetDC(); if(pDC) { pDC->SelectObject(m\_fnt); } }
Then m_fnt can't be shown. And when I select some characters, the caret isn't in correct position. :(
There is some white cloud floating on the blue sky. That's the landscape I like.
Try it :) :
CWnd* pcWnd = GetDlgItem(IDC_ED_COLOR);
if (pcWnd->GetSafeHwnd()) {
pcWnd->SetFont(&m_cFont); // Please note:
// the member CFont m_cFont
// has been already created !
}virtual void BeHappy() = 0;
-
Try it :) :
CWnd* pcWnd = GetDlgItem(IDC_ED_COLOR);
if (pcWnd->GetSafeHwnd()) {
pcWnd->SetFont(&m_cFont); // Please note:
// the member CFont m_cFont
// has been already created !
}virtual void BeHappy() = 0;
Thx for your reply! :) The position of caret is right now. But the font isn't be used in general. Only when I select the characters, the font can work. That means, when not select any character, the OnPaint() respond function in the derived class hadn't work. Because I draw the characters using specific font in it. Maybe I make a mistake, isn't it? Pls help me more! Thx!
There is some white cloud floating on the blue sky. That's the landscape I like.
-
Thx for your reply! :) The position of caret is right now. But the font isn't be used in general. Only when I select the characters, the font can work. That means, when not select any character, the OnPaint() respond function in the derived class hadn't work. Because I draw the characters using specific font in it. Maybe I make a mistake, isn't it? Pls help me more! Thx!
There is some white cloud floating on the blue sky. That's the landscape I like.
It works in my
OnInitDialog()
(I have not performed any font manipulations forWM_CTLCOLOR
) :) :static CFont cFont; // test only
cFont.CreatePointFont(120, _T("Arial"));CWnd* pcWnd = GetDlgItem(IDC_EDIT1);
if (pcWnd->GetSafeHwnd()) {
pcWnd->SetFont(&cFont);
}virtual void BeHappy() = 0;
-
It works in my
OnInitDialog()
(I have not performed any font manipulations forWM_CTLCOLOR
) :) :static CFont cFont; // test only
cFont.CreatePointFont(120, _T("Arial"));CWnd* pcWnd = GetDlgItem(IDC_EDIT1);
if (pcWnd->GetSafeHwnd()) {
pcWnd->SetFont(&cFont);
}virtual void BeHappy() = 0;
I had test the code you provided. That can work correct. And I know that the problem was generated by my own class derived from CEdit. Thank you, Eugen Podsypalnikov!
There is some white cloud floating on the blue sky. That's the landscape I like.