' This Class was develpoted by SomeBody and I change It to this shape!
'It changes caption of msgbox to persian word
'Baabak Bakhshayesh
'1384
Imports System
Imports System.Windows.Forms
Imports System.Runtime.InteropServices
Imports System.Text
PublicClass Pmsgbox
PrivateDelegateFunction CallBack_WinProc(ByVal uMsg AsInteger, ByVal wParam AsInteger, ByVal lParam AsInteger) AsInteger
PrivateDelegateFunction CallBack_EnumWinProc(ByVal hWnd AsInteger, ByVal lParam AsInteger) AsInteger
<DllImport("user32.dll")> _
PrivateSharedFunction GetWindowLong(ByVal hwnd AsInteger, ByVal nIndex AsInteger) AsInteger
EndFunction
<DllImport("kernel32.dll")> _
PrivateSharedFunction GetCurrentThreadId() AsInteger
EndFunction
<DllImport("user32.dll")> _
PrivateSharedFunction SetWindowsHookEx(ByVal idHook AsInteger, ByVal lpfn As CallBack_WinProc, ByVal hmod AsInteger, ByVal dwThreadId AsInteger) AsInteger
EndFunction
<DllImport("user32.dll")> _
PrivateSharedFunction UnhookWindowsHookEx(ByVal hHook AsInteger) AsInteger
EndFunction
<DllImport("user32.dll", CharSet:=CharSet.Auto)> _
PrivateSharedFunction SetWindowText(ByVal hwnd AsInteger, ByVal lpString AsString) AsInteger
EndFunction
<DllImport("user32.dll")> _
PrivateSharedFunction EnumChildWindows(ByVal hWndParent AsInteger, ByVal lpEnumFunc As CallBack_EnumWinProc, ByVal lParam AsInteger) AsInteger
EndFunction
<DllImport("user32.dll")> _
PrivateSharedFunction GetClassName(ByVal hwnd AsInteger, ByVal lpClassName As StringBuilder, ByVal nMaxCount AsInteger) AsInteger
EndFunction
Shared TopCount AsInteger
Shared ButtonCount AsInteger
PrivateConst GWL_HINSTANCE AsInteger = (-6)
PrivateConst HCBT_ACTIVATE AsInteger = 5
PrivateConst WH_CBT AsInteger = 5
PrivateShared hHook AsInteger
Shared strCaption1 AsString = ""
Shared strCaption2 AsString = ""
Shared strCaption3 AsString = ""
SharedFunction ShowMessage(ByVal hParent AsInteger, ByVal Prompt AsString, OptionalByVal Title AsString = "", OptionalByVal buttons As MessageBoxButtons = MessageBoxButtons.OK, _
OptionalByVal icon As MessageBoxIcon = MessageBoxIcon.None, OptionalByVal DefaultButton As MessageBoxDefaultButton = MessageBoxDefaultButton.Button1, _
OptionalByVal options As MessageBoxOptions = MessageBoxOptions.RtlReading, OptionalByVal m As MsgBoxStyle = MsgBoxStyle.ApplicationModal) As DialogResult
'
Dim hInst AsInteger
Dim Thread AsInteger
TopCount = 0
ButtonCount = 0
SelectCase buttons
Case MessageBoxButtons.AbortRetryIgnore
strCaption1 = "رها کردن"
strCaption2 = "کوشش مجدد"
strCaption3 = "چشم پوشی"
Case MessageBoxButtons.OK
strCaption1 = "تایید"
Case MessageBoxButtons.OKCancel
strCaption1 = "تایید"
strCaption2 = "لغو"
Case MessageBoxButtons.RetryCancel
strCaption1 = "کوشش مجدد"
strCaption2 = "لغو"
Case MessageBoxButtons.YesNo
strCaption1 = "بله"
strCaption2 = "خیر"
Case MessageBoxButtons.YesNoCancel
strCaption1 = "بله"
strCaption2 = "خیر"
strCaption3 = "لغو"
Case MessageBoxButtons.OK
strCaption1 = "تایید"
EndSelect
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 )
Return MsgBox(Prompt, buttons + icon + DefaultButton + MsgBoxStyle.MsgBoxRight + options + m, Title)
EndFunction
PrivateSharedFunction 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
PrivateSharedFunction 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