PDA

View Full Version : مبتدی: نوشتن msgbox فارسی



mjShojaei
شنبه 31 اردیبهشت 1390, 13:31 عصر
سلام دوستان
من می خوام وقتی که یک msgbox می نویسیم که دارای کلید های yes و no است. به جای yes و no ، بله و خیر نمایش داده بشه .
اگر این امکان در VB وجود داره . لطفا راهنمایم کنید. با تشکر

barbodsoft.com
شنبه 31 اردیبهشت 1390, 15:33 عصر
کلاس زیر رو به پروژت اضافه کن و از این به بعد به جای MessageBox بنویس MessageBoxFa . بقیه روش کار کردن عینا همون MessageBox هست.



Imports System
Imports System.Windows.Forms
Imports System.Runtime.InteropServices
Imports System.Text

Public Class MessageBoxFa
Public Delegate Function CallBack_WinProc(ByVal uMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
Public Delegate Function CallBack_EnumWinProc(ByVal hWnd As Integer, ByVal lParam As Integer) As Integer

<DllImport("user32.dll")> _
Private Shared Function GetWindowLong(ByVal hwnd As Integer, ByVal nIndex As Integer) As Integer
End Function
<DllImport("kernel32.dll")> _
Private Shared Function GetCurrentThreadId() As Integer
End Function
<DllImport("user32.dll")> _
Private Shared Function SetWindowsHookEx(ByVal idHook As Integer, ByVal lpfn As CallBack_WinProc, ByVal hmod As Integer, ByVal dwThreadId As Integer) As Integer
End Function
<DllImport("user32.dll")> _
Private Shared Function UnhookWindowsHookEx(ByVal hHook As Integer) As Integer
End Function
<DllImport("user32.dll", CharSet:=CharSet.Auto)> _
Private Shared Function SetWindowText(ByVal hwnd As Integer, ByVal lpString As String) As Integer
End Function
<DllImport("user32.dll")> _
Private Shared Function EnumChildWindows(ByVal hWndParent As Integer, ByVal lpEnumFunc As CallBack_EnumWinProc, ByVal lParam As Integer) As Integer
End Function
<DllImport("user32.dll")> _
Private Shared Function GetClassName(ByVal hwnd As Integer, ByVal lpClassName As StringBuilder, ByVal nMaxCount As Integer) As Integer
End Function

Shared TopCount As Integer
Shared ButtonCount As Integer
Private Const GWL_HINSTANCE As Integer = (-6)
Private Const HCBT_ACTIVATE As Integer = 5
Private Const WH_CBT As Integer = 5
Private Shared hHook As Integer
Shared strCaption1 As String = ""
Shared strCaption2 As String = ""
Shared strCaption3 As String = ""
Shared Drk As New Form

Shared Function Show(ByVal Prompt As String _
, Optional ByVal Title As String = "", Optional ByVal buttons As MessageBoxButtons = MessageBoxButtons.OK _
, Optional ByVal icon As MessageBoxIcon = MessageBoxIcon.None _
, Optional ByVal DefaultButton As MessageBoxDefaultButton = MessageBoxDefaultButton.Button1 _
, Optional ByVal options As MessageBoxOptions = MessageBoxOptions.RtlReading _
, Optional ByVal m As MsgBoxStyle = MsgBoxStyle.ApplicationModal) As DialogResult
'
Dim hInst As Integer
Dim Thread As Integer
TopCount = 0
ButtonCount = 0
Select Case (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 = "تایید"
End Select
'If Title = "" Then Title = Application.ProductName
Dim myWndProc As CallBack_WinProc = New CallBack_WinProc(AddressOf WinProc)
hInst = GetWindowLong(1, 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)
End Function

Private Shared Function WinProc(ByVal uMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
Dim myEnumProc As CallBack_EnumWinProc = New CallBack_EnumWinProc(AddressOf EnumWinProc)
If uMsg = HCBT_ACTIVATE Then
EnumChildWindows(wParam, myEnumProc, 0)
UnhookWindowsHookEx(hHook)
End If
Return 0
End Function

Private Shared Function EnumWinProc(ByVal hWnd As Integer, ByVal lParam As Integer) As Integer
Dim strBuffer As StringBuilder = New StringBuilder(256)
TopCount += 1
GetClassName(hWnd, strBuffer, strBuffer.Capacity)
Dim ss As String = strBuffer.ToString()
If (ss.ToUpper().StartsWith("BUTTON")) Then
ButtonCount += 1
Select Case (ButtonCount)
Case 1
SetWindowText(hWnd, strCaption1)
Exit Select
Case 2
SetWindowText(hWnd, strCaption2)
Exit Select
Case 3
SetWindowText(hWnd, strCaption3)
Exit Select
End Select
End If
Return ButtonCount
End Function
End Class

hamidhassas
شنبه 31 اردیبهشت 1390, 16:37 عصر
این همه کد فقط به خاطر یک بله وخیر فارسی

میشه یک کم نوضیح بدین داره چه اتفاقی می افته

من بی سواد چیزی سر در نیاوردم که داره چه اتفاقی می افته

hamidhassas
شنبه 31 اردیبهشت 1390, 16:38 عصر
راستی طرز استفاده را هم قدم به قدم میشه توضیح بدین

barbodsoft.com
شنبه 31 اردیبهشت 1390, 17:26 عصر
من بالا توضیح دادم. این کد که بالا می بینی یک کلاس هست. یعنی شما هر بار لازم نیست که این کد رو تکرار کنی.
1- به پروژه ات یک کلاس با نام MessageBoxFa اضافه کن
2- کد های کلاس MessageBoxFa رو کلا پک کن و کد بالا رو به جاش کپی کن
3- حالا همونطور که از تابع MessageBox استفاده می کردی می تونی از این تابع استفاده کنی. فقط به جای نوشتن MessageBox بنویس MessageBoxfa

Navid Asadi
یک شنبه 01 خرداد 1390, 14:56 عصر
سلام
تو
Return sal_mali
sal_mali رو ایراد میگیره...

mjShojaei
دوشنبه 02 خرداد 1390, 22:10 عصر
با تشکر از دوست عزیز که کمک کردن
ولی آیا راهی به جز ایجاد کلاس جیدی نیست؟
چون خود VB برای رفع برخی از این مشکلات توابع آماده داره. (مثل تاریخ شمسی - قمری). گفتم شاید راهی هم برای این وجود داشته باشه، بدون تعریف کلاس جدید ...

barbodsoft.com
سه شنبه 03 خرداد 1390, 16:57 عصر
سلام
تو
Return sal_mali
sal_mali رو ایراد میگیره...

اشتباه شده بود. اصلاح کردم.