Announcement

Collapse

Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

SetDefaultPrinter

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    SetDefaultPrinter

    Code:
       #Compile Exe
       #Register None
       #Dim All
       #Include "WIN32API.INC"
    
       Declare Function SetDefaultPrinter (Asciiz) As Long
    
       Function PbMain()
          Dim PrinterName As Asciiz * 255
          GetProfileString "WINDOWS", "DEVICE", ",,,", PrinterName, SizeOf(PrinterName)
          MsgBox "Default is " + PrinterName
          Dim Section As Asciiz * 32767, nb As Long, kb As Long
          nb = GetProfileSection ("PrinterPorts", Section, SizeOf(Section)): kb = 0
          Dim p As Asciiz Ptr, hSetDefaultPrinter As Dword, hLibWinSpool As Long
          p = VarPtr(Section)
          Do
             If Len(@p) = 0 Then Exit Do
             If MsgBox (@p, %MB_YESNO, "To set as default printer") = 6 Then
                hLibWinSpool= LoadLibrary("winspool.drv")
                If hLibWinSpool Then hSetDefaultPrinter = GetProcAddress(hLibWinSpool, "SetDefaultPrinterA")
                If hSetDefaultPrinter Then
                   Call Dword hSetDefaultPrinter Using SetDefaultPrinter(Parse$(@p, "=", 1))
                Else
                   WriteProfileString "WINDOWS", "DEVICE", @p
                   SendNotifyMessage %HWND_BROADCAST, %WM_WININICHANGE, 0, ByVal p
                End If
                If hLibWinSpool Then FreeLibrary hLibWinSpool
                Exit Do
             End If
             p = p + Len(@p) + 1
          Loop
       End Function

    [This message has been edited by Semen Matusovski (edited March 07, 2001).]
Working...
X
😀
🥰
🤢
😎
😡
👍
👎