Re: How to write graphics to MS Windows clipboard
- Posted by DB James <larches at comcast.net> May 17, 2007
- 753 views
CChris wrote: > > DB James wrote: > > > > CChris wrote: > > > A way nicer version using a Pixmap: <SNIP> > > Thanks, that works like a charm. > > > > Do you think a bitmap-in-memory can be sent (with OLE or DDE or whatever) to > > be pasted into some other program? It isn't uncommon to see programs do > > this, such as IrfanView's send of an image that does not exist as a disk > > file > > to some other graphic editor. > > > > --Quark > > There is a dedicated Windows message for that, which is WM_COPYDATA. > The trick there is that the data you pass must be accessible from the > process you are sending this message to, so it must not contain private > pointers. Here is the reference for this message: > <quote> > WM_COPYDATA > wParam = (WPARAM) (HWND) hwnd; // handle of sending window > lParam = (LPARAM) (PCOPYDATASTRUCT) pcds; // pointer to structure with data > > > The WM_COPYDATA message is sent when an application passes data to another > application. > > Parameters > hwnd: > Identifies the window passing the data. > pcds: > Points to a COPYDATASTRUCT structure that contains the data to be passed. > > > Return Value > > If the receiving application processes this message, it should return TRUE; > otherwise, it should return FALSE. > > Remarks > > An application must use the SendMessage function to send this message, not > the PostMessage function. > The data being passed must not contain pointers or other references to > objects not accessible to the application receiving the data. > While this message is being sent, the referenced data must not be changed by > another thread of the sending process. > The receiving application should consider the data read-only. The pcds > parameter is valid only during the processing of the message. The receiving > application should not free the memory referenced by pcds. If the receiving > application must access the data after SendMessage returns, it must copy the > data into a local buffer. > </quote> > > The COPYDATASTRUCT referred here is very simple: > DWORD dwData -- single dword to pass: used only if lpData is 0 > DWORD cbData -- number of bytes pointed by lpData > PVOID lpData -- pointer to data > > The constant WM_COPYDATA is #004A. > The copying of data must take place inside the raw message handler you'll > set for WM_COPYDATA. > Google for the WM_COPYDATA for more articles on using this message for > interprocess communication. > > CChris Thanks for that information. After I sent my message I rooted around on the MS site and, among many other things, saw the SendMessage and WM_COPYDATA and wondered if that was a way to go. Now that I know you think so, I'll poke into it and do some testing. Hold not thy breath,though. Thanks again, --Quark