Foxite.COM Community Weblog

Foxite.COM Community Weblog - free weblog service for the Visual FoxPro Community.
Welcome to Foxite.COM Community Weblog Sign in | Join | Help
in
Home Blogs Forum Photos Forum Archives

VFP IMAGING



  • FoxyPreviewer 1.10a

    Direct download the latest version of FoxyPreviewer

    Export your reports to Images, RTF, PDF or HTML super easy! Enhance the look of your previews!

    *** v1.10 - UPDATED 2010-02-07***

    • Fixed forced preview close (Vivek Deodhar)
    • Included new "Printer preferences" button in toolbar and context menu (using codes from Barbara Peisch)
    • Fixed "lPrintVisible" property error (Zen Tes)

    *** UPDATED 2010-02-04***

    • Included translation to Italian (thanks to Fabio Lenzarini)
    • Fix: Printing in a network printer was not working correctly
    • Fix: method RunReport, missing "This" in some lines of code (Benny Thomas)
    • Fixed RTFListener colors initialization, thanks to Hector Urrutia
    • Removed the "NORESET" clause on merged reports. Users should add it by themselves in case they need
    • Renamed the ReportListener helper classes
      (PDFx became PR_PDFX and FRX_RTF became PR_RTFListener),
      in order to avoid people messing with the original versions from the authors.
      The versions distributed with FoxyPreviewer are tweaked ones

    *** UPDATED 2010-02-02***

    • Tweaked German translation
    • Fixed GotoPage dialog not working when toolbar was not visible
    • Fixed Default printer in Combobox

     

    *** UPDATED  2010-02-03***

    • Included translation to Turkish (thanks to Soykan Ozcelik)
    • Fix: RTF Listener was omitting 1st page when Range clause was used
    • Fix: Property "lSaved" was not becoming 'True' when an image file was saved

     

    *** UPDATED 2010-02-01***

    • Included translation to German (Thanks to Tom Knauf)
    • Fixed toolbar regeneration when user closed the toolbar using the "X" button
    • Now compatible with VFP9 1st release and SP1 (SP2 strongly recommended)

    FoxyPreviewer is my report generating class, that brings some cool and useful functions, as you can see in the pictures below.

     

    FEATURES 

     

    1 - Preview Toolbar

    The original toolbar was modified, with some new button images, and new buttons too !

     

    2 - Printers ComboBox

    The printers combobox will show you all the available printers (local and in the network), and allows you to change the deviate the output to any printer that you want.

    3 - Copies spinner

    Determine on the fly the quantity of copies that you want to print!

     

    4 - Miniatures button

    View miniatures of all pages of the current report. Clicking on any miniature will jump the output page to the selected one.

     

     

    5 - Save As.

    A new button that calls a context menu that allows you to save the current report as:

    • ImageFIles - EMF, PNG, JPG, BMP, GIF, TIFF
    • HTML
    • PDF
    • RTF, a MS-Word compatible format

    6 - Context menu

    The report context menu was updated as well, receiving all the new buttons and pictures. For the case of the "Save as." button, a submenu brings all the output possibilities. 

     

     

    7 - Translating ALL report windows, dialogs, tooltips and captions.

    Have you noticed that the context menu above is in spanish ? You can determine in what language your report will be working with. Currently FoxyPreviewer is available in English, Portuguese and Spanish. It's up to you to decide in what language the dialogs will be shown.

     

    Go to page dialog in spanish

     

     

    USAGE

     

    To test FoxyPreviewer, download this file, unzip it, and run the file TESTPREVIEWER.PRG. Please make sure to start VFP from this file, by doubleclicking on this file from Explorer, to make sure that the default path is automatically set, and all the needed files will be found.

     

    To use it with your own reports is super simple, with just three lines of code:

    LOCAL loReport AS "PreviewHelper" OF "FoxyPreviewer.prg"
    loReport = CREATEOBJECT("PreviewHelper")
    loReport.AddReport(_Samples + "\Solution\Reports\colors.frx", "RANGE 1,1 NODIALOG") && FRX File, Clauses
    loReport.RunReport()

     

    The main file is FOXYPREVIEWER.PRG that contains the PreviewHelper class that is the class that you need to instantiate to have the new toolbar options. It uses the ReportListener's ExtensionHandler class to make all the changes in the original toolbar. This file also brings the classes from Colin Nicholls, that generate the miniatures sheet.

    For the RTF output, kudos go to Vladimir Zhuravlev's RTFListener class. Impressive how he managed to make it! No need of any external library, RTF Listener converts your report into an RTF file, that can be perfectly opened and viewed in MS-Word ! I applied some fixes in the original version, now allowing all the text output to be shown correctly, enabled colors for texts, backgrounds and shapes, and also images stored in general fields. Another small tweak was added to allow merging reports.

    The PDF files are generated using Luis Navas' amazing PDFx class. It uses an external library, Haru Free PDF Library 2.0.8, from Takeshi Kanno. Super light weight, no need to install a ghostscript printer, no dependancies to generate your PDFs! More info at Luis Navas' blog: http://weblogs.foxite.com/luisnavas/archive/2008/10/06/7025.aspx. The original version from Luis also received some few tweaks, to allow merging reports, and also eliminating the need to use the GdiPlusX library from VFPX. Now it used the _GdiPlus.vcx FFC class, that is already stored in the Report*.App files, that are already available in all VFP9 sources. I decided doing that because the GDI+ usage was really very very simple, and the FFC classes were enough for that purpose. Hey ! I keep recommending to everybody to use GdiPlusX !!!

     

    CUSTOMIZING

    Of course, you may choose what features will be available in the report preview toolbar. There are some few and obvious properties that you may set in order to fit your needs. Below are the methods and properties available:

     

    Methods - all obligatory

    • AddReport(tcFRXFile, tcClauses)
                  That's the place where you determine what report and which clauses will be used
                  tcFRXFile - character, the FRX to be run
                  tcClauses - character, the report clauses
                  eg.: .AddReport(_Samples + "\Solution\Reports\wrapping.frx", "NODIALOG FOR title = 'S' RANGE 3,3")

     

    • RunReport()
                  Runs the chosen report, and shows the preview window and FoxyPreviewer toolbar

     

    Properties - all optional

    • cTitle - character, the preview window title
    • lSendToEmail - logical, determines if the "send to email" button will be shown (not available yet)
    • lSaveToFile - logical, determines if the "saveto file" button will be shown
    • lShowCopies - logical, shows the copies spinner
    • lShowMiniatures - logical, shows the miniatures page
    • nCopies - numeric, the default quantity of copies to be printed
    • lPrintVisible - logical, shows the print button in the toolbar
    • cDefaultListener - character or object, the name or object from the default listener to be used; the default one is "FXLISTENER"
    • nCanvasCount - numeric, the initial nr of pages rendered on the preview form. Valid values are 1 (default), 2, or 4.
    • nZoomLevel - numeric, the initial zoom level of the preview window. Possible values are:
      1-10%, 2-25%, 3-50%, 4-75%, 5-100% default, 6-150% ;
      7-200%, 8-300%, 9-500%, 10-whole page

     

    AUTOMATING WITH INTELLISENSE

    I've also created a small PRG that updates the FOXCODE table in order to add an Intellisense script to use it. Please run the file INSTALLFOXCODE.PRG to update the Intellisense.

    To test it, open any empty PRG or Method, and just type:

    FOXYPREVIEW and a complete script with all available options will be shown. Obviously, you may delete or comment all the properties that you don't want to use.

     

    CHANGING ALL PREVIEWS

    Another cool feature is that you can also set the Global _REPORTPREVIEW variable to "FoxyPreviewer.prg", and all your reports, even those that will not create the Helper Object will have that look. Unfortunately, I could not add all the options from the toolbar to them, because it is impossible to retrieve the "FOR" clauses after a report is run.

    Just type the following in your command window:

           _ReportPreview = "FoxyPreviewer.prg"
           REPORT FORM _Samples + "Solution\Reports\Colors.frx" PREVIEW

    Notice that some functions are not available in this option, but some cool ones remain, like the changes picture buttons, translations, the Miniatures is still avalable, and the save to file can only save the report in image file.

     

    TRANSLATING TO NON ENGLISH LANGUAGES

     

    To enable it, just open the FoxyPreviewer.Prg, and you'll find in the first lines the language definitions. Comment the line that defines the default language to English, and uncomment the one that sets it to the desired language. It's very simple to add another language, just open FoxyPreviewer.prg and translate the #DEFINE's constants to your native language. I'll be very happy to add other localized languages to the main download ! Please, if you do translate it to another language, send to me your translation !

    To enable the spanish language, for instance just leave the desired language uncommented

    * #DEFINE PR_ENGLISH 
    * #DEFINE PR_PORTUGUES
    * #DEFINE PR_GERMAN
    * #DEFINE PR_ITALIANO
    * #DEFINE PR_TURKISH

        #DEFINE PR_ESPANIOL

     

    FUTURE IMPROVEMENTS

    The only missing point is the "SendToEmail" option, that I still need to put there. This envolves an HTML editor form, and a CDOSYS email class, lots of images, etc. I hope to add it to FoxyPreviewer soon. I already have this working in my own framework, but I still have to disconnect some objects in order to add them to this project, and to allow some other customizations, like allowing you to choose another email component to send your emails. The HTML editor was adapted from the original from Frederick Steczicky and Tracy Pearson, published in www.atoutfox.com .

     

    SPECIAL THANKS / AUTHORS

    As you could see, FoxyPreviewer is the result of some researches, and the use of some amazing tools provided as open source and free from other foxers. The VFP community is amazing !!!

     

    Lisa Slater Nicholls - for the great job that she made with the reporting system of VFP9 SP2. And more than that, for her great blog, the excellent and well documented articles.

     

    Colin Nicholls - He's the author of the Miniatures form; for his many great articles too regarding the new reporting system, specially for the article Exploring and Extending Report Previewing in VFP9. I took the miniatures preview form classes from there.

     

    Luis Navas - He's the author of the PDF Listener. A terrific job, great code. More info about PDFx can be obtained in his blog: PDFx Update Support for some SP2 Features. This brings a new, lightweight and very reliable option for us to export our reports to PDFs. Thanks a lot for your support and help with this project !

     

    Vladimir Zhuravlev - He's the author of the RTF Listener together with Dmitriy Petrov and Valeriy Liftshits with help of Vadim Pirozhkov. It was published in the Foxite downloads section - http://www.foxite.com/downloads/default.aspx?id=166. Another impressive and courageous work. Thanks very much !

     

    Leandro Walfrans for testing and Luis Maria Guayan, for his continuous support and for the spanish translations. Tom Knauf, for the german translation.

     

    Takeshi Kanno, the author of the HARU PDF library, and all his collaborators, for making PDFx come true with HARU library. More information about this great project: http://libharu.org/wiki/Main_Page

     

    DOWNLOAD

    FoxyPreviewer Sources and Samples

     

     

    Hope you enjoy !

  • FoxCharts v1.20 Production version released !!!

     

    At last !!!

     

    FoxCharts has just been pushed to Production release - Version 1.20.

     

    The challenge has been really very big, due to all the possible variations that charts may have and all the correlations that each chart type has with another. In the last months the library has grown, and received lots of improvements.

     

    Collaborators

    This has been a fantastic experience to me. During these times I received lots of support from many foxers, that provided solutions, reported bugs, helped documenting, offered new samples, "impossible improvements", all these things that brought encouragement, and fuel to continue enhancing it.

    The thing that makes me feel most proud is the great help that I received from people from all sides of the world. Below is a list with the names of people that offered some great support to FoxCharts. In advance, I'm sorry for the missing names.

    Alex Yudin (Ukraine)
    Augusto Minari (Brazil)
    Bernard Bout (Australia)
    Bo Durban (USA)
    Borislav Borissov (Bulgaria)
    Carlos Alloatti (Argentina)
    Christof Wollenhaupt (Germany)
    Demetrius Kandirys - Grego (Brazil)
    Emerson Reed (Brazil)
    Harry Lode (Cambodia)
    Jim Nelson (USA)
    Karl Schierman (Germany)
    Klaus Hentschel (Germany)
    Koen Piller (Holland)
    Leandro Walfrans (Brazil)
    Luis Maria Guayan (Argentina)
    Mauricio Marques - Moshe (Brazil)
    Matt Weinbender
    Matt Slay (USA)
    Paulo Henrique de Almeida (Brazil)
    Peter Wagner (Brazil)
    Ricardo Soares (Brazil)
    Thiago Takehana (Brazil)
    Yousfi Benameur (Algeria)

    Some people deserve a special attention:

    Bo Durban, for his help and support in the first steps, and for making it possible with GdiPlusX;

    Jim Nelson, for his great help in some parts of codes, specially with the scales, Memberdata support, PEM editor special support, for testing, samples, support classes (VCD - visual chart designer) and documenting. For always being available, for a fantastic and continuous support. Thanks dude !;

    Alex Yudin, for some great improvements and samples;

    Ricardo Soares, for starting the help project;

    Koen Piller, for his great and impressive support, testing every version of the classes, samples and HELP file with great patience in all details, for his support in forums;

    ... and all other people who have been testing the class, and have reported bugs, asked questions or improvements. THANK YOU VERY MUCH !!!

     

    License

    FoxCharts is a totally free and open source VFPX project, and it's under its license

     

    Samples and Documentation

    At this moment, FoxCharts brings 17 official chart types, that can be derived or adapted to generate other kinds. It's really very easy to use it. We have already some great documentation, based on a HELP file and a DOC file, explaining how to use it, full of images

    The main FoxCharts file brings lots of samples as well, destinated to beginners and to advanced users. I hope to make some posts showing some very simple and easy ways to create your own charts.

    You can download it directly from the VFPX website at CodePlex from this link, where you'll find also the HELP file and additional documentation, tutorials and a teaser video.

    To begin, unzip the files, and run the file FoxChartsSamplesMain.Scx , that will fire the form below, that will help you to access all the available samples.

     FoxChartsSamplesMain.Scx

     

    Prerequisites:

    Visual FoxPro 9 (preferrably SP2 for a faster image rendering) and the GdiPlusX library from VFPX

     

    Main Features:

    • Create good looking and modern charts in pure VFP
    • No ActiveX components
    • Easy to setup and customize
    • Easy to save to disk or print - Save as EMF, resulting in perfect charts when printed in VFP reports
    • Open Source
    • Benefit from all the GdiPlusX drawing capabilities, allowing users to modify the charts the way they like.
    • Explore all kinds of colors, solid colors, gradients, hatch brushes
    • Random colors, color pallettes
    • Customize scales
    • Text Fonts
    • Alignments
    • Formatting
    • Detach or hide interactively pie or doughnut slices
    • Tooltips
    • Draw legends inside shapes
    • Customize side legends
    • PEM Editor 5 Friendly

    Samples:

    Below are some screenshots of some charts that you can create very easilly using FoxCharts. Click on the images to get a full script to generate those charts. All you have to do is to download FoxCharts first, and make sure to choose the directory where FoxCharts.Vcx resides, when the PRG asks for that file.

     









































































    Related Links

    FoxCharts downloads

    FoxCharts Info page at VFPX

    FoxCharts Tools Info page at VFPX (by Jim Nelson)

  • Extended MessageBox function - Updated ! - change button captions, main icon, disable buttons

    Updated version - now allowing changing icons and disabling buttons

     

    lnOption = MsgBoxEx( ;
       "You have entered a wrong password for 5 times.
    " + CHR(13) + ;
       "For security reasons this login was suspended.", ; && Main message
       0, ; && Default icon info
       "Password incorrect", ; && Title bar caption
       "\&Retry,&Exit,Get &new pwd", ; && New button captions
       "41.ico") && Icon file

     

     

     

    This is a simple function that allows us to customize the captions of buttons of the MessageBox() dialog window, like in the image shown above.

    Thanks to Mike Gagnon and Anatolyi Mogylevetz, here's an updated version of the version that allows to change the icon and also to disable the buttons.

    Basically I followed Anatolyi's instructions to allow disabling the buttons. Changing the dialog icon was also very simple, with a short research in his great site - Using Win32 functions in Visual FoxPro .

    I just adapted a sample provided by Craig Boyd in his blog article - BindEvent on Steroids using the VFPEX.FLL that he provided in that article. Please refer to the original article for more details.

    I called it MsgBoxEx.Prg , and can be used very simply, to obtain the result below - notice the 4th parameter, that contains the captions of the buttons to be used, delimited by a comma:

    lnOption = MsgBoxEx(;
       "An unexpected error has occurred and the system needs to be restarted" + ;
       CHR(13) + CHR(13) + "What do you want to do ?", ;
       "X", ;
       "MsgBoxEx Sample", ;
       "Restart &Now,Restart &Later,&Never Restart")

     

     

    lnOption = MsgBoxEx( ;
       "Could not find the file 'Import.csv' in the selected folder", ;
       0, ;
       "File not found", ;
       "&Abort,\&Retry,Change folder", ;
       "17.ico")

     

     

    Function: MSGBOXEX.PRG

    Description: Modifies the captions of MessageBox buttons

    Parameters:

    • tcCaption - the text that appears in the dialog box.
    • tnIcon - the icon sign - can be numeric, using the default MESSAGEBOX() icon values or character:
         - Stop sign: 16 or "X"
         - Question mark: 32 or "?"
         - Exclamation point: 48 or "!"
         - Information: 64 or "I"
    • tcTitle - the text that appears in the title bar of the dialog box
    • tcButtons - The captions to be used in the buttons using the comma "," delimiter
      Use the "&" character to determine the hotkeys to be used - eg: "Option&1,Option&2,Option&3" - The "\" backslash can be used to show the current button disabled.
    • tcIconFile - (optional) The icon image file

    Returns: the index number according to the option selected - eg. returns the value 3 if the 3rd button was selected.

     

    PROS:

    Use the same dialog interface from the MESSAGEBOX() function, allowing us to easilly customize existing dialog boxes.

    Almost the same structure of parameters of the original function

    Behaves correctly in all operating systems.

    Allows hotkeys (Thanks to Thiago Takehana for reminding about this possibility)

     

    CONS:

    Up to 3 buttons are allowed

    Size of buttons is limited to the original MESSAGEBOX() buttons size, not allowing big sized buttons.

     

    LPARAMETERS tcCaption, tnIcon, tcTitle, tcButtons, tcIconFile
    * MSGBOXEX.PRG
    * Description: Modifies the captions of MessageBox buttons
    * Prerequisites: Needs VFPEX.FLL by CraigBoyd
    *
    http://www.sweetpotatosoftware.com/spsblog/ct.ashx?id=f7644db8-b155-4d43-8216-4cfde233edb7&url=http%3a%2f%2fwww.sweetpotatosoftware.com%2ffiles%2fvfpex.zip
    * More Info about VFPEX.FLL
    *
    http://www.sweetpotatosoftware.com/spsblog/2005/08/07/BindEventOnSteroids.aspx
    * Parameters:
    * tcCaption - the text that appears in the dialog box.
    * tnIcon - the icon sign
    * tcTitle - the text that appears in the title bar of the dialog box
    * tcButtons - The captions to be used in the buttons using the comma "," delimiter
    * Use the "&" character to determine the hotkeys to be used - eg: "Option&1,Option&2,Option&3"
    * Use a "\" to disable the button
    * tcIconFile - the icon file to replace the default from MessageBox()
    * Returns: the index number according to the option selected - eg. returns the value 3 if the 3rd button was selected.
    * Sample:
    * =MsgBoxEx("This is a common text", "!", "Window Title", "Option1,Option2,Option3")
    IF VARTYPE(tnTimeOut) = "C" AND (PCOUNT
    () = 4)
       tcButtons = tnTimeOut
       tnTimeOut = 0
    ENDIF

    PRIVATE pnButtonCnt, pcButtons, pnButtType, pcIconFile, phIcon
    pcIconFile =
    IIF(EMPTY
    (tcIconFile),"", tcIconFile)
    pnButtonCnt =
    GETWORDCOUNT
    (tcButtons, ",")
    pcButtons = tcButtons
    *!* Stop 16
    *!* Question 32
    *!* Exclamation 48
    *!* Info 64
    IF VARTYPE
    (tnIcon) = "C"
       tnIcon =
    UPPER
    (tnIcon)
       DO CASE
       CASE
    tnIcon = "X"
          tnIcon = 16
       CASE
    tnIcon = "?"
          tnIcon = 32
       CASE
    tnIcon = "!"
          tnIcon = 48
       CASE
    tnIcon = "I"
          tnIcon = 64
       OTHERWISE
          tnIcon = 0
       ENDCASE
    ENDIF

    * Check if an icon will be shown
    * If an icon file was passed, we need to ensure that MessageBox() will
    * show an icon, that will be changed further.

    #DEFINE IMAGE_BITMAP 0
    #
    DEFINE
    IMAGE_ICON 1
    #
    DEFINE
    LR_LOADFROMFILE 0x0010
    #
    DEFINE
    LR_DEFAULTSIZE 0x0040
    phIcon = 0
    IF NOT EMPTY(pcIconFile) AND ;
       (NOT (BITTEST(tnIcon, 4) OR BITTEST(tnIcon, 5) OR BITTEST
    (tnIcon, 6)))
       tnIcon = tnIcon + 16
       phIcon = xmbLoadImage(0, FULLPATH(pcIconFile), IMAGE_ICON,;
    0,0, LR_LOADFROMFILE + LR_DEFAULTSIZE)
    ENDIF

     
    * Windows Hook constants
    #define WH_CBT 5

    * Set library so BindEventEx and UnBindEventEx can be used in VFP
    LOCAL
    lcOldSetLib
    lcOldSetLib =
    SET
    ("Library")
    SET LIBRARY TO (LOCFILE
    ("vfpex.fll"))
    BindEventEx('wineventhandler()', WH_CBT)
    && SetWindowsHookEx

    * This messagebox will be modified before it is shown
    LOCAL
    lnOption, lnIndex
    DO CASE
    CASE
    pnButtonCnt = 1
       pnButtType = 0
    && Ok
    CASE
    pnButtonCnt = 2
       pnButtType = 4
    && Yes / No
    CASE
    pnButtonCnt = 3
       pnButtType = 2
    && Abort / Retry / Ignore
    OTHERWISE
    ENDCASE

    lnOption = MESSAGEBOX(tcCaption, tnIcon + pnButtType, tcTitle)

    LOCAL lnOffSet
    lnOffSet =
    ICASE
    (pnButtonCnt = 3, 2, pnButtonCnt = 2, 5 , 0)
    lnIndex = lnOption - lnOffSet

    IF phIcon <> 0
       =xmbDeleteObject(phIcon) && Clear icon handle
    ENDIF

    IF NOT EMPTY(lcOldSetLib)
       SET LIBRARY TO
    (lcOldSetLib)
    ENDIF
    RETURN
    lnIndex


     
    PROCEDURE wineventhandler
    #
    DEFINE
    DLG_CTRLID_ICON 0x0014
    #
    DEFINE
    STM_SETICON 0x0170
    #
    DEFINE
    STM_SETIMAGE 0x0172
    IF nCode == 5
       IF NOT EMPTY(phIcon
    )
          * Changing the Dialog icon
          LOCAL
    lhIconWindow
          lhIconWindow = xmbGetDlgItem(wParam, DLG_CTRLID_ICON)
          IF
    lhIconWindow <> 0
             IF
    phIcon <> 0
                =xmbSendMessage(lhIconWindow, STM_SETICON, phIcon, 0)
             ENDIF
          ENDIF
       ENDIF

       * Change button attributes
       LOCAL
    n, lnOffSet, lcCaption
       lnOffSet =
    ICASE
    (pnButtonCnt = 3, 2, pnButtonCnt = 2, 5 , 0)
       FOR n = 1 TO
    pnButtonCnt
          lcCaption =
    GETWORDNUM
    (pcButtons, n, ",")
          * Disable current button
          IF LEFT
    (lcCaption, 1) = "\"
             lcCaption =
    SUBSTR(lcCaption, 2)
    && Get the rest of the string
             LOCAL
    lnBtnHwnd
             lnBtnHwnd = xmbGetDlgItem(wParam, lnOffSet + n)
             =xmbEnableWindow(lnBtnHwnd, 0)
          ENDIF

          * Change the caption
          =xmbSetDlgItemText(wParam, lnOffSet + n, lcCaption)
       ENDFOR

       =xmbCallNextHookEx(hHook, nCode, wParam, LPARAM) && all 4 variables exist
       UnBindEventEx()
    ELSE
       =xmbCallNextHookEx(hHook, nCode, wParam, LPARAM)
    && all 4 variables created by FLL
    ENDIF

    RELEASE nCode, wParam, LPARAM, hHook
    ENDPROC

     

    *********************************************************************
    FUNCTION
    xmbSetDlgItemText(hDlg, nIDDlgItem, lpString)
    *********************************************************************
    DECLARE INTEGER SetDlgItemText IN user32 AS
    xmbSetDlgItemText ;
       LONG
    hDlg,;
       LONG
    nIDDlgItem,;
       STRING
    lpString
    RETURN
    xmbSetDlgItemText(hDlg, nIDDlgItem, lpString)
    ENDFUNC

    *********************************************************************
    FUNCTION
    xmbCallNextHookEx(hHook, nCode, wParam, lParam)
    *********************************************************************
    DECLARE LONG CallNextHookEx IN user32 AS
    xmbCallNextHookEx ;
       LONG hHook, LONG nCode, LONG wParam, LONG
    lParam
    RETURN
    xmbCallNextHookEx(hHook, nCode, wParam, lParam)
    ENDFUNC

    *********************************************************************
    FUNCTION
    xmbGetDlgItem(hDlg, nIDDlgItem)
    *********************************************************************
    * hDlg [in] Handle to the dialog box that contains the control.
    * nIDDlgItem [in] Specifies the identifier of the control to be retrieved.
    *
    http://msdn.microsoft.com/en-us/library/ms645481(VS.85).aspx
    DECLARE INTEGER GetDlgItem IN user32 AS xmbGetDlgItem ;
       LONG
    hDlg,;
       LONG
    nIDDlgItem
    RETURN
    xmbGetDlgItem(hDlg, nIDDlgItem)
    ENDFUNC

    *********************************************************************
    FUNCTION xmbEnableWindow(hwnd
    , fEnable)
    *********************************************************************
    DECLARE INTEGER EnableWindow IN user32 AS xmbEnableWindow INTEGER hwnd, INTEGER
    fEnable
    RETURN xmbEnableWindow(hwnd
    , fEnable)
    ENDFUNC

    *********************************************************************
    FUNCTION
    xmbSendMessage(hWindow, Msg, wParam, lParam)
    *********************************************************************
    *
    http://msdn.microsoft.com/en-us/library/bb760780(VS.85).aspx
    * http://www.news2news.com/vfp/?group=-1&function=312
    DECLARE INTEGER SendMessage IN user32 AS
    xmbSendMessage;
       INTEGER hWindow, INTEGER
    Msg,;
       INTEGER wParam, INTEGER
    lParam
    RETURN
    xmbSendMessage(hWindow, Msg, wParam, lParam)
    ENDFUNC

    *********************************************************************
    FUNCTION
    xmbLoadImage(hinst, lpszName, uType, cxDesired, cyDesired, fuLoad)
    *********************************************************************
    DECLARE INTEGER LoadImage IN user32 AS
    xmbLoadImage;
       INTEGER
    hinst,;
       STRING
    lpszName,;
       INTEGER
    uType,;
       INTEGER
    cxDesired,;
       INTEGER
    cyDesired,;
       INTEGER
    fuLoad
    RETURN
    xmbLoadImage(hinst, lpszName, uType, cxDesired, cyDesired, fuLoad)
    ENDFUNC

    *********************************************************************
    FUNCTION
    xmbDeleteObject(hObject)
    *********************************************************************
    DECLARE INTEGER DeleteObject IN gdi32 AS xmbDeleteObject INTEGER
    hObject
    RETURN
    xmbDeleteObject(hObject)
    ENDFUNC
     

    Download the vfpex.fll here, created by Craig Boyd, directly from the SPS Weblog. 

     

    History:

    2009-10-19 Original version (change captions)

    2009-10-23 Updated, allowing icon change and disabling buttons

     

  • A GdiPlusX analog clock

    After I posted a gauge sample with GdiPlusX some months ago, Rafael Lippert from Brazil adapted my original code and created this cool analog watch, using GdiPlusX and the ImageCanvas class:

    Cool isn't it ? It permits many customizations, and you may use it as a sample to learn other GdiPlusX techniques.

    You may get it directly from Rafael' blog, at: http://lipsil.spaces.live.com/blog/cns!9498DCF62578E128!192.entry

    It's worth to spend some time in Rafael's blog and website - www.lipsil.com.br . I'm sure you'll find some really very neat utilities.

  • SW Fox accessible to everyone !

    Southwest Fox

    SW Fox conference has just begun !

    And the good news that for us people who could not attend this fabulous source of knowledge, some very interesting sessions are being broadcasted in live by Steve Bodnar.

    There's also a cool option for chatting online with other people that are watching the broadcasting, and even interact with people from the conference !

    Last night I had the oportunity to watch the keynote session, when I "met" some other fellas in the chat room - that was really cool!

    All sessions can be reached directly from the broadcasting channel
    http://www.ustream.tv/channel/swfoxtv

    More info can be obtained directly at the conference blog:
    http://swfox.net/blog/index.htm


    The next available sessions schedule:

    VFPX Users Meeting - Bonus session
    Friday, 10/16/2009 05:15 pm (Arizona Time)

    The Future of the VFP Developer - Bonus session
    Friday, 10/16/2009 08:30 pm (Arizona Time)

    Enhancing the VFP IDE with VFPX Tools
    Saturday, 10/17/2009 11:30 am (Arizona Time)

    Hope to meet you in the chat room !

  • Draw rounded rectangles with GdiPlusX

    This post is just to answer a question from Mr. Reed.

    Bob Powell, in his great website site says: "The trick here is to use a GraphicsPath object to assemble a collection of  lines and arcs that make up the rounded rectangle shape.

    Arcs are used to round off the corners, so you have to position the lines 1 radius, whatever that may be, from the actual corner."

     

    The code below shows Bob's function converted to VFP and GdiPlusX, to obtain this result:

     

    LOCAL loBmp as xfcBitmap, loGfx as xfcGraphics
    WITH _Screen.System.Drawing as
    xfcDrawing
       * Create a new bitmap
       loBmp = .Bitmap
    .New(200,170)
       * Get a Graphics object for drawing
       loGfx = .Graphics.FromImage(loBmp)
       * Clear the drawing canvas
       loGfx.Clear(.Color
    .LightCoral)
       * Draw the rounded rectangle
       =DrawRoundRect(loGfx, .Pens.Blue, 20, 30, 150, 100, 20)
       * Save image to file
       loBmp.Save
    ("RoundedRect.Png", .Imaging.ImageFormat.Png)
    ENDWITH
    RUN
    /N Explorer.Exe RoundedRect
    .Png
     
     
     
    FUNCTION DrawRoundRect(toGfx as xfcGraphics, toPen as
    xfcPen, ;
          tnX, tnY, tnWidth, tnHeight, tnRadius)
       * Adapted by Cesar from Bob Powell's sample taken from
       *
    http://www.bobpowell.net/roundrects.htm

       LOCAL loGPath as xfcGraphicsPath
       loGPath =
    _Screen.System
    .Drawing.Drawing2D.GraphicsPath.New()

       WITH loGPath
          .AddLine(tnX + tnRadius, tnY, tnX + tnWidth - (tnRadius*2), tnY)
          .AddArc(tnX + tnWidth - (tnRadius*2), tnY, tnRadius*2, tnRadius*2, 270, 90)
          .AddLine(tnX + tnWidth, tnY + tnRadius, tnX + tnWidth, tnY + tnHeight - (tnRadius*2))
          .AddArc(tnX + tnWidth - (tnRadius*2), tnY + tnHeight - (tnRadius*2), tnRadius*2, tnRadius*2,0,90)
          .AddLine(tnX + tnWidth - (tnRadius*2), tnY + tnHeight, tnX + tnRadius, tnY + tnHeight)
          .AddArc(tnX, tnY + tnHeight - (tnRadius*2), tnRadius*2, tnRadius*2, 90, 90)
          .AddLine(tnX, tnY + tnHeight - (tnRadius*2), tnX, tnY + tnRadius)
          .AddArc(tnX, tnY, tnRadius*2, tnRadius*2, 180, 90)
          .CloseFigure()
       ENDWITH
       toGfx.DrawPath(toPen, loGPath)
    ENDFUNC

    Notice that the above function receives a xfcPen object to draw the rounded rectangle. In order to draw a FILLED rounded rectangle, all we need is to add a small tweak in the above function to use a Brush object instead a Pen, and call the FillPath function instead of DrawPath.

    I leave this easy exercise to you :-D

     

     

     

     

     

     

     

  • Drawing shapes using the PolyPoints property

    VFP9 brought a new property that allows us to draw all kinds of shapes, without the need of any external component, even a single Windoes API call.

    According to the VFP9 Help, The PolyPoints property of the Shape control "specifies an array of coordinates for creating polygon shapes using the Shape control and polygon lines using the Line control. Read/write at design time and run time. For Shape controls, PolyPoints creates a polygon shape."

    MVP Luis Maria Guayan from Argentina already did an amazing job using the polypoints property, in 2 articles.

    Dibujando polígonos con VFP 9.0 - a simple article with some samples showing how we can draw a TRaiangle and an Ogtogon. The article is in spanish, but it is very simple to run the provided samples and reproduce the proposed result.

    The 2nd one, Gráficas con objetos 100% VFP, is a real masterpiece, where he uses the polypoints property to create chart shapes, providing a very nice charting tool. Download the source code and play with the samples, amazing !

     

    Using the PolyPoints property we can also draw rounded shapes, pie slices, circles and ellipses.

    Create an empty form, size it the way you like, and paste the following code to the INIT() event, to reproduce the shape below:

    Thisform.AddObject("Shape1", "Shape")
    * Add a shape object to the current form
    * and set some basic properties
    LOCAL loShape
    as Shape
    loShape = Thisform
    .Shape1
    loShape.
    Width = Thisform.
    Width
    loShape.Height = Thisform.
    Height
    loShape.Anchor = 15
    && Resize Width and Height
    loShape.BackColor = RGB
    (255,0,0)
    loShape.
    PolyPoints = "aPoly"
    && Array of points
    loShape.Visible
    = .T.
     
    * Defining the PolyPoints array
    * Change the values of lnStart and lnFinal to determine
    * the angle of the pie slice
    LOCAL
    lnStart, lnFinal, lnSweep, n, lnRadius, lnAngle
    lnStart = 0
    lnFinal = 360

    lnSweep = lnFinal - lnStart
    lnRadius = 50

    PUBLIC aPoly(lnSweep + 2, 2)
    FOR n = 1 TO
    lnSweep + 1
       lnAngle = lnStart + n - 1
       aPoly(n,1) = (lnRadius *
    COS(DTOR
    (lnAngle)) + lnRadius)
       aPoly(n,2) = (lnRadius *
    SIN(DTOR
    (lnAngle)) + lnRadius)
    ENDFOR

    IF lnSweep = 360 && Closed ellipse, so dont draw the center point
       aPoly(n,1) = aPoly(n-1,1)
       aPoly(n,2) = aPoly(n-1,2)
    ELSE
       * Determine the Center point
       aPoly(n,1) = lnRadius
       aPoly(n,2) = lnRadius
    ENDIF

     

    To obtain pie slices, just change the values of the variables lnStart and lnFinal, to determine the starting and ending angle.

    Here's the result if you use:

    lnStart = 90
    lnFinal = 210

     

    The very cool feature of polypoints is that it generates vectorial pictures. You can resize the form the way you like, and you'll see your shape changing accordingly. All I did for that purpose was to setup the property Anchor to the value 15 (resize width and height).

     

  • Change the shape of your pictures with GdiPlusX

    The samples below use the Graphics.SetClip function to draw shaped borders in your pictures.

    The trick here is to use the CombineMode.XOR enumeration, that forces the drawing to the external part of the shape, like in the samples below.

    Playing with the source image below:

    Prerequisites
    Visual FoxPro 9 and the GdiPlusX library from VFPX 

    Please make sure that you have the latest version, because this sample may be using some functions that were added or fixed recently.
    http://www.codeplex.com/VFPX/Wiki/View.aspx?title=GDIPlusX&referringTitle=Home

     

    Sample 1: Ellipse shape

    DO LOCFILE("System.app")
    WITH _Screen.System
    .Drawing
    * Get an image file
    LOCAL loBmp as
    xfcBitmap
    loBmp = .
    Bitmap.FromFile(GETPICT
    ())
    * Create a Gfx object that will allow us to make the transformation
    LOCAL loGfx as
    xfcGraphics
    loGfx = .Graphics.FromImage(loBmp)
    LOCAL
    lnWidth, lnHeight
    lnWidth = loBmp.
    Width
    lnHeight = loBmp.
    Height
     
    * Create GraphicsPath object.
    LOCAL loClipPath as
    xfcGraphicsPath
    loClipPath = .Drawing2D.GraphicsPath.New()
     
    * An Ellipse shape
    loClipPath.AddEllipse(0, 0, lnWidth, lnHeight)
     
     
    * Set clipping region to path.
    * CombineMode enumeration
    *
    http://msdn.microsoft.com/en-us/library/system.drawing.drawing2d.combinemode.aspx
    * CombineMode.Xor - Two clipping regions are combined by taking only the areas
    * enclosed by one or the other region, but not both.
    loGfx.SetClip(loClipPath, ;
    _Screen.System
    .Drawing.Drawing2D.CombineMode.Xor)
    * Fill rectangle to demonstrate clipping region.
    loGfx.FillRectangle( .Brushes.White, 0, 0, loBmp.Width, loBmp.Height
    )
    * Save the image to the disk and show
    loBmp.Save
    ("Clipped.Jpg", "image/jpeg")
    RUN /n Explorer.Exe
    Clipped.Jpg
    ENDWITH

     

     

     

     

     

     

    Sample 2: Doughnut shape

    DO LOCFILE("System.app")
    WITH _Screen.System
    .Drawing
    * Get an image file
    LOCAL loBmp as
    xfcBitmap
    loBmp = .
    Bitmap.FromFile(GETPICT
    ())
    * Create a Gfx object that will allow us to make the transformation
    LOCAL loGfx as
    xfcGraphics
    loGfx = .Graphics.FromImage(loBmp)
    LOCAL
    lnWidth, lnHeight
    lnWidth = loBmp.
    Width
    lnHeight = loBmp.
    Height
     
    * Create GraphicsPath object.
    LOCAL loClipPath as
    xfcGraphicsPath
    loClipPath = .Drawing2D.GraphicsPath.New()
     
     
    * A Doughnut slice shape
    loClipPath.AddEllipse(0, 0, lnWidth, lnHeight * 2)
    loClipPath.AddEllipse(lnWidth / 4, lnHeight / 2, lnWidth/2, lnHeight * 4)
     
     
    * Set clipping region to path.
    * CombineMode enumeration
    *
    http://msdn.microsoft.com/en-us/library/system.drawing.drawing2d.combinemode.aspx
    * CombineMode.Xor - Two clipping regions are combined by taking only the areas
    * enclosed by one or the other region, but not both.
    loGfx.SetClip(loClipPath, ;
    _Screen.System
    .Drawing.Drawing2D.CombineMode.Xor)
    * Fill rectangle to demonstrate clipping region.
    loGfx.FillRectangle( .Brushes.White, 0, 0, loBmp.Width, loBmp.Height
    )
    * Save the image to the disk and show
    loBmp.Save
    ("Clipped.Jpg", "image/jpeg")
    RUN /n Explorer.Exe
    Clipped.Jpg
    ENDWITH

     

     

     

     

    Sample 3: Star shape


    DO LOCFILE("System.app")
    WITH _Screen.System
    .Drawing
    * Get an image file
    LOCAL loBmp as
    xfcBitmap
    loBmp = .
    Bitmap.FromFile(GETPICT
    ())
    * Create a Gfx object that will allow us to make the transformation
    LOCAL loGfx as
    xfcGraphics
    loGfx = .Graphics.FromImage(loBmp)
    LOCAL
    lnWidth, lnHeight
    lnWidth = loBmp.
    Width
    lnHeight = loBmp.
    Height
     
    * Create GraphicsPath object.
    LOCAL loClipPath as
    xfcGraphicsPath
    loClipPath = .Drawing2D.GraphicsPath.New()
     
     
     
    * Source for the star drawing
    *
    http://www.java2s.com/Code/VB/2D/GraphicsPathDrawwithFillModeWinding.htm
    LOCAL lnRadius, lnPi, lnRadian72, n, lnEdges
    lnRadius = lnHeight / 2
    lnPi = 3.141592
    lnEdges = 5
    lnRadian72 = (lnPi * 4.0 ) / lnEdges
    LOCAL
    laPoints(lnEdges)
    FOR n = 1 TO
    lnEdges
    laPoints(n) = .
    Point
    .New(;
    + lnRadius *
    SIN
    ( n * lnRadian72 ) + lnRadius , ;
    - lnRadius *
    COS
    ( n * lnRadian72 ) + lnRadius )
    ENDFOR
    loClipPath.AddPolygon(@laPoints)
    * Set the Clip Mode to Winding
    * ClipMode enumeration
    *
    http://msdn.microsoft.com/en-us/library/system.drawing.drawing2d.fillmode.aspx
    loClipPath.FillMode = _Screen.System.Drawing.Drawing2D.FillMode.Winding
     
    * Set clipping region to path.
    * CombineMode enumeration
    *
    http://msdn.microsoft.com/en-us/library/system.drawing.drawing2d.combinemode.aspx
    * CombineMode.Xor - Two clipping regions are combined by taking only the areas
    * enclosed by one or the other region, but not both.
    loGfx.SetClip(loClipPath, ;
    _Screen.System
    .Drawing.Drawing2D.CombineMode.Xor)
    * Fill rectangle to demonstrate clipping region.
    loGfx.FillRectangle( .Brushes.White, 0, 0, loBmp.Width, loBmp.Height
    )
    * Save the image to the disk and show
    loBmp.Save
    ("Clipped.Jpg", "image/jpeg")
    RUN /n Explorer.Exe
    Clipped.Jpg
    ENDWITH

     

    Notice that the only difference between the code samples is the shape definition !

  • Circular Gauge chart with GdiPlusX

    Drawing shapes with GdiPlusX is super easy, and we can very easilly transport this to solve some of our chart needs.

    In this post I'm sending you a very primitive sample for creating Circular Gauge charts. Obviously I hope to apply the techniques shown here in FoxCharts. But FoxCharts is getting big, and I confess that learning from the methods in FoxCharts may not be easy for people that are not that familiar with GdiPlusX.

    Please note that this is an unfinished sample. I'm posting it here to let people see that drawing is not that complicated. Just using some imagination, merging it with some geometrical thoughts, and voilá !

    Download the Gauge sample, unzip and run TESTGAUGE.SCX ! I'm including the GdiPlusX sources to let everybody immediately run the samples.

     

    Notice that you can control the colors of the background and pointer.

    The pointer shape can be modified too. Play with all the spinners to modify the shape and size! And please tell me which you like most. I'll apreciate receiving some image samples with some desired gauge charts.

     

    Below is the relevant code for the circular gauge drawing. You'll find it in the "BeforeDraw()" event of the ImageCanvas class. It extracts the information from the form controls, and it's very easy to adapt it to your needs.

     

     

    LOCAL lnAngle, lnBaseW, lnBaseX, lnBaseY, lnTopW, lnHeightPercent, lnTopY
    LOCAL lnType, lnPointClr, lnBackClr, lnTicks
    lnTicks =
    Thisform.SpnTicks.Value
    lnType = Thisform.OptShape.Value
    lnAngle = Thisform.SpnAngle.Value
    lnBaseW = Thisform.SpnBottomW.Value
    lnTopW = Thisform.SpnTopW.Value
    lnBaseX = This.Width/2 -lnBaseW/2
    lnBaseY =
    This.Height/2
    lnHeightPercent =
    Thisform.SpnHeight.Value / 100
    lnTopY = lnBaseY - (lnBaseY * lnHeightPercent) + lnTopW / 2
    lnPointClr =
    Thisform.ShpPointerColor.BackColor
    lnBackClr = Thisform.ShpBackColor.BackColor
    LOCAL
    loGfx as xfcGraphics
    loGfx =
    This.oGfx

    WITH _Screen.System.Drawing
       LOCAL loBrush as xfcSolidBrush
       loBrush = .SolidBrush.New(.
    Color.FromRGB(lnPointClr))

       loGfx.Clear(.Color.FromRGB(Thisform.BackColor))

       * Create a Shape for the pointer
       LOCAL loPath as xfcGraphicsPath
       loPath = .Drawing2D.GraphicsPath.New()
       loPath.StartFigure()
       loGfx.FillEllipse(.SolidBrush.New(.Color.FromRGB(lnBackClr)), ;
             This.Rectangle)

       IF lnType = 1
          loPath.AddArc(lnBaseX,
    This.Height/2 -lnBaseW/2, lnBaseW, lnBaseW, 0, 180)
       ENDIF

       loPath.AddLine(lnBaseX, lnBaseY, This.Width/2 - lnTopW/2, lnTopY)
       IF lnType = 1
          LOCAL laPoints(3)
          laPoints(1) = .
    Point.New(This.Width/2 - lnTopW/2, lnTopY)
          laPoints(2) = .
    Point.New(This.Width/2 , lnTopY - lnTopW / 2)
          laPoints(3) = .
    Point.New(This.Width/2 + lnTopW/2, lnTopY)
          loPath.AddCurve(@laPoints)
       ENDIF

       loPath.AddLine( This.Width/2 + lnTopW/2, lnTopY, lnBaseX + lnBaseW, lnBaseY)
       loPath.CloseFigure()

       * Rotate the shape pointer
       loGfx.TranslateTransform(This.Width/2, This.Height/2)
       loGfx.RotateTransform(lnAngle)
       loGfx.TranslateTransform(-
    This.Width/2, - This.Height/2)

       * Draw the pointer
       loGfx.FillPath(loBrush, loPath)

       * Restore the original Gfx rotation state
       loGfx.ResetTransform()
     

       IF lnTicks > 0
          FOR lnAngle = 0 TO 360 STEP 360 / lnTicks

             * Rotate the Gfx
             loGfx.TranslateTransform(This.Width/2, This.Height/2)
             loGfx.RotateTransform(lnAngle)
             loGfx.TranslateTransform(-
    This.Width/2, - This.Height/2)

             * Draw the ticks
             loGfx.DrawLine(.Pens.Black, This.Width/2, 0, This.Width/2, 10)

             * Restore the original Gfx rotation state
             loGfx.ResetTransform()
          ENDFOR 
       ENDIF

    ENDWITH

     

    Enjoy !!!

    Download Gauge Prototype sample with GdiPlusX

     

    I've prepared a much more complete sample using FoxCharts.
    People can get it from the main download, and run the sample "ChartsSample_CircularGauge.scx"
    It allows lots of customizations, like the picture below.

    You can get the latest version of FoxCharts here:
    http://vfpx.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=18515

  • Drawing Unicode texts with GdiPlusX

    We forgot to add to GdiPlusX a specific function to allow sending Unicodes directly, similar to the function DrawString.

     

    But as you'll see below, it's really simple to adapt the original function and provide this possibility:

    In the sample below you'll see the function "DrawStringW", that is just an adapted version from the original xfcGraphics.DrawString function.

    It accepts the same parameters and overloads from the original function - the sole difference is the first parameter that was introduced - the Graphics object.

    Another helper function - "HexToUnicode" was introduced. It converts a string containing Hex values separated by a space into the Unicode needed by GdiPlus.dll to  draw the string.

    Just run the script and you'll obtain a result similar to the one below:

     

     

    Prerequisites
    Visual FoxPro 9 and the GdiPlusX library from VFPX 

    Please make sure that you have the latest version, because this sample may be using some functions that were added or fixed recently.
    http://www.codeplex.com/VFPX/Wiki/View.aspx?title=GDIPlusX&referringTitle=Home

     


    DO LOCFILE("System.App")

    LOCAL n, x, y, lnColor
    LOCAL loBmp as xfcBitmap, loGfx as xfcGraphics, loFont as xfcFont
    LOCAL loBrush as xfcSolidBrush
    LOCAL laWords(9,2)
    * Greek
    laWords(1,1) = "Greek"
    laWords(1,2) = "03B5 03B9 03C1 03AE 03BD 03B7"
    * Korean
    laWords(2,1) = "Korean"
    laWords(2,2) = "D3C9 D654"
    * Hebrew
    laWords(3,1) = "Hebrew"
    laWords(3,2) = "05E9 05DC 05D5 05DD"
    * Bulgarian
    laWords(4,1) = "Bulgarian"
    laWords(4,2) = "043C 0438 0440"
    * Arabic
    laWords(5,1) = "Arabic"
    laWords(5,2) = "0633 0644 0627 0645"
    * Simplified Chinese
    laWords(6,1) = "Chinese"
    laWords(6,2) = "548C 5E73"
    * Thai
    laWords(7,1) = "Thai"
    laWords(7,2) = "0E04 0E27 0E32 0E21 0E2A 0E07 0E1A"
    * Russian
    laWords(8,1) = "Russian"
    laWords(8,2) = "043C 0438 0440"
    * Japanese
    laWords(9,1) = "Japanese"
    laWords(9,2) = "5E73 548C"
     
     
    WITH _Screen.System.Drawing
    loFont = .
    Font.New("Tahoma", 18)
    loBmp = .
    Bitmap.New(350,370)
    loGfx = .Graphics.FromImage(loBmp)
    loGfx.
    Clear(.Color.White)
    loGfx.DrawString("Gdi+X Drawing Unicodes", loFont,;
       .Brushes.Black, 10,5)
     
    FOR n = 1 TO 9
       y = n * 35
       x = 160

       lnColor =
    RGB(RAND() * 255, RAND() * 255, RAND() * 255)
       * Create a SolidBrush with randomic color
       loBrush = .SolidBrush.New(.Color.FromRGB(lnColor))

       * Draw the language name
       loGfx.DrawString(laWords(n,1), .Font.New("Tahoma", 10),;
             .Brushes.Black, 65, y + 5)

       * Draw the text in Unicodes
       =DrawStringW(loGfx, HexToUnicode(laWords(n,2)), loFont,;
             loBrush, x, y)
    ENDFOR
    loBmp.Save("TestUnicodes.Png", .Imaging.ImageFormat.Png)
     
    ENDWITH

     

     


    FUNCTION
    DrawStringW(toGfx, ;
       tcString, toFont
    AS xfcFont, toBrush AS xfcBrush, tnX, tnY ;
       , toFormat
    AS xfcStringFormat)
       *********** tcString, toFont AS xfcFont, toBrush AS xfcBrush, toPoint AS xfcPointF ;
       , toFormat AS xfcStringFormat
       *********** tcString, toFont AS xfcFont, toBrush AS xfcBrush, toRectangle AS xfcRectangleF ;
       , toFormat AS xfcStringFormat

    LOCAL lqLayoutRect
    LOCAL lnWidth, lnHeight, loPoint AS xfcPointF, loRect AS xfcRectangleF
    LOCAL lhFormat
    STORE 0 TO lnWidth, lnHeight
    STORE NULL TO loPoint, loRect
    m.lqLayoutRect = 0h00

    ** Handle overload parameters
    DO CASE
    CASE VARTYPE
    (tnX) = "N"

    CASE VARTYPE(tnX) = "O" AND INLIST(tnX.BaseName,"Point","PointF")
       m.loPoint = m.tnX
       m.toFormat = m.tnY
       m.loPoint.GetExtent(@tnX, @tnY)

    CASE VARTYPE(tnX) = "O" AND INLIST(tnX.BaseName,"Rectangle","RectangleF")
       m.loRect = m.tnX
       m.toFormat = m.tnY
       m.loRect.GetExtent(@tnX, @tnY, @lnWidth, @lnHeight)
    ENDCASE

    ** Optional parameter
    ** The C++ classes show this parameter as NULL if not specified
    IF VARTYPE(m.toFormat) = "O"
       m.lhFormat = m.toFormat.Handle
    ELSE
       m.lhFormat = 0
    ENDIF

    m.lqLayoutRect = BINTOC(m.tnX,"F")+BINTOC(m.tnY,"F")+;
       BINTOC(m.lnWidth,"F")+BINTOC(m.lnHeight,"F")

    =xfcGdipDrawString(toGfx.Handle, m.tcString+0h00,
    LENC(tcString)/2, ;
       m.toFont.Handle, @lqLayoutRect, m.lhFormat, m.toBrush.Handle)
    ENDFUNC

     
    FUNCTION
    HexToUnicode(tcHex)
       LOCAL n, lcHex, lcUnicode
       lcUnicode =
    SPACE(0)
       FOR n = 1 TO GETWORDCOUNT(tcHex, SPACE(1))
          lcHex =
    EVALUATE("0x" + GETWORDNUM(tcHex, n, SPACE(1)))
          lcUnicode = lcUnicode +
    BINTOC(lcHex, "4RS")
       ENDFOR 
       RETURN
    lcUnicode
    ENDFUNC

  • Convert your buttons to BMPs keeping transparency with GdiPlusX - REVISITED

    This is just an update for an old post with the same title. Erik Gomez and Russel Campbell had some problems on the conversions of some specific PNG images, so I recoded this function, this time using a safer code.

    NEW UPDATE:

    Thanks to Bernard Bout and Craig Boyd, I've updated the code below. In fact it contained a small bug, that was not adjusting the White colors. Now it seems to be working nice. Thanks !

     

     

    This runs a little bit slower than the other aproach, but in my tests, the success was 100%.

     

    The function below converts any button image to a BMP to be used in VFP forms.

    There are lots of cool and free icons available on the web, but the vast majority are in .ICO, GIF or PNG image formats, that are not very familiar and reliable to be used in VFP. For us, the best image format, for a lot of reasons, is the BMP format.

    Some transformations are needed to make this BMP to show exactly how we desire, specially when converting source images in a PNG, GIF or ICO formats.

    VFP shows the pure white - RGB(255,255,255) as transparent in our buttons and image objects. The code below first converts the original whites to RGB(254,254,254) that is visually the same, but does not become transparent, and eliminates the need to create a mask image (.MSK) and next, converts the background color of the original bitmap to pure white, that will show transparent in VFP forms.

    For more details, please check these prior posts:

    BMPs with Transparent Backgrounds

    How to put one image over another in a form

     

    IMPORTANT
    Requires VFP9 and GdiPlusX to run. 
    Please make sure that you have the latest version, because this sample may be using some functions that were added or fixed recently.
    http://www.codeplex.com/VFPX/Wiki/View.aspx?title=GDIPlusX&referringTitle=Home

     

    Save the program below as BUTTON2BMP.PRG, and call it this way:

    Button2Bmp(GETPICT(), "c:\NewIcon.bmp")

    When you compile this program in your executable, please don't forget to remove the LOCFILE() command, and just use a DO System.App instead

     

    LPARAMETERS tcSourceFile, tcDestFile

    * tcSourcefile = GETPICT()
    * tcDestFile = FORCEEXT(tcSourceFile, "Bmp")
    
    DO LOCFILE("System.App")
    
    LOCAL loBmp AS xfcBitmap
    LOCAL loGfx AS xfcGraphics
    LOCAL loBorderClr AS xfcColor
    LOCAL loRect AS xfcRectangle
    LOCAL loAttr AS xfcImageAttributes
    LOCAL loColorMap AS xfcColorMap
    LOCAL loDestBmp as xfcBitmap
     
    WITH _SCREEN.SYSTEM.Drawing
    	loColorMap = .Imaging.ColorMap.New()
    	loAttr = .Imaging.ImageAttributes.New()
    	loBmp = .Bitmap.FromFile(tcSourceFile)
    	loGfx = .Graphics.FromImage(loBmp)
    
    	loDestBmp = .Bitmap.New(loBmp.Width, loBmp.Height, .Imaging.PixelFormat.Format24bppRGB)
    	loDestGfx = .Graphics.FromImage(loDestBmp)
    
    	* Clear the new bitmap
    	loDestGfx.Clear(.Color.White)
    
    	* By Craig Boyd - For enhancing the smoothless and quality
    	loDestGfx.SmoothingMode     = .Drawing2D.SmoothingMode.HighQuality 
    	loDestGfx.InterpolationMode = .Drawing2D.InterpolationMode.HighQualityBicubic
    	loDestGfx.PixelOffsetMode   = .Drawing2D.PixelOffsetMode.HighQuality
    
    	loRect = loBmp.GetBounds()
    
    	* Get the top left pixel color, presuming this color is the BackGround color to become transparent
    	* For our BMP case, this will become PURE WHITE - RGB(255,255,255)
    	* that becomes transparent when used in VFP objects
    	loBorderClr = loBmp.GetPixel(0,0)
    
    	* Convert original Whites RGB(255,255,255) to OFF WHITE - RGB(254,254,254)
    	* this way, the whites will remain without the need of a mask
    	loColorMap.OldColor = .Color.White
    	loColorMap.NewColor = .Color.FromARGB(255,254,254,254)
    
    	loAttr.SetRemapTable(loColorMap)
    	loDestGfx.DrawImage(loBmp, loRect, loRect, .GraphicsUnit.Pixel, loAttr)
    
    	* Next step, convert the borders to pure White, RGB(255,255,255) that will become transparent in buttons
    	loColorMap.OldColor = loBorderClr
    	loColorMap.NewColor = .Color.White
    	loAttr.SetRemapTable(loColorMap)
    
    	loDestGfx.DrawImage(loDestBmp, loRect, loRect, .GraphicsUnit.Pixel, loAttr)
    
    	loDestBmp.Save(tcDestFile, .Imaging.ImageFormat.Bmp)
    ENDWITH
    

     

     

  • FoxCharts 0.40 BETA Released

    New features:
    - Vertical lines and bars in the scale background
    - Alpha allowed in all of the chart shapes and in scale background
    - Triangular and cylinder bar charts
    - Angles compensation for pie and doughnut charts, allowing charts with good precision when width is bigger than the height (by Bo Durban).
    - New sample, see: FoxCharts_New, that allows you to interactively change almost every property of the charts, creating lots of different and interesting charts.
    - Included an EXE sample project, for testing purposes
    - BackGround line of chart can be set in width, and also use some predefined dotted lines
    - Hiding slices from pies or doughnuts allowed
    - MemberData scripts for picking colors - in the properties window, double clicking any property that receives a color, will fire the colorpicker window
    - Colors may be passed using the RGB value, or using a VFP expression, like: "=RGB(0,0,255)" or even just like the way VFP uses for its native color properties: "0,0,255".

     

    Lots of fixes were applied in this version
    - Fixed cylinder and bars positions.
    - Fixed font assignment
    - Fixed class initialization that caused erros
    - Now the class does not show the "X" image in the class initialization
    - Fixed plain gradient Pie chart bug, that sometimes did not show the chart
    - Fixed print command
    - FoxCharts resizes faster
    - .... and many minor other fixes



    SPECIAL THANKS:
    To the FoxBrazilian friends: Peter Wagner, Grego, Emerson Reed, Minari, Moshe, Arcadio, Edgar, Paulo Henrique, Ninja Takehana, Walfrans, Joni and others for their extensive testing, and for providing important suggestions.
    And also:
    Bo Durban (the best) and Carlos Alloatti (always there, with great insights)
    These guys have been providing important help and support. THANKS VERY MUCH !


    Any feedback will be very much appreciated.
    If you would like to contribute, find any bug or would like to have some specific features, feel free to post in the VFPX Discussions forum or send directly a message to vfpimaging@hotmail.com

     

    Get the latest release directly from the VFPX  / FoxCharts page at Codeplex:

    http://www.codeplex.com/VFPX/Release/ProjectReleases.aspx?ReleaseId=14851

     

    Below are some pictures showing what FoxCharts can do so far:

    Enjoy !

     







     






     





























     
     

















     
     
     
  • Full Justified texts in reports with GdiPlusX - REVISITED

    As I've shown in a previous post from last year, this is totally possible for us in VFP, using the GdiPlusX library together with ReportListeners, remember?

     

    BUT I've been receiving some emails about the Full-Justified ReportListener I published last year.

    It did not deal with the possibility of multipage reports. In fact, when a string that had to be printed in FullJustified mode had to be divided in more than one page, in the next page the whole string was redrawn.

    To solve this, I needed to make some adjustments in the report listener source, more specifically in the "Render" event, in order to deal with the parameters "nObjectContinuationType" and "cContentsToBeRendered". I had totally missed them. In the first version, I was only using the "Text" property that I retrieved in the "EvaluateContents" method. The first tells us if the text could be totally drawn, or partially. The 2nd, brings the text that is to be drawn, not the whole text.

    It's amazing how we can control our output with all these new enhancements from the VFP9 Reporting System. In fact, we can control almost everything !

    It's a pity I couldn't explore this tool as much as I would like, the possibilities seem to be infinite.

     

    In HELP I found all the info I needed to fix it:

    • nObjectContinuationType
      * Indicates the current continuation state for the rendered element. When layout elements span pages, they are rendered in multiple sections (once for each page).
      * Value  Continuation Type 
      *   0    Complete (no continuation).
      *   1    Start of layout element occurrence, will not finish on the current page.
      *   2    Mid-element, neither started nor finished on the current page.
      *   3    End of element, completed on the current page.

     

    • cContentsToBeRendered
      * Indicates the text to be rendered for Expression (Field) and Label layout elements.
      * If your derived class sends the text value through some additional processing, such as storage in a table, you can use the STRCONV() function, and its optional regional script parameter, to convert the string to DBCS first. For more information, see STRCONV( ) Function.

     

    Some important tweaks and fixes were needed in the GdiPlusX library too, more specifically in the xfcGraphics.DrawStringJustified function. I added to it a new parameter, "tlJustifyLast", in order fo force the justifying in the last sentence. This is for the case of reports, when an unfinished sentence needs to be justified as well.

     

    The source code is below, you can adapt it to your needs !

     

     

    The idea is to add a "<FJ>" tag in the USER tab or in the beginning of any string from a textbox in a report, to tell the ReportListener that it will draw the text using the DRAWSTRINGJUSTIFIED method from GdiPlusX. Special thanks to Victor Espinoza, from Miami, FL, for his important feedback, suggestions and fixes.

     

    The "FullJustifyListener" performs the following actions:

    - Initializes GdiPlusX

    - Creates a GDI+ Graphics object that will be used to draw in the report

    - Stores in an array the required information needed to draw the string(Font, Size, Style and Color)

    - Before Rendering the string, checks if the "<FJ>" tag is at the beginning of text or at the "USER" tab in the report designer - if yes, draws the string using the new method.

    Here are the steps for you to bring this to your reports:

     

    1 - Download the updated GdiPlusX library - the System.App file

    VERY IMPORTANT - READ THIS !

    This report listener needs the updated version of the GdiPlusX main file of the library, "System.App". As it will take some time till a new version will be released, I've uploaded this file separately, so that people can try this feature from now.

    Go to this link: http://www.codeplex.com/VFPX/Release/ProjectReleases.aspx?ReleaseId=8606

    And download the file "GdiPlusX Updated System.App for FullJustified purposes"

    If you prefer, this file is found in the downloadable source code from this article.

     

     

    2 - Save the ReportListener:

    Please Copy and Paste the code below, and save it as FJLISTENER.PRG in the samples folder of GdiPlusX 

     

    * Program : FJLISTENER.PRG
    * Version : 2.0
    * Purpose : Provides a Report Listener that allows rendering text in
    * Full Justify alignment.
    * Authors : Cesar Ch
    http://weblogs.foxite.com/vfpimaging
    * Class based on article "Listening to a report" by Doug Hennig
    * New tweaked version allows drawing strings that need to be divided in more than one page

    * Special thanks to Victor Espinoza 
    *
    http://msdn2.microsoft.com/en-us/library/ms947682.aspx

    DEFINE CLASS FullJustifyListener AS _ReportListener OF HOME() + 'FFC\_ReportListener.VCX'
    oGDIGraphics =
    NULL
    nSaveGraphicsHandle = 0
    nTimes = 1
    DIMENSION aRecords[1]
     
    * Before we run the report, go through the FRX and store information about any
    * field with our expected directive in its USER memo into the aRecords array.
    FUNCTION BEFOREREPORT
       DODEFAULT
    ()
       * Check if we already have the "System" object in "_Screen"
       IF NOT PEMSTATUS(_Screen,"System",5)
          DO LOCFILE("System.App")
       ENDIF
       WITH This
          .oGDIGraphics = _SCREEN.SYSTEM.Drawing.Graphics.New()
          .SetFRXDataSession()
          DIMENSION .aRecords[reccount(), 13]
          SCAN FOR "<FJ>" $ UPPER(User)
             .aRecords[recno(), 13] = "FJ"
          ENDSCAN
         .ResetDataSession()
       ENDWITH
    ENDFUNC

    FUNCTION BEFOREBAND(nBandObjCode, nFRXRecNo)
       This.SharedGDIPlusGraphics = This.GDIPLUSGRAPHICS
       This
    .oGDIGraphics.Handle = This.SharedGDIPlusGraphics
       DODEFAULT(nBandObjCode, nFRXRecNo)
    ENDFUNC
     
    PROCEDURE RENDER
    (tnFRXRecNo,;
       tnLeft,tnTop,tnWidth,tnHeight,;
       nObjectContinuationType, ;
       cContentsToBeRendered, GDIPlusImage)

       LOCAL lcText, llFlag
       llFlag = .F.
       lcText =
    This.aRecords(tnFRXRecNo,1)

       IF (VARTYPE(lcText) = "C" AND LEFT(lcText,4) = "<FJ>") OR ;
          (
    VARTYPE(This.aRecords(tnFRXRecNo,13)) = "C" AND This.aRecords(tnFRXRecNo,13) == "FJ")

          IF nObjectContinuationType > 0

          * nObjectContinuationType
          * -----------------------
          * Indicates the current continuation state for the rendered element. When layout elements span pages, they are rendered in multiple sections (once for each page).
          * Value Continuation Type
          * 0 Complete (no continuation).
          * 1 Start of layout element occurrence, will not finish on the current page.
          * 2 Mid-element, neither started nor finished on the current page.
          * 3 End of element, completed on the current page.

          * cContentsToBeRendered
          * ---------------------
          * Indicates the text to be rendered for Expression (Field) and Label layout elements.
          * If your derived class sends the text value through some additional processing, such as storage in a table, you can use the STRCONV() function, and its optional regional script parameter, to convert the string to DBCS first. For more information, see STRCONV( ) Function.

             lcText = STRCONV(cContentsToBeRendered,6)

                IF INLIST(nObjectContinuationType, 1, 2)
                   llFlag = .T.
                ENDIF
             ENDIF
     
             IF UPPER
    (LEFT(lcText,4)) = "<FJ>"
                lcText =
    SUBSTR(lcText,5) && Remove the <FJ> tag from string
             ENDIF

             WITH _SCREEN.SYSTEM.Drawing

             This.oGDIGraphics.Handle = This.GDIPlusGraphics
             *!* Create a GDI+ Rectangle which specifies where on the
             *!* surface we're drawing the text.
             LOCAL loRectF as xfcRectangleF
             loRectF = .RectangleF.New(tnLeft, tnTop, tnWidth, tnHeight)

             LOCAL loFont as xfcFont
             loFont = .
    Font.New(This.aRecords(tnFRXRecNo,2) ;
                ,
    This.aRecords(tnFRXRecNo,4), This.aRecords(tnFRXRecNo,3) ;
                , .GraphicsUnit.
    Point)

             * Retrieve colors for the background
             LOCAL lnRed, lnGreen, lnBlue, lnAlpha
             lnRed =
    This.aRecords[tnFRXRecno,5]
             lnGreen =
    This.aRecords[tnFRXRecno,6]
             lnBlue =
    This.aRecords[tnFRXRecno,7]
             lnAlpha =
    This.aRecords[tnFRXRecno,8]
             LOCAL loBackBrush as xfcSolidBrush
             loBackBrush = .SolidBrush.New(;
                .
    Color.FromArgb(lnAlpha,lnRed, lnGreen, lnBlue))

             This.oGdiGraphics.FillRectangle(loBackBrush, tnLeft, tnTop, tnWidth, tnHeight)

             * Retieve colors for the Text
             lnRed = This.aRecords[tnFRXRecno,9]
             lnGreen =
    This.aRecords[tnFRXRecno,10]
             lnBlue =
    This.aRecords[tnFRXRecno,11]
             lnAlpha =
    This.aRecords[tnFRXRecno,12]
             LOCAL loTextBrush as xfcSolidBrush
             loTextBrush = .SolidBrush.New(;
                .
    Color.FromArgb(lnAlpha,lnRed, lnGreen, lnBlue))

             This.oGdiGraphics.DrawStringJustified(lcText, loFont, loTextBrush, loRectF, llFlag)

             ENDWITH
          ELSE
          *!* If we're not drawing a full justified string,
          *!* let Fox draw the text as usual.
             DODEFAULT(tnFRXRecNo, tnLeft, tnTop, tnWidth, tnHeight, ;
                nObjectContinuationType, cContentsToBeRendered, GDIPlusImage)
          ENDIF

          *!* Since we already drew the text, we don't want the default
          *!* behavior to occur.
       NODEFAULT
    ENDPROC

    FUNCTION EvaluateContents
    (tnFRXRecno, toObjProperties)
       * Get the FRX data
       This.aRecords[tnFRXRecno,1] = toObjProperties.Text
       This
    .aRecords[tnFRXRecno,2] = toObjProperties.FontName
       This
    .aRecords[tnFRXRecno,3] = toObjProperties.FontStyle
       This.aRecords[tnFRXRecno,4] = toObjProperties.FontSize
       This
    .aRecords[tnFRXRecno,5] = toObjProperties.FillRed
       This.aRecords[tnFRXRecno,6] = toObjProperties.FillGreen
       This.aRecords[tnFRXRecno,7] = toObjProperties.FillBlue
       This.aRecords[tnFRXRecno,8] = toObjProperties.FillAlpha
       This.aRecords[tnFRXRecno,9] = toObjProperties.PenRed
       This.aRecords[tnFRXRecno,10] = toObjProperties.PenGreen
       This.aRecords[tnFRXRecno,11] = toObjProperties.PenBlue
       This.aRecords[tnFRXRecno,12] = toObjProperties.PenAlpha
    ENDFUNC

    ENDDEFINE

     

    3 - Update the report:

    Below is a short tutorial for the beginners:

    - Open any of your reports, that contains a field of more than one line that will receive the effect. Double-Click on that field, select the GENERAL tab, and add BEFORE your expression, this simple string: [  "<FJ>" +  ], like in the picture below.

     

     

    Another better option is to add the tag to the USER tab, that is available only in VFP9 Report Designer. Just like before, double-click in the desired field, select the "OTHER" tab, then click on the "EDIT USER DATA" button, and add the <FJ> tag to the window, just like the picture below. This is the most recommended approach, because the original data will not be affected, and if one day you decide to stop using the report listener, your report data will not be affected.

     

     

    4 - Run the report

     

    * Tell VFP that we'll be using the new report features
    SET REPORTBEHAVIOR 90
    LOCAL loReportListener
    loReportListener = CREATEOBJECT("FullJustifyListener")
    loReportListener.ListenerType = 1
    REPORT FORM YourReport OBJECT loReportListener

     

     

    Below a last screenshot, showing the of the continued field issue solved:

     

    Enjoy !!!

     

    CLICK HERE TO DOWNLOAD THE SOURCE CODE AND SAMPLE FROM THIS ARTICLE

  • GdiPlusX undocumented functions

     

    The GdiPlusX library is intended to be compatible with the .NET Framework’s System.Drawing namespace. That means that you can use the MSDN online documentation for the “System.Drawing” in order to obtain accurate information about the GdiPlusX classes. objects and functions. More than that, you can also convert the huge amount of samples published in various forums, blogs, articles and e-magazines to be used in VFP. It really does not matter if the sample was published in VB, C or ASP. The conversion to VFP is really intuitive.

     

    When GdiPlusX was coded, we used a .NET conversion tool, called Reflector, which showed us all the source codes involved in each function, bringing us the possibility to code calling the same API functions, working with the same parameters.

     

     

    BUT, during the coding phase, we had some great discussions about things that could be enhanced in order to ease user’s lives.

     

     

    We had a premise not changing the behavior of any function, even if we disagreed with some things there, in order to keep the full compatibility.

     

    On the other hand, we have decided that we could add new functions

     

     

    Below is a short list of some functions that have been added to GdiPlusX, that are not present in the .NET original classes. Most of them have already been used in some samples posted in this blog, but till now, no documentation was published. So, here are some of those new functions, that came to my mind. Probably Bo or Craig will remember to add something here. I hope to be updating this post with some other improvements that only VFP users have available.

     

    Of course, we know that GdiPlusX still needs some documentation, and we’re working on it. But for now, we hope that the list below will bring you some help.

     

     

     

     

     

    xfcGraphics class

     

    DrawStringJustified

     

                Draws the specified text string at the specified location with the specified Brush and Font objects in a Full Justified format.

     

                Parameters: tcString, ;

                            toFont as xfcFont, ;

                            toBrush as xfcBrush, ;

                            toRectangle as xfcRectangle

               

         where:

                            tcString: text to be drawn

                            toFont: Gdi+X font object

                            toBrush: Gdi+X brush object

                            toRectangle: Gdi+X Rectangle object with position and dimensions to draw

     

                Returns: Nothing

                See also: Full-Justified Text with GdiPlus-X

                               Full Justified Texts in your reports with GdiPlus X

     

                GdiPlusX Sample: FullJustified.scx  /  FullJustify.Prg

     

                Code sample:

     

     

    LOCAL lcText
    TEXT TO
    lcText
    NOSHOW
    This library
    was intended to provide Visual FoxPro 9.0 developers with an object based library to wrap the 600+ functions included with the GDI+ API. The intent is to mimic the System.Drawing namespace in the .NET Framework. All classes in the library are based on the classes included in the System.Drawing namespace and other classes that are dependencies for classes in the System.Drawing namespace. Some additional additional functionality has been added to take advantage of features built in to VFP 9.0

    ENDTEXT

    DO LOCFILE("System.app")
    WITH _Screen.System.Drawing
       LOCAL
    loGfx as xfcGraphics
       loGfx = .Graphics.FromHwnd(
    _Screen.HWnd
    )
       loGfx.DrawStringJustified(lcText, .
    Font
    .New("Tahoma",12);
          , .Brushes.Red, .Rectangle.New(0,0,250,400))
    ENDWITH

     

     

     

     

     

    xfcBitmap class

     

     

    ToClipboard

     

                Sends the current bitmap to the clipboard

     

                Parameters: None

                Returns: Nothing

                See also: Send Images to the Clipboard with GdiPlus-X Revisited

     

                Code sample:

     

    DO LOCFILE("System.app")

     
    WITH _Screen
    .System.Drawing

       LOCAL
    loBmp as xfcBitmap
       loBmp = .
    Bitmap.FromFile(GETPICT
    ())
       loBmp.ToClipboard()
    ENDWITH

     

     

     

     

     

    FromClipboard

     

                Creates a GDI+ bitmap object from the clipboard data

     

                Parameters: None

                Returns: Gdi+ bitmap object

     

                Code sample:

     

    DO LOCFILE("System.app")

    WITH _Screen.System.Drawing

       LOCAL
    loBmp as xfcBitmap
      
    loBmp = .
    Bitmap
    .FromClipboard()
       loBmp.
    Save
    ("c:\FromClip.png", .Imaging.ImageFormat.Png)

    ENDWITH

     

     

     

     

    FromVarbinary

     

                Creates an Image object from the specified VarBinary string. Useful to start manipulating an image directly without having to convert the binaries from the image to a file.

     

                Parameters: tcBinary

     

                Returns: GdiPlusX Bitmap object

     

                Code sample:

     


    DO LOCFILE("System.app")

    WITH _Screen.System.Drawing

       LOCAL
    lcBinary
       lcBinary =
    FILETOSTR(GETPICT
    ())

       LOCAL
    loBmp as xfcBitmap
       loBmp = .
    Bitmap
    .FromVarBinary(lcBinary)
       loBmp.
    Save
    ("c:\FromVarBinary.png", .Imaging.ImageFormat.Png)

    ENDWITH

     

     

     

    FromScreen

     

                Captures the specified window or object image to a new GDI+ bitmap object

     

                Parameters:

    tHWnd,                 tiX, tiY, tiWidth, tiHeight, tlEnsureVisible

                                    toForm [, tiX, tiY, tiWidth, tiHeight [, tlEnsureVisible]]

                                   toControl [, tlEnsureVisible]

     

                Returns: Gdi+ bitmap object

     

                See also: Capture Screens with GdiPlus-X

     

                Code sample:

     

     
    DO LOCFILE
    ("System.app")

    WITH _Screen
    .System.Drawing

       LOCAL
    loBmp as xfcBitmap
       loBmp = .
    Bitmap.FromScreen()
       loBmp.
    Save("c:\FromScreen.png", .Imaging.ImageFormat.Png)

    ENDWITH

     

     

     

     

    GetMonochrome

     

                Returns a monochrome GDI+ bitmap (1bpp) of this Image object.

                The image must be saved in the BMP Image Format in order to keep the 1bpp format. Because the resulting bitmap is in an indexed pixel format, GDI+ cannot create a xfcGraphics object in order to draw on it. This function is recommended to be used immediately before saving to a file, in order to obtain the minimum file size. For some specific TIFF compression types, a monochrome image of 1bpp is required too, see more details in these articles:

     

                Parameters: None

     

                Returns: Gdi+ bitmap object

     

                See also: Convert Images to Monochrome with GdiPlus X

                            Using TIFFs with the new GDI+ classes - UPDATE

                            TIFFS and the latest release of GdiPlusX

     

                Code sample:

     


    DO LOCFILE("System.app")

    WITH _Screen
    .System.Drawing

       LOCAL
    loBmp as xfcBitmap
       loBmp = .
    Bitmap.FromFile(GETPICT
    ())

       LOCAL
    loMonoch as xfcBitmap
       loMonoch = loBmp.GetMonochrome()

       loMonoch.
    Save
    ("c:\Monoch.bmp", .Imaging.ImageFormat.Bmp)

    ENDWITH

     

     

     

     

    GetPictureVal

     

                Returns a String containing the PictureVal of this Image object, according to the ImageFormat passed. You can retrieve the binaries of the image with NO disk access, in any Image format supported by GDI+

     

                Parameters: ImageFormat Object

                                       EncoderParameter Object (optional)

                Returns: String

     

                See also: Manipulate images with no disk access with GdiPlusX

     

                Code sample:

     


    DO LOCFILE("System.App")

    LOCAL loBmp as xfcBitmap
    * Obtaining the PictureVal directly
    WITH _Screen
    .System
    .Drawing 
       loBmp = .Bitmap.FromFile(GETPICT())
       Thisform.Image1.PictureVal = loBmp.GetPictureVal (.Imaging.ImageFormat.Bmp)

    ENDWITH

     

     

     

     

    GetPictureValFromHBitmap

     

                Returns a String containing the PictureVal of this Image object using the HBitmap GDI technique. The binaries retrieved are always in BMP format, what makes it a big string in most times. But, in most cases, this technique runs about 40% faster than using GetPictureVal() function shown above. The ImageCanvas objects uses this function to obtain the binaries from the images drawn.

     

                Parameters: None

     

                Returns: String

     

                See also: Manipulate images with no disk access with GdiPlusX

     

     


    DO LOCFILE("System.App")

    LOCAL loBmp as xfcBitmap

    * Obtaining the PictureVal directly
    WITH _Screen
    .System
    .Drawing
       loBmp = .
    Bitmap.FromFile(GETPICT
    ())
       Thisform.Image1.PictureVal = loBmp.GetPictureValFromHBitmap()

    ENDWITH

     

     

     

     

    ApplyColorMatrix

     

                Applies the received color matrix to the current bitmap object

                This is very useful, and provides an easy and quick way to apply image transformations in just one step, without having to use the ImageAttributes class.

     

                Parameters:

                            toColorMatrix

     

                Returns: NULL

     

                See also: Special effects on images with GdiPlusX- Part1

                               Special effects on images with GdiPlusX – Part2

                               Draw Logos in your images with GdiPlusX - Part 2

                           

                Code sample:

     


    DO LOCFILE("System.app")

    WITH _Screen.System.Drawing 
       LOCAL loBmp as xfcBitmap
       loBmp = .
    Bitmap.FromFile(GETPICT())
     
       LOCAL loClrMatrix as xfcColorMAtrix
       loClrMatrix = .Imaging.ColorMatrix.New(;
          0.33, 0.33, 0.33, 0, 0, ;
          0.33, 0.33, 0.33, 0, 0, ;
          0.33, 0.33, 0.33, 0, 0, ;
          0, 0, 0, 1, 0, ;
          0, 0, 0, 0, 1) 
       loBmp.ApplyColorMatrix(loClrMatrix)
       loBmp.
    Save("c:\ClrMatrix.Png", .Imaging.ImageFormat.Png)

    ENDWITH

     

     

     

     

     

    GetMask

     

               Returns a Bitmap object with the mask from the current bitmap

               In fact this function returns a bitmap with all the transparent parts of the image. Useful when you need to convert a PNG image that contains transparencies to be used in the BMP image format.

     

                Parameters: None

     

                Returns: Gdi+ bitmap object

     

                See also: Convert your buttons to BMPs keeping transparency with GdiPlusX

     

     

     

     

     

     

     

    ToPrinter

     

                Sends the image object to the Printer

               

    Parameters: tnStretch, tcPrinterName, tnOrientation, tnAlignment

                           

                            tnStretch

                            *   Specifies how an image is sized to fit inside a control.

                            *   0 - Clip. The image is clipped to fit the page. (Default)

                            *   1 - Isometric. The image resizes to fit the page while maintaining its original proportions.

                            *   2 - Stretch. The image resizes to fit the page, but does not maintain its original proportions.

                           

                            tcPrinterName

                            *   Specifies the name of the printer, the same of GETPRINTER()

                           

                            tnOrientation:

                            *   0 - Portrait

                            *   1 - Landscape

                           

                            tnAlignment

                            *   Specifies a numerical value representing the alignment of the image in the page.

                            *   0 - Vertically Centered Left.

                            *   1 - Vertically Centered Right.

                            *   2 - Centered. Centers image vertically and horizontally.

                            *   4 - Top Left. Aligns image in top left corner of the page.

                            *   5 - Top Right. Aligns image in top right corner of the page.

                            *   6 - Top Center. Aligns image at the top and horizontally centered on the page.

                            *   7 - Bottom Left. Aligns image in the bottom left corner of the page.

                            *   8 - Bottom Right. Aligns image in bottom right corner of the page.

                            *   9 - Bottom Center. Aligns image at the bottom and vertically centered on the page.

     

                Returns: Nothing

     

                Code sample:

     

     

    DO LOCFILE("System.app")

     
    WITH _Screen
    .System.Drawing

       LOCAL
    loBmp as xfcBitmap
       loBmp = .
    Bitmap.FromFile(GETPICT
    ())
       loBmp.ToPrinter()
    ENDWITH

     

     

     
     

     

     

    xfcColorMatrix class

     

    MatrixMultiply

     

                Returns a new Color Matrix object resulting of the multiplication of two color matrices. This is very useful when more than one color matrix is needed to be applied to an image. Multiplying the color matrices before they are applied to the image will bring a HUGE gain of performance.

     

                Parameters: toColorMatrixOne, ;

                            toColorMatrixTwo

                           

                Returns: a new color matrix containing the resultant matrix

     

                Code sample:

     

     

    DO LOCFILE("System.app")


    WITH _Screen
    .System.Drawing


       LOCAL
    loBmp as xfcBitmap
       loBmp = .
    Bitmap.FromFile(GETPICT())

       LOCAL loClrMatrix1 as xfcColorMatrix && GreyScale matrix 
       loClrMatrix1 = .Imaging.ColorMatrix.New(;
          0.33, 0.33, 0.33, 0, 0, ;
          0.33, 0.33, 0.33, 0, 0, ;
          0.33, 0.33, 0.33, 0, 0, ;
          0, 0, 0, 1, 0, ;
          0, 0, 0, 0, 1)

       LOCAL loClrMatrix2 as xfcColorMatrix && Half Brightness Matrix
       loClrMatrix2 = .Imaging.ColorMatrix.New(;
          0.5, 0, 0, 0, 0, ;
          0, 0.5, 0, 0, 0, ;
          0, 0, 0.5, 0, 0, ;
          0, 0, 0, 1, 0, ;
          0, 0, 0, 0, 1)

       LOCAL loNewClrMatrix as xfcColorMatrix
       loNewClrMatrix = loClrMatrix1.Multiply(loClrMatrix1, loClrMatrix2)

       loBmp.ApplyColorMatrix(loNewClrMatrix)
       loBmp.
    Save("c:\MultClrMatrix.Png", .Imaging.ImageFormat.Png)

    ENDWITH

     

     

     

     

     

    xfcSize class

     

    ToRectangle

                Returns a xfcRectangle object from the current xfcSizeF object

     

     

     

     

     

    xfcSizef class

     

    ToRectanglef

                Returns a xfcRectangleF object from the current xfcSizeF object

  • FoxCharts 0.20 Alpha

    Here's a new release of FoxCharts

    https://www.codeplex.com/Release/ProjectReleases.aspx?ProjectName=VFPX&ReleaseId=13477

     

    Prerequisites:
    Visual FoxPro 9 and the GdiPlusX library from VFPX 









     

    As you can see, 2 new charts are now available:

    - Stacked Area

    - Cylinder

     

    • The StackedArea chart can be defined using the "ChartType" property, that must be set to the numeric 10
    • The Cylinder chart is derived from the original Bars chart. To have it, select ChartType for the bar option, and then set the BarType property to numeric 1 (0 = Bar Default; 1 = Cylinder)

     

    Apart from this, many other important modifications were applied:

    The main difference is that now FoxCharts' base class is a Container, that contains the GdiPlusX ImageCanvas, and the legend objects, responsible for drawing all the text needed.

    Now we can customize any of those labels in lots of ways. Every piece of text, legend in the chart now has the following properties:


    Alignment - 0 Left; 1 Right; 2 Center
    BackColor
    BackColorAlpha - this is cool, (0-255) determines the transparency of the background of the label
    Caption
    FontBold
    FontItalic
    FontName
    FontSize
    FontStrikethru
    FontUnderline
    ForeColor
    ForeColorAlpha - determines the transparency of the label


    The legends are represented by the following objects:

    Title
    SubTitle
    XAxis
    XAxisLegend2
    YAxis
    ShapeLegend
    ScaleLegend
    SideLegend

    This way, every piece of text in the chart can be fully customized, not only the font, but the backcolor and the alpha (transparency). Now you can also change the alignment of the text, for example, to set the title to Right Alignment, all you have to do is to:

    Thisform.FoxCharts1.Title.Alignment = 1 && Right

     

    I still need to remind you that this is still a preview version, destined for people that are interested in helping testing this tool.



    Please continue sending your suggestions and feedback!
    It is really very appreciated

    https://www.codeplex.com/Release/ProjectReleases.aspx?ProjectName=VFPX&ReleaseId=13477



    Contains the ALPHA version of the FoxCharts project.

    Unzip the file and run the form ChartsSample to see how it works.

    This version also distributes the two main files from GdiPlusX - System.app and GdiPlusX.vcx.
    If you are already a GdiPlusX user, you can use your own GdiPlusX version.
    Just make sure to be using the latest GdiPlusX version.

    GdiPlusX is also a VFPX project. For more information, please visit the GdiPlusX page at VFPX.


    More information and pictures about this project can be obtained at the VFPIMAGING weblog:

    http://weblogs.foxite.com/vfpimaging/archive/2008/04/04/5919.aspx

    http://weblogs.foxite.com/vfpimaging/archive/2008/04/24/6040.aspx


    This new release contains lots of enhancements:

    Chart Types
    - Bar charts
    - Multiple bars
    - Stacked bars

    - Pie
    - Doughnut

    - Lines
    - Area
    - Stacked Area
    - Points and Shapes


    Color variations:
    - Basic colors
    - Custom colors
    - Gradient colors
    - Random colors
    - Monochrome
    - Gradient or solid colors


    Legends in many places: Axys, shapes, side legends

    Scales

    Customize:
    - Titles
    - Subtitles
    - Backgrounds (solid or gradient)
    - Fonts
    - Colors

More Posts Next page »