Generating windows bitmap file for window.

For questions and postings not covered by the other forums
ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Generating windows bitmap file for window.

Postby ConvertFromOldNGs » Fri Aug 07, 2009 11:41 am

by Carl Ranson >> Mon, 21 Jun 1999 0:01:17 GMT

I have an app that makes a drawing on a picture control using window.drawLine etc.

Anyone know how to generate a bitmap from a jade window that has been drawn on?

Thanks
Carl

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Generating windows bitmap file for window.

Postby ConvertFromOldNGs » Fri Aug 07, 2009 11:41 am

by Arjan van Hasselt >> Mon, 21 Jun 1999 0:17:16 GMT

The method is called "createPicture"

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Generating windows bitmap file for window.

Postby ConvertFromOldNGs » Fri Aug 07, 2009 11:41 am

by Arjan van Hasselt >> Mon, 21 Jun 1999 4:13:37 GMT

This an undocumented feature which will be released in JADE 5.

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Generating windows bitmap file for window.

Postby ConvertFromOldNGs » Fri Aug 07, 2009 11:41 am

by Carl Ranson >> Mon, 21 Jun 1999 22:05:08 GMT

Cool, got that part working in the following method:

mnuCopy_click(menuItem: MenuItem input) updating;

vars
b : Binary;begin

b := myPicture.createPicture(true, false, 4);
write 'drumroll please';
write b.pictureType; // writes "1" = bitmap - correct.

if (call openClipboard(null)).Boolean then
call emptyClipboard();
call setClipboardData (2 , b.bufferAddress); // 2 = bitmap
call closeClipboard;
else
write 'open Clipboard call failed';
endif;

end;

Can anyone spot whats wrong with the way I'm copying that to the clipboard. Do I need to allocate windows global memory or somthing like that?
Seems like what I've done "should" work.

Any help appreciated.

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Generating windows bitmap file for window.

Postby ConvertFromOldNGs » Fri Aug 07, 2009 11:41 am

by Craig Shearer >> Tue, 22 Jun 1999 0:44:44 GMT

Well, I don't know about your problems with the createPicture method, but I had to do the same thing - copy the contents of a picture control to the clipboard. Here's the code I came up with. Note, this is a method I added to the Picture control. Also, there are lots of Windows API calls here that you'd need to setup as external functions within JADE.



copyToClipboard(): Boolean;
/*
Date: 19 February 1999 by CDS

Description:
Copies the picture in the control to the clipboard.

Returns:
False is anything goes wrong, otherwise true.

*/
constants
CF_BITMAP = 2;
SRCCOPY = #CC0020;

vars
dc : Integer;
compatibleDC : Integer;

hBmp : Integer;
begin

dc := call getDC(hwnd);

compatibleDC := call createCompatibleDC(dc);
hBmp := call createCompatibleBitmap(dc, width.Integer, height.Integer); if hBmp = 0 then
return false;
endif;

if call selectObject(compatibleDC, hBmp) = 0 then
return false;
endif;

if call bitBlt
(
compatibleDC,
0,0,
width.Integer, height.Integer,
dc,
0,0,
SRCCOPY
) = 0 then
return false;
endif;

if call openClipboard(null) > 0 then
call emptyClipboard;
call setClipboardData(CF_BITMAP, hBmp);
call closeClipboard;
return true;
else
return false;
endif;

epilog
call releaseDC(hwnd, dc);
call deleteDC(compatibleDC);
call deleteObject(hBmp);

end;

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Generating windows bitmap file for window.

Postby ConvertFromOldNGs » Fri Aug 07, 2009 11:41 am

by Carl Ranson >> Tue, 22 Jun 1999 8:40:33 GMT

Interesting technique, Craig

The problem I have with this approach is that it will only copy the visible portion of the window.

This isn't a problem if the picture happens to be all on screen, but mine doesn't.

I suppose one could programatically scroll and repaint the picture to grab one section at a time and stitch them together to make a single bitmap, but that sounds like a bit of a trial to me.

The copyPicture method that Arjan mentioned is effected by the scroll bars. So if you want to get the whole picture you have to make sure both the scroll bars are at 0 and make the picture control wide enough to not require scroll bars.

It would be much nicer if this routine let one specify the region to copy or have no region give the whole picture *regardless* of what is visible on screen.

Anyhow, I can work around the dificulties with the createPicture method, but I still don't know why my orginal routine didn't copy to the clipboard.

Any more suggestions, anyone?

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Generating windows bitmap file for window.

Postby ConvertFromOldNGs » Fri Aug 07, 2009 11:41 am

by Craig Shearer >> Tue, 22 Jun 1999 19:54:37 GMT

I've thought about your problem a little more, and it would seem that the reason your original method didn't work is because you were trying to pass the address of the buffer containing your bitmap to Windows, when Windows actually expects to receive a handle to a bitmap, ie. one of Window's own internal identifiers that "point" to a bitmap elsewhere in memory.

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Generating windows bitmap file for window.

Postby ConvertFromOldNGs » Fri Aug 07, 2009 11:42 am

by Carl Ranson >> Wed, 23 Jun 1999 0:00:45 GMT

Craig's diagnosis of my problem sounds reasonable to me.

So now the question is "does anyone know how to convert from the buffer address to a handle I can feed to windows?"

Someone in the plant must know the answer to this, surely.

Whats the magic windows spell, people?

Thanks all for the help,
CR

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Generating windows bitmap file for window.

Postby ConvertFromOldNGs » Fri Aug 07, 2009 11:42 am

by Carl Ranson >> Thu, 24 Jun 1999 1:41:20 GMT

Sod it - I think I'll just write a haiku instead.

Jade, why is it hard?
To do fairly simple things.
Delphi here I come.

:)

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Generating windows bitmap file for window.

Postby ConvertFromOldNGs » Fri Aug 07, 2009 11:42 am

by Torrie Moore >> Thu, 24 Jun 1999 22:30:03 GMT

We had the same problem, wanting to create a bitmap from a window. We wrote a dll in Delphi that does it for us and only requires one line of code in Jade (but does require distributing the dll). I guess there are things that are easier to do in Delphi or C than in Jade so why not use these languages and a dll?


Return to “General Discussion”

Who is online

Users browsing this forum: No registered users and 8 guests