Advertisement
ASP_Volume2 Windows System Services #29743

Changing Windows Printer w/o using priint dialog

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.

AI

Riepilogo AI: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Codice sorgente
original-source
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")
<html>
<head>
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>New Page 1</title>
</head>
<body>
<p>If you want to dynamically generate an image and display the image in a Web 
Page, then you actually need to create two ASP.NET pages. You create one page 
that generates the byte data for the actual image. This page is then displayed 
in a second page, the display page, with an HTML &lt;img&gt;&nbsp; tag.<br>
This example creates a pair of pages that displays a red circle. We'll generate 
a GIF image for the circle in an ASP.NET page named Circle.aspx. </p>
<p>1. Circle.aspx<br>
-----------<br>
<br>
&lt;%@ Page ContentType=&quot;image/gif&quot; %&gt;<br>
&lt;%@ Import namespace=&quot;System.Drawing&quot; %&gt;<br>
&lt;%@ Import namespace=&quot;System.Drawing.Imaging&quot; %&gt;<br>
&lt;Script Runat=&quot;Server&quot;&gt;<br>
Sub Page_Load<br>
Dim objBitmap As Bitmap<br>
Dim objGraphics As Graphics<br>
' Create Bitmap<br>
objBitmap = New Bitmap( 200, 200 )<br>
' Initialize Graphics Class<br>
objGraphics = Graphics.FromImage( objBitmap )<br>
objGraphics.FillEllipse( Brushes.Red, 0, 0, 200, 200 )<br>
' Display Bitmap<br>
objBitmap.Save( Response.OutputStream, ImageFormat.Gif )<br>
End Sub<br>
&lt;/Script&gt;<br>
<br>
<br>
The purpose of the ContentType directive that appears at the very top of the 
page is to actually pretend that ASP .NET page to be a GIF image. When the page 
is requested, the ContentType directive tells the Web browser that it should 
expect a GIF image instead of a normal HTML page.<br>
Normally you will need to open the page in a second page to use it effectively 
in a web page.<br>
The second page contains an HTML &lt;img&gt; tag that loads the above page. This page 
contains normal HTML content that appears around the image.<br>
<br>
2. <u>DisplayCircle.aspx</u><br>
<br>
<br>
&lt;html&gt;<br>
&lt;head&gt;&lt;title&gt;DisplayCircle.aspx&lt;/title&gt;&lt;/head&gt;<br>
&lt;body&gt;<br>
&lt;h1&gt;Here is an image:&lt;/h1&gt;<br>
&lt;img src=&quot;Circle.aspx&quot;&gt;<br>
&lt;h1&gt;The image appears above!&lt;h1&gt;<br>
&lt;/body&gt;<br>
&lt;/html&gt;<br>
<br>
<br>
The Web browser treats the Circle.aspx page as a normal GIF image. It has no 
idea that the image was dynamically generated in an ASP.NET page.</p>
</body>
</html>
Commenti originali (3)
Recuperato da Wayback Machine