Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Default printer name
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00616962
Message ID:
00618012
Views:
18
So, here is solution of my problem:

*--------------
*GetDefaultPrinterName()
*--------------
LOCAL lcPrinterName
LOCAL lcVersion
LOCAL lcReturnedString

LOCAL lnResult
LOCAL lnVersion
LOCAL lnSize
LOCAL lnPos

lcPrinterName = ''
lcVersion = OS()

IF '5.0' $ lcVersion
*-- OS is Windows NT/2000/XP
lnVersion = VAL(SUBSTR(lcVersion, AT('5', lcVersion), 4))

IF lnVersion >= 5
*-- OS is Windows 2000 or later
DECLARE INTEGER GetDefaultPrinter IN WinSpool.drv STRING @lpReturnedString,;
INTEGER @lpnSize

lnSize = 4096
lcReturnedString = REPLICATE(CHR(0), lnSize)
lnResult = GetDefaultPrinter(@lcReturnedString, @lnSize)

lnPos = AT(CHR(0), lcReturnedString) - 1

IF lnPos > 0
lcPrinterName = SUBSTR(lcReturnedString, 1, lnPos)
ENDIF

ELSE
*-- OS is Windows NT 4.0 or earlier
DECLARE INTEGER GetProfileString IN kernel32 STRING pAppName,;
STRING lpKeyName,;
STRING lpDefault, STRING @lpReturnedString, INTEGER nSize

lnSize = 4096
lcReturnedString = REPLICATE(CHR(0), lnSize)
lnResult = GetProfileString('windows', 'device',;
'#empty#', @lcReturnedString, lnSize)

lnPos = AT(',', lcReturnedString) - 1

IF lnPos > 0
lcPrinterName = LEFT(lcReturnedString, lnPos)
ENDIF

ENDIF
ENDIF

RETURN lcPrinterName
Previous
Reply
Map
View

Click here to load this message in the networking platform