Using Win32 functions in Visual FoxPro Image Gallery
Shell Functions
..msdn
AssocQueryString
DllGetVersion
DragAcceptFiles
DragFinish
DragQueryFile
DragQueryPoint
FileIconInit
FindExecutable
GetFileNameFromBrowse
GetMenuContextHelpId
GetWindowContextHelpId
InetIsOffline
IsUserAnAdmin
LoadUserProfile
PathMakeUniqueName
PathYetAnotherMakeUniqueName
RealDriveType
RestartDialog
SHAddToRecentDocs
SHBrowseForFolder
SHCreateDirectory
ShellAbout
ShellExecute
ShellExecuteEx
Shell_GetImageLists
Shell_NotifyIcon
SHEmptyRecycleBin
SHFileOperation
SHFormatDrive
SHGetFileInfo
SHGetFolderPath
SHGetPathFromIDList
SHGetSpecialFolderLocation
SHGetStockIconInfo
SHParseDisplayName
SHQueryRecycleBin
SHSimpleIDListFromPath
UnloadUserProfile
WinHelp
Code examples:
Accessing Adobe Reader 7.0 main menu from VFP application
Accessing examples contained in this reference from a VFP application
Accessing examples contained in this reference through Web Services
Accessing Windows Control Panel from VFP Application
GDI+: converting text strings to images and saving in a graphics file
GDI+: creating a gradient
GDI+: creating scaled copy of image file
GDI+: cropping images
GDI+: Drawing a Pie Chart
How to access a file using not its name but an alias (hard link)
How to control Adobe Reader 9.0 (SDI mode) from VFP application
How to display Windows On-Screen Keyboard
Mapping and disconnecting network drives
Reading the structure of VFP main menu
Saving local machine ODBC Registry Entries to XML file
Storing content of the Clipboard to a bitmap file
Using Shell for performing operations on files
GDI+: Drawing a Pie Chart

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:
This code sample shows how to use PieChart GDI+ functions to build a simple chart and store it in a graphics file.



The code is based on custom GDI+ class. Download the class module first and save it in gdiplus.prg file.

* an instance of gdiplusinit should be created before 
* and released after using any of gdi+ objects 
SET PROCEDURE TO gdiplus ADDITIVE
PRIVATE oGdiplus
oGdiplus = CREATEOBJECT("gdiplusinit")

LOCAL oChart As PieChart, cFilename
oChart = CREATEOBJECT("PieChart", 200, 200)
cFilename = "c:\temp\temp.png"

WITH oChart
    .AddPie(24, "Maintenance")  && percent, legend
    .AddPie(30, "Payroll")
    .AddPie(5, "Insurance")
    .AddPie(21, "Transportation")
    .AddPie(10, "Storage")
    .AddPie(10, "Other")

    * build a piechart and save result 
    * to the specified graphics file
    .SaveToFile(cFilename)

    OpenResultImage(cFilename)
ENDWITH
* end of main

DEFINE CLASS PieChart As Session
    pieslices=NULL  && collection

    piewidth=0  && main rectangle
    pieheight=0

    startangle=-90  && degrees; starts from 12:00
    marginx=10
    marginy=10
    legendwidth=140
    legendheight=30

PROCEDURE Init(nWidth, nHeight)
    THIS.piewidth=m.nWidth
    THIS.pieheight=m.nHeight
    THIS.pieslices = CREATEOBJECT("Collection")

PROCEDURE AddPie(nPercent, cLegend)
    LOCAL oSlice As PieSlice, nSweepAngle
    nSweepAngle = (360 * nPercent)/100

    oSlice = CREATEOBJECT("PieSlice", THIS.startangle, m.nSweepAngle,;
        m.cLegend, THIS.pieslices.Count)

    THIS.pieslices.Add(m.oSlice)
    THIS.startangle = THIS.startangle + m.nSweepAngle
    oSlice=NULL

PROCEDURE SaveToFile(cFilename)
    DECLARE INTEGER GdipDrawPieI IN gdiplus;
        INTEGER graphics, INTEGER pen, INTEGER x,;
        INTEGER y, INTEGER width, INTEGER height,;
        SINGLE startAngle, SINGLE sweepAngle

    DECLARE INTEGER GdipFillPieI IN gdiplus;
        INTEGER graphics, INTEGER brush, INTEGER x,;
        INTEGER y, INTEGER width, INTEGER height,;
        SINGLE startAngle, SINGLE sweepAngle

    LOCAL objpen As gdipen, objbrush As gdisolidbrush,;
        objbitmap As gdibitmap, objslice As PieSlice,;
        nFillColor

    objbitmap = CREATEOBJECT("gdibitmap",;
        THIS.piewidth+THIS.marginx*4+THIS.legendwidth,;
        THIS.pieheight+THIS.marginy*2)

    * Pen and Font objects to be used for drawing the chart
    objpen = CREATEOBJECT("gdipen", ARGB(255,255,255,255), 1)
    objfont = CREATEOBJECT("gdifont", "Arial", 9, 0, ARGB(0,0,0,128))

    WITH objbitmap
        .graphics.FillRectangle(ARGB(255,255,255,255), 0, 0,;
            .imgwidth, .imgheight)

        FOR EACH objslice IN THIS.pieslices
            nFillColor = ARGB(64+INT(RAND()*128),;
                64+INT(RAND()*128), 64+INT(RAND()*128),;
                100+RAND()*155)

            * the Brush with random color is created for each pie slice
            objbrush = CREATEOBJECT("gdisolidbrush", m.nFillColor)

            LOCAL nLegendX, nLegendY
            nLegendX = THIS.piewidth+THIS.marginx*3
            nLegendY = objslice.sliceindex*THIS.legendheight+THIS.marginy

            .graphics.FillRectangle(m.nFillColor,;
                m.nLegendX, m.nLegendY, 12, 12)

            .graphics.DrawText(objslice.legend, objfont,;
                m.nLegendX+20, m.nLegendY,;
                THIS.legendwidth, THIS.legendheight)

            * draw the background of the pie slice
            = GdipFillPieI(.graphics.graphics, objbrush.brush,;
                THIS.marginx, THIS.marginy,;
                THIS.piewidth, THIS.pieheight,;
                objslice.startangle, objslice.sweepangle)

            * draw the contour of the pie slice
            = GdipDrawPieI(.graphics.graphics, objpen.hpen,;
                THIS.marginx, THIS.marginy,;
                THIS.piewidth, THIS.pieheight,;
                objslice.startangle, objslice.sweepangle)

            objbrush=NULL
        NEXT

        .SaveToFile(m.cFilename)
    ENDWITH
ENDDEFINE

DEFINE CLASS PieSlice As Session
* in C++ that would be a STRUCT
    startangle=0
    sweepangle=0
    legend=""
    sliceindex=0

PROCEDURE Init(nStartAngle, nSweepAngle, cLegend, nIndex)
    THIS.startangle=m.nStartAngle
    THIS.sweepangle=m.nSweepAngle
    THIS.legend=m.cLegend
    THIS.sliceindex=m.nIndex

ENDDEFINE

PROCEDURE OpenResultImage(cFilename)
* opens image file using default application
    DECLARE INTEGER ShellExecute IN shell32;
        INTEGER hWindow, STRING lpOperation,;
        STRING lpFile, STRING lpParameters,; 
        STRING lpDirectory, INTEGER nShowCmd
    = ShellExecute(0, "open", m.cFilename, "", "", 3)



User rating: 0/10 (0 votes)
Rate this code sample:
  • ~
4037 bytes  
Created: 2006-05-12 16:40:08  
Modified: 2006-05-12 18:37:31  
Visits in 7 days: 42  
Listed functions:
GdipDrawPieI
GdipFillPieI
ShellExecute
Printer friendly API declarations
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-2018 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.39), 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.55.151)
14 sec.Function: 'SHCreateDirectory'
Function group: 'Shell Functions'
41 sec.Function: 'mixerClose'
Function group: 'Windows Multimedia'
54 sec.Function: 'GetFileNameFromBrowse'
Function group: 'Shell Functions'
1.13 min.Example: 'System Image List Viewer'
1.37 min.Function: 'CeFindAllFiles'
Function group: 'Remote Application Programming (RAPI)'
1.67 min.Function: 'CeRegQueryInfoKey'
Function group: 'Remote Application Programming (RAPI)'
1.98 min.Function: 'DragFinish'
Function group: 'Shell Functions'
2.33 min.Example: 'GDI+: creating scaled copy of image file'
2.67 min.
Function group: 'Power Management'
2.98 min.
Function group: 'Hook'
Google
Advertise here!