Results 1 to 3 of 3

Thread: Find Default Printer Name

  1. #1

    Thread Starter
    Hyperactive Member JazzBass's Avatar
    Join Date
    Jun 1999
    Posts
    393

    Post

    Good morning.

    I would like users to print a file using the default printer and I want to show them where it printing. Is there a API for this? Please bear with me as I'm using VB Professional 3.

    Thanks,
    JazzBass

  2. #2
    Junior Member
    Join Date
    Feb 2000
    Location
    England
    Posts
    26

    Post

    This is howe it works with API, not sure this will work with VB3 though, you'll have to check it out ?


    Add a command button to your form and paste this code into the form


    Private Declare Function RegOpenKeyEx Lib "advapi32" Alias _
    "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, _
    ByVal dwReserved As Long, ByVal samDesired As Long, phkResult _
    As Long) As Long

    Private Declare Function RegQueryValueEx Lib "advapi32" Alias _
    "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName$, _
    ByVal lpdwReserved As Long, lpdwType As Long, lpData As Any, _
    lpcbData As Long) As Long

    Private Declare Function RegCloseKey Lib "advapi32" (ByVal hKey As Long) As Long

    Private Declare Function WNetConnectionDialog Lib _
    "mpr.dll" (ByVal hWnd As _
    Long, ByVal dwType As Long) As Long

    Const HKEY_CURRENT_CONFIG As Long = &H80000005

    Function RegGetString$(hInKey As Long, ByVal subkey$, ByVal valname$)

    'Needed declarations
    Dim RetVal$, hSubKey As Long, dwType As Long, SZ As Long
    Dim R As Long

    RetVal$ = ""

    Const KEY_ALL_ACCESS As Long = &HF0063
    Const ERROR_SUCCESS As Long = 0
    Const REG_SZ As Long = 1

    'Open the key
    R = RegOpenKeyEx(hInKey, subkey$, 0, KEY_ALL_ACCESS, hSubKey)

    If R <> ERROR_SUCCESS Then GoTo Quit_Now

    SZ = 256: v$ = String$(SZ, 0)
    R = RegQueryValueEx(hSubKey, valname$, 0, dwType, ByVal v$, SZ)

    If R = ERROR_SUCCESS And dwType = REG_SZ Then
    RetVal$ = Left$(v$, SZ - 1)
    Else
    RetVal$ = "--Not String--"
    End If

    If hInKey = 0 Then
    R = RegCloseKey(hSubKey)
    End If

    Quit_Now:
    RegGetString$ = RetVal$
    End Function

    Private Sub Command1_Click()
    Dim GetCurrPrinter As String

    GetCurrPrinter = RegGetString$(HKEY_CURRENT_CONFIG, _
    "System\CurrentControlSet\Control\Print\Printers", "Default")
    MsgBox GetCurrPrinter
    End
    End Sub


    Regards,

    Hutchie

  3. #3

    Thread Starter
    Hyperactive Member JazzBass's Avatar
    Join Date
    Jun 1999
    Posts
    393

    Post Thanks Hutchie

    Thanks for trying, but your right. It won't work under VB3. To my knowledge, it does not have any Registry API's.
    Thanks though,
    JazzBass

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width