Using Win32 functions in Visual FoxPro Image Gallery
Printing and Print Spooler
..msdn
AddPort
AddPrinter
ClosePrinter
ConfigurePort
ConnectToPrinterDlg
DeletePort
DeviceCapabilities
DocumentProperties
EndDoc
EndPage
EnumForms
EnumJobs
EnumPorts
EnumPrinterData
EnumPrinterDrivers
EnumPrinters
EnumPrintProcessorDatatypes
EnumPrintProcessors
Escape
FindClosePrinterChangeNotification
FindFirstPrinterChangeNotification
FindNextPrinterChangeNotification
FreePrinterNotifyInfo
GetDefaultPrinter
GetPrinter
GetPrinterData
GetPrinterDriverDirectory
GetPrintProcessorDirectory
OpenPrinter
PrinterProperties
SetDefaultPrinter
SetJob
SetPrinter
StartDoc
StartPage
Code examples:
Configuring DEVMODE structure for a printer
Displaying printer-properties Property Sheet for the specified printer
Enumerating forms supported by a specified printer
Enumerating print jobs and retrieving information for default printer (JOB_INFO_1 structures)
How to delete all print jobs for a printer
How to retrieve configuration data for a specified printer stored in the registry (PrinterDriverData key)
How to retrieve the number of print jobs queued for the printer
Printing Image File, programmatically set print page orientation to landscape
Retrieving default spooling directory name
Retrieving the name of the default printer for the current user on the local computer (Win NT/XP)
Simple printer queue monitor: deletes, pauses, resumes print jobs for local printer
Using Change Notification Objects to monitor changes to the printer or print server
How to retrieve configuration data for a specified printer stored in the registry (PrinterDriverData key)

User rating: 0/10 (0 votes)
Rate this code sample:
  • ~
More code examples    Listed functions    Add comment     W32 Constants      Translate this page Printer friendly version of this code sample
Before you begin:
EnumPrinterData retrieves printer configuration data set by the SetPrinterData function. A printer"s configuration data consists of a set of named and typed values.
 
#DEFINE ERROR_SUCCESS  0
#DEFINE ERROR_NO_MORE_ITEMS  259
#DEFINE ERROR_MORE_DATA      234
 
#DEFINE REG_SZ       1  && string
#DEFINE REG_BINARY   3
#DEFINE REG_DWORD    4
#DEFINE REG_MULTI_SZ 7  && array of strings
 
DO decl
 
PRIVATE cPrinter, hPrinter
cPrinter = GetPrnName()
 
hPrinter = 0
IF OpenPrinter(cPrinter, @hPrinter, 0) = 0
    ? "Unable to get printer handle for [" + cPrinter + "]"
    RETURN
ENDIF
 
LOCAL lnIndex, lcValueName, lnValueName, lnValueType,;
    lcBuffer, lnBufsize, lnResult, lcValue
 
CREATE CURSOR csResult ( valuename C(30), value2str C(50),;
    binvalue M, valuetype I, bufsize I)
 
lnIndex = 0
DO WHILE .T.
    lcValueName = Repli(Chr(0), 100)
    STORE 0 TO lnValueName, lnValueType, lnBufsize
    lcBuffer = Repli(Chr(0), 4096)
 
    lnResult = EnumPrinterData(hPrinter, lnIndex,;
        @lcValueName, Len(lcValueName), @lnValueName,;
        @lnValueType, @lcBuffer, Len(lcBuffer), @lnBufsize)
 
    IF lnResult = ERROR_NO_MORE_ITEMS
        EXIT
    ENDIF
 
    lcValueName = SUBSTR(lcValueName, 1, AT(Chr(0),lcValueName)-1)
    lcBuffer = SUBSTR(lcBuffer, 1, lnBufsize)
 
    DO CASE
    CASE INLIST(lnValueType, REG_SZ, REG_MULTI_SZ)
        lcValue = SUBSTR(lcBuffer, 1, AT(Chr(0),lcBuffer)-1)
    CASE lnValueType = REG_BINARY
        lcValue = LTRIM(STR(lnBufsize)) + " bytes of binary data"
    CASE lnValueType = REG_DWORD
        lcValue = LTRIM(STR(buf2dword(lcBuffer)))
    ENDCASE
 
    INSERT INTO csResult (valuename, valuetype, bufsize, value2str);
        VALUES (lcValueName, lnValueType, lnBufsize, lcValue)
 
    IF lnValueType = REG_BINARY
        UPDATE csResult SET binvalue = lcBuffer WHERE valuename == m.lcValueName
    ENDIF
    lnIndex = lnIndex + 1
ENDDO
 
= ClosePrinter(hPrinter)
GO TOP
BROWSE NORMAL NOWAIT
* end of main
 
FUNCTION GetPrnName
* returns default printer name from registry
    LOCAL lcBuffer, lnPos
    lcBuffer = Repli(Chr(0), 120)
    = GetProfileString("Windows", "Device", ",,,",;
        @lcBuffer, Len(lcBuffer))
    lcBuffer = STRTRAN(lcBuffer, Chr(0), "")
    lnPos = AT(",", lcBuffer, 1)
RETURN SUBSTR(lcBuffer, 1, lnPos-1)
 
PROCEDURE decl
    DECLARE INTEGER EnumPrinterData IN winspool.drv;
        INTEGER hPrinter, INTEGER dwIndex, STRING @pValueName,;
        INTEGER cbValueName, INTEGER @pcbValueName, INTEGER @pType,;
        STRING @pData, INTEGER cbData, INTEGER @pcbData
 
    DECLARE INTEGER OpenPrinter IN winspool.drv;
        STRING pPrinterName, INTEGER @phPrinter, INTEGER pDefault
 
    DECLARE INTEGER ClosePrinter IN winspool.drv INTEGER hPrinter 
    DECLARE INTEGER GetLastError IN kernel32
 
    DECLARE INTEGER GetProfileString IN kernel32;
        STRING lpApp, STRING lpKey, STRING lpDefault,;
        STRING @lpReturnedString, INTEGER nSize
 
FUNCTION  buf2dword (lcBuffer)
RETURN Asc(SUBSTR(lcBuffer, 1,1)) + ;
    BitLShift(Asc(SUBSTR(lcBuffer, 2,1)),  8) +;
    BitLShift(Asc(SUBSTR(lcBuffer, 3,1)), 16) +;
    BitLShift(Asc(SUBSTR(lcBuffer, 4,1)), 24)
 
 
 

User rating: 0/10 (0 votes)
Rate this code sample:
  • ~
2867 bytes  
Created: 2003-01-17 08:18:57  
Modified: 2003-01-17 08:20:41  
Visits in 7 days: 141  
Listed functions:
ClosePrinter
EnumPrinterData
GetLastError
GetProfileString
OpenPrinter
Printer friendly API declarations
Word Index links for this example:
Translate this page:
  Spanish    Portuguese    German    French    Italian  
FreeTranslation.com offers instant, free translations of text or web pages.
User Contributed Notes:
There are no notes on this subject.


Copyright © 2001-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 (184.73.74.47)
5.74 hrs.Example: 'How to print FoxPro form'
 Example: 'Reading VFP settings from the Windows Registry'
7.2 hrs.Example: 'Using FlashWindowEx to flash the taskbar button of the VFP application'
 Example: 'Running a regular FoxPro form while main VFP window is minimized'
7.77 hrs.Example: 'How to display the port-configuration dialog box for a port on the specified server'
9.05 hrs.Example: 'Drawing Windows predefined bitmaps using the LoadBitmap functions'
 
16.28 hrs.Function: 'inet_ntoa'
Function group: 'Windows Sockets 2 (Winsock)'
 Function: 'waveOutReset'
Function group: 'Windows Multimedia'
19.29 hrs.Function: 'GetPrivateProfileSectionNames'
Google
Advertise here!