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. Why this is happening? -- Why this is capturing screen image instead of ClientDC

Why this is happening? -- Why this is capturing screen image instead of ClientDC

Scheduled Pinned Locked Moved C / C++ / MFC
graphicstutorialquestion
5 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.
  • J Offline
    J Offline
    JHAKAS
    wrote on last edited by
    #1

    Hi Well i am drawing on my clientDc and then i am writing to MemDC. This MemDc i am using for saving clientDc content to Image file. Class MyView { CDC MemDC; CBitmap m_MyBitmap; }; Class MyView:rawDiag() { CClientDC dc(this); **--------------- Drawing code goes here. With default mapping mode ---------------** m_MyBmp.DeleteObject (); MemDC.CreateCompatibleDC (&ClientDC); m_MyBmp.CreateCompatibleBitmap (&ClientDC, 860, 1100); CBitmap *OldBitmap = MemDC.SelectObject (&m_MyBmp); MemDC.PatBlt (0,0,860,1100,WHITENESS); if(MemDC.StretchBlt(50, 0, 860, 1100, &ClientDC, 0, 0, 860, 1100, SRCCOPY) == FALSE) AfxMessageBox("Failed to draw WFR diagram"); MemDC.SelectObject (OldBitmap); ClientDC.SetMapMode(MM_LOENGLISH); } **Function for saving dc to Bitmap file. This code i got from codeproject post** Class MyView::SaveDCtoBMP() { CString Filename; CFileDialog dlgFile (false,"*.*",NULL, OFN_HIDEREADONLY,"BMP Files: (*.bmp)|*.bmp||"); dlgFile.m_ofn.lpstrTitle = "Save As Image File"; int ret = dlgFile.DoModal(); if(IDOK == ret) { Filename = dlgFile.GetFileName (); // Create a temporary bitmap compatible with client DC CClientDC clientDC(::AfxGetMainWnd()); clientDC.SetMapMode (MM_LOENGLISH); CBitmap TmpBitmap; TmpBitmap.CreateCompatibleBitmap(&clientDC, 860, 1100); // Replace the bitmap in the DC, even though the DC is const. CDC& ncDC = const_cast(MemDC); ncDC.SelectObject(TmpBitmap); ncDC.SetMapMode (MM_LOENGLISH); // Save the bitmap that is now deselected from the DC. CDIBSectionLite dib; HBITMAP hnd = (HBITMAP)m_WfrBmp.GetSafeHandle (); dib.SetBitmap (hnd); dib.Save(Filename); // Select the bitmap in the DC again. ncDC.SelectObject(m_WfrBmp); // Done with the bitmap now delete that one. TmpBitmap.DeleteObject (); } } I get following image as bitmap file. I want only the clientdc content but it seems that it provides screen capture How to attach image file alongwith post? Leave your mark wherever you go

    J A 2 Replies Last reply
    0
    • J JHAKAS

      Hi Well i am drawing on my clientDc and then i am writing to MemDC. This MemDc i am using for saving clientDc content to Image file. Class MyView { CDC MemDC; CBitmap m_MyBitmap; }; Class MyView:rawDiag() { CClientDC dc(this); **--------------- Drawing code goes here. With default mapping mode ---------------** m_MyBmp.DeleteObject (); MemDC.CreateCompatibleDC (&ClientDC); m_MyBmp.CreateCompatibleBitmap (&ClientDC, 860, 1100); CBitmap *OldBitmap = MemDC.SelectObject (&m_MyBmp); MemDC.PatBlt (0,0,860,1100,WHITENESS); if(MemDC.StretchBlt(50, 0, 860, 1100, &ClientDC, 0, 0, 860, 1100, SRCCOPY) == FALSE) AfxMessageBox("Failed to draw WFR diagram"); MemDC.SelectObject (OldBitmap); ClientDC.SetMapMode(MM_LOENGLISH); } **Function for saving dc to Bitmap file. This code i got from codeproject post** Class MyView::SaveDCtoBMP() { CString Filename; CFileDialog dlgFile (false,"*.*",NULL, OFN_HIDEREADONLY,"BMP Files: (*.bmp)|*.bmp||"); dlgFile.m_ofn.lpstrTitle = "Save As Image File"; int ret = dlgFile.DoModal(); if(IDOK == ret) { Filename = dlgFile.GetFileName (); // Create a temporary bitmap compatible with client DC CClientDC clientDC(::AfxGetMainWnd()); clientDC.SetMapMode (MM_LOENGLISH); CBitmap TmpBitmap; TmpBitmap.CreateCompatibleBitmap(&clientDC, 860, 1100); // Replace the bitmap in the DC, even though the DC is const. CDC& ncDC = const_cast(MemDC); ncDC.SelectObject(TmpBitmap); ncDC.SetMapMode (MM_LOENGLISH); // Save the bitmap that is now deselected from the DC. CDIBSectionLite dib; HBITMAP hnd = (HBITMAP)m_WfrBmp.GetSafeHandle (); dib.SetBitmap (hnd); dib.Save(Filename); // Select the bitmap in the DC again. ncDC.SelectObject(m_WfrBmp); // Done with the bitmap now delete that one. TmpBitmap.DeleteObject (); } } I get following image as bitmap file. I want only the clientdc content but it seems that it provides screen capture How to attach image file alongwith post? Leave your mark wherever you go

      J Offline
      J Offline
      JHAKAS
      wrote on last edited by
      #2

      Is there any solution for this problem? why i am getting complete mainframe window while i am using teh clientDC I had even tried with ClientDc clientDC(this) still then.? Leave your mark wherever you go

      A 1 Reply Last reply
      0
      • J JHAKAS

        Is there any solution for this problem? why i am getting complete mainframe window while i am using teh clientDC I had even tried with ClientDc clientDC(this) still then.? Leave your mark wherever you go

        A Offline
        A Offline
        Anthony_Yio
        wrote on last edited by
        #3

        How about to use GetDCEx where you can be more specific in getting your DC. And by the way, why is it that your bitmap size is hard-coded (below)? Why not to use CWnd::GetClientRect(...) instead to get the size? CBitmap TmpBitmap; TmpBitmap.CreateCompatibleBitmap(&clientDC, 860, 1100); Sonork 100.41263:Anthony_Yio

        1 Reply Last reply
        0
        • J JHAKAS

          Hi Well i am drawing on my clientDc and then i am writing to MemDC. This MemDc i am using for saving clientDc content to Image file. Class MyView { CDC MemDC; CBitmap m_MyBitmap; }; Class MyView:rawDiag() { CClientDC dc(this); **--------------- Drawing code goes here. With default mapping mode ---------------** m_MyBmp.DeleteObject (); MemDC.CreateCompatibleDC (&ClientDC); m_MyBmp.CreateCompatibleBitmap (&ClientDC, 860, 1100); CBitmap *OldBitmap = MemDC.SelectObject (&m_MyBmp); MemDC.PatBlt (0,0,860,1100,WHITENESS); if(MemDC.StretchBlt(50, 0, 860, 1100, &ClientDC, 0, 0, 860, 1100, SRCCOPY) == FALSE) AfxMessageBox("Failed to draw WFR diagram"); MemDC.SelectObject (OldBitmap); ClientDC.SetMapMode(MM_LOENGLISH); } **Function for saving dc to Bitmap file. This code i got from codeproject post** Class MyView::SaveDCtoBMP() { CString Filename; CFileDialog dlgFile (false,"*.*",NULL, OFN_HIDEREADONLY,"BMP Files: (*.bmp)|*.bmp||"); dlgFile.m_ofn.lpstrTitle = "Save As Image File"; int ret = dlgFile.DoModal(); if(IDOK == ret) { Filename = dlgFile.GetFileName (); // Create a temporary bitmap compatible with client DC CClientDC clientDC(::AfxGetMainWnd()); clientDC.SetMapMode (MM_LOENGLISH); CBitmap TmpBitmap; TmpBitmap.CreateCompatibleBitmap(&clientDC, 860, 1100); // Replace the bitmap in the DC, even though the DC is const. CDC& ncDC = const_cast(MemDC); ncDC.SelectObject(TmpBitmap); ncDC.SetMapMode (MM_LOENGLISH); // Save the bitmap that is now deselected from the DC. CDIBSectionLite dib; HBITMAP hnd = (HBITMAP)m_WfrBmp.GetSafeHandle (); dib.SetBitmap (hnd); dib.Save(Filename); // Select the bitmap in the DC again. ncDC.SelectObject(m_WfrBmp); // Done with the bitmap now delete that one. TmpBitmap.DeleteObject (); } } I get following image as bitmap file. I want only the clientdc content but it seems that it provides screen capture How to attach image file alongwith post? Leave your mark wherever you go

          A Offline
          A Offline
          Anonymous
          wrote on last edited by
          #4

          Waht are you trying to do.. Are u calling the save bitmap. actually it seems to get the main window and draws the client area.. Tell me ur requirement. Han

          J 1 Reply Last reply
          0
          • A Anonymous

            Waht are you trying to do.. Are u calling the save bitmap. actually it seems to get the main window and draws the client area.. Tell me ur requirement. Han

            J Offline
            J Offline
            JHAKAS
            wrote on last edited by
            #5

            Please follow the following link for better idea http://www.codeguru.com/forum/showthread.php?s=d09323bd39f2dd0a942e34fe1155af42&threadid=296795 My main aim is to draw the content to view such that when user wants he can save the same to image file. Thats it? What i tried that i drawn completely into the ClientDc and at the end (see first post) i am making the memory device context and then storing teh content to the image file. Well but it seems that MemDC is taking the complete Mainwindow instead of the required clientdc. Help me in this regard Thanks in advance sandeep Leave your mark wherever you go

            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