Using Win32 functions in Visual FoxPro Image Gallery
Code examples:
Custom GDI+ class
Splash Screen for the VFP application
Displaying dimmed window behind VFP top-level form
Vertical Label control
Subclassing CommandButton control to create BackColor property
Storing content of the Clipboard to a bitmap file
Printing text with the Escape function
How to make a VFP form fading out when released (GDI version)
How to put a vertical text scrolling on the form (a movie cast)
How to put a horizontal text scrolling on the form (a news line, marquee)
Storing screen shot of a form to bitmap file
Bitmap Class for Visual FoxPro application
Playing WAV sounds simultaneously
Custom FTP Class for Visual FoxPro application
How to play AVI file on the _screen
Obtaining names and positions for shortcuts located on the Windows Desktop
Enumerating devices installed on the local machine
How to view icons stored in executable files (Icon Viewer) - II
Enumerating Processes -- WinNT
Passing data records between VFP applications via the Clipboard
Copying picture of the active form to the Clipboard using Enhanced Metafile API functions
CryptoAPI: Collection of Providers class
Monitoring clipboard content changes (VFP9)
Placing an arbitrary rectangular area of main VFP window on the Clipboard
GDI+: enumerating fonts installed on the system

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
Versions:
click to open
Before you begin:
The code is based on custom GDI+ class. Download the class module first and save it in gdiplus.prg file.


SET PROCEDURE TO gdiplus ADDITIVE

LOCAL oForm
oForm = CREATEOBJECT("Tform")
oForm.Show(1)
* end of main

DEFINE CLASS Tform As Form
    Width=500
    Height=240
    Autocenter=.T.
    Caption="GDI+: InstalledFontCollection"
    MinButton=.F.
    MaxButton=.F.
    BorderStyle=2
    gdi=0
    fontcollection=0

    ADD OBJECT lst As ListBox WITH Top=0, Left=0,;
    Width=160, Height=230, FontSize=8

    ADD OBJECT styles As ComboBox WITH Top=10, Left=180,;
    Width=80, style=2, BoundTo=.T., BoundColumn=2, FontSize=8

    ADD OBJECT fontsizes As ComboBox WITH Top=10, Left=262,;
    Width=40, style=2, FontSize=8

PROCEDURE Init
    THIS.gdi=CREATEOBJECT("gdiplusinit")
    THIS.GetFontFamilies

PROCEDURE Activate
    ThisForm.DrawString

PROCEDURE fontsizes.InteractiveChange
    ThisForm.DrawString

PROCEDURE styles.InteractiveChange
    ThisForm.DrawString

PROCEDURE lst.InteractiveChange
    ThisForm.DrawString

PROCEDURE fontsizes.Init
    THIS.AddItem("8")  && add as much as you want :)
    THIS.AddItem("10")
    THIS.AddItem("12")
    THIS.AddItem("16")
    THIS.AddItem("20")
    THIS.AddItem("24")
    THIS.AddItem("32")
    THIS.AddItem("36")
    THIS.AddItem("42")
    THIS.AddItem("54")
    THIS.AddItem("72")
    THIS.Value="16"

PROCEDURE styles.EnableStyles(p0, p1, p2, p3)
    LOCAL OldValue
    WITH THIS
        OldValue=.Value
        .Clear
        IF m.p0
            .AddItem("Regular")
            .List(.ListCount,2)="0"
        ENDIF
        IF m.p1
            .AddItem("Bold")
            .List(.ListCount,2)="1"
        ENDIF
        IF m.p2
            .AddItem("Italic")
            .List(.ListCount,2)="2"
        ENDIF
        IF m.p3
            .AddItem("BoldItalic")
            .List(.ListCount,2)="3"
        ENDIF
        .Value = m.OldValue
        IF .ListIndex=0
            .ListIndex=1
        ENDIF
    ENDWITH

PROCEDURE GetFontFamilies
    THIS.fontcollection = CREATEOBJECT("gdifontcollection")
    LOCAL oFamily
    FOR EACH oFamily IN THIS.fontcollection.fontfamilies
        THIS.lst.AddItem(oFamily.familyname)
    ENDFOR
    THIS.lst.ListIndex=1

PROCEDURE DrawString
#DEFINE carret CHR(13)+CHR(10)
#DEFINE dcarret carret+carret
#DEFINE ccDrawString "The quick brown fox jumps over a lazy dog." +;
    dcarret + "0123456789"
    LOCAL oFamily, oFont, oGraphics, oImage, rectf

    oFamily=THIS.fontcollection.GetFontFamily(THIS.lst.ListIndex)
    WITH oFamily
        THIS.styles.EnableStyles(.hasregular,;
            .hasbold, .hasitalic, .hasbolditalic)
    ENDWITH

    oFont=CREATEOBJECT("gdifont", oFamily,;
        VAL(THIS.fontsizes.Value),;
        VAL(THIS.styles.Value), ARGB(64,64,64,255))

    * creating virtual canvas
    oImage = CREATEOBJECT("gdibitmap", 300,160)

    * painting background and printing text
    rectf = CREATEOBJECT("rectf", 0,0, oImage.imgwidth, oImage.imgheight)
    WITH oImage
        .graphics.FillRectangle(ARGB(255,255,255,255), rectf)
        .graphics.DrawText(ccDrawString, oFont, rectf)
    ENDWITH

    * preparing to draw on the Form
    oGraphics = CREATEOBJECT("graphics", THIS.HWnd)
    oGraphics.drawimage(oImage, 180, 50)
ENDDEFINE



User rating: 0/10 (0 votes)
Rate this code sample:
  • ~
2901 bytes  
Created: 2004-07-30 13:40:24  
Modified: 2009-02-25 15:02:58  
Visits in 7 days: 111  
Listed functions:
Printer friendly API declarations
My comment:
On every FontFamily selection the Font object is created based on the FontFamily object, style and fontsize. Then the Bitmap object is created. This particular Bitmap object has its own Graphics object, which makes it an ideal canvas for drawing.

So the drawing fills the background with white color and puts some text using the Font object that has been just created.

Then the code creates another canvas (graphics). This time the canvas is nothing else but the surface of current FoxPro form. The Bitmap object is drawn on the second canvas.

Also you can use the SaveToFile method of the Bitmap object to save the drawn image to file.

The way this code can be improved is to place the Image control on the form and use its Picture property to display temporary bitmap files instead of direct drawing on the form. Unfortunately the Image control can not use HBITMAP as parameter.

#kwd: sln_gdiplus.
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:
grosner@icuecorp.com | 2005-09-11 16:32:34
Does not work with vfp7.
Uses Try/Catch code
GDIPlus.Prg uses vfp8 Createobject("collection") which is unsupported in vfp7.
A.M. | 2005-09-11 19:17:33
Gary,

Try to use custom Collection class at
http://fox.wikis.com/wc.dll?Wiki~Vfp6CollectionClass

Copyright 2001-2017 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.6.38), the Open Source standard SQL database, AceHTML Freeware Version 4, freeware HTML Editor of choice.   Hosted by Korax Online Inc.
Last Topics Visited (54.82.112.193)
18 sec.Function: 'GdipGetImageGraphicsContext'
34 sec.Function: 'GdipDeleteGraphics'
Function group: 'GDI+ Graphics'
51 sec.Function: 'GdipScaleMatrix'
1.1 min.Function: 'GdipGetDC'
Function group: 'GDI+ Graphics'
1.38 min.Function: 'GdipFillPieI'
Function group: 'GDI+ Graphics'
1.93 min.Function: 'GdipGetImageType'
2.2 min.Function: 'GdipShearMatrix'
2.48 min.Articles
2.78 min.Example: 'GDI+: printing image file'
3.08 min.Function: 'GdipGetFamilyName'
Google
Advertise here!