Using Win32 functions in Visual FoxPro Image Gallery
Code examples:
How to change display settings: screen resolution, screen refresh rate
Custom GDI+ class
Capturing keyboard activity of another application with the Raw Input API (VFP9)
How to display Windows On-Screen Keyboard
How to print a bitmap file
Winsock: sending email messages (SMTP, port 25)
Using the LoadImage function to have a bitmap file loaded and displayed on VFP main window
System Image List Viewer
Custom HttpRequest class (WinHTTP)
Creating the Save dialog box to specify the drive, directory, and name of a file to save
The window and its ancestors
Printing Image File, programmatically set print page orientation to landscape
How to convert a bitmap file to monochrome format (1 bpp)
Using Video Capture: displaying on FoxPro form frames and previewing video obtained from a digital camera
Mapping and disconnecting network drives
Using EnumPrinters function to enumerate locally installed printers
Custom FTP Class for Visual FoxPro application
Displaying the associated icons and descriptions for files and folders
How to activate Windows Calculator
How to download a file from the FTP server using FtpGetFile
Sending email messages with Simple MAPI
Confining Windows calculator inside the VFP main window
Windows Shell Icons displayed and exported to ICO files (Vista)
How to print FoxPro form
How to retrieve the number of print jobs queued for the printer

User rating: 0/10 (0 votes)
Rate this code sample:
  • ~
More code examples    Listed functions    Add comment     W32 Constants      Translate this page Printer friendly version of this code sample
Versions:
click to open
Before you begin:
See also:
  • How to delete all print jobs for a printer
  • Retrieving default spooling directory name
  • Simple printer queue monitor

  • Enumerating locally installed printers
  • Enumerating printer drivers installed
  • Enumerating the print processors and supporting data types installed on the specified server

  • Enumerating print jobs and retrieving information for default printer
  • Enumerating the ports that are available for printing on a specified server

  •  
    #include "stdafx.h"
    #include "conio.h"
    #include "windows.h"
     
    int _tmain()
    {
        char szBuffer[100], szPrinterName[100];
     
        GetProfileStringA("Windows", "Device", ",,,", 
            szBuffer, sizeof(szBuffer));
     
        char *position = strstr(szBuffer, ",");
        RtlZeroMemory(szPrinterName, sizeof(szPrinterName));
        strncpy(szPrinterName, szBuffer, position - &szBuffer[0]);
        printf("Default printer: %s\n", szPrinterName);
     
        HANDLE hPrinter;
        if (OpenPrinterA(szPrinterName, &hPrinter, 0))
        {
            DWORD dwBufsize;
            GetPrinter(hPrinter, 2, NULL, 0, &dwBufsize);
     
            PRINTER_INFO_2* pinfo = (PRINTER_INFO_2*)
                GlobalAlloc(GPTR, dwBufsize);
     
            GetPrinter(hPrinter, 2, (LPBYTE)pinfo, dwBufsize, &dwBufsize);
     
            printf("Server name: %ls\n", pinfo->pServerName);
            printf("Printer name: %ls\n", pinfo->pPrinterName);
            printf("Port name: %ls\n", pinfo->pPortName);
            printf("Driver name: %ls\n", pinfo->pDriverName);
            printf("Print Processor: %ls\n", pinfo->pPrintProcessor);
     
            printf("\nAttributes: 0x%x\n", pinfo->Attributes);
            printf("Status: 0x%x\n", pinfo->Status);
            printf("Print jobs queued: %d\n", pinfo->cJobs);
     
            ClosePrinter(hPrinter);
        }
        else
        {
            //1801=ERROR_INVALID_PRINTER_NAME
            printf("OpenPrinter call failed: %d\n", GetLastError());
        }
     
        printf("\nPress any key to exit...\n");
        getch();
        return 0;
    }
     

    User rating: 0/10 (0 votes)
    Rate this code sample:
    • ~
    1349 bytes  
    Created: 2003-01-14 10:44:29  
    Modified: 2011-12-10 09:20:22  
    Visits in 7 days: 76  
    Listed functions:
    ClosePrinter
    GetLastError
    GetPrinter
    GetProfileString
    OpenPrinter
    Printer friendly API declarations
    My comment:
    This is a very simple code that uses the GetPrinter API function with Level parameter set to 2. The default printer name is retrieved from Windows Registry. For Windows NT/XP you can use the GetDefaultPrinter function instead.

    To run this code for another printer, not the default one, assign its name to lcPrinter variable.

    More detailed information about the printer queue is returned by the EnumJobs function. It includes MachineName, UserName, Document, Status, SysTime, PagesPrinter and other parameters.
    Word Index links for this example:
    Translate this page:
      Spanish    Portuguese    German    French    Italian  
    FreeTranslation.com offers instant, free translations of text or web pages.
    User Contributed Notes:
    There are no notes on this subject.


    Copyright © 2001-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 (50.16.36.153)
    1.34 hrs.Example: 'Placing an arbitrary rectangular area of main VFP window on the Clipboard'
     Example: 'Converting strings between ANSI and OEM'
     Function: 'RegQueryInfoKey'
    Function group: 'Registry'
    1.77 hrs.Function: 'SHBrowseForFolder'
    Function group: 'Shell Functions'
     Example: 'Setting the last-error code for the FoxPro'
    1.78 hrs.Example: 'Using LoadLibrary'
    2.2 hrs.Example: 'Setting the last-error code for the FoxPro'
     Example: 'Creating a clipping region from the path selected into the device context of a form'
    3.18 hrs.Example: 'How to print FoxPro form -- II'
     Function: 'mciSendString'
    Google
    Advertise here!