Click here to Skip to main content
15,915,160 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: BITMAP DISPLAY (NON MFC) Pin
Mark Salsbery7-Nov-06 6:17
Mark Salsbery7-Nov-06 6:17 
GeneralRe: BITMAP DISPLAY (NON MFC) Pin
WindowsProject7-Nov-06 19:06
WindowsProject7-Nov-06 19:06 
Questioncan anybody give me link of COM component to learn ease? Pin
baldha rakesh7-Nov-06 2:38
baldha rakesh7-Nov-06 2:38 
AnswerRe: can anybody give me link of COM component to learn ease? Pin
James R. Twine7-Nov-06 2:46
James R. Twine7-Nov-06 2:46 
QuestionWebcam in WMP Pin
ceejeeb7-Nov-06 2:27
ceejeeb7-Nov-06 2:27 
QuestionGDI+ for downlaod [modified] Pin
georgekjolly7-Nov-06 2:25
georgekjolly7-Nov-06 2:25 
AnswerRe: GDI+ for downlaod Pin
James R. Twine7-Nov-06 2:44
James R. Twine7-Nov-06 2:44 
Questioncan anybody explain me vtable and related things using this code snippet? Pin
baldha rakesh7-Nov-06 2:07
baldha rakesh7-Nov-06 2:07 
AnswerRe: can anybody explain me vtable and related things using this code snippet? Pin
Cedric Moonen7-Nov-06 2:21
Cedric Moonen7-Nov-06 2:21 
GeneralRe: can anybody explain me vtable and related things using this code snippet? Pin
baldha rakesh7-Nov-06 2:32
baldha rakesh7-Nov-06 2:32 
GeneralRe: can anybody explain me vtable and related things using this code snippet? Pin
Cedric Moonen7-Nov-06 3:20
Cedric Moonen7-Nov-06 3:20 
QuestionStatic variable into a MFC DLL class Pin
NorGUI7-Nov-06 2:03
NorGUI7-Nov-06 2:03 
AnswerRe: Static variable into a MFC DLL class Pin
Mark Salsbery7-Nov-06 6:24
Mark Salsbery7-Nov-06 6:24 
QuestionListCtrl on VC7 Pin
Get_Rakesh7-Nov-06 2:00
Get_Rakesh7-Nov-06 2:00 
AnswerRe: ListCtrl on VC7 Pin
prasad_som7-Nov-06 2:10
prasad_som7-Nov-06 2:10 
GeneralRe: ListCtrl on VC7 Pin
Get_Rakesh7-Nov-06 2:32
Get_Rakesh7-Nov-06 2:32 
QuestionRe: ListCtrl on VC7 Pin
prasad_som7-Nov-06 2:58
prasad_som7-Nov-06 2:58 
QuestionRe: ListCtrl on VC7 Pin
David Crow7-Nov-06 2:54
David Crow7-Nov-06 2:54 
QuestionWant to control a plugged in USB storage drive Pin
Biju Raman7-Nov-06 0:57
Biju Raman7-Nov-06 0:57 
AnswerRe: Want to control a plugged in USB storage drive Pin
Cedric Moonen7-Nov-06 1:35
Cedric Moonen7-Nov-06 1:35 
GeneralRe: Want to control a plugged in USB storage drive Pin
Biju Raman30-Nov-06 0:39
Biju Raman30-Nov-06 0:39 
QuestionDraw something on CreateDC()'s HDC Pin
Toubou7-Nov-06 0:30
Toubou7-Nov-06 0:30 
AnswerRe: Draw something on CreateDC()'s HDC Pin
Steve S7-Nov-06 0:58
Steve S7-Nov-06 0:58 
GeneralRe: Draw something on CreateDC()'s HDC Pin
Toubou7-Nov-06 1:30
Toubou7-Nov-06 1:30 
GeneralRe: Draw something on CreateDC()'s HDC Pin
Steve S7-Nov-06 2:45
Steve S7-Nov-06 2:45 
If you want to create a memory DC to keep the image in, you need to do something like this:

HDC wDC = ::GetDC(m_hWnd);
HDC memDC = ::CreateCompatibleDC(wDC);
HBITMAP hBMP = ::CreateCompatibleBitmap(wDC, 500,500); // or whichever size

hBmp = (HBITMAP)SelectObject(memDC, hBMP);
// Now do your drawing to your memory DC

// Now do your BitBlt

// And tidy up..
ReleaseDC(m_hWnd, wDC);

// To clean up memory DC
hBMP = (HBITMAP)SelectObject(memDC, hBMP); // Restore 1x1 bitmap
DeleteObject(hBMP);
DeleteDC(memDC);

The DC is a precious resource. Using CreateDC("DISPLAY",..) just to get a DC to create a screen-compatible DC when you have a window is wasteful, your code did not have a way to delete the DC you created in this way. If you don't clean up, you'll run out of DCs. Maybe not today, maybe not tomorrow, but soon.

You probably want to make the bitmap and memory dc handles member variables for the dialog object class.

HTH

Steve S
Developer for hire

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.