![]() |
(RESOLVED) Copy to clipboard |
Post Reply
|
| Author | |
markr
Senior Member
Joined: 01 August 2004 Status: Offline Points: 443 |
Post Options
Thanks(0)
Quote Reply
Topic: (RESOLVED) Copy to clipboardPosted: 07 April 2011 at 11:15am |
|
Hello,
I need to copy a chart image (rendered via CXTPChartControl) to the Windows clipboard. I tried deriving from CXTPChartControl and adding a method that copies the contents of the CBitmap cache object (m_bmpCache member) to the clipboard, but it does not work. Here's what I'm trying to do (stripped of error checking for brevity): VERIFY(OpenClipboard()); VERIFY(EmptyClipboard()); VERIFY(SetClipboardData(CF_BITMAP, m_bmpCache.GetSafeHandle())); CloseClipboard(); None of these function calls fail, but clipboard contents are not valid. Perhaps CBitmap cache object is not safe to use for this purpose? |
|
![]() |
|
Oleg
Senior Member
Joined: 21 May 2003 Location: United States Status: Offline Points: 11234 |
Post Options
Thanks(0)
Quote Reply
Posted: 07 April 2011 at 12:05pm |
|
You better create copy of bitmap because you should "detach" it to clipboard:
VERIFY(SetClipboardData(CF_BITMAP, bmpCopy.Detach()));
|
|
|
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS |
|
![]() |
|
markr
Senior Member
Joined: 01 August 2004 Status: Offline Points: 443 |
Post Options
Thanks(0)
Quote Reply
Posted: 07 April 2011 at 1:36pm |
|
Thanks for the tip, Oleg. Working fine now. :-)
|
|
![]() |
|
znakeeye
Senior Member
Joined: 26 July 2006 Status: Offline Points: 1672 |
Post Options
Thanks(0)
Quote Reply
Posted: 17 April 2011 at 4:27pm |
|
I keep getting a black image. What am I doing wrong?
This is my copy-function: BOOL CopyBitmap(CBitmap &bmpDest, CBitmap &bmpSource) { bmpDest.DeleteObject(); BITMAP bm; bmpSource.GetBitmap(&bm); CDC sourceDC; sourceDC.CreateCompatibleDC(NULL); bmpDest.CreateCompatibleBitmap(&sourceDC, bm.bmWidth, bm.bmHeight); CDC destDC; destDC.CreateCompatibleDC(NULL); CBitmap *pOldSourceBitmap = sourceDC.SelectObject(&bmpSource); CBitmap *pOldDestBitmap = destDC.SelectObject(&bmpDest); destDC.BitBlt(0, 0, bm.bmWidth, bm.bmHeight, &sourceDC, 0, 0, SRCCOPY); sourceDC.SelectObject(pOldSourceBitmap); destDC.SelectObject(pOldDestBitmap); return (bmpDest.m_hObject != NULL); } |
|
|
PokerMemento - http://www.pokermemento.com/
|
|
![]() |
|
markr
Senior Member
Joined: 01 August 2004 Status: Offline Points: 443 |
Post Options
Thanks(0)
Quote Reply
Posted: 18 April 2011 at 9:56am |
|
Hi,
Here's the code I'm currently using for this purpose. void CDFDChartControl::CopyToClipboard() { BITMAP bmpInfo; m_bmpCache.GetBitmap(&bmpInfo); CBitmap bitmap; CClientDC dcClient(AfxGetMainWnd()); CDC dcDest; dcDest.CreateCompatibleDC(&dcClient); CDC dcSource; dcSource.CreateCompatibleDC(&dcClient); HBITMAP oldhBitmap = (HBITMAP)dcSource.SelectObject((HBITMAP)m_bmpCache); bitmap.CreateCompatibleBitmap(&dcClient, bmpInfo.bmWidth, bmpInfo.bmHeight); CBitmap* pOldBitmap = dcDest.SelectObject(&bitmap); ::BitBlt(dcDest, 0, 0, bmpInfo.bmWidth, bmpInfo.bmHeight, dcSource, 0, 0, SRCCOPY); dcSource.SelectObject(oldhBitmap); dcDest.SelectObject(pOldBitmap); VERIFY(::OpenClipboard(AfxGetMainWnd()->m_hWnd)); VERIFY(::EmptyClipboard()); VERIFY(::SetClipboardData(CF_BITMAP, bitmap.Detach())); ::CloseClipboard(); } |
|
![]() |
|
znakeeye
Senior Member
Joined: 26 July 2006 Status: Offline Points: 1672 |
Post Options
Thanks(0)
Quote Reply
Posted: 20 April 2011 at 1:53am |
|
Thanks!
|
|
|
PokerMemento - http://www.pokermemento.com/
|
|
![]() |
|
znakeeye
Senior Member
Joined: 26 July 2006 Status: Offline Points: 1672 |
Post Options
Thanks(0)
Quote Reply
Posted: 22 May 2011 at 4:28pm |
|
When pasting the image into Paint, it tells me:
--------------------------- Paint --------------------------- The information on the Clipboard can't be inserted into Paint. --------------------------- OK --------------------------- What?!
|
|
|
PokerMemento - http://www.pokermemento.com/
|
|
![]() |
|
markr
Senior Member
Joined: 01 August 2004 Status: Offline Points: 443 |
Post Options
Thanks(0)
Quote Reply
Posted: 23 May 2011 at 3:50pm |
|
> The information on the Clipboard can't be inserted into Paint
You're using the code I shared with you? Not sure what's going on there. I'm using that exact code in a production release without any problems. |
|
![]() |
|
znakeeye
Senior Member
Joined: 26 July 2006 Status: Offline Points: 1672 |
Post Options
Thanks(0)
Quote Reply
Posted: 13 June 2011 at 1:48am |
|
It seems CClientDC is the key. This does not work:
hdc = ::GetDC(m_hWnd); // Tried NULL too... // Create compatible dc What's the difference between GetDC and CClientDC?
|
|
|
PokerMemento - http://www.pokermemento.com/
|
|
![]() |
|
Post Reply
|
|
|
Tweet
|
| Forum Jump | Forum Permissions ![]() You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |