1. How to write graphics to MS Windows clipboard
- Posted by Andrew Katz <Akatz712 at gmail.com> May 13, 2007
- 758 views
Does win32Lib support the writing of graphics to MS Windows clipboard? In the documentation, I saw some functions dealing with DIBs, and I saw some functions dealing with text to the clipboard. I am looking for a way for my program, which generates graphics, to copy it so that Paint can paste it. Andy Katz B.S. Computer Science, 1978 Rensselaer Polytechnic Institute (RPI)
2. Re: How to write graphics to MS Windows clipboard
- Posted by Andrew Katz <Akatz712 at gmail.com> May 15, 2007
- 757 views
Andrew Katz wrote: > > Does win32Lib support the writing of graphics to MS Windows clipboard? > > In the documentation, I saw some functions dealing with DIBs, and I saw some > functions dealing with text to the clipboard. > > I am looking for a way for my program, which generates graphics, to copy it > so that Paint can paste it. > > Andy Katz > > B.S. Computer Science, 1978 > Rensselaer Polytechnic Institute (RPI)
3. Re: How to write graphics to MS Windows clipboard
- Posted by Guillermo Bonvehi <gbonvehi at gmail.com> May 15, 2007
- 744 views
I made a mini library, it's not tested and allows you to only paste DIB and BITMAPs. -- File: clipboard.ew
include dll.e include msgbox.e constant -- Borrowed from win32lib (file w32user.ew) user32 = open_dll("user32.dll"), cOpenClipboard = define_c_func(user32,"OpenClipboard",{C_POINTER},C_INT), cCloseClipboard = define_c_func(user32,"CloseClipboard",{},C_INT), cEmptyClipboard = define_c_func(user32,"EmptyClipboard",{},C_INT), cSetClipboardData = define_c_func(user32,"SetClipboardData",{C_UINT,C_POINTER},C_POINTER) -- End borrow atom IsClipboardOpen -- Clipboard handle -- window must be a valid handle to a window, from win32lib, use getHWND(window) to get the real window handle -- hDIB must be a handle to a dib, as a example, the value returned by createDIB or loadBitmapFromFile in win32lib global procedure ClipboardPasteDIB(atom window, atom hDIB) IsClipboardOpen = c_func(cOpenClipboard, {window}) if not IsClipboardOpen then if message_box("Failed to open clipboard.","Error",MB_ICONERROR+MB_OK) then end if end if if c_func(cEmptyClipboard,{}) then end if if c_func(cSetClipboardData,{CF_DIB,hDIB}) != hDIB then if c_func(cSetClipboardData,{CF_BITMAP,hDIB}) != hDIB then if message_box("Failed to paste DIB in clipboard.","Error",MB_ICONERROR+MB_OK) then end if end if end if if c_func(cCloseClipboard,{}) then end if end procedure
-- File: test.exw
include win32lib.ew include clipboard.ew constant win = create( Window, "Test Clipboard", 0, Default, Default, 400, 400, 0 ), btn = create(PushButton, "Copy to clipboard", win, 1, 1, 40, 30, 0) atom hBit hBit = loadBitmapFromFile("test.bmp")} -- Code borrowed from a win32lib example -- create a bitmap, and display it atom hBitmap sequence pixels, pal -- the pixels data pixels = { { 0,0,0,0 }, -- scan line 1 { 0,1,1,0 }, -- scan line 2 { 0,1,1,0 }, -- scan line 3 { 0,0,0,0 } } -- scan line 4 -- the pal data (color tuples) pal = { { 255, 0, 0 }, -- color 0 is bright red { 0, 0, 255 } } -- color 1 is bright blue -- create the DIB hBitmap = createDIB( {pal, pixels} ) -- End borrow procedure onClickbtn(integer s, integer e, sequence p) ClipboardPasteDIB(getHWND(win),hBitmap) -- ClipboardPasteDIB(getHWND(win),hBit) -- Create a test.bmp file to test this end procedure setHandler(btn,w32HClick,routine_id("onClickbtn")) WinMain(win,Normal)
Any suggestions, questions, just do it :) Best regards, Guillermo Bonvehi
4. Re: How to write graphics to MS Windows clipboard
- Posted by CChris <christian.cuvier at agriculture.gouv.fr> May 15, 2007
- 783 views
Andrew Katz wrote: > > Does win32Lib support the writing of graphics to MS Windows clipboard? > > In the documentation, I saw some functions dealing with DIBs, and I saw some > functions dealing with text to the clipboard. > > I am looking for a way for my program, which generates graphics, to copy it > so that Paint can paste it. > > Andy Katz > > B.S. Computer Science, 1978 > Rensselaer Polytechnic Institute (RPI) I assume your graphics are displayed on some window.
include win32lib.ew -- first a simplified version of Guillermo's code constant cOpenClipboard = define_c_func(user32,"OpenClipboard",{C_POINTER},C_INT), cCloseClipboard = define_c_func(user32,"CloseClipboard",{},C_INT), cEmptyClipboard = define_c_func(user32,"EmptyClipboard",{},C_INT), cSetClipboardData = define_c_func(user32,"SetClipboardData",{C_UINT,C_POINTER},C_POINTER), xGetWindowDC = define_c_func(user32,"GetWindowDC",{C_POINTER},C_POINTER) -- hBmp must be a bitmap handle integer void global procedure bmpToClipboard(atom hBmp) if not c_func(cOpenClipboard, {NULL}) then void=message_box("Failed to open clipboard.","Error",MB_ICONERROR+MB_OK) return end if -- current thread now has exclusive access to clipboard c_proc(cEmptyClipboard,{}) if c_func(cSetClipboardData,{CF_BITMAP,hBmp}) != hBmp then void=message_box("Failed to copy bitmap to clipboard.","Error",MB_ICONERROR+MB_OK) end if c_proc(cCloseClipboard,{}) end procedure global procedure captureToClipboard(integer id,integer x,integer y,integer cx,integer cy,integer client) -- id is the surce window; copy rectangle at {x,y}, cx pixel wide and cy poxel high -- if client is true, x and y are client coordinates, else absolute window coordinates atom hDC,hMemDC,hOldBmp,hBmp,hWnd -- where's the pic? hWnd=getHandle(id) if client then hDC=getDC(id) else hDC=c_func(xGetWindowDC,{hWnd}) end if if not hDC then void=message_box("Not a valid window.","Error",MB_ICONERROR+MB_OK) return end if -- create a memory target DC hMemDC=w32Func(xCreateCompatiblzDC,{hDC}) if not hMemDC then void=message_box("Failed to create temporary bitmap.","Error",MB_ICONERROR+MB_OK) return end if -- create the bitmap we'll send to clipboard, with supplied dimensions. -- It will be written to using hMemDC. hBmp=w32Func(xCreateCompatibleBitmap,{hMemDC,cx,cy}) if not hBmp then void=message_box("Failed to create temporary bitmap.","Error",MB_ICONERROR+MB_OK) return end if -- use hMemDC o write to it. hOldBmp=w32Func(xSelectObject,{hMemDC,hBmp}) -- now copy source rectangle to it bitBlt(hMemDC,0,0,hDC,x,y,cx,cy,SrcCopy) -- deselect the bitmap so as to own it hBmp=w32Func(xSelectObject,{hMemDC,hOldBmp}) -- send bitmap to clipboard bmpToClipBoard(id,hBmp) -- now we no longer own it -- clean up deleteObject(hOldBmp) hMemDC=w32Func(xDeleteDC,{hMemDC}) hDC=w32Func(xReleaseDC,{hWnd,hDC}) end procedure
Didn't test it; part of cleanup may be redundant. CChris
5. Re: How to write graphics to MS Windows clipboard
- Posted by Andrew Katz <Akatz712 at gmail.com> May 15, 2007
- 767 views
- Last edited May 16, 2007
CChris wrote: > > > I assume your graphics are displayed on some window. > > Didn't test it; part of cleanup may be redundant. > > CChris
-- from my global code: constant ptx = 1 constant pty = 2 -- atom hDC,hMemDC,hOldBmp,hBmp atom void sequence DRAWINsize -- place my child window control DRAWIN in clipboard hDC=getDC(DRAWIN) -- create a memory target DC hMemDC=w32Func(xCreateCompatibleDC,{hDC}) if not hMemDC then void=message_box("Failed to create temporary bitmap.","Error",MB_ICONERROR+MB_OK) else -- create the bitmap we'll send to clipboard, with supplied dimensions. -- It will be written to using hMemDC. DRAWINsize = getCtlSize(DRAWIN) hBmp=w32Func(xCreateCompatibleBitmap,{hMemDC,DRAWINsize[ptx],DRAWINsize[pty]}) if not hBmp then void=message_box("Failed to create temporary bitmap.","Error",MB_ICONERROR+MB_OK) else -- use hMemDC o write to it. hOldBmp=w32Func(xSelectObject,{hMemDC,hBmp}) -- now copy source rectangle to it void=w32Func( xBitBlt, {hMemDC, 0, 0, DRAWINsize[ptx], DRAWINsize[pty], hDC, 0, 0, SrcCopy} ) -- send bitmap to clipboard if not w32Func(xOpenClipboard, {NULL}) then void=message_box("Failed to open clipboard.","Error",MB_ICONERROR+MB_OK) else -- current thread now has exclusive access to clipboard void=w32Func(xEmptyClipboard,{}) if w32Func(xSetClipboardData,{CF_BITMAP,hBmp}) != hBmp then void=message_box("Failed to copy bitmap to clipboard.","Error",MB_ICONERROR+MB_OK) end if w32Proc(xCloseClipboard,{}) -- now we no longer own it -- clean up -- releaseDC(hMemDC) Not sure how to clean up -- deselect the bitmap so as to own it hBmp=w32Func(xSelectObject,{hMemDC,hOldBmp}) releaseDC(DRAWIN) end if end if end if
I have made many small changes to CChris's code and tested it. And I have managed to get the drawing into Paint with Paste. Except that it only has 2 colors - white or black - and any color is being seen as black. So, where do we go from here? Andy Katz B.S. Computer Science, 1978 Rensselaer Polytechnic Institute (RPI)
6. Re: How to write graphics to MS Windows clipboard
- Posted by Andrew Katz <Akatz712 at gmail.com> May 16, 2007
- 779 views
Andrew Katz wrote: > > CChris wrote: > > > > > I assume your graphics are displayed on some window. > > > > Didn't test it; part of cleanup may be redundant. > > > > CChris > > > }}} <eucode> > -- from my global code: > constant ptx = 1 > constant pty = 2 > -- > > atom hDC,hMemDC,hOldBmp,hBmp > atom void > sequence DRAWINsize > > -- place my child window control DRAWIN in clipboard > > hDC=getDC(DRAWIN) > -- create a memory target DC > hMemDC=w32Func(xCreateCompatibleDC,{hDC}) > if not hMemDC then > void=message_box("Failed to create temporary > bitmap.","Error",MB_ICONERROR+MB_OK) > else > -- create the bitmap we'll send to clipboard, with supplied dimensions. > -- It will be written to using hMemDC. > DRAWINsize = getCtlSize(DRAWIN) > -- Wrong: > hBmp=w32Func(xCreateCompatibleBitmap,{hMemDC,DRAWINsize[ptx],DRAWINsize[pty]}) hBmp=w32Func(xCreateCompatibleBitmap,{hDC,DRAWINsize[ptx],DRAWINsize[pty]}) > if not hBmp then > void=message_box("Failed to create temporary > bitmap.","Error",MB_ICONERROR+MB_OK) > else > -- use hMemDC o write to it. > hOldBmp=w32Func(xSelectObject,{hMemDC,hBmp}) > -- now copy source rectangle to it > void=w32Func( xBitBlt, {hMemDC, 0, 0, DRAWINsize[ptx], DRAWINsize[pty], hDC, > 0, 0, SrcCopy} ) > -- send bitmap to clipboard > if not w32Func(xOpenClipboard, {NULL}) then > void=message_box("Failed to open clipboard.","Error",MB_ICONERROR+MB_OK) > else > -- current thread now has exclusive access to clipboard > void=w32Func(xEmptyClipboard,{}) > if w32Func(xSetClipboardData,{CF_BITMAP,hBmp}) != hBmp then > void=message_box("Failed to copy bitmap to > clipboard.","Error",MB_ICONERROR+MB_OK) > end if > w32Proc(xCloseClipboard,{}) > > -- now we no longer own it > -- clean up > -- releaseDC(hMemDC) Not sure how to clean up > -- deselect the bitmap so as to own it > hBmp=w32Func(xSelectObject,{hMemDC,hOldBmp}) > releaseDC(DRAWIN) > end if > end if > end if > </eucode> {{{ > > I have made many small changes to CChris's code and tested it. And I have > managed > to get the drawing into Paint with Paste. Except that it only has 2 colors - > white or black - and any color is being seen as black. So, where do we go from > here? > I found the problem: B.S. Computer Science, 1978 Rensselaer Polytechnic Institute (RPI)
7. Re: How to write graphics to MS Windows clipboard
- Posted by CChris <christian.cuvier at agriculture.gouv.fr> May 16, 2007
- 794 views
Andrew Katz wrote: > > Andrew Katz wrote: > > > > CChris wrote: > > > The following example code was tested and works for me, with colors and all:
include win32lib.ew -- first a simplified version of Guillermo's code constant xGetWindowDC = registerw32Function(user32,"GetWindowDC",{C_POINTER},C_POINTER) 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 -- current thread now has exclusive access to clipboard void=w32Func(xEmptyClipboard,{}) if w32Func(xSetClipboardData,{CF_BITMAP,hBmp}) != hBmp then void=message_box("Failed to copy bitmap to clipboard.","Error",MB_ICONERROR+MB_OK) end if -- release clipboard w32Proc(xCloseClipboard,{}) end procedure global procedure captureToClipboard(integer id,integer x,integer y,integer cx,integer cy,integer client) -- id is the surce window; copy rectangle at {x,y}, cx pixel wide and cy poxel high -- if client is true, x and y are client coordinates, else absolute window coordinates atom hDC,hBmp,hWnd,hMemDC,hOldBmp -- where's the pic? hWnd=getHandle(id) if client then hDC=getDC(id) else hDC=w32Func(xGetWindowDC,{hWnd}) end if if not hDC then void=message_box("Not a valid window.","Error",MB_ICONERROR+MB_OK) return end if -- create a target compatible DC hMemDC=w32Func(xCreateCompatibleDC,{hDC}) -- create the bitmap we'll send to clipboard, with supplied dimensions. -- It will be written to using hMemDC. hBmp=w32Func(xCreateCompatibleBitmap,{hDC,cx,cy}) if not hBmp then void=message_box("Failed to create temporary bitmap.","Error",MB_ICONERROR+MB_OK) return end if -- select bitmap into tempDC hOldBmp=w32Func(xSelectObject,{hMemDC,hBmp}) -- now copy source rectangle to it void=w32Func(xBitBlt,{hMemDC,0,0,cx,cy,hDC,x,y,SrcCopy}) -- send bitmap to clipboard bmpToClipboard(hBmp) -- now we no longer own it -- clean up hOldBmp=w32Func(xSelectObject,{hMemDC,hOldBmp}) deleteObject(hOldBmp) void=w32Func(xDeleteDC,{hMemDC}) if client then releaseDC(id) else hDC=w32Func(xReleaseDC,{hWnd,hDC}) end if end procedure 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,1) end procedure setHandler(b,w32HClick,routine_id("p")) WinMain(w,Normal)
Perhaps using a temporary Pixmap will cut down on raw API calls, I'll check that later. Using the currently undocumented replaceObject() procedure will help too. But at least this is a correct starting point. CChris
8. Re: How to write graphics to MS Windows clipboard
- Posted by CChris <christian.cuvier at agriculture.gouv.fr> May 16, 2007
- 749 views
Andrew Katz wrote: > > Andrew Katz wrote: > > > > CChris wrote: > > > > > > > > I assume your graphics are displayed on some window. > > > A way nicer version using a Pixmap:
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 -- current thread now has exclusive access to clipboard void=w32Func(xEmptyClipboard,{}) if w32Func(xSetClipboardData,{CF_BITMAP,hBmp}) != hBmp then void=message_box("Failed to copy bitmap to clipboard.","Error",MB_ICONERROR+MB_OK) end if w32Proc(xCloseClipboard,{}) end procedure global procedure captureToClipboard(integer id,integer x,integer y,integer cx,integer cy) -- id is the source window; copy rectangle at {x,y}, cx pixel wide and cy poxel high integer tmpx -- create a temporary area for the bitmap tmpx=create(Pixmap,"",0,0,0,cx,cy,0) -- copy pic bitBlt(tmpx,0,0,id,x,y,cx,cy,SrcCopy) -- send bitmap to clipboard bmpToClipboard(getHandle(tmpx)) -- clean up destroy(tmpx) end procedure constant xGetWindowDC = registerw32Function(user32,"GetWindowDC",{C_POINTER},C_POINTER) global procedure captureToClipboardEx(integer id,integer x,integer y,integer cx,integer cy,integer client) -- id is the surce window; copy rectangle at {x,y}, cx pixel wide and cy poxel high -- if client is true, x and y are client coordinates, else absolute window coordinates atom hDC,hWnd integer tmpx -- where's the pic? hWnd=getHandle(id) if client then hDC=getDC(id) else hDC=w32Func(xGetWindowDC,{hWnd}) end if if not hDC then void=message_box("Not a valid window.","Error",MB_ICONERROR+MB_OK) return end if tmpx=create(Pixmap,"",0,0,0,cx,cy,0) -- create a target compatible DC void=w32Func(xBitBlt,{getDC(tmpx),0,0,cx,cy,hDC,x,y,SrcCopy}) -- send bitmap to clipboard bmpToClipboard(getHandle(tmpx)) -- now we no longer own it -- clean up destroy(tmpx) if client then releaseDC(id) else hDC=w32Func(xReleaseDC,{hWnd,hDC}) end if end procedure 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)
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
9. Re: How to write graphics to MS Windows clipboard
- Posted by DB James <larches at comcast.net> May 17, 2007
- 749 views
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
10. Re: How to write graphics to MS Windows clipboard
- Posted by CChris <christian.cuvier at agriculture.gouv.fr> May 17, 2007
- 755 views
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
11. Re: How to write graphics to MS Windows clipboard
- Posted by DB James <larches at comcast.net> May 17, 2007
- 757 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