Option Explicit
'---------------------------------------------|
' ******************************************* |
' * Sujet : Boutons de MsgBox personnalisés * |
' ******************************************* |
'---------------------------------------------|
Private Declare Function SetWindowsHookEx& Lib "USER32" Alias "SetWindowsHookExA" (ByVal idHook&, ByVal lpfn&, ByVal hmod&, ByVal dwThreadId&)
Private Declare Function GetCurrentThreadId Lib "kernel32" () As Long
Private Declare Function CallNextHookEx Lib "USER32" (ByVal hHook As Long, ByVal CodeNo As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function GetWindow Lib "USER32" (ByVal hWnd As Long, ByVal wCmd As Long) As Long
Private Declare Function SetWindowText Lib "USER32" Alias "SetWindowTextA" (ByVal hWnd As Long, ByVal lpString As String) As Long
Private Declare Function UnhookWindowsHookEx& Lib "USER32" (ByVal hHook&)
Private msgHook&
Private TitreBtn$(1 To 2)
Function MsgBoxPerso(Titr$, Msg$, Btn1$, Btn2$, BtnCancel As Boolean) As Byte
Dim Reply%, hInstance&
TitreBtn(1) = Btn1
TitreBtn(2) = Btn2
msgHook = SetWindowsHookEx(5, AddressOf CaptionBoutons, hInstance, GetCurrentThreadId())
Reply = MsgBox(Msg, IIf(BtnCancel, vbYesNoCancel, vbYesNo) + vbQuestion, Titr)
MsgBoxPerso = Application.Max(Reply - 5, 0)
Erase TitreBtn
End Function
Private Function CaptionBoutons&(ByVal nCode&, ByVal wParam&, ByVal lParam&)
Dim hWndChild&
If nCode < 0 Then
CaptionBoutons = CallNextHookEx(msgHook, nCode, wParam, lParam)
Exit Function
End If
If nCode = 5 Then
hWndChild = GetWindow(wParam, 5)
Call SetWindowText(hWndChild, TitreBtn(1))
hWndChild = GetWindow(hWndChild, 2)
Call SetWindowText(hWndChild, TitreBtn(2))
UnhookWindowsHookEx msgHook
End If
CaptionBoutons = False
End Function
sub message()
' Affiche le message. pour savoir le nombre de faces 1 ou 2
Dim Msg, Style, Title, MyString ', response
Msg = "La carte comporte t elle 2 faces ?" ' Définit le message.
Style = vbYesNo + vbQuestion + vbDefaultButton1 + vbApplicationModal ' Définit les boutons.
Title = "Nombre de faces " ' Définit le titre.
'response = MsgBox(Msg, Style, Title)
Dim choix As Byte
choix = MsgBoxPerso("Nombre de faces", "Combien de faces comporte la carte ?", "1", "2", False)
Select Case choix
Case 1
response = 7
Case 2
response = 6
End Select
end sub