Click here to Skip to main content
15,913,487 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionHDC Pin
kumar sanghvi16-Aug-09 22:43
kumar sanghvi16-Aug-09 22:43 
AnswerRe: HDC Pin
Cedric Moonen16-Aug-09 22:53
Cedric Moonen16-Aug-09 22:53 
AnswerRe: HDC Pin
Code-o-mat16-Aug-09 22:59
Code-o-mat16-Aug-09 22:59 
GeneralRe: HDC Pin
kumar sanghvi16-Aug-09 23:01
kumar sanghvi16-Aug-09 23:01 
GeneralRe: HDC Pin
Code-o-mat16-Aug-09 23:05
Code-o-mat16-Aug-09 23:05 
GeneralRe: HDC Pin
kumar sanghvi16-Aug-09 23:15
kumar sanghvi16-Aug-09 23:15 
GeneralRe: HDC Pin
Cedric Moonen16-Aug-09 23:21
Cedric Moonen16-Aug-09 23:21 
GeneralRe: HDC Pin
Code-o-mat16-Aug-09 23:44
Code-o-mat16-Aug-09 23:44 
Well, first of all, why you should do it is because the documentation[^] clearly states so:
This function returns the previously selected object of the specified type. An application should always replace a new object with the original, default object after it has finished drawing with the new object.


Aside of this, i believe if you don't do it, it can lead to resource leaks. For example, when you later on destroy your CFont object, it will try to call DeleteObject on the font resource, however, since this font is still selected into your DC, it will fail, but your CFont gets destroyed anyways, and since this CFont was your only "connection" to the actual font resource (your CFont's m_hFont member held the handle to this resource), you loose control over it, it will sit in memory, taking up space in Windows's resource pool, and never get freed up (unless it gets destroyed when your application quits, i believe the system now does that, it didn't used to in the old WIn95-98 times i think). There are probably many other possibilities how one can screw up things by forgetting to restore graphic tools, but i am not aware of them, never did any "research" about this topic really.

> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <

QuestionDialogBox Pin
kk.tvm16-Aug-09 22:26
kk.tvm16-Aug-09 22:26 
AnswerRe: DialogBox Pin
Code-o-mat16-Aug-09 22:30
Code-o-mat16-Aug-09 22:30 
GeneralRe: DialogBox Pin
kk.tvm16-Aug-09 22:32
kk.tvm16-Aug-09 22:32 
GeneralRe: DialogBox Pin
Code-o-mat16-Aug-09 22:49
Code-o-mat16-Aug-09 22:49 
GeneralRe: DialogBox Pin
kk.tvm16-Aug-09 23:00
kk.tvm16-Aug-09 23:00 
AnswerRe: DialogBox Pin
Rajesh R Subramanian16-Aug-09 22:36
professionalRajesh R Subramanian16-Aug-09 22:36 
GeneralRe: DialogBox Pin
kk.tvm16-Aug-09 22:58
kk.tvm16-Aug-09 22:58 
GeneralRe: DialogBox Pin
Rajesh R Subramanian16-Aug-09 23:08
professionalRajesh R Subramanian16-Aug-09 23:08 
AnswerRe: DialogBox Pin
Michael Schubert17-Aug-09 3:07
Michael Schubert17-Aug-09 3:07 
AnswerRe: DialogBox Pin
KarstenK17-Aug-09 3:48
mveKarstenK17-Aug-09 3:48 
QuestionMessage Closed Pin
16-Aug-09 21:21
coopoll16-Aug-09 21:21 
AnswerBlatant advertisement! Pin
Rajesh R Subramanian16-Aug-09 22:11
professionalRajesh R Subramanian16-Aug-09 22:11 
Questiondraw Visualization in custom directshow mp3 player Pin
raj157616-Aug-09 20:18
raj157616-Aug-09 20:18 
AnswerRe: draw Visualization in custom directshow mp3 player Pin
zhu_lin17-Aug-09 14:47
zhu_lin17-Aug-09 14:47 
GeneralRe: draw Visualization in custom directshow mp3 player Pin
raj157617-Aug-09 20:23
raj157617-Aug-09 20:23 
QuestionChange CFrameWnd background color Pin
Tran Vu Quan16-Aug-09 18:41
Tran Vu Quan16-Aug-09 18:41 
AnswerRe: Change CFrameWnd background color Pin
«_Superman_»16-Aug-09 19:45
professional«_Superman_»16-Aug-09 19:45 

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.