Default System Printer 
Author Message
 Default System Printer

I would like to set the default system printer from within a vb
application.   I know it will involve the API but don't know the
specifics.  If anyone could tell me where to look for such information
it would be so much appreciated.  

Thanks everyone,  I've found help here before that was major valuable.



Sat, 21 Dec 2002 03:00:00 GMT  
 Default System Printer
Here is some code for reading and/or changing the default printer:

Public Declare Function GetProfileString Lib "kernel32" _
  Alias "GetProfileStringA" (ByVal lpAppName As String, _
  ByVal lpKeyName As String, ByVal lpDefault As String, _
  ByVal lpReturnedString As String, ByVal nSize As Long) As Long

Public Declare Function WriteProfileString Lib "kernel32" _
  Alias "WriteProfileStringA" (ByVal lpszSection As String, _
  ByVal lpszKeyName As String, ByVal lpszString As String) As Long

Public Declare Function SendNotifyMessage Lib "user32" _
  Alias "SendNotifyMessageA" (ByVal hwnd As Long, _
  ByVal msg As Long, ByVal wParam As Long, _
  ByVal lParam As String) As Long

Public Const WM_WININICHANGE = &H1A
Public Const HWND_BROADCAST = &HFFFF&

Sub MySub
    Dim szPrinter As String

    ' Read default printer
    ' --------------------
    szPrinter = Space$(1000)
    GetProfileString "Windows", "Device", ",,,", szPrinter, Len(szPrinter)
    ' --------------------

    ' Set default printer
    ' -------------------
    szPrinter = Printer(1).DeviceName & "," & Printer(1).DriverName & "," &
Printer(1).Port
    WriteProfileString "Windows", "Device", szPrinter
    SendNotifyMessage HWND_BROADCAST, WM_WININICHANGE, 0, "Device"
    ' -------------------
End Sub

Jason Bouzane


Quote:
> I would like to set the default system printer from within a vb
> application.   I know it will involve the API but don't know the
> specifics.  If anyone could tell me where to look for such information
> it would be so much appreciated.

> Thanks everyone,  I've found help here before that was major valuable.



Sat, 21 Dec 2002 03:00:00 GMT  
 Default System Printer
Try http://www.allapi.net.  They've got lots of sample code there
involving printers.

Jennifer


Quote:

> I would like to set the default system printer from within a vb
> application.   I know it will involve the API but don't know the
> specifics.  If anyone could tell me where to look for such information
> it would be so much appreciated.

> Thanks everyone,  I've found help here before that was major valuable.

Sent via Deja.com http://www.deja.com/
Before you buy.


Sun, 22 Dec 2002 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. VB 3.0 and the default-system-printer

2. Default system printer

3. Default System Printer win95

4. Changing default system printer

5. Change the Default System Printer

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

7. printer default to non-default printer

8. How can I change the system-default-printer

9. How to change system's default printer?

10. How can I change the system-default-printer

11. System Wide Default Printer

12. Changing system default printer settings

 

 
Powered by phpBB® Forum Software