1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
Const HWND_BROADCAST = &HFFFF
Const WM_WININICHANGE = &H1A
Private Declare Function GetPrivateProfileString Lib "Kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
Private Declare Function GetWindowsDirectory Lib "Kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Integer, ByVal lParam As Any) As Long
Private Declare Function WritePrivateProfileString Lib "Kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
Dim Chemin As String
Dim NC As Long
Dim Ret As String
Public StrImprimante As String
Sub ChangeImprimanteParDéfaut(Nom As String)
Chemin = String(260, 0)
Chemin = Left$(Chemin, GetWindowsDirectory(Chemin, Len(Chemin))) + "\win.ini"
Ret = String(255, 0)
NC = GetPrivateProfileString("Devices", Nom, "", Ret, 255, Chemin)
Ret = Left(Ret, NC)
WritePrivateProfileString "windows", "device", Nom & "," & Ret, Chemin
SendMessage HWND_BROADCAST, WM_WININICHANGE, 0, "windows"
End Sub
Function ImprimanteParDéfaut() As String
Chemin = String(260, 0)
Chemin = Left$(Chemin, GetWindowsDirectory(Chemin, Len(Chemin))) + "\win.ini"
Ret = String(255, 0)
NC = GetPrivateProfileString("windows", "device", "", Ret, 255, Chemin)
Ret = Left(Ret, NC)
NC = InStr(Ret, ",")
ImprimanteParDéfaut = Left(Ret, NC - 1)
End Function |
Partager