Re: How to write graphics to MS Windows clipboard

new topic     » goto parent     » topic index » view thread      » older message » newer message

DB James wrote:
> 
> CChris wrote:
> > A way nicer version using a Pixmap:
> > }}}
<eucode>
> > include win32lib.ew
> > 
> > integer void
> > global procedure bmpToClipboard(atom hBmp) 
> > -- hBmp must be a bitmap handle
> >     if not w32Func(xOpenClipboard, {NULL}) then
> >         void=message_box("Failed to open
> >         clipboard.","Error",MB_ICONERROR+MB_OK)
> >         return
> > 	end if
> <SNIP>
> > constant
> > w=create(Window,"test",0,50,50,300,300,0)
> > ,b=create(Button,"push",w,20,200,60,30,0)
> > 
> > procedure q(integer self,integer event,sequence data)
> > setWindowBackColor(w,Green)
> > setPenColor(w,Red)
> > drawRectangle(w,w32True,100,100,200,200)
> > end procedure
> > setHandler(w,w32HActivate,routine_id("q"))
> > 
> > procedure p(integer self,integer event,sequence data)
> > captureToClipboard(w,30,80,100,120)
> > end procedure
> > setHandler(b,w32HClick,routine_id("p"))
> > 
> > WinMain(w,Normal)
> > </eucode>
{{{

> > Both routine work and the clipboard holds he expected value.
> > 
> > I'll have to add support for full window DCs in the library so that the
> > distinction wbetween the non -Ex and -Ex routines is no longer necessary.
> > 
> > Also, I had noticed earlier, and forgotten, that if you call
> > registerw32function() on some dll routine, then define_c_func() returns -1
> > if invoked on the same routine thereafter. I'll have to investigate.
> > Derek, any idea?
> > 
> > CChris
> 
> 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

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu