Using HDC thats NULL
-
Hey Can anyone tell what will happen if i use a HDC thats NULL? For eg, HDC hDc = {0}; DrawTextEx(hDc, ........); I found that it will not throw an exception or something. So is it OK to use like this? Is there any MSDN documentation that talks about null HDC? Thanks in advance
-
Hey Can anyone tell what will happen if i use a HDC thats NULL? For eg, HDC hDc = {0}; DrawTextEx(hDc, ........); I found that it will not throw an exception or something. So is it OK to use like this? Is there any MSDN documentation that talks about null HDC? Thanks in advance
That depends on the function you are using it in. For example, the
CreateCompatibleDC
function says that ifHDC
isNULL
it uses the current screen as the reference. So if there is nothing mentioned about the behavior whenHDC
isNULL
, if sure the behavior is undefined and you should not do that.«_Superman_» I love work. It gives me something to do between weekends.
Microsoft MVP (Visual C++) -
That depends on the function you are using it in. For example, the
CreateCompatibleDC
function says that ifHDC
isNULL
it uses the current screen as the reference. So if there is nothing mentioned about the behavior whenHDC
isNULL
, if sure the behavior is undefined and you should not do that.«_Superman_» I love work. It gives me something to do between weekends.
Microsoft MVP (Visual C++)I am using HDC to write to a PDF printer. But the code is so entagled that, there's pieces of a text file writing code is also between that. So when there's a case that only a text file need to be written and no PDF, then i pass the HDC for PDF as NULL. So far in my testing i have seen that this works perfect. Is there any other function that will return me a valid HDC, but will not mess up any text file writing? Can i use CreateCompatibleDC to pass an HDC that will not mess up any other part of the application? But at the same time there will be a valid HDC rather than a NULL one. Thanks
-
I am using HDC to write to a PDF printer. But the code is so entagled that, there's pieces of a text file writing code is also between that. So when there's a case that only a text file need to be written and no PDF, then i pass the HDC for PDF as NULL. So far in my testing i have seen that this works perfect. Is there any other function that will return me a valid HDC, but will not mess up any text file writing? Can i use CreateCompatibleDC to pass an HDC that will not mess up any other part of the application? But at the same time there will be a valid HDC rather than a NULL one. Thanks
I think I have too little understanding to give a reliable answer. You will need to break up your question and isolate it from your domain if I need to understand.
«_Superman_» I love work. It gives me something to do between weekends.
Microsoft MVP (Visual C++)