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+: converting text strings to images and saving in a graphics file

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:
In this code sample lines of text are printed on GDI+ bitmap object using a specified font. The result is saved in a graphics file. Such functionality can be used, for example, for displaying adhoc images on a web page.

This PNG file is created by the code below from TEXT ... ENDTEXT output:.

Also an image is downloaded from VFP Home website and placed on the background before drawing the text.

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 cText, gr As graphics, fnt As gdifont, oRect,;
    cFilename, imagefile As gdiimage

* the name of the target file
cFilename = SYS(2023) + "\temp.png"

* this text is about to be converted to image
SET TEXTMERGE ON
TEXT TO m.cText NOSHOW
Visual FoxPro
From Wikipedia, the free encyclopedia

Visual FoxPro is a data-centric object-oriented and procedural 
programming language produced by Microsoft. It is derived from 
FoxPro (originally known as FoxBASE) which was developed by 
Fox Technologies beginning in 1984; Fox Technologies merged 
with Microsoft in 1992 and the software acquired further 
features and the prefix "Visual". 

<< LOWER(m.cFilename) >>
ENDTEXT
SET TEXTMERGE OFF

#DEFINE FONT_NAME "Arial"
#DEFINE FONT_SIZE 9
#DEFINE BACKGROUND_COLOR ARGB(230,240,255,255)
#DEFINE TEXT_COLOR ARGB(40,40,128,255)

* download image file from the Internet
LOCAL imagefile As gdiimage
= DownloadImageFile(@imagefile)

* create GDI+ Graphics and Font objects
gr = CREATEOBJECT("graphics", _screen.HWnd)
fnt = CREATEOBJECT("gdifont", FONT_NAME, FONT_SIZE, 0, TEXT_COLOR)

* calculate bounding rectangle for the text drawn with this font
oRect = gr.MeasureString(m.cText, m.fnt)

* create target bitmap making it slightly larger
* than the bounding rectangle;
* also add some vertical space for the image
bmp = CREATEOBJECT("gdibitmap",;
    MAX(imagefile.imgwidth, oRect.rwidth) + 10,;
    imagefile.imgheight+oRect.rheight + 20)

WITH bmp
    * fill the background of the bitmap with color
    .graphics.FillRectangle(BACKGROUND_COLOR, 0, 0, .imgwidth, .imgheight)

    * draw the image
    IF imagefile.imgwidth > 0
        .graphics.DrawImage(imagefile, 5, 5)
    ENDIF

    * draw the text on the bitmap below the image
    .graphics.DrawText(m.cText, fnt,;
        5, imagefile.imgheight+10,;
        .imgwidth, .imgheight)

    * save the bitmap to a file 
    .SaveToFile(m.cFilename)
ENDWITH

* open the file using default application
DO OpenResultImage WITH m.cFilename
* end of main

PROCEDURE DownloadImageFile(imagefile As gdiimage)
* downloads image file from remote HTTP server
* it works while the url below is valid
#DEFINE VFP_ONLINE_IMAGE "http://msdn.microsoft.com/" +;
    "msdn-online/shared/graphics/right_bnr_vfoxpro.jpg"

    imagefile=NULL

    DECLARE INTEGER URLDownloadToCacheFile IN urlmon;
        INTEGER lpUnkcaller, STRING szURL, STRING @szFileName,;
        INTEGER dwBufLength, INTEGER dwReserved, INTEGER pBSC

    LOCAL cImageFile
    cImageFile = REPLICATE(CHR(0), 260)
    WAIT WINDOW NOWAIT "Downloading remote image file..."

    TRY
        = URLDownloadToCacheFile(0, VFP_ONLINE_IMAGE,;
            @cImageFile, LEN(cImageFile), 0,0)
    CATCH
    ENDTRY
    WAIT CLEAR

    cImageFile = STRTRAN(cImageFile, CHR(0), "")
    imagefile = CREATEOBJECT("gdiimage", m.cImageFile)

PROCEDURE OpenResultImage(cFilename)
    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:
  • ~
3263 bytes  
Created: 2006-05-10 20:41:09  
Modified: 2006-06-02 08:52:07  
Visits in 7 days: 26  
Listed functions:
ShellExecute
URLDownloadToCacheFile
Printer friendly API declarations
My comment:
Before creating the target bitmap, the GdipMeasureString function is used to calculate the bounding rectangle for the lines of text drawn with a specified font.
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.227.17.101)
19 sec.Function: 'SHAddToRecentDocs'
Function group: 'Shell Functions'
59 sec.Function: 'MQHandleToFormatName'
Function group: 'Message and Message Queue'
1.33 min.Function: 'SetupGetInfFileList'
Function group: 'Setup API functions'
1.72 min.Function: 'OpenFile'
Function group: 'File Management'
2.05 min.Function: 'waveOutGetPosition'
Function group: 'Windows Multimedia'
2.37 min.Function: 'CeRegDeleteKey'
Function group: 'Remote Application Programming (RAPI)'
2.72 min.Function: 'CreateDesktop'
3.02 min.Function: 'GetRTTAndHopCount'
3.35 min.Function: 'FileIconInit'
3.63 min.Example: 'How to play AVI file on the _screen'
Google
Advertise here!