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. converting this code tot non-mfc

converting this code tot non-mfc

Scheduled Pinned Locked Moved C / C++ / MFC
c++comgraphicsquestion
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.
  • T Offline
    T Offline
    Tommy2k
    wrote on last edited by
    #1

    i tried to convert the code showed in this article (http://www.codeproject.com/bitmap/screencapture.asp) to non-mfc Standard Win32 code, with a bit of WTL. I came up with this: void CMainDlg::CopyWndToClipboard(HWND pWnd ) { CBitmap bitmap; CClientDC dc(pWnd); HDC memDC; RECT rect; memDC = ::CreateCompatibleDC(dc.m_hDC); ::GetWindowRect(pWnd,&rect); bitmap.CreateCompatibleBitmap(dc.m_hDC, rect.right-rect.left,rect.top-rect.bottom ); CBitmap* pOldBitmap= (CBitmap*)(HBITMAP)::SelectObject(memDC,&bitmap); ::BitBlt(memDC,0, 0, rect.right-rect.left,rect.top-rect.bottom, dc.m_hDC, 0, 0, SRCCOPY); ::OpenClipboard(::GetParent(pWnd)) ; EmptyClipboard() ; SetClipboardData (CF_BITMAP, (HBITMAP)bitmap ) ; CloseClipboard () ; SelectObject(memDC,pOldBitmap); bitmap.Detach(); } Which doesn't seem to work. All is does is throw some rubbish on the clipboard. Does somebody know a function to replace my code or does somebody know what i'm doing wrong? Thanks :-)

    U 1 Reply Last reply
    0
    • T Tommy2k

      i tried to convert the code showed in this article (http://www.codeproject.com/bitmap/screencapture.asp) to non-mfc Standard Win32 code, with a bit of WTL. I came up with this: void CMainDlg::CopyWndToClipboard(HWND pWnd ) { CBitmap bitmap; CClientDC dc(pWnd); HDC memDC; RECT rect; memDC = ::CreateCompatibleDC(dc.m_hDC); ::GetWindowRect(pWnd,&rect); bitmap.CreateCompatibleBitmap(dc.m_hDC, rect.right-rect.left,rect.top-rect.bottom ); CBitmap* pOldBitmap= (CBitmap*)(HBITMAP)::SelectObject(memDC,&bitmap); ::BitBlt(memDC,0, 0, rect.right-rect.left,rect.top-rect.bottom, dc.m_hDC, 0, 0, SRCCOPY); ::OpenClipboard(::GetParent(pWnd)) ; EmptyClipboard() ; SetClipboardData (CF_BITMAP, (HBITMAP)bitmap ) ; CloseClipboard () ; SelectObject(memDC,pOldBitmap); bitmap.Detach(); } Which doesn't seem to work. All is does is throw some rubbish on the clipboard. Does somebody know a function to replace my code or does somebody know what i'm doing wrong? Thanks :-)

      U Offline
      U Offline
      Uma Mahes
      wrote on last edited by
      #2

      The problem i think its because of Detaching bitmap at the end. Comment out that and try. May be you can move Bitmap variable to class variable. Hope this helps!!!

      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