发布网友 发布时间:2022-09-22 20:44
共1个回答
热心网友 时间:2024-01-04 13:45
Set Printer = Printers(0) 注释: 将预设打印机设定成第一种打印机Set Printer = Printers(1) 注释: 将预设打印机设定成第二种打印机 但实际上以上叙述有时候不会成功(原因不详), 为了能够成功地改变预设打印机,以下是呼叫Windows API 的方法:( 此一解决方案适用於 Windows 95)1. API 的宣告:Const HWND_BROADCAST = &HFFFF&Const WM_WININICHANGE = &H1APrivate 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 LongPrivate Declare Function WriteProfileString Lib "kernel32" Alias _"WriteProfileStringA" (ByVal lpszSection As String, ByVal lpszKeyName _As String, ByVal lpszString As String) As LongPrivate Declare Function SendMessage Lib "user32" Alias "SendMessageA" _(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _lParam As Any) As Long2. 程式范例:PrinterName = "您想设定的打印机名称"Dim S As String, length As Long, hKey As LongS = String(80, Chr(0))length = GetProfileString("devices", PrinterName, "", S, Len(S))S = Left(S, length)Call WriteProfileString("windows", "device", PrinterName & "," & S)Call SendMessage(HWND_BROADCAST, WM_WININICHANGE, &H7FFF&, ByVal "windows") 至於改变 NT 预设打印机的方法, 则是改变登录资料库(Registry)打印机的设定,在登录资料库中纪录预设打印机的 Value 是: