Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Saving container class as image - is it possible ?

Status
Not open for further replies.

global3000

Programmer
Jan 1, 2004
3
0
0
AU
Hi Everyone,

I have a program that needs to print out reports containing UCC128/EAN128 barcodes.

This barcode format contains extensive start and stop character information and although barcodes fonts exist for this standard I have never found one which I find particularly useful.

Consequently I am trying to write a custom component in VFP7.0 that when given a string of characters is capable of saving the appropriate bar code to disk as a BMP file.
( I would love to be able to put such a component straight onto a report but I do not believe this is possible )

The BMP file(s) would then be loaded into a cursor which the report would then run off.

I have created a custom class based on the container class which I believe I can add line objects to, to form the bar code but I do not know if it is possible to save the result as an image )

I have performed the equivalent task in Delphi 6.0 using Delphi's "canvas" property but VFP doesn't seem to be particularly graphics friendly.

I hope I have made myself clear.

Anyone have any ideas ?

Andrew
 
Hi

1. You can save the whole report as a PDF and then print it as if printing a pdf file.
2. You can save it as htm and then print it using web component.

We have FAQs related to the above.

:)

____________________________________________
ramani - (Subramanian.G) :)
When you ask VFP questions, please add VFP version.
Merry Christmas & Happy New Year
 
Thank you Ramani but I fear I have not explained myself very well.

My problem is that I need to be able to write a piece of code that when given a character string it generates a bitmap file representing the barcode equivalent of the string.

To create this barcode picture I figured I would use the line objects in VFP, essentially placing a whole heap of vertical lines in sequence to form the barcode. I found that the container class could contain numerous line objects - and created a class that inherited from it. I then rigged my custom class so that on the init event it looked at a custom property to determine the character string to encode. Based on this it would then draw all the appropriate lines inside my inherited object on the form. Although I haven't completely finished I don't believe I'll have a problem with that part. When the form is run my object appears on the form with the lines of the barcode inside it just fine. But I have no way of getting this pattern of lines inside my inherited container class into a bitmap image for use in a report.

The actual use of a visual class is superflous to my needs as the barcode will never be dispalyed on the form. But I still do not know how to the draw lines straight to a bitmap file.

Any more ideas would be greatly appreciated.

 
I've pasted below code that will copy a forms image to the clipboard using the forms hWnd property which you might then be able use. Let me know if that sounds interesting.

You say you've nearly got as far as creating the barcode image in your container. Have you tried printing that imaage (you can grab it by using Ctrl-PrintScreen, pasting the result into Paint and printing it from there) and reading it with a scanner? I ask because I think I'm right in saying that barcodes have to be fairly precisely laid out.

Hope that helps,

Stewart

here's the code...
lParameters oForm
Local nHwnd, tnHwnd, hDC, hDC_Mem, hBitMap, hPrevBmp
* Must use the Foxtools library, somewhere.
Declare integer FindWindow in Win32Api String cClassName, String cWindName
Declare integer GetDC in Win32Api integer nhwnd
Declare integer CreateCompatibleDC in Win32Api integer nhcd
Declare Integer BitBlt in Win32Api Integer hDestDC, Integer x, Integer y, ;
Integer nWidth, Integer nHeight, Integer hScrDC, ;
Integer xsrc, Integer ysrc, Integer dwRop
Declare Integer SelectObject in Win32Api Integer hDC, Integer hObject
Declare Integer CreateCompatibleBitmap in Win32Api Integer hDC, Integer nWidth, ;
Integer nHeight
Declare Integer SetClipboardData in Win32Api Integer nFormat, Integer hObject
Declare Integer DeleteDC in Win32Api Integer hDC
Declare Integer ReleaseDC in Win32Api Integer nwnd, Integer hdc
Declare Integer DeleteObject in Win32Api Integer hDC
lnwhandle = _WFindTitl(oForm.Caption)
nHwnd = _WhToHWnd(lnwhandle)
hDC = GetDC( nHwnd )
hDC_Mem = CreateCompatibleDC( hDC )
hBitMap = CreateCompatibleBitMap( hDC, oForm.Width, oForm.Height )
If hBitMap#0
hPrevBmp = SelectObject( hDC_Mem, hBitMap )
BitBlt( hDC_Mem, 0, 0, oForm.Width, oForm.Height, hDC, 0, 0, 13369376 )
If OpenClip( nHwnd )
EmptyClip()
SetClipboardData( 2, hBitMap )
CloseClip()
Else
MessageBox( 'Error opening the clipboard', 48, 'Message' )
Endif
Else
MessageBox( 'Error creating bitmap', 48, 'Menssage' )
Endif
DeleteDC( hDC_Mem )
ReleaseDC( nHwnd, hDC )
Return .t.
 
Hi StewartUK,

Thank you for your code and post. My knowledge of manipulating bitmaps and the GDI in C++ is very limited but I can make sense of your code. However my only problem is that I need to get the bitmap to a file on disk and despite looking on the net I haven't been able to find a way to save the file given the bitmap handle. Everything I've found uses a C++ CBitmap class.

Would you perhaps be able to direct me to some relevant info ?

Thanks in advance.

Andrew

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top