|
▼亜矢 さん、こんばんわ、ちんといいます。
サンプルを記述します。コピー・ペするので見えにくいかもしれません。
以上参考までに・・・
Public Const VER_PLATFORM_WIN32s = 0
Public Const VER_PLATFORM_WIN32_WINDOWS = 1
Public Const VER_PLATFORM_WIN32_NT = 2
Private Const HWND_BROADCAST = &HFFFF&
Private Const WM_WININICHANGE = &H1A
Private Const WM_SETTINGCHANGE = WM_WININICHANGE
Private Declare Function GetProfileString Lib "Kernel32.dll" Alias "GetProfileStringA" (ByVal lpAppName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long) As Long
Private Declare Function WriteProfileString Lib "Kernel32.dll" Alias "WriteProfileStringA" (ByVal lpszSection As String, ByVal lpszKeyName As String, ByVal lpszString As String) As Long
Private Declare Function SendMessage Lib "User32.dll" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function SetDefaultPrinter Lib "Winspool.drv" Alias "SetDefaultPrinterA" (ByVal pszPrinter As String) As Long
Sub TEST()
Dim strPrinterName As String
Dim vntPrinter As Variant
Dim i As Integer
strPrinterName = String$(255, vbNullChar)
GetProfileString "Windows", "Device", ",,,", strPrinterName, 255
DEFALUT_PRT = GetDeviceName(strPrinterName) '**** 通常使用するプリンター名を取得する。
HENKOU_PRT = "DocuWorks Printer" '**** 変更するプリンター名を記述する。
SetDefaultPrinter HENKOU_PRT '**** プリンターを変更する。
SetDefaultPrinter DEFALUT_PRT '**** 通常使用するプリンタに戻す。
End Sub
'-- 取得文字列のバッファよりデバイス名を切り出す
Private Function GetDeviceName(strDeviceName) As String
GetDeviceName = Left(strDeviceName, InStr(1, strDeviceName, ",") - 1)
End Function
|
|