P
pascal
Guest
Bonjour,
voici mon pb j'utilise API user32.dll pour trouver l'imprimante par défaut et attribue une autre et ensuite remettre celle par defaut.
Cela marche tres bien sous win2000 mais sous xp cela ne marche pas .voici une partie du code .
quand le programme arrive sur la ligne suivante le programme mouline
ligne de la function SwitchDefaultPrinter:
apiSendMessage HWND_BROADCAST, WM_WININICHANGE, 0, 'windows'
Const HWND_BROADCAST = &HFFFF
Const WM_WININICHANGE = &H1A
Private Declare Function apiSendMessage Lib 'user32' _
Alias 'SendMessageA' ( _
ByVal hwnd As Long, ByVal wMsg As Long, _
ByVal wParam As Integer, ByVal lParam As Any) As Long
Sub SwitchDefaultPrinter(Nom As String)
' modifie le nom de l'imprimante par défaut
strPath = String(260, 0)
' récupère le chemin de win.ini
strPath = Left$(strPath, apiGetWindowsDirectory(strPath, Len(strPath))) + '\\win.ini'
strRet = String(255, 0)
lngNC = apiGetPrivateProfileString('Devices', Nom, '', strRet, 255, strPath)
strRet = Left(strRet, lngNC)
' écrit dans win.ini le nom de l'imprimante souhaitée
apiWritePrivateProfileString 'windows', 'device', Nom & ',' & strRet, strPath
' signale à MS Windows de prendre en compte la modification de win.ini
apiSendMessage HWND_BROADCAST, WM_WININICHANGE, 0, 'windows'
End Sub
merci d'avance
voici mon pb j'utilise API user32.dll pour trouver l'imprimante par défaut et attribue une autre et ensuite remettre celle par defaut.
Cela marche tres bien sous win2000 mais sous xp cela ne marche pas .voici une partie du code .
quand le programme arrive sur la ligne suivante le programme mouline
ligne de la function SwitchDefaultPrinter:
apiSendMessage HWND_BROADCAST, WM_WININICHANGE, 0, 'windows'
Const HWND_BROADCAST = &HFFFF
Const WM_WININICHANGE = &H1A
Private Declare Function apiSendMessage Lib 'user32' _
Alias 'SendMessageA' ( _
ByVal hwnd As Long, ByVal wMsg As Long, _
ByVal wParam As Integer, ByVal lParam As Any) As Long
Sub SwitchDefaultPrinter(Nom As String)
' modifie le nom de l'imprimante par défaut
strPath = String(260, 0)
' récupère le chemin de win.ini
strPath = Left$(strPath, apiGetWindowsDirectory(strPath, Len(strPath))) + '\\win.ini'
strRet = String(255, 0)
lngNC = apiGetPrivateProfileString('Devices', Nom, '', strRet, 255, strPath)
strRet = Left(strRet, lngNC)
' écrit dans win.ini le nom de l'imprimante souhaitée
apiWritePrivateProfileString 'windows', 'device', Nom & ',' & strRet, strPath
' signale à MS Windows de prendre en compte la modification de win.ini
apiSendMessage HWND_BROADCAST, WM_WININICHANGE, 0, 'windows'
End Sub
merci d'avance