copy a bmp to the clipboard using VA ST

VA Smalltalk is a "100% VisualAge compatible" IDE that includes the original VisualAge technology and the popular VA Assist and WidgetKit add-ons.

Moderators: Eric Clayberg, wembley, tc, Diane Engles, solveig

copy a bmp to the clipboard using VA ST

Postby xabialonso2 » Sun Apr 10, 2011 10:49 pm

Hi all
Does anybody out there know where I am going wrong with this code?
I am shielded from where it is going wrong as it goes off to the OS.
I am trying to copy a GUI to the clipboard, but when I run OSClipboard getBitmap after executing this code below I always get nil.



| theDisplay widget rootWindow anExtent hDC hBitmapDC hBitmap hOldBitmap |
widget := self primaryWidget.
rootWindow := widget window.
anExtent :=rootWindow extent.
hDC := rootWindow getDC.
hBitmapDC := hDC createCompatibleDC.
hBitmap := hDC createCompatibleBitmap: widget width nHeight: widget height.
hOldBitmap := hBitmapDC selectObject: hBitmap.
theDisplay := rootWindow display.
theDisplay openClipboardForCopy.
theDisplay setClipboardData: hBitmap format: CfBitmap.


If I do a standard Ctrl + c and run OSClipboard getBitmap I get OSHbitmap {1980046955} as an example.
I am on version 6.0.2 of VA Smalltalk.

Thanks
Xavi
xabialonso2
 
Posts: 6
Joined: Mon Jun 14, 2010 6:59 pm

Re: copy a bmp to the clipboard using VA ST

Postby PhotonDemon » Mon Apr 11, 2011 6:43 am

Hi Xavi,

The following works for me:

Code: Select all
| rootWindow pixMap osBitMap |

rootWindow := self primaryWidget window.
pixMap := rootWindow createPixmap: rootWindow width height: rootWindow height depth: rootWindow depth.
rootWindow copyArea: pixMap gc: CgGC default srcX: 0 srcY: 0 width: rootWindow width height: rootWindow height destX: 0 destY: 0.

osBitMap := CwDataInterchangeConverter convert: pixMap formatName: 'PIXMAP' interchangeFormat: (CwWINFormatEtcFormat cfFormat: 2).

osBitMap dataRef notNil ifTrue: [
   OSClipboard reset.
   OSClipboard setBitmap: osBitMap dataRef.
].
pixMap freePixmap.


If you replace:
rootWindow := self primaryWidget window.
with:
rootWindow := Transcript mainWindow window.
you can try it from the Transcript or a workspace.

Lou
Louis LaBrunda
Keystone Software Corp.
SkypeMe callto://PhotonDemon
mailto:Lou@Keystone-Software.com http://www.Keystone-Software.com
PhotonDemon
[|]
 
Posts: 176
Joined: Thu Dec 20, 2007 1:45 pm

Re: copy a bmp to the clipboard using VA ST

Postby xabialonso2 » Mon Apr 11, 2011 9:40 pm

That worked great Lou.
Thanks very much for you help.

I have ended up saving it to a file and adding the file as an attachment to a newOutlook email.
Is it possible to send the contents of the clipboard to hTMLBody: of a OutlookMailItemWrapper instance?
It needs to be in html format.

It works fine if I Ctrl + P (if I inspect the hTMLBody) but I want the program to automatically add it to a newly opened email.

Cheers
Xabi
xabialonso2
 
Posts: 6
Joined: Mon Jun 14, 2010 6:59 pm

Re: copy a bmp to the clipboard using VA ST

Postby PhotonDemon » Tue Apr 12, 2011 5:53 am

Sorry Xavi,

I don't know enough about #OutlookMailItemWrapper to help. I think you do have a few ways to skin this cat. You could save the image to disk (without the involvement of the clipboard) and point to the disk file as an attachment (I think images in email are attachments identified as such that they get displayed by most email clients). There may also be some way to pass the image directly to #OutlookMailItemWrapper or one of its friends (again without the clipboard). Or with the clipboard if there is some way to tell Outlook to get the image from there.

Lou
Louis LaBrunda
Keystone Software Corp.
SkypeMe callto://PhotonDemon
mailto:Lou@Keystone-Software.com http://www.Keystone-Software.com
PhotonDemon
[|]
 
Posts: 176
Joined: Thu Dec 20, 2007 1:45 pm

Re: copy a bmp to the clipboard using VA ST

Postby xabialonso2 » Tue Apr 12, 2011 3:05 pm

Thanks again Lou
I have gone with option of saving to a file and then adding it as an attachment and it looks quiet good.
I would love to be able to save it in the body of the email somehow but it seems difficult.
Was think of somehow trying to invoke the code that a Ctrl + p stroke of the keyboard kicks off.

Cheers
Xabi
xabialonso2
 
Posts: 6
Joined: Mon Jun 14, 2010 6:59 pm


Return to VA Smalltalk 7.0, 7.5 & 8.0

Who is online

Users browsing this forum: No registered users and 1 guest

cron