Je voudrais faire un appercu avant impression et empecher l'utilisateur
de quitter cet appercu tant qu'il n'as pas imprimer puis afficher un
UserForm. Ou alors desactiver le bouton imprimer pour obliger
l'utilisateur a fermer l'appercu puis afficher un UserForm.
Déja est-ce possible et si oui existe t'il une solution pour récupérer
mettre un code sur le bouton fermer.
Cette action est irreversible, confirmez la suppression du commentaire ?
Signaler le commentaire
Veuillez sélectionner un problème
Nudité
Violence
Harcèlement
Fraude
Vente illégale
Discours haineux
Terrorisme
Autre
Alain CROS
Bonjour.
Ce code permet d'empécher d'imprimer depuis l'apperçu avant impression. A adapter en fonction de l'effet recherché.
Alain CROS
Dans un module.
Private Declare Function SetWindowsHookEx& _ Lib "user32" Alias "SetWindowsHookExA" _ (ByVal idHook&, ByVal lpfn&, ByVal hmod&, ByVal dwThreadId&)
Private Declare Function GetCurrentThreadId& _ Lib "kernel32" _ ()
Private Declare Function UnhookWindowsHookEx& _ Lib "user32" _ (ByVal hHook&)
Private Declare Function GetClassName& Lib "user32" _ Alias "GetClassNameA" (ByVal hWnd&, ByVal lpClassName$, ByVal nMaxCount&)
Private Declare Function GetDlgCtrlID& Lib "user32" _ (ByVal hWnd&)
Private Declare Function SetWindowLong& _ Lib "user32" Alias "SetWindowLongA" _ (ByVal hWnd&, ByVal nIndex&, ByVal dwNewLong&)
Private Declare Function CallWindowProc& _ Lib "user32" Alias "CallWindowProcA" _ (ByVal lpPrevWndFunc&, ByVal hWnd&, ByVal Msg&, ByVal wParam&, ByVal lParam&)
Private LeHook&, OldWinProc&
Private Function NomDeClass$(hWnd&) NomDeClass = Space$(20&) NomDeClass = Left$(NomDeClass, GetClassName(hWnd, NomDeClass, 20&)) End Function
Sub ApercuAvantImpression() Const WH_CBT& = &H5 LeHook = SetWindowsHookEx(WH_CBT, AddressOf HookMsgb, 0&, GetCurrentThreadId) Application.Dialogs(xlDialogPrintPreview).Show UnhookWindowsHookEx LeHook End Sub
Private Function ImpProc&(ByVal hWnd&, ByVal Msg&, ByVal wParam&, ByVal lParam&) Const WM_DESTROY& = &H2, GWL_WNDPROC& = -4&, BM_SETSTATE& = &HF3 If Msg = WM_DESTROY Then SetWindowLong wParam, GWL_WNDPROC, OldWinProc End If If Msg = BM_SETSTATE Then If wParam = 1& Then MsgBox "Impossible d'imprimer.", vbCritical, "Spécial Lyssandre" End If Exit Function End If ImpProc = CallWindowProc(OldWinProc, hWnd, Msg, wParam, lParam) End Function
Private Function HookMsgb&(ByVal lMsg&, ByVal wParam&, ByRef lParam&) Const HCBT_ACTIVATE& = 5&, GWL_WNDPROC& = -4&, HCBT_SETFOCUS& = 9& If lMsg = HCBT_SETFOCUS Then If NomDeClass(wParam) = "Button" Then If GetDlgCtrlID(wParam) = 3& Then UnhookWindowsHookEx LeHook OldWinProc = SetWindowLong(wParam, GWL_WNDPROC, AddressOf ImpProc) End If End If End If End Function
"Lyssandre" a écrit dans le message de news: | Salut a tous, | | Je voudrais faire un appercu avant impression et empecher l'utilisateur | de quitter cet appercu tant qu'il n'as pas imprimer puis afficher un | UserForm. Ou alors desactiver le bouton imprimer pour obliger | l'utilisateur a fermer l'appercu puis afficher un UserForm. | | Déja est-ce possible et si oui existe t'il une solution pour récupérer | mettre un code sur le bouton fermer. | | Désolé pour cette colle ....... ;) | | Merci d'avance | | Lyss.
Bonjour.
Ce code permet d'empécher d'imprimer depuis l'apperçu avant impression.
A adapter en fonction de l'effet recherché.
Alain CROS
Dans un module.
Private Declare Function SetWindowsHookEx& _
Lib "user32" Alias "SetWindowsHookExA" _
(ByVal idHook&, ByVal lpfn&, ByVal hmod&, ByVal dwThreadId&)
Private Declare Function GetCurrentThreadId& _
Lib "kernel32" _
()
Private Declare Function UnhookWindowsHookEx& _
Lib "user32" _
(ByVal hHook&)
Private Declare Function GetClassName& Lib "user32" _
Alias "GetClassNameA" (ByVal hWnd&, ByVal lpClassName$, ByVal nMaxCount&)
Private Declare Function GetDlgCtrlID& Lib "user32" _
(ByVal hWnd&)
Private Declare Function SetWindowLong& _
Lib "user32" Alias "SetWindowLongA" _
(ByVal hWnd&, ByVal nIndex&, ByVal dwNewLong&)
Private Declare Function CallWindowProc& _
Lib "user32" Alias "CallWindowProcA" _
(ByVal lpPrevWndFunc&, ByVal hWnd&, ByVal Msg&, ByVal wParam&, ByVal lParam&)
Private LeHook&, OldWinProc&
Private Function NomDeClass$(hWnd&)
NomDeClass = Space$(20&)
NomDeClass = Left$(NomDeClass, GetClassName(hWnd, NomDeClass, 20&))
End Function
Sub ApercuAvantImpression()
Const WH_CBT& = &H5
LeHook = SetWindowsHookEx(WH_CBT, AddressOf HookMsgb, 0&, GetCurrentThreadId)
Application.Dialogs(xlDialogPrintPreview).Show
UnhookWindowsHookEx LeHook
End Sub
Private Function ImpProc&(ByVal hWnd&, ByVal Msg&, ByVal wParam&, ByVal lParam&)
Const WM_DESTROY& = &H2, GWL_WNDPROC& = -4&, BM_SETSTATE& = &HF3
If Msg = WM_DESTROY Then
SetWindowLong wParam, GWL_WNDPROC, OldWinProc
End If
If Msg = BM_SETSTATE Then
If wParam = 1& Then
MsgBox "Impossible d'imprimer.", vbCritical, "Spécial Lyssandre"
End If
Exit Function
End If
ImpProc = CallWindowProc(OldWinProc, hWnd, Msg, wParam, lParam)
End Function
Private Function HookMsgb&(ByVal lMsg&, ByVal wParam&, ByRef lParam&)
Const HCBT_ACTIVATE& = 5&, GWL_WNDPROC& = -4&, HCBT_SETFOCUS& = 9&
If lMsg = HCBT_SETFOCUS Then
If NomDeClass(wParam) = "Button" Then
If GetDlgCtrlID(wParam) = 3& Then
UnhookWindowsHookEx LeHook
OldWinProc = SetWindowLong(wParam, GWL_WNDPROC, AddressOf ImpProc)
End If
End If
End If
End Function
"Lyssandre" <lyssandre63@gmail.com> a écrit dans le message de news: ueWtZx7WFHA.1384@TK2MSFTNGP09.phx.gbl...
| Salut a tous,
|
| Je voudrais faire un appercu avant impression et empecher l'utilisateur
| de quitter cet appercu tant qu'il n'as pas imprimer puis afficher un
| UserForm. Ou alors desactiver le bouton imprimer pour obliger
| l'utilisateur a fermer l'appercu puis afficher un UserForm.
|
| Déja est-ce possible et si oui existe t'il une solution pour récupérer
| mettre un code sur le bouton fermer.
|
| Désolé pour cette colle ....... ;)
|
| Merci d'avance
|
| Lyss.
Ce code permet d'empécher d'imprimer depuis l'apperçu avant impression. A adapter en fonction de l'effet recherché.
Alain CROS
Dans un module.
Private Declare Function SetWindowsHookEx& _ Lib "user32" Alias "SetWindowsHookExA" _ (ByVal idHook&, ByVal lpfn&, ByVal hmod&, ByVal dwThreadId&)
Private Declare Function GetCurrentThreadId& _ Lib "kernel32" _ ()
Private Declare Function UnhookWindowsHookEx& _ Lib "user32" _ (ByVal hHook&)
Private Declare Function GetClassName& Lib "user32" _ Alias "GetClassNameA" (ByVal hWnd&, ByVal lpClassName$, ByVal nMaxCount&)
Private Declare Function GetDlgCtrlID& Lib "user32" _ (ByVal hWnd&)
Private Declare Function SetWindowLong& _ Lib "user32" Alias "SetWindowLongA" _ (ByVal hWnd&, ByVal nIndex&, ByVal dwNewLong&)
Private Declare Function CallWindowProc& _ Lib "user32" Alias "CallWindowProcA" _ (ByVal lpPrevWndFunc&, ByVal hWnd&, ByVal Msg&, ByVal wParam&, ByVal lParam&)
Private LeHook&, OldWinProc&
Private Function NomDeClass$(hWnd&) NomDeClass = Space$(20&) NomDeClass = Left$(NomDeClass, GetClassName(hWnd, NomDeClass, 20&)) End Function
Sub ApercuAvantImpression() Const WH_CBT& = &H5 LeHook = SetWindowsHookEx(WH_CBT, AddressOf HookMsgb, 0&, GetCurrentThreadId) Application.Dialogs(xlDialogPrintPreview).Show UnhookWindowsHookEx LeHook End Sub
Private Function ImpProc&(ByVal hWnd&, ByVal Msg&, ByVal wParam&, ByVal lParam&) Const WM_DESTROY& = &H2, GWL_WNDPROC& = -4&, BM_SETSTATE& = &HF3 If Msg = WM_DESTROY Then SetWindowLong wParam, GWL_WNDPROC, OldWinProc End If If Msg = BM_SETSTATE Then If wParam = 1& Then MsgBox "Impossible d'imprimer.", vbCritical, "Spécial Lyssandre" End If Exit Function End If ImpProc = CallWindowProc(OldWinProc, hWnd, Msg, wParam, lParam) End Function
Private Function HookMsgb&(ByVal lMsg&, ByVal wParam&, ByRef lParam&) Const HCBT_ACTIVATE& = 5&, GWL_WNDPROC& = -4&, HCBT_SETFOCUS& = 9& If lMsg = HCBT_SETFOCUS Then If NomDeClass(wParam) = "Button" Then If GetDlgCtrlID(wParam) = 3& Then UnhookWindowsHookEx LeHook OldWinProc = SetWindowLong(wParam, GWL_WNDPROC, AddressOf ImpProc) End If End If End If End Function
"Lyssandre" a écrit dans le message de news: | Salut a tous, | | Je voudrais faire un appercu avant impression et empecher l'utilisateur | de quitter cet appercu tant qu'il n'as pas imprimer puis afficher un | UserForm. Ou alors desactiver le bouton imprimer pour obliger | l'utilisateur a fermer l'appercu puis afficher un UserForm. | | Déja est-ce possible et si oui existe t'il une solution pour récupérer | mettre un code sur le bouton fermer. | | Désolé pour cette colle ....... ;) | | Merci d'avance | | Lyss.
Lyssandre
Merci a toi allain pour cette aide.
Je suis sur le code et ça fonctionne bien avec le bouton imprimer par contre j'essaye de faire pareil pour les autres boutons de l'apercu ( en fait tous sauf prec et suivant ,zoom et fermer) , mais franchement je comprend rien a l'articulation du code ( des fois le cerveau est sur off). Normalement le wParam sert bien à indiquer le bouton ?
Merci d'eclairer ma lanterne.
Lyss
Bonjour.
Ce code permet d'empécher d'imprimer depuis l'apperçu avant impression. A adapter en fonction de l'effet recherché.
Alain CROS
Dans un module.
Private Declare Function SetWindowsHookEx& _ Lib "user32" Alias "SetWindowsHookExA" _ (ByVal idHook&, ByVal lpfn&, ByVal hmod&, ByVal dwThreadId&)
Private Declare Function GetCurrentThreadId& _ Lib "kernel32" _ ()
Private Declare Function UnhookWindowsHookEx& _ Lib "user32" _ (ByVal hHook&)
Private Declare Function GetClassName& Lib "user32" _ Alias "GetClassNameA" (ByVal hWnd&, ByVal lpClassName$, ByVal nMaxCount&)
Private Declare Function GetDlgCtrlID& Lib "user32" _ (ByVal hWnd&)
Private Declare Function SetWindowLong& _ Lib "user32" Alias "SetWindowLongA" _ (ByVal hWnd&, ByVal nIndex&, ByVal dwNewLong&)
Private Declare Function CallWindowProc& _ Lib "user32" Alias "CallWindowProcA" _ (ByVal lpPrevWndFunc&, ByVal hWnd&, ByVal Msg&, ByVal wParam&, ByVal lParam&)
Private LeHook&, OldWinProc&
Private Function NomDeClass$(hWnd&) NomDeClass = Space$(20&) NomDeClass = Left$(NomDeClass, GetClassName(hWnd, NomDeClass, 20&)) End Function
Sub ApercuAvantImpression() Const WH_CBT& = &H5 LeHook = SetWindowsHookEx(WH_CBT, AddressOf HookMsgb, 0&, GetCurrentThreadId) Application.Dialogs(xlDialogPrintPreview).Show UnhookWindowsHookEx LeHook End Sub
Private Function ImpProc&(ByVal hWnd&, ByVal Msg&, ByVal wParam&, ByVal lParam&) Const WM_DESTROY& = &H2, GWL_WNDPROC& = -4&, BM_SETSTATE& = &HF3 If Msg = WM_DESTROY Then SetWindowLong wParam, GWL_WNDPROC, OldWinProc End If If Msg = BM_SETSTATE Then If wParam = 1& Then MsgBox "Impossible d'imprimer.", vbCritical, "Spécial Lyssandre" End If Exit Function End If ImpProc = CallWindowProc(OldWinProc, hWnd, Msg, wParam, lParam) End Function
Private Function HookMsgb&(ByVal lMsg&, ByVal wParam&, ByRef lParam&) Const HCBT_ACTIVATE& = 5&, GWL_WNDPROC& = -4&, HCBT_SETFOCUS& = 9& If lMsg = HCBT_SETFOCUS Then If NomDeClass(wParam) = "Button" Then If GetDlgCtrlID(wParam) = 3& Then UnhookWindowsHookEx LeHook OldWinProc = SetWindowLong(wParam, GWL_WNDPROC, AddressOf ImpProc) End If End If End If End Function
"Lyssandre" a écrit dans le message de news: | Salut a tous, | | Je voudrais faire un appercu avant impression et empecher l'utilisateur | de quitter cet appercu tant qu'il n'as pas imprimer puis afficher un | UserForm. Ou alors desactiver le bouton imprimer pour obliger | l'utilisateur a fermer l'appercu puis afficher un UserForm. | | Déja est-ce possible et si oui existe t'il une solution pour récupérer | mettre un code sur le bouton fermer. | | Désolé pour cette colle ....... ;) | | Merci d'avance | | Lyss.
Merci a toi allain pour cette aide.
Je suis sur le code et ça fonctionne bien avec le bouton imprimer par
contre j'essaye de faire pareil pour les autres boutons de l'apercu ( en
fait tous sauf prec et suivant ,zoom et fermer) , mais franchement je
comprend rien a l'articulation du code ( des fois le cerveau est sur
off). Normalement le wParam sert bien à indiquer le bouton ?
Merci d'eclairer ma lanterne.
Lyss
Bonjour.
Ce code permet d'empécher d'imprimer depuis l'apperçu avant impression.
A adapter en fonction de l'effet recherché.
Alain CROS
Dans un module.
Private Declare Function SetWindowsHookEx& _
Lib "user32" Alias "SetWindowsHookExA" _
(ByVal idHook&, ByVal lpfn&, ByVal hmod&, ByVal dwThreadId&)
Private Declare Function GetCurrentThreadId& _
Lib "kernel32" _
()
Private Declare Function UnhookWindowsHookEx& _
Lib "user32" _
(ByVal hHook&)
Private Declare Function GetClassName& Lib "user32" _
Alias "GetClassNameA" (ByVal hWnd&, ByVal lpClassName$, ByVal nMaxCount&)
Private Declare Function GetDlgCtrlID& Lib "user32" _
(ByVal hWnd&)
Private Declare Function SetWindowLong& _
Lib "user32" Alias "SetWindowLongA" _
(ByVal hWnd&, ByVal nIndex&, ByVal dwNewLong&)
Private Declare Function CallWindowProc& _
Lib "user32" Alias "CallWindowProcA" _
(ByVal lpPrevWndFunc&, ByVal hWnd&, ByVal Msg&, ByVal wParam&, ByVal lParam&)
Private LeHook&, OldWinProc&
Private Function NomDeClass$(hWnd&)
NomDeClass = Space$(20&)
NomDeClass = Left$(NomDeClass, GetClassName(hWnd, NomDeClass, 20&))
End Function
Sub ApercuAvantImpression()
Const WH_CBT& = &H5
LeHook = SetWindowsHookEx(WH_CBT, AddressOf HookMsgb, 0&, GetCurrentThreadId)
Application.Dialogs(xlDialogPrintPreview).Show
UnhookWindowsHookEx LeHook
End Sub
Private Function ImpProc&(ByVal hWnd&, ByVal Msg&, ByVal wParam&, ByVal lParam&)
Const WM_DESTROY& = &H2, GWL_WNDPROC& = -4&, BM_SETSTATE& = &HF3
If Msg = WM_DESTROY Then
SetWindowLong wParam, GWL_WNDPROC, OldWinProc
End If
If Msg = BM_SETSTATE Then
If wParam = 1& Then
MsgBox "Impossible d'imprimer.", vbCritical, "Spécial Lyssandre"
End If
Exit Function
End If
ImpProc = CallWindowProc(OldWinProc, hWnd, Msg, wParam, lParam)
End Function
Private Function HookMsgb&(ByVal lMsg&, ByVal wParam&, ByRef lParam&)
Const HCBT_ACTIVATE& = 5&, GWL_WNDPROC& = -4&, HCBT_SETFOCUS& = 9&
If lMsg = HCBT_SETFOCUS Then
If NomDeClass(wParam) = "Button" Then
If GetDlgCtrlID(wParam) = 3& Then
UnhookWindowsHookEx LeHook
OldWinProc = SetWindowLong(wParam, GWL_WNDPROC, AddressOf ImpProc)
End If
End If
End If
End Function
"Lyssandre" <lyssandre63@gmail.com> a écrit dans le message de news: ueWtZx7WFHA.1384@TK2MSFTNGP09.phx.gbl...
| Salut a tous,
|
| Je voudrais faire un appercu avant impression et empecher l'utilisateur
| de quitter cet appercu tant qu'il n'as pas imprimer puis afficher un
| UserForm. Ou alors desactiver le bouton imprimer pour obliger
| l'utilisateur a fermer l'appercu puis afficher un UserForm.
|
| Déja est-ce possible et si oui existe t'il une solution pour récupérer
| mettre un code sur le bouton fermer.
|
| Désolé pour cette colle ....... ;)
|
| Merci d'avance
|
| Lyss.
Je suis sur le code et ça fonctionne bien avec le bouton imprimer par contre j'essaye de faire pareil pour les autres boutons de l'apercu ( en fait tous sauf prec et suivant ,zoom et fermer) , mais franchement je comprend rien a l'articulation du code ( des fois le cerveau est sur off). Normalement le wParam sert bien à indiquer le bouton ?
Merci d'eclairer ma lanterne.
Lyss
Bonjour.
Ce code permet d'empécher d'imprimer depuis l'apperçu avant impression. A adapter en fonction de l'effet recherché.
Alain CROS
Dans un module.
Private Declare Function SetWindowsHookEx& _ Lib "user32" Alias "SetWindowsHookExA" _ (ByVal idHook&, ByVal lpfn&, ByVal hmod&, ByVal dwThreadId&)
Private Declare Function GetCurrentThreadId& _ Lib "kernel32" _ ()
Private Declare Function UnhookWindowsHookEx& _ Lib "user32" _ (ByVal hHook&)
Private Declare Function GetClassName& Lib "user32" _ Alias "GetClassNameA" (ByVal hWnd&, ByVal lpClassName$, ByVal nMaxCount&)
Private Declare Function GetDlgCtrlID& Lib "user32" _ (ByVal hWnd&)
Private Declare Function SetWindowLong& _ Lib "user32" Alias "SetWindowLongA" _ (ByVal hWnd&, ByVal nIndex&, ByVal dwNewLong&)
Private Declare Function CallWindowProc& _ Lib "user32" Alias "CallWindowProcA" _ (ByVal lpPrevWndFunc&, ByVal hWnd&, ByVal Msg&, ByVal wParam&, ByVal lParam&)
Private LeHook&, OldWinProc&
Private Function NomDeClass$(hWnd&) NomDeClass = Space$(20&) NomDeClass = Left$(NomDeClass, GetClassName(hWnd, NomDeClass, 20&)) End Function
Sub ApercuAvantImpression() Const WH_CBT& = &H5 LeHook = SetWindowsHookEx(WH_CBT, AddressOf HookMsgb, 0&, GetCurrentThreadId) Application.Dialogs(xlDialogPrintPreview).Show UnhookWindowsHookEx LeHook End Sub
Private Function ImpProc&(ByVal hWnd&, ByVal Msg&, ByVal wParam&, ByVal lParam&) Const WM_DESTROY& = &H2, GWL_WNDPROC& = -4&, BM_SETSTATE& = &HF3 If Msg = WM_DESTROY Then SetWindowLong wParam, GWL_WNDPROC, OldWinProc End If If Msg = BM_SETSTATE Then If wParam = 1& Then MsgBox "Impossible d'imprimer.", vbCritical, "Spécial Lyssandre" End If Exit Function End If ImpProc = CallWindowProc(OldWinProc, hWnd, Msg, wParam, lParam) End Function
Private Function HookMsgb&(ByVal lMsg&, ByVal wParam&, ByRef lParam&) Const HCBT_ACTIVATE& = 5&, GWL_WNDPROC& = -4&, HCBT_SETFOCUS& = 9& If lMsg = HCBT_SETFOCUS Then If NomDeClass(wParam) = "Button" Then If GetDlgCtrlID(wParam) = 3& Then UnhookWindowsHookEx LeHook OldWinProc = SetWindowLong(wParam, GWL_WNDPROC, AddressOf ImpProc) End If End If End If End Function
"Lyssandre" a écrit dans le message de news: | Salut a tous, | | Je voudrais faire un appercu avant impression et empecher l'utilisateur | de quitter cet appercu tant qu'il n'as pas imprimer puis afficher un | UserForm. Ou alors desactiver le bouton imprimer pour obliger | l'utilisateur a fermer l'appercu puis afficher un UserForm. | | Déja est-ce possible et si oui existe t'il une solution pour récupérer | mettre un code sur le bouton fermer. | | Désolé pour cette colle ....... ;) | | Merci d'avance | | Lyss.