Imports System
Imports System.Windows.Forms
Imports System.Runtime.InteropServices
Imports System.Text
PublicDelegateFunction CallBack_WinProc(ByVal uMsg AsInteger, ByVal wParam AsInteger, ByVal lParam AsInteger) AsInteger
PublicDelegateFunction CallBack_EnumWinProc(ByVal hWnd AsInteger, ByVal lParam AsInteger) AsInteger
PublicClass CMessageBox
<DllImport("user32.dll")> _
PublicSharedFunction GetWindowLong(ByVal hwnd AsInteger, ByVal nIndex AsInteger) AsInteger
EndFunction
<DllImport("kernel32.dll")> _
PublicSharedFunction GetCurrentThreadId() AsInteger
EndFunction
<DllImport("user32.dll")> _
PublicSharedFunction SetWindowsHookEx(ByVal idHook AsInteger, ByVal lpfn As CallBack_WinProc, ByVal hmod AsInteger, ByVal dwThreadId AsInteger) AsInteger
EndFunction
<DllImport("user32.dll")> _
PublicSharedFunction UnhookWindowsHookEx(ByVal hHook AsInteger) AsInteger
EndFunction
<DllImport("user32.dll", CharSet:=CharSet.Auto)> _
PublicSharedFunction SetWindowText(ByVal hwnd AsInteger, ByVal lpString AsString) AsInteger
EndFunction
<DllImport("user32.dll")> _
PublicSharedFunction EnumChildWindows(ByVal hWndParent AsInteger, ByVal lpEnumFunc As CallBack_EnumWinProc, ByVal lParam AsInteger) AsInteger
EndFunction
<DllImport("user32.dll")> _
PublicSharedFunction GetClassName(ByVal hwnd AsInteger, ByVal lpClassName As StringBuilder, ByVal nMaxCount AsInteger) AsInteger
EndFunction
Dim TopCount AsInteger
Dim ButtonCount AsInteger
PrivateConst GWL_HINSTANCE AsInteger = (-6)
PrivateConst HCBT_ACTIVATE AsInteger = 5
PrivateConst WH_CBT AsInteger = 5
Private hHook AsInteger
Dim strCaption1 AsString
Dim strCaption2 AsString
Dim strCaption3 AsString
PublicFunction ShowMessage(ByVal hParent AsInteger, ByVal Prompt AsString, ByVal Title AsString, ByVal Caption1 AsString, ByVal Caption2 AsString, ByVal Caption3 AsString, ByVal buttons As MessageBoxButtons, ByVal icon As MessageBoxIcon, ByVal DefaultButton As MessageBoxDefaultButton, ByVal options As MessageBoxOptions) As DialogResult
Dim hInst AsInteger
Dim Thread AsInteger
TopCount = 0
ButtonCount = 0
strCaption1 = Caption1
strCaption2 = Caption2
strCaption3 = Caption3
If Title = ""Then Title = Application.ProductName
Dim myWndProc As CallBack_WinProc = New CallBack_WinProc(AddressOf WinProc)
hInst = GetWindowLong(hParent, GWL_HINSTANCE)
Thread = GetCurrentThreadId()
hHook = SetWindowsHookEx(WH_CBT, myWndProc, hInst, Thread)
Return MessageBox.Show(Prompt, Title, buttons, icon, DefaultButton, options)
EndFunction
PrivateFunction WinProc(ByVal uMsg AsInteger, ByVal wParam AsInteger, ByVal lParam AsInteger) AsInteger
Dim myEnumProc As CallBack_EnumWinProc = New CallBack_EnumWinProc(AddressOf EnumWinProc)
If uMsg = HCBT_ACTIVATE Then
EnumChildWindows(wParam, myEnumProc, 0)
UnhookWindowsHookEx(hHook)
EndIf
Return 0
EndFunction
PrivateFunction EnumWinProc(ByVal hWnd AsInteger, ByVal lParam AsInteger) AsInteger
Dim strBuffer As StringBuilder = New StringBuilder(256)
TopCount += 1
GetClassName(hWnd, strBuffer, strBuffer.Capacity)
Dim ss AsString = strBuffer.ToString()
If (ss.ToUpper().StartsWith("BUTTON")) Then
ButtonCount += 1
SelectCase ButtonCount
Case 1
SetWindowText(hWnd, strCaption1)
ExitSelect
Case 2
SetWindowText(hWnd, strCaption2)
ExitSelect
Case 3
SetWindowText(hWnd, strCaption3)
ExitSelect
EndSelect
EndIf
Return 1
EndFunction
EndClass
تاپيك رو ببند!