Using Win32 functions in Visual FoxPro Image Gallery
Code examples:
Using the NetMessageBufferSend to send messages on the network
Wininet last error description
Form Magnifier
How to build UDP responder
Locking and unlocking file of a VFP table
Playing WAV sounds simultaneously
Retrieving information about the main VFP window
Simple Window Viewer
Accessing examples contained in this reference from a VFP application
Customizing the frame of top-level form: removing the standard frame (VFP9, Vista)
Disk in drive A:
GDI+: Drawing a Pie Chart
Obtaining list of tables stored in an ODBC Data Source
Using FillMemory
Validating URLs using moniker functions
Winsock: resolving an address to a host name
How to delete IE cookies, clear IE history and delete files in Temporary Internet Files directory
How to Start a Process as Another User (NT/XP/2K)
Using the CreateFile
Converting a hexadecimal string to an integer
How to enable the SE_SHUTDOWN_NAME privilege for the application
Retrieving the User Datagram Protocol (UDP) listener table
Using custom Simple MapiSendMail class
A class that encrypts and decrypts files using Cryptography API Functions
GDI+: printing vertical text on VFP reports via generated images (VFP8)

User rating: 0/10 (0 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. While this one is VFP8 based, the other version requires VFP9 and employs its unique features -- ReportListener and its GDIPlus Graphics object.

This is what we are going to achieve in this code sample. For each record two images are generated and imported into general fields BARCODE and BARCODE1. The second image is created by rotating the first one 90-degree counter clockwise.

Two general fields are used for demonstration purposes only -- showing the object before and after being rotated. In a real-life situation there is no need in interim BARCODE field.



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

* * *
Here the fields from the cursor are displayed in a sample report:


See also:
  • Adding a background image to VFP report (VFP9, 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)
     
    * replace with valid barcode font name
    #DEFINE BARCODE_FONT "barcod39"
     
    * an instance of gdiplusinit should be created before
    * and released after using any of gdi+ objects
    SET PROCEDURE TO gdiplus ADDITIVE
    PRIVATE gdiplus As gdiplusinit, img As gdibitmap
    gdiplus = CREATEOBJECT("gdiplusinit")
     
    PRIVATE oFont1 As gdifont, oFont2 As gdifont, oFont3 As gdifont,;
        oMatrix as gdimatrix
    STORE 0 TO oFont1, oFont2, oFont3, oMatrix
     
    DO CreateFonts
    DO CreateMatrix
    DO GenerateData
    DO BrowseResults
    * end of main
     
    PROCEDURE GenBarcode(cBarcode, cMailtype)
        LOCAL oImage As gdibitmap, oImage1 As gdibitmap
     
        * create blank image
        oImage = CREATEOBJECT("gdibitmap",;
            IMAGE_WIDTH, IMAGE_HEIGHT)
     
        * printing text including barcode on the first image
        WITH oImage
     
            * setting the background, otherwise it is black
            .graphics.FillRectangle(IMAGE_BACKCOLOR,;
                0, 0, .imgwidth, .imgheight)
     
            .graphics.DrawText(m.cBarcode,;
                oFont1, 2, 5, .imgwidth, .imgheight)
     
            .graphics.DrawText(ALLTRIM(m.cMailtype),;
                oFont2, .imgwidth-70, 3, 68, .imgheight)
     
            .graphics.DrawText(m.cBarcode,;
                oFont2, 10, .imgheight-16, .imgwidth, 14)
     
            .graphics.DrawText(MDY(DATE()),;
                oFont3, .imgwidth-80, .imgheight-14, 78, 13)
        ENDWITH
     
        * the first image is saved to bitmap file
        * then imported to general field
        oImage.savetofile(IMAGE_TARGETFILE)
        SELECT cs
        APPEND GENERAL barcode FROM IMAGE_TARGETFILE
     
        * create another blank image
        * note that image width and height are switched
        oImage1 = CREATEOBJECT("gdibitmap", IMAGE_HEIGHT, IMAGE_WIDTH)
     
        WITH oImage1
            * setting the background, otherwise it is black
            .graphics.FillRectangle(IMAGE_BACKCOLOR,;
                0, 0, .imgwidth, .imgheight)
     
            * rotation matrix applied
            .graphics.SetTransform(oMatrix)
     
            * the second image is used as a canvas
            * to draw the first image on it
            * note that X coordinate is not zero 
            .graphics.drawimage(oImage, -.imgheight, 0)
        ENDWITH
     
        oImage1.savetofile(IMAGE_TARGETFILE)
        SELECT cs
        APPEND GENERAL barcode1 FROM IMAGE_TARGETFILE
     
    PROCEDURE CreateMatrix
        oMatrix = CREATEOBJECT("gdimatrix")
        oMatrix.Rotate(270)
     
    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)
            oFont1 = CREATEOBJECT("gdifont", oFamily,;
                14, 1, BARCODE_FORECOLOR)
     
            = MESSAGEBOX("Barcode font [" + BARCODE_FONT +;
                "] not found on the local computer.     " + CHR(13) +;
                "The " + _screen.FontName + " font is used instead.     ",;
                64, "Font not found")
        ELSE
            oFont1 = CREATEOBJECT("gdifont", oFamily,;
                28, 0, BARCODE_FORECOLOR)
        ENDIF
     
        oFamily = oFontcollection.GetFontFamily(IMAGE_FONT)
        oFont2 = CREATEOBJECT("gdifont", oFamily,;
            8, 0, IMAGE_FORECOLOR)
     
        oFamily = oFontcollection.GetFontFamily(IMAGE_FONT)
        oFont3 = CREATEOBJECT("gdifont", oFamily,;
            7, 0, IMAGE_FORECOLOR)
     
    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")
     
        * adding two GENERAL fields for storing images
        ALTER TABLE cs ADD COLUMN barcode G  && regular
        ALTER TABLE cs ADD COLUMN barcode1 G  && rotated
     
        SELECT cs
        SCAN ALL
            DO GenBarcode WITH;
                ALLTRIM(cs.zip)+cs.state, cs.mailtype
        ENDSCAN
     
    PROCEDURE BrowseResults
        DEFINE WINDOW cs FROM 1,1 TO 14,114 IN SCREEN;
        SYSTEM FONT "Arial", 8 FLOAT CLOSE
     
        DEFINE WINDOW barcode FROM 15,1 TO 25,30 IN SCREEN;
        SYSTEM FLOAT CLOSE
     
        DEFINE WINDOW barcode1 FROM 15,40 TO 35,50 IN SCREEN;
        SYSTEM FLOAT CLOSE
     
        SELECT cs
        GO TOP
     
        MODIFY GENERAL barcode WINDOW barcode NOWAIT
        MODIFY GENERAL barcode1 WINDOW barcode1 NOWAIT
     
        BROWSE FIELDS firstname:16, lastname:16,;
            city:25, state:8, zip:12, mailtype:30,;
            barcode, barcode1;
            NORMAL WINDOW cs NOWAIT
     
     
     

    User rating: 0/10 (0 votes)
    Rate this code sample:
    • ~
    5230 bytes  
    Created: 2006-03-10 14:26:26  
    Modified: 2009-12-17 09:45:06  
    Visits in 7 days: 80  
    Listed functions:
    Printer friendly API declarations
    My comment:
    This is VFP8 solution. It works quite slow, mainly because of multiple bitmap files imported into general fields. Some ways can be found to optimize the speed, still it is rather lenghy process -- about 25..50 seconds per 100 APPEND GENERAL calls.

    As shown in the second version of this code sample, in VFP9 the ReportListener used with GDI+ library speeds up the process very much due to the images directly rendered in report without going through file and general field stages.

    * * *
    This is how GDI+ rotates images:



    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)
    4 sec.Example: 'Drawing icons associated with the VFP main window'
    10.09 hrs.Example: 'Testing Clipboard functions: emptying the clipboard'
     Function: 'AVIFileOpen'
    15.85 hrs.Function: 'NetScheduleJobEnum'
    Function group: 'Network Management'
     Example: 'Using vendor-neutral SQL constructs'
    19.55 hrs.Function: 'GetAclInformation'
    Function group: 'Security'
     Function: 'InternetCrackUrl'
    Function group: 'Internet Functions (WinInet)'
    Google
    Advertise here!