problem getting default printer hdc in NT4 
Author Message
 problem getting default printer hdc in NT4

I show below two functions designed to get a Handle to the Device
Context of the default printer. Both work alright with Windows95. Can
anyone explain why with Windows NT v4.0 (and Service Pack 3) the
second method works, while the first method fails, returning a zero
handle. In that Function, the strings "device" and "driver" are
correctly set up: it is only the CreateDC call that fails.

Declare Function CreateDCBynum Lib "gdi32" Alias "CreateDCA" (ByVal
lpDriverName As String, ByVal lpDeviceName As String, ByVal lpOutput
As String, lpInitData As Long) As Long

Public Const PD_RETURNDEFAULT = &H400
Public Const PD_RETURNDC = &H100

Type PRINTDLG
        lStructSize As Long
        hwndOwner As Long
        hDevMode As Long
        hDevNames As Long
        hdc As Long
        flags As Long
        nFromPage As Integer
        nToPage As Integer
        nMinPage As Integer
        nMaxPage As Integer
        nCopies As Integer
        hInstance As Long
        lCustData As Long
        lpfnPrintHook As Long
        lpfnSetupHook As Long
        lpPrintTemplateName As String
        lpSetupTemplateName As String
        hPrintTemplate As Long
        hSetupTemplate As Long
End Type

Declare Function MyPrintDlg Lib "comdlg32.dll" Alias "PrintDlgA"
(pPrintdlg As PRINTDLG) As Long

Public Function getDefaultPrinterDC_1() As Long
    Dim devStr As String * 255
    Dim i As Integer, j As Integer
    Dim device As String, driver As String

    GetProfileString "windows", "device", "", devStr, Len(devStr)
    i = InStr(1, devStr, ",")
    j = InStr(i + 1, devStr, ",")
    device = Mid(devStr, 1, i - 1)
    driver = Mid(devStr, i + 1, j - i - 1)
    getDefaultPrinterDC_1 = CreateDCBynum(driver, device,
vbNullString, 0)
End Function

Public Function getDefaultPrinterDC_2() As Long
    Dim pdsetup As PRINTDLG
    Dim ok As Long

    pdsetup.lStructSize = Len(pdsetup)
    pdsetup.flags = PD_RETURNDEFAULT + PD_RETURNDC
    pdsetup.lpPrintTemplateName = String$(1, 0)
    pdsetup.lpSetupTemplateName = String$(1, 0)
    ok = MyPrintDlg(pdsetup)
    getDefaultPrinterDC_2 = IIf(ok <> 0, pdsetup.hdc, 0)
End Function



Fri, 14 Jan 2000 03:00:00 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Using PrintDlg and getting hDC of named printer

2. Getting default printer name from Printers Collection

3. BitBlitting from Picture.hDC to Printer.hDC

4. Switching Default Printer under NT4 (Second Try)

5. Switching Default Printer under NT4 (Second Try)

6. Switching Default Printer under NT4 (Second Try)

7. Macro to change default printer and then restore original default printer settin

8. printer default to non-default printer

9. Problem setting the active printer of Word 97 without changing the Windows default printer

10. Problem printing to printer wich is not the default printer

11. Printer hDC -> Printer Name with WinAPI

12. Printer hDC -> Printer Name with WinAPI

 

 
Powered by phpBB® Forum Software