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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. Problem with HDCs

Problem with HDCs

Scheduled Pinned Locked Moved Managed C++/CLI
graphicshelpcsharpc++json
1 Posts 1 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.
  • S Offline
    S Offline
    Serge Lobko Lobanovsky
    wrote on last edited by
    #1

    Hi, everyone! I'm a newbie in MC++ and Win32 API programming. I want to create a Bitmap object with an image of a Windows.Forms form. So far I've written the following code: Bitmap *De3DFormView::GetWindowBitmap(Form *pForm) { System::Drawing::Graphics *pGraph = Graphics::FromHwnd(pForm->Handle); int pSrc=pGraph->GetHdc().ToInt32(); HDC destDC; HBITMAP destBmp; DWORD err; destDC = CreateCompatibleDC((HDC)pSrc); destBmp = CreateCompatibleBitmap((HDC)pSrc, pForm->Width, pForm->Height); SelectObject(destDC, destBmp); SendMessage(HWND((int)pForm->Handle), WM_PRINT, WPARAM(destDC), PRF_CLIENT | PRF_NONCLIENT | PRF_CHILDREN | PRF_ERASEBKGND); Bitmap *pB = Image::FromHbitmap(destBmp); pGraph->ReleaseHdc(pSrc); pGraph->Dispose(); return pB; } When I run it, I get the following exception "ArgumentException" with message "hdc". Debugging shows that this error occurs after the "SendMessage" call. The other thing is that when I step through the "destDC = CreateCompatibleDC((HDC)pSrc);" line, I notice that destDC has "undefined value". Can you tell me what I am doing wrong? Regards, Serge (Logic Software)

    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