Private Declare Function GetCurrentThreadId& Lib "kernel32" ()
Private Declare Function SetDlgItemText& Lib "user32" Alias "SetDlgItemTextA" _
(ByVal hDlg As Long, ByVal nIDDlgItem As Long, ByVal lpString As String)
Private Declare Function SetWindowsHookEx& Lib "user32" Alias "SetWindowsHookExA" _
(ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, ByVal dwThreadId As Long)
Private Declare Function UnhookWindowsHookEx& Lib "user32" (ByVal hHook As Long)
Private hHook As Long
Private Const WH_CBT = 5
Private Const HCBT_ACTIVATE = 5
Public NE_PLUS_AFFICHER As Boolean
Public Const IDOK = 1
Public Const IDCANCEL = 2
Public Const IDABORT = 3
Public Const IDRETRY = 4
Public Const IDIGNORE = 5
Public Const IDYES = 6
Public Const IDNO = 7
Public Function myMsgBox() As Long
hHook = SetWindowsHookEx(WH_CBT, AddressOf MsgBoxHookProc, 0, GetCurrentThreadId)
myMsgBox = MsgBox("Mon message", vbAbortRetryIgnore, "Mon titre de MsgBox") 'corps et titre du message à adapter
End Function
Private Function MsgBoxHookProc(ByVal lMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If lMsg = HCBT_ACTIVATE Then
SetDlgItemText wParam, IDABORT, "Action 1"
SetDlgItemText wParam, IDRETRY, "Action 2"
SetDlgItemText wParam, IDIGNORE, "Ne plus afficher"
UnhookWindowsHookEx hHook
End If
MsgBoxHookProc = False
End Function
Sub AfficherMessage()
Dim result&
If NE_PLUS_AFFICHER Then Exit Sub
result& = myMsgBox
Select Case result&
Case IDABORT
MsgBox "Action1"
Case IDRETRY
MsgBox "Action2"
Case IDIGNORE
NE_PLUS_AFFICHER = True
With Sheets("test")
.CommandButton1.BackColor = &HFF&
.CommandButton2.Visible = True
End With
End Select
End Sub
Sub ReactiverMessage()
NE_PLUS_AFFICHER = False
With Sheets("test")
.CommandButton1.BackColor = &H8000000F
.CommandButton2.Visible = False
End With
End Sub