Using Win32 functions in Visual FoxPro Image Gallery
Code examples:
How to change display settings: screen resolution, screen refresh rate
Adding and deleting Scheduled Tasks using NetScheduleJob API functions
Capturing keyboard activity of another application with the Raw Input API (VFP9)
Converting Unicode data from the Clipboard to a character string using a given code page
Custom GDI+ class
Establishing connection using the SQLDriverConnect
Custom FTP Class for Visual FoxPro application
Detecting changes in connections to removable drives (VFP9)
Splash Screen for the VFP application
How to print a bitmap file
How to create non-blocking Winsock server
Winsock: sending email messages (SMTP, port 25)
GDI+: copying to the Clipboard (a) image of active FoxPro window/form, (b) image file
Peer-to-peer LAN messenger built with Mailslot API functions
Custom HttpRequest class (WinINet)
Sending email messages with Simple MAPI
How to create MD-5 and SHA-1 hash values from a string
Displaying animated images on FoxPro form with BitBlt and StretchBlt functions
Displaying bitmap using the AlphaBlend function
Enumerating raw input devices attached to the system (keyboard, mouse, human interface device)
Enumerating data formats currently available on the clipboard
How to put a vertical text scrolling on the form (a movie cast)
Mapping and disconnecting network drives
How to prevent users from accessing the Windows Desktop and from switching to other applications
GDI+: printing vertical text on VFP reports via generated images (VFP9)

User rating: 9/10 (2 votes)
Rate this code sample:
  • ~
More code examples    Listed functions    Add comment     W32 Constants      Translate this page Printer friendly version of this code sample
Before you begin:
The code is based on custom GDI+ class. Download the class module first and save it in gdiplus.prg file.

This code sample is presented in two versions, each shows how to generate images (adhoc) and display them on VFP report. This particular version requires VFP9 and employs its unique features -- ReportListener and its GDIPlus Graphics object.

The other one is VFP8 based and gets same results through creating adhoc bitmap files and importing them into general fields of a cursor.

This is how a sample report looks:


Note: these above are entirely fictional names and addresses. Any coincidence is completely unintentional.

See also:
  • Adding a background image to VFP report
  •  
    SET PROCEDURE TO gdiplus ADDITIVE
     
    LOCAL oListener As TListener
    oListener = CREATEOBJECT("TListener")
    DO GenerateData
     
    * create your own report as shown on the picture above
    * Picture control is not required
    * just provide some empty space at the detail`s left margin
    REPORT FORM test OBJECT oListener NOCONSOLE
    * end of main
     
    PROCEDURE GenerateData
        CREATE CURSOR cs (firstname C(20), lastname C(30), city C(50),;
            state C(2), zip C(7), mailtype C(50))
     
        * preparing test data
        * these are entirely fictional names and addresses
        * any coincidence is completely unintentional
        * the mailtypes do not make any sense either
     
        INSERT INTO cs VALUES ("JOHN", "BROWN", "HOUSTON", "TX",;
            "12545", "First Class Mail and Periodicals")
     
        INSERT INTO cs VALUES ("MARK", "HARRIS", "CHICAGO", "IL",;
            "01331", "Standard Mail ")
     
        INSERT INTO cs VALUES ("MARTHA", "COLLETTE", "LONG BEACH", "NY",;
            "06783", "First Class Mail and Periodicals")
     
        INSERT INTO cs VALUES ("RICHARD", "COOK", "WASHINGTON", "DC",;
            "11106", "First Class Mail and Periodicals")
     
        INSERT INTO cs VALUES ("ALANA", "WOOLF", "NEW YORK", "NY",;
            "10306", "Standard Mail ")
     
        INSERT INTO cs VALUES ("DAVID", "KNIGHT", "TRENTON", "NJ",;
            "01524", "Standard Letters")
     
        INSERT INTO cs VALUES ("JAMES", "GARRISON", "SAN ANTONIO", "TX",;
            "32906", "Standard Letters")
     
    DEFINE CLASS TListener As ReportListener
    #DEFINE IMAGE_WIDTH 180
    #DEFINE IMAGE_HEIGHT 60
    #DEFINE IMAGE_TARGETFILE SYS(2023)+"\barcode.bmp"
    #DEFINE IMAGE_BACKCOLOR ARGB(255,255,255,255)
    #DEFINE IMAGE_FORECOLOR ARGB(64,64,64,255)
    #DEFINE IMAGE_FONT "Arial"
    #DEFINE BARCODE_FORECOLOR ARGB(0,0,0,255)
    #DEFINE BARCODE_FONT "barcod39"
     
        ListenerType=1  && renders all pages
        InDetails=.F.
        gdiplus=NULL
        font1=NULL
        font2=NULL
        font3=NULL
        matrix=NULL
     
    PROCEDURE Init
        ReportListener::Init()
        THIS.gdiplus = CREATEOBJECT("gdiplusinit")
        THIS.CreateFonts
        THIS.CreateMatrix
     
    PROTECTED PROCEDURE CreateFonts
        LOCAL oFontcollection As gdifontcollection
        oFontcollection = CREATEOBJECT("gdifontcollection")
     
        LOCAL oFamily as gdifontfamily
        oFamily = oFontcollection.GetFontFamily(BARCODE_FONT)
     
        IF EMPTY(oFamily.familyname)
        * barcode font not found, default font used
            oFamily = oFontcollection.GetFontFamily(_screen.FontName)
            THIS.font1 = CREATEOBJECT("gdifont", oFamily,;
                14, 1, BARCODE_FORECOLOR)
        ELSE
            THIS.font1 = CREATEOBJECT("gdifont", oFamily,;
                28, 0, BARCODE_FORECOLOR)
        ENDIF
     
        oFamily = oFontcollection.GetFontFamily(IMAGE_FONT)
        THIS.font2 = CREATEOBJECT("gdifont", oFamily,;
            8, 0, IMAGE_FORECOLOR)
     
        oFamily = oFontcollection.GetFontFamily(IMAGE_FONT)
        THIS.font3 = CREATEOBJECT("gdifont", oFamily,;
            7, 0, IMAGE_FORECOLOR)
     
    PROTECTED PROCEDURE CreateMatrix
        THIS.matrix = CREATEOBJECT("gdimatrix")
        THIS.matrix.Rotate(270)
     
    PROCEDURE BeforeBand
    LPARAMETERS nBandObjCode, nFRXRecNo
        DODEFAULT(nBandObjCode, nFRXRecNo)
        IF nBandObjCode = 4
            THIS.InDetails=.T.
        ENDIF
     
    PROCEDURE Render(nFRXRecNo, nLeft,nTop,nWidth,nHeight,;
        nObjectContinuationType, cContentsToBeRendered, GDIPlusImage)
     
        IF THIS.InDetails
            THIS.PrintBarcode(nLeft,nTop)
            THIS.InDetails = .F.
        ENDIF
     
        DODEFAULT(nFRXRecNo, nLeft,nTop,nWidth,nHeight,;
            nObjectContinuationType, ;
            cContentsToBeRendered, GDIPlusImage)
     
    PROTECTED PROCEDURE PrintBarcode(nLeft, nTop)
        LOCAL cBarcode, cMailtype
        cBarcode = ALLTRIM(cs.zip) + "-" + cs.state
        cMailtype = ALLTRIM(cs.mailtype)
     
        LOCAL oImage As gdibitmap, graphics As graphics
        oImage = CREATEOBJECT("gdibitmap", IMAGE_WIDTH, IMAGE_HEIGHT)
     
        WITH oImage
            .graphics.FillRectangle(IMAGE_BACKCOLOR,;
                0, 0, .imgwidth, .imgheight)
     
            .graphics.DrawText(m.cBarcode,;
                THIS.font1, 2, 5, .imgwidth, .imgheight)
     
            .graphics.DrawText(ALLTRIM(m.cMailtype),;
                THIS.font2, .imgwidth-70, 3, 68, .imgheight)
     
            .graphics.DrawText(m.cBarcode,;
                THIS.font2, 10, .imgheight-16, .imgwidth, 14)
     
            .graphics.DrawText(MDY(DATE()),;
                THIS.font3, .imgwidth-80, .imgheight-14, 78, 13)
        ENDWITH
     
        LOCAL oImage1 As gdibitmap
        oImage1 = CREATEOBJECT("gdibitmap", IMAGE_HEIGHT, IMAGE_WIDTH)
     
        WITH oImage1
            .graphics.FillRectangle(IMAGE_BACKCOLOR,;
                0, 0, .imgwidth, .imgheight)
     
            .graphics.SetTransform(THIS.matrix)
            .graphics.drawimage(oImage, -oImage.imgwidth, 0)
     
            nResult = GdipDrawImageRectI(THIS.GDIPlusGraphics,;
                .himage, 500, nTop-300, .imgwidth*10, .imgheight*10)
        ENDWITH
     
    ENDDEFINE
     
     
     

    User rating: 9/10 (2 votes)
    Rate this code sample:
    • ~
    4513 bytes  
    Created: 2006-03-26 12:47:18  
    Modified: 2009-12-17 09:44:39  
    Visits in 7 days: 82  
    Listed functions:
    Printer friendly API declarations
    My comment:
    The TListener extends the ReportListener class. It overrides the BeforeBand and Render methods of the parent with its own methods that draw the barcode image on report`s detail band.

    A small issue is created by the fact that my GDI+ library uses pixels while the ReportListener prefers units of 1/960 inch. I`m working on a solution.

    * * *
    Using GDI+ in the VFP 9 Report Writer written by Christof Wollenhaupt and published in July 2004 issue of FoxPro Advisor.
    Word Index links for this example:
    Translate this page:
      Spanish    Portuguese    German    French    Italian  
    FreeTranslation.com offers instant, free translations of text or web pages.
    User Contributed Notes:
    There are no notes on this subject.


    Copyright © 2001-2013 News2News, Inc. Before reproducing or distributing any data from this site please ask for an approval from its owner. Unless otherwise specified, this page is for your personal and non-commercial use. The information on this page is presented AS IS, meaning that you may use it at your own risk. Microsoft Visual FoxPro and Windows are trade marks of Microsoft Corp. All other trademarks are the property of their respective owners. 

    Privacy policy
    Credits: PHP (4.4.9), an HTML-embedded scripting language, MySQL (5.1.55-log), the Open Source standard SQL database, AceHTML Freeware Version 4, freeware HTML Editor of choice.   Hosted by Korax Online Inc.
    Last Topics Visited (54.226.5.29)
    1.39 hrs.Function: 'CeDeleteFile'
    1.62 hrs.Gallery
    Page 8
    5.58 hrs.Example: 'GDI+: printing vertical text on VFP reports via generated images (VFP8)'
    5.59 hrs.Example: 'Drawing icons associated with the VFP main window'
    15.67 hrs.Example: 'Testing Clipboard functions: emptying the clipboard'
    15.68 hrs.Function: 'AVIFileOpen'
    21.43 hrs.Function: 'NetScheduleJobEnum'
    Function group: 'Network Management'
    21.44 hrs.Example: 'Using vendor-neutral SQL constructs'
    1 day(s)Function: 'GetAclInformation'
    Function group: 'Security'
     Function: 'InternetCrackUrl'
    Function group: 'Internet Functions (WinInet)'
    Google
    Advertise here!