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#
  4. hDC problem

hDC problem

Scheduled Pinned Locked Moved C#
graphicsquestionhelp
2 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.
  • I Offline
    I Offline
    IceWater42
    wrote on last edited by
    #1

    I am trying to supply an hDC to a dll that needs a picture drawing area. I think i have 2 choices: 1. Use Form1 itself and just specify where the dll should draw the object. 2. Use a PictureBox1. I do not understand the structures well enough to know if i can: a. use the windowHandle of Form1 as an hDC. --- Does the windowHandle qualify as an hDC? If not, how can i get a suitable hDC for Form1? b. get the hDC of pictureBox1. --- I need the hDC in an event-handler (a Form1 keypress event) that does not have access to an e argument that allows: hdc = e.Graphics.GetHdc(); . All suggestions are welcome. Thank you.

    D 1 Reply Last reply
    0
    • I IceWater42

      I am trying to supply an hDC to a dll that needs a picture drawing area. I think i have 2 choices: 1. Use Form1 itself and just specify where the dll should draw the object. 2. Use a PictureBox1. I do not understand the structures well enough to know if i can: a. use the windowHandle of Form1 as an hDC. --- Does the windowHandle qualify as an hDC? If not, how can i get a suitable hDC for Form1? b. get the hDC of pictureBox1. --- I need the hDC in an event-handler (a Form1 keypress event) that does not have access to an e argument that allows: hdc = e.Graphics.GetHdc(); . All suggestions are welcome. Thank you.

      D Offline
      D Offline
      DigitalKing
      wrote on last edited by
      #2

      A window handle cannot be used as a hDC (device context). If you want to get the hDC for any control or form, use something similar to this:

      Graphics g = [this/pictureBox1].CreateGraphics();
      g.GetHdc(); //returns handle to device context

      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