Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Using HDC thats NULL

Using HDC thats NULL

Scheduled Pinned Locked Moved C / C++ / MFC
question
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dipuks
    wrote on last edited by
    #1

    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

    _ 1 Reply Last reply
    0
    • D dipuks

      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

      _ Offline
      _ Offline
      _Superman_
      wrote on last edited by
      #2

      That depends on the function you are using it in. For example, the CreateCompatibleDC function says that if HDC is NULL it uses the current screen as the reference. So if there is nothing mentioned about the behavior when HDC is NULL, 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++)

      D 1 Reply Last reply
      0
      • _ _Superman_

        That depends on the function you are using it in. For example, the CreateCompatibleDC function says that if HDC is NULL it uses the current screen as the reference. So if there is nothing mentioned about the behavior when HDC is NULL, 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++)

        D Offline
        D Offline
        dipuks
        wrote on last edited by
        #3

        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

        _ 1 Reply Last reply
        0
        • D dipuks

          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

          _ Offline
          _ Offline
          _Superman_
          wrote on last edited by
          #4

          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++)

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups