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. Need help on MemDC , Drawtext() coding

Need help on MemDC , Drawtext() coding

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
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.
  • E Offline
    E Offline
    econy
    wrote on last edited by
    #1

    Hi,with the following code, I marked 3 statements, with the following statements, nothing on the screen,I mean no "TEST,TEST" string and no black box.

    pStatic->GetWindowRect(&rect); //display nothing
    ScreenToClient(&rect); //display nothing

    while with

    /pStatic->GetClientRect(&rect); //Display well

    "TEST,TEST",black background box display well. Is anybody know the reason? Thanks

    void CStaticTextTstDlg::OnPaint()
    {
    if (IsIconic())
    {
    ...
    }
    else
    {
    CDC *pDC = GetDC();
    CBitmap memBmp;
    CBitmap *pBmpOld;
    CDC memDC;

    CStatic \*pStatic = (CStatic\*)GetDlgItem(IDC\_STATIC\_TXT1);
    pStatic->ModifyStyle(0, BS\_OWNERDRAW); 
    
    CRect rect;
    

    //pStatic->GetClientRect(&rect); //Display well
    pStatic->GetWindowRect(&rect); //display nothing
    ScreenToClient(&rect); //display nothing

    memBmp.CreateCompatibleBitmap(pDC,176,50);
    memDC.CreateCompatibleDC(NULL);
    pBmpOld = memDC.SelectObject(&memBmp);
    
    memDC.SetTextColor(RGB(0,230,0));
    memDC.SetBkMode(TRANSPARENT);
    memDC.FillSolidRect(rect.left,rect.top,176,50,RGB(0,0,0));
    
    memDC.DrawText(\_T("TEST   TEST"),-1,&rect,DT\_CENTER|DT\_VCENTER|DT\_SINGLELINE);
    

    CPaintDC dc(this);

    dc.BitBlt(137,107,176,50,&memDC,rect.left,rect.top,SRCCOPY);  
    	
    memDC.SelectObject(pBmpOld);
    memBmp.DeleteObject();
    memDC.DeleteDC();
    CDialog::OnPaint();
    

    }

    }

    Thanks

    P L 2 Replies Last reply
    0
    • E econy

      Hi,with the following code, I marked 3 statements, with the following statements, nothing on the screen,I mean no "TEST,TEST" string and no black box.

      pStatic->GetWindowRect(&rect); //display nothing
      ScreenToClient(&rect); //display nothing

      while with

      /pStatic->GetClientRect(&rect); //Display well

      "TEST,TEST",black background box display well. Is anybody know the reason? Thanks

      void CStaticTextTstDlg::OnPaint()
      {
      if (IsIconic())
      {
      ...
      }
      else
      {
      CDC *pDC = GetDC();
      CBitmap memBmp;
      CBitmap *pBmpOld;
      CDC memDC;

      CStatic \*pStatic = (CStatic\*)GetDlgItem(IDC\_STATIC\_TXT1);
      pStatic->ModifyStyle(0, BS\_OWNERDRAW); 
      
      CRect rect;
      

      //pStatic->GetClientRect(&rect); //Display well
      pStatic->GetWindowRect(&rect); //display nothing
      ScreenToClient(&rect); //display nothing

      memBmp.CreateCompatibleBitmap(pDC,176,50);
      memDC.CreateCompatibleDC(NULL);
      pBmpOld = memDC.SelectObject(&memBmp);
      
      memDC.SetTextColor(RGB(0,230,0));
      memDC.SetBkMode(TRANSPARENT);
      memDC.FillSolidRect(rect.left,rect.top,176,50,RGB(0,0,0));
      
      memDC.DrawText(\_T("TEST   TEST"),-1,&rect,DT\_CENTER|DT\_VCENTER|DT\_SINGLELINE);
      

      CPaintDC dc(this);

      dc.BitBlt(137,107,176,50,&memDC,rect.left,rect.top,SRCCOPY);  
      	
      memDC.SelectObject(pBmpOld);
      memBmp.DeleteObject();
      memDC.DeleteDC();
      CDialog::OnPaint();
      

      }

      }

      Thanks

      P Offline
      P Offline
      pasztorpisti
      wrote on last edited by
      #2

      Is it OK if I record it into mp3 format before mailing it to you? Maybe wav would be too large but today saving a few hundred megabytes is no big deal and it has a bit better quality...

      E 1 Reply Last reply
      0
      • P pasztorpisti

        Is it OK if I record it into mp3 format before mailing it to you? Maybe wav would be too large but today saving a few hundred megabytes is no big deal and it has a bit better quality...

        E Offline
        E Offline
        econy
        wrote on last edited by
        #3

        what?

        1 Reply Last reply
        0
        • E econy

          Hi,with the following code, I marked 3 statements, with the following statements, nothing on the screen,I mean no "TEST,TEST" string and no black box.

          pStatic->GetWindowRect(&rect); //display nothing
          ScreenToClient(&rect); //display nothing

          while with

          /pStatic->GetClientRect(&rect); //Display well

          "TEST,TEST",black background box display well. Is anybody know the reason? Thanks

          void CStaticTextTstDlg::OnPaint()
          {
          if (IsIconic())
          {
          ...
          }
          else
          {
          CDC *pDC = GetDC();
          CBitmap memBmp;
          CBitmap *pBmpOld;
          CDC memDC;

          CStatic \*pStatic = (CStatic\*)GetDlgItem(IDC\_STATIC\_TXT1);
          pStatic->ModifyStyle(0, BS\_OWNERDRAW); 
          
          CRect rect;
          

          //pStatic->GetClientRect(&rect); //Display well
          pStatic->GetWindowRect(&rect); //display nothing
          ScreenToClient(&rect); //display nothing

          memBmp.CreateCompatibleBitmap(pDC,176,50);
          memDC.CreateCompatibleDC(NULL);
          pBmpOld = memDC.SelectObject(&memBmp);
          
          memDC.SetTextColor(RGB(0,230,0));
          memDC.SetBkMode(TRANSPARENT);
          memDC.FillSolidRect(rect.left,rect.top,176,50,RGB(0,0,0));
          
          memDC.DrawText(\_T("TEST   TEST"),-1,&rect,DT\_CENTER|DT\_VCENTER|DT\_SINGLELINE);
          

          CPaintDC dc(this);

          dc.BitBlt(137,107,176,50,&memDC,rect.left,rect.top,SRCCOPY);  
          	
          memDC.SelectObject(pBmpOld);
          memBmp.DeleteObject();
          memDC.DeleteDC();
          CDialog::OnPaint();
          

          }

          }

          Thanks

          L Offline
          L Offline
          leon de boer
          wrote on last edited by
          #4

          GetClientRect returns the area of the drawable area inside the window. It will usually return something like 0,0,width,height in your rect structure GetWindowRect returns the co-ordinates of the Window itself relative to the upper left of the screen so they will be rather large. If you try to use GetWindowRect co-ordinates to draw on the window they will be way outside the right and bottom and the drawing wont be visible unless you drag the window right up to the top left off screen. You need to use GetClientRect co-ordinates to draw with. Looking at your code I am guessing this line is the problem if you have a position problem

          dc.BitBlt(137,107,176,50,&memDC,rect.left,rect.top,SRCCOPY);

          Are you sure that is right?

          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