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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Drawing on a Static control [modified]

Drawing on a Static control [modified]

Scheduled Pinned Locked Moved C / C++ / MFC
dotnetgraphicsquestion
2 Posts 2 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.
  • K Offline
    K Offline
    koumodaki
    wrote on last edited by
    #1

    I am working on a Win32 based GUI, which has a menu with a static area defined as CONTROL "",IDC_GRAPH,"Static",SS_GRAYFRAME,17,119,264,54 in the rc file. In my OnPaint(), the following code gets executed HWND hStatic = GetDlgItem(m_hWnd,IDC_GRAPH); //m_hWnd is CWnd handle RECT pRect; HDC hStaticDC= GetDC(hStatic ); GetClientRect(hStatic,&pRect); iCX = (pRect->right - pRect->left)/2; iCY = (pRect->bottom - pRect->top)/2; COLORREF bkColor = GetBkColor(hStaticDC); HPEN pen = CreatePen(PS_SOLID,8,bkColor); MoveToEx(hStaticDC,iCX+4,iCY,NULL); LineTo(hStaticDC,iCX1+4,iCY); The code compiles correctly. But the bkColor gets CLR_INVALID and MoveToEx and LineTo returns a zero value. Where have I gone wrong?

    modified on Thursday, December 11, 2008 4:20 AM

    C 1 Reply Last reply
    0
    • K koumodaki

      I am working on a Win32 based GUI, which has a menu with a static area defined as CONTROL "",IDC_GRAPH,"Static",SS_GRAYFRAME,17,119,264,54 in the rc file. In my OnPaint(), the following code gets executed HWND hStatic = GetDlgItem(m_hWnd,IDC_GRAPH); //m_hWnd is CWnd handle RECT pRect; HDC hStaticDC= GetDC(hStatic ); GetClientRect(hStatic,&pRect); iCX = (pRect->right - pRect->left)/2; iCY = (pRect->bottom - pRect->top)/2; COLORREF bkColor = GetBkColor(hStaticDC); HPEN pen = CreatePen(PS_SOLID,8,bkColor); MoveToEx(hStaticDC,iCX+4,iCY,NULL); LineTo(hStaticDC,iCX1+4,iCY); The code compiles correctly. But the bkColor gets CLR_INVALID and MoveToEx and LineTo returns a zero value. Where have I gone wrong?

      modified on Thursday, December 11, 2008 4:20 AM

      C Offline
      C Offline
      Code o mat
      wrote on last edited by
      #2

      Are you using the static as a placeholder on your dialog where your drawing is suposed to go? If so, why don't you simply acquire its position and then draw into the dialog's DC? And make your static non-visible? I think it's a simpler method than trying to draw onto a static from another windows OnPaint... anyhows, are you sure you get a correct DC for that static? And why do you MoveToEx and LineTo the same coord? (*iCX+4,iCY), if you want to make a point use SetPixel or SetPixelV instead. Am not sure if 0 length lines are drawn as a point by GDI or not though.

      > The problem with computers is that they do what you tell them to do and not what you want them to do. <

      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