Using Win32 functions in Visual FoxPro Image Gallery
Code examples:
How to change display settings: screen resolution, screen refresh rate
Enumerating data formats currently available on the clipboard
Custom GDI+ class
Mapping and disconnecting network drives
Winsock: retrieving directory listing from an FTP server using passive data connection (FTP, port 21)
Capturing keyboard activity of another application with the Raw Input API (VFP9)
Winsock: sending email messages (SMTP, port 25)
How to display the Properties dialog box for a file (ShellExecuteEx)
Disk in drive A:
Using Font and Text functions
Detecting changes in connections to removable drives (VFP9)
How to download a file from the FTP server using FtpGetFile
Enumerating raw input devices attached to the system (keyboard, mouse, human interface device)
How to play AVI file on the _screen
Using Video Capture: displaying on FoxPro form frames and previewing video obtained from a digital camera
Using EnumPrinters function to enumerate locally installed printers
Running MSDOS Shell as a child process with redirected input and output (smarter RUN command)
Splash Screen for the VFP application
Subclassing CommandButton control to create BackColor property
Creating irregularly shaped FoxPro form using transparency color key
Vertical Label control
Converting Unicode data from the Clipboard to a character string using a given code page
Creating a console window for Visual FoxPro application
Enumerating network resources
GDI+: sending image of FoxPro form to printer

User rating: 10/10 (1 votes)
Rate this code sample:
  • ~
More code examples    Listed functions    Add comment     W32 Constants      Translate this page Printer friendly version of this code sample
Versions:
click to open
Before you begin:
The code is based on custom GDI+ class. Download the class module first and save it in gdiplus.prg file.

Call this code from a method or event of a FoxPro form when that form is active, i.e. posesses the keyboard focus.

See also:

Download ScreenCapture Library

  • How to print FoxPro form
  • How to print FoxPro form -- II (using metafile)
  • Storing screen shot of a form to a BMP file
  • Storing clipboard contents to a BMP file
  •  
    using System;
    using System.Drawing;
    using System.Drawing.Printing;
    using System.Windows.Forms;
    using System.Runtime.InteropServices;
     
    namespace PrintForm
    {
        public class PrintForm
        {
            Form form;
            Bitmap bmp;
            int x=0; int y=0;
            int width=0; int height=0;
     
            public PrintForm(Form form) {this.form = form;}
     
            public void Print() {Print(0, 0);}
     
            public void Print(int x, int y)
            {
                this.x = x; this.y = y;
                width = form.ClientSize.Width;
                height = form.ClientSize.Height;
                bmp = GetFormBitmap();
     
                //create new PrintDocument object
                //and assign a method for the PrintPage event
                PrintDocument pd = new PrintDocument();
                pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
                pd.Print();
            }
     
            private void pd_PrintPage(object sender, 
                System.Drawing.Printing.PrintPageEventArgs e) 
            {
                //Graphics object for the current printer
                e.Graphics.DrawImage(bmp, x, y, width, height);
            }
     
            private Bitmap GetFormBitmap() 
            {    //creates new Bitmap object containing 
                //the image of the form
                const int SRCCOPY = 0xcc0020;
     
                //create Graphics objects for the form
                Graphics gg = form.CreateGraphics();
                IntPtr formhdc = gg.GetHdc();
     
                //create new Bitmap object
                Bitmap bmp = new Bitmap(width, height);
                Graphics g = Graphics.FromImage(bmp);
                IntPtr bmphdc = g.GetHdc();
     
                //copy the bitmap data of the form to the new Bitmap
                BitBlt(bmphdc, 0, 0, width, height, 
                    formhdc, 0, 0, SRCCOPY);
     
                //the hdc of Bitmap object must be released 
                //before sending this object to print
                g.ReleaseHdc(bmphdc);
                gg.ReleaseHdc(formhdc);
     
                return bmp;
            }
     
            [DllImport("gdi32.dll")]
            static extern bool BitBlt(IntPtr hdc, int nXDest, 
                int nYDest, int nWidth, int nHeight, 
                IntPtr hdcSrc, int nXSrc, int nYSrc, uint dwRop);
     
        }
    }
     
     
     

    User rating: 10/10 (1 votes)
    Rate this code sample:
    • ~
    1863 bytes  
    Created: 2004-07-13 10:11:10  
    Modified: 2011-03-28 09:41:52  
    Visits in 7 days: 115  
    Listed functions:
    BitBlt
    DeleteDC
    EndDoc
    EndPage
    GetFocus
    GetWindowDC
    GetWindowRect
    PrintDlg
    ReleaseDC
    StartDoc
    StartPage
    Printer friendly API declarations
    My comment:

    #kwd: sln_gdiplus, sln_printform
    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:
    65.13.0.61 | 2006-08-19 11:49:49
    Anatoliy,

    I am creating a thematic map of the United States. It consists of a container object on a form. The container object contains shape objects in the form of each state in the U.S.

    I would like to save the image of the map to a .BMP, .JPG or .PNG without making the form visible. How do I do this?

    Dan
    danrhymes@bellsouth.net | 2006-08-19 11:50:11
    Anatoliy,

    I am creating a thematic map of the United States. It consists of a container object on a form. The container object contains shape objects in the form of each state in the U.S.

    I would like to save the image of the map to a .BMP, .JPG or .PNG without making the form visible. How do I do this?

    Dan
    Hugh Winters | 2006-08-30 12:55:10
    I am having trouble finding the gdiplus.prg you refer to in your code setup. Please tell me exactly where I might find this program. I have looked everywhere.

    Perhaps this program was outmoded by the new GDIPlusX.vcx class library and is no longer available. If so, please adjust your code to work with it.

    Thanks!

    Hugh Winters
    A.M. | 2006-08-30 19:34:07
    Hugh,

    There's a link to this code in Before You Begin section on this page

    http://www.news2news.com/vfp/?example=450

    This GDI+ library is not freeware though. It is also not compatible with GDI+ FFC code, since I have decided to create this library from scratch.

    Copyright © 2001-2013 News2News, Inc. Before reproducing or distributing any data from this site please ask for an approval from its owner. Unless otherwise specified, this page is for your personal and non-commercial use. The information on this page is presented AS IS, meaning that you may use it at your own risk. Microsoft Visual FoxPro and Windows are trade marks of Microsoft Corp. All other trademarks are the property of their respective owners. 

    Privacy policy
    Credits: PHP (4.4.9), an HTML-embedded scripting language, MySQL (5.1.55-log), the Open Source standard SQL database, AceHTML Freeware Version 4, freeware HTML Editor of choice.   Hosted by Korax Online Inc.
    Last Topics Visited (23.22.252.150)
    1.52 hrs.Function: 'waveOutSetVolume'
    1.53 hrs.Function: 'GetModuleHandle'
    Function group: 'Dynamic-Link Library'
    4.3 hrs.Example: 'Retrieving information about the specified icon'
     Example: 'Exporting DLL icon resources as .ICO files'
    7.14 hrs.Function: 'FrameRgn'
     Example: 'Starting a dialog box for connecting to network resources and passing input parameters'
    10.4 hrs.Function: 'GdipRotateWorldTransform'
     Example: 'Retrieving configuration information for the specified server (Win2000/XP)'
     Example: 'How to retrieve the number of print jobs queued for the printer'
    10.87 hrs.Example: 'Moving shortcut to a specified position on the Windows Desktop'
    Google
    Advertise here!