How to get a dynamic created control's dc
-
I need to create a control dynamicly and then get its DC to draw text and so on,just do as the following code: BOOL bCreate = m_hEdit.Create(WS_CHILD | WS_TABSTOP | WS_VISIBLE |ES_LEFT , rectEdit,this, IDC_COMBOTREE_EDIT); if (bCreate) { CWnd* pParent = GetParent (); CFont* pFont = pParent->GetFont (); m_hEdit.SetFont (pFont); } CDC *dc=m_hEdit.GetDC(); dc->DrawTextW(_T("ok"),-1,CRect(0,0,30,20),DT_LEFT); dc->SetBkColor(RGB(0,0,0)); m_hEdit.ReleaseDC(dc); but it doesn't work,I can never see the "ok" in the edit. Any help is appricited. Thanks! para
-
I need to create a control dynamicly and then get its DC to draw text and so on,just do as the following code: BOOL bCreate = m_hEdit.Create(WS_CHILD | WS_TABSTOP | WS_VISIBLE |ES_LEFT , rectEdit,this, IDC_COMBOTREE_EDIT); if (bCreate) { CWnd* pParent = GetParent (); CFont* pFont = pParent->GetFont (); m_hEdit.SetFont (pFont); } CDC *dc=m_hEdit.GetDC(); dc->DrawTextW(_T("ok"),-1,CRect(0,0,30,20),DT_LEFT); dc->SetBkColor(RGB(0,0,0)); m_hEdit.ReleaseDC(dc); but it doesn't work,I can never see the "ok" in the edit. Any help is appricited. Thanks! para
Can you use SetWindowText since its an edit window?
-
Can you use SetWindowText since its an edit window?
-
paraGOD wrote:
Thank u , but this method can't draw the text in the edit contol.
SetWindowText()
*can* draw the text in the edit-ctrl. In fact, its the only way to do it this side from owner-drawing the whole control. Your way paints the text at the exact place where the Edit-ctrl is located, triggering the edit-ctrls redraw. Your text gets overwritten. If what you want to acomplish is putting your Text into the Edit-ctrl, thenSetWindowText()
is the way to tell the Edit-ctrl what text it has to draw. If you want something different, you should subclassCEdit
and do it yourself, possibly delegating routine tasks to your baseclass CEdit.
"We trained hard, but it seemed that every time we were beginning to form up into teams we would be reorganised. I was to learn later in life that we tend to meet any new situation by reorganising: and a wonderful method it can be for creating the illusion of progress, while producing confusion, inefficiency and demoralisation." -- Caius Petronius, Roman Consul, 66 A.D.