Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to get a dynamic created control's dc

How to get a dynamic created control's dc

Scheduled Pinned Locked Moved C / C++ / MFC
help
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    paraGOD
    wrote on last edited by
    #1

    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

    D 1 Reply Last reply
    0
    • P paraGOD

      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

      D Offline
      D Offline
      douglasjordan
      wrote on last edited by
      #2

      Can you use SetWindowText since its an edit window?

      P 1 Reply Last reply
      0
      • D douglasjordan

        Can you use SetWindowText since its an edit window?

        P Offline
        P Offline
        paraGOD
        wrote on last edited by
        #3

        Thank u , but this method can't draw the text in the edit contol.

        J 1 Reply Last reply
        0
        • P paraGOD

          Thank u , but this method can't draw the text in the edit contol.

          J Offline
          J Offline
          jhwurmbach
          wrote on last edited by
          #4

          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, then SetWindowText() is the way to tell the Edit-ctrl what text it has to draw. If you want something different, you should subclass CEdit 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.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups