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