Click here to Skip to main content
15,881,173 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: problem with sprintf_s() on win 7 Pin
Member 935377613-Nov-12 22:48
Member 935377613-Nov-12 22:48 
Questionhow to get motherboard SN Pin
buffay1-Nov-12 19:42
buffay1-Nov-12 19:42 
AnswerRe: how to get motherboard SN Pin
Richard MacCutchan2-Nov-12 0:37
mveRichard MacCutchan2-Nov-12 0:37 
QuestionChart Control Pin
Tom Paronis1-Nov-12 6:04
Tom Paronis1-Nov-12 6:04 
AnswerRe: Chart Control Pin
Richard MacCutchan1-Nov-12 6:48
mveRichard MacCutchan1-Nov-12 6:48 
GeneralRe: Chart Control Pin
Tom Paronis1-Nov-12 7:34
Tom Paronis1-Nov-12 7:34 
QuestionCopy CDC Pin
_Flaviu31-Oct-12 22:29
_Flaviu31-Oct-12 22:29 
AnswerRe: Copy CDC Pin
Santhosh G_1-Nov-12 1:38
Santhosh G_1-Nov-12 1:38 
C++
    CSize sizeDoc = pDoc->GetBitmapSize();
CDC MemDC, TempDC;
MemDC.CreateCompatibleDC(pDC);
TempDC.CreateCompatibleDC(pDC);
CBitmap* pOldBitmap = MemDC.SelectObject(&pDoc->GetBitmap());
pDC->SetStretchBltMode(HALFTONE);
TempDC.StretchBlt(0, 0, sizeLog.cx, sizeLog.cy, &MemDC, 0, 0, sizeDoc.cx, sizeDoc.cy, SRCCOPY);
pDC->StretchBlt(0, 0, sizeLog.cx, sizeLog.cy, &TempDC, 0, 0, sizeDoc.cx, sizeDoc.cy, SRCCOPY);
pDC->SelectObject(pOldBitmap);


When a memory device context is created, GDI automatically selects a 1-by-1 monochrome stock bitmap for it. GDI output functions can be used with a memory device context only if a bitmap has been created and selected into that context.

Here TempDC is not attached to any Bitmap, and therefore GDI function StretchBlt will not draw to TempDC.
You have to create a Bitmap compatible to your DC, and attach the same to temperory memory DC.
C++
    CSize sizeDoc = pDoc->GetBitmapSize();
CDC MemDC, TempDC;
MemDC.CreateCompatibleDC(pDC);
TempDC.CreateCompatibleDC(pDC);
CBitmap* pOldBitmap = MemDC.SelectObject(&pDoc->GetBitmap());
pDC->SetStretchBltMode(HALFTONE);

    // Creating Bitmap for Memory DC.
    HDC hdc = ::GetDC(NULL);
    HBITMAP hScreenBmp = CreateCompatibleBitmap( hdc , nWidth, m_nImageHeight );

    // Attach temporary bitmap with DC.
    TempDC.SelectObject( hScreenBmp );

    // Draw bitmap to Temporary MemDC.
TempDC.StretchBlt(0, 0, sizeLog.cx, sizeLog.cy, &MemDC, 0, 0, sizeDoc.cx, sizeDoc.cy, SRCCOPY);
pDC->StretchBlt(0, 0, sizeLog.cx, sizeLog.cy, &TempDC, 0, 0, sizeDoc.cx, sizeDoc.cy, SRCCOPY);
pDC->SelectObject(pOldBitmap);

GeneralRe: Copy CDC Pin
_Flaviu1-Nov-12 2:20
_Flaviu1-Nov-12 2:20 
QuestionStrange memory leak Pin
miniman0631-Oct-12 21:58
miniman0631-Oct-12 21:58 
AnswerRe: Strange memory leak Pin
Sivaraman Dhamodharan31-Oct-12 22:45
Sivaraman Dhamodharan31-Oct-12 22:45 
GeneralRe: Strange memory leak Pin
miniman0631-Oct-12 23:10
miniman0631-Oct-12 23:10 
AnswerRe: Strange memory leak Pin
Rolf Kristensen31-Oct-12 22:47
Rolf Kristensen31-Oct-12 22:47 
GeneralRe: Strange memory leak Pin
miniman0631-Oct-12 23:11
miniman0631-Oct-12 23:11 
AnswerRe: Strange memory leak Pin
Santhosh G_31-Oct-12 23:22
Santhosh G_31-Oct-12 23:22 
GeneralRe: Strange memory leak Pin
miniman0631-Oct-12 23:31
miniman0631-Oct-12 23:31 
AnswerRe: Strange memory leak Pin
Jochen Arndt31-Oct-12 23:35
professionalJochen Arndt31-Oct-12 23:35 
GeneralRe: Strange memory leak Pin
miniman061-Nov-12 0:09
miniman061-Nov-12 0:09 
GeneralRe: Strange memory leak Pin
Jochen Arndt1-Nov-12 0:29
professionalJochen Arndt1-Nov-12 0:29 
AnswerRe: Strange memory leak Pin
BCN-1631-Nov-12 16:01
BCN-1631-Nov-12 16:01 
Questionabout accessing PDF file, compile error. Pin
BCN-16331-Oct-12 15:18
BCN-16331-Oct-12 15:18 
AnswerRe: about accessing PDF file, compile error. Pin
Richard MacCutchan31-Oct-12 23:41
mveRichard MacCutchan31-Oct-12 23:41 
GeneralRe: about accessing PDF file, compile error. Pin
BCN-1631-Nov-12 15:56
BCN-1631-Nov-12 15:56 
GeneralRe: about accessing PDF file, compile error. Pin
Richard MacCutchan1-Nov-12 22:35
mveRichard MacCutchan1-Nov-12 22:35 
GeneralRe: about accessing PDF file, compile error. Pin
BCN-1634-Nov-12 13:39
BCN-1634-Nov-12 13:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.