VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Changing Windows Printer w/o using priint dialog

by VB FAQ (6 Submissions)
Category: Windows System Services
Compatability: Visual Basic 3.0
Difficulty: Unknown Difficulty
Date Added: Wed 3rd February 2021
Rating: (41 Votes)

How can I change the printer Windows uses in code without using the print common dialog? How can I change orientation?
You can change the printer the VB 3.0 Printer object is pointing to programmatically (without using the common dialogs). Just use the WriteProfileString API call and rewrite the [WINDOWS], DEVICE entry in the WIN.INI file! VB will instantly use the new printer, when the next Printer.Print command is issued. If you get the old printer string before you rewrite it (GetProfileString API call), you can set it back after using a specific printer. This technique is especially useful, when you want to use a FAX printer driver: Select the FAX driver, send your fax by printing to it and switch back to the normal default printer.

Rate Changing Windows Printer w/o using priint dialog

It is recommended (and polite, as we're multitasking) to send a WM_WININCHANGE (&H1A) to all windows to tell them of the change. Also, under some circumstances the printer object won't notice that you have changed the default printer unless you do this. 

Declare Function SendMessage(ByVal hWnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, lParam As Any) As Long 
Global Const WM_WININICHANGE = &H1A 
Global Const HWND_BROADCAST = &HFFFF 
' Dummy means send to all top windows. 
' Send name of changed section as lParam. 
lRes = SendMessage(HWND_BROADCAST, WM_WININICHANGE, 0, ByVal "Windows")

Download this snippet    Add to My Saved Code

Changing Windows Printer w/o using priint dialog Comments

No comments have been posted about Changing Windows Printer w/o using priint dialog. Why not be the first to post a comment about Changing Windows Printer w/o using priint dialog.

Post your comment

Subject:
Message:
0/1000 characters