当前位置:优德中文版 > 外国军情 > [转]动态更动MessageBox的按键文本的言语

[转]动态更动MessageBox的按键文本的言语

文章作者:外国军情 上传时间:2019-10-06

正文转自:


 

 

通过安装CultureUIInfo不可能改造MessageBox的按键的文本语言,因为那么些文件是基于你所设置的操作系统的言语决定的:你装的德语操作系统,

 

w88优德中文 ,那正是说正是"Yes""No";你装的华语操作系统,那么便是“是”“否”。

Visual Basic允许技师改动一个CommandButton的背景象--轻松的将样式设为Graphical然后改变BackColor就行了。但却尚未提供五个回顾的格局去更换CommandButton的文字的水彩。本文将告诉您如何依照你的愿望改换CommandButton的公文颜色,况兼假如开关上有图片的话,还足以将文件显示在按键的最底层。

故而对于能够转移语言版本的应用程序,就能够赶过保加汉诺威语版应用程序下的MessageBox的按键显示“是”“否”(汉语操作系统);中文版应用程序下的

在工程中增加以下模块(Module):

MessageBox的开关突显"Yes""No"。傻呼呼。

Module modExtButton.bas

想到达指标,还是能的,只是比较劳苦,要不择手腕。要运用win-API函数,以及Hook技艺
下边是本土精考着C++代码写的C#代码
一、首先注明Hook的花色
   public enum HookType
        {
            Keyboard = 2,//键盘操作

 

            CBT = 5,//窗口操作

Option Explicit

            Mouse = 7, //鼠标操作
        };

 

二、声明API函数
        [DllImport("kernel32.dll")]
        static extern int GetCurrentThreadId();//获得当前的线程ID

==================================================================

        [DllImport("user32.dll")]
        static extern int GetDlgItem(IntPtr hDlg, int nIDDlgItem);//获得Dialog窗口的子项

modExtButton.bas

        [DllImport("user32", EntryPoint = "SetDlgItemText")]
        static extern int SetDlgItemTextA(IntPtr hDlg, int nIDDlgItem, string lpString);//设置Dialog窗口子项的公文

本模块可令你改动命令开关的公文颜色。

        [DllImport("user32.dll")]
        static extern void UnhookWindowsHookEx(IntPtr handle);//解掉挂钩

使用方法:

        [DllImport("user32.dll")]
        static extern IntPtr SetWindowsHookEx(int idHook, [MarshalAs(UnmanagedType.FunctionPtr)] HookProc lpfn, IntPtr

  • 优德88 ,在安排时将文件的Style设为Graphical.

hInstance, int threadID);//设置挂钩

  • 自由设定背景观和图象属性.

        [DllImport("user32.dll")]
        static extern IntPtr CallNextHookEx(IntPtr handle, int code, IntPtr wparam, IntPtr lparam);//进行下叁个联络,纵然部分话

  • 在Form_Load中调用 SetButton :

    优德中文版 ,SetButton Command1.hWnd, vbBlue

    (你能够大五回的调用该进度竟然不用先调用 RemoveButton.)

三、定义局地变量
        static IntPtr _nextHookPtr;
        static HookProc myProc = new HookProc(MyHookProc);//must be global, or it will be Collected by GC, then no callback

  • 在Form_Unload中调用 RemoveButton :

    RemoveButton Command1.hWnd

func can be used for the Hook
 delegate IntPtr HookProc(int code, IntPtr wparam, IntPtr lparam);

==================================================================

四、自定义HookProck逻辑,那是最要害的有的,如何威胁人质,怎么样敲诈人质,怎么着释放人质
   static IntPtr MyHookProc(int code, IntPtr wparam, IntPtr lparam)
          {
            IntPtr hChildWnd;// msgbox is "child"

 

            // notification that a window is about to be activated
            // window handle is wParam
            if (code == 5)//HCBT_ACTIVATE = 5
            {
                // set window handles of messagebox
                hChildWnd = wparam;
                //to get the text of yes button

Private Type RECT

                int result;

Left As Long

                if (GetDlgItem(hChildWnd, 6) != 0)//IDYES = 6
                {
                    result = SetDlgItemTextA(hChildWnd, 6, Properties.Resources.YES);//在Project.Resources里自定义文本
                }
                if (GetDlgItem(hChildWnd, 7) != 0)//IDNO = 7
                {
                    result = SetDlgItemTextA(hChildWnd, 7, Properties.Resources.NO);
                }
            }
            else
            {
                CallNextHookEx(_nextHookPtr, code, wparam, lparam);// otherwise, continue with any possible chained hooks
            }

Top As Long

            //return (IntPtr)1; //直接重回了,该音讯就管理完成了
            return IntPtr.Zero;//重返,让后面包车型客车程序管理该消息

Right As Long

        }
五、提须求外部调用的Hook方法,如在Form_Load时SetHook,Form_Closing时UnHook.
  public static void SetHook()
        {
            if (_nextHookPtr != IntPtr.Zero)//Hooked already
            {
                return;
            }

Bottom As Long

            _nextHookPtr = SetWindowsHookEx((int)HookType.CBT, myProc, IntPtr.Zero, GetCurrentThreadId());

End Type

        }

 

        public static void UnHook()
        {
            if (_nextHookPtr != IntPtr.Zero)
            {
                UnhookWindowsHookEx(_nextHookPtr);

Private Declare Function GetParent Lib "user32" _

                _nextHookPtr = IntPtr.Zero;
            }
        }

(ByVal hWnd As Long) As Long

地点的代码能够放在叁个独门文件如APIHelper.cs,供User使用。
指标达到了,看代码就明白,这样不只可以够让button的公文能够依赖语言退换,文本的内容也能够自定义。
事实注脚抢劫的获取是迷人的,然则风险费用也是异常高的,
1.对于挂钩Hook本领,大家还不是很熟习,比方怎样死后SetHook(),几时UnHook()正是值得思量的二个标题,你也足以在前后相继运转就

 

SetHook,也能够在实行某项操作后就SetHook,但是一定毫无忘了UnHook,否则你的Hook会招致你意外的范围的影响。
2.回调函数要一口咬住不放音讯号,全体的Form在Activate的时候都以code = 5,不过大家只有在弹出MessageBox的时候设置Button的文件。所以假如自身

Private Declare Function GetWindowLong Lib "user32" Alias _

们在起步程序的时候就SetHook(),必然会让每一次消息管理多走了几段代码,就算眼睛不能够辨别这么些差别,不过真正不须要。

"GetWindowLongA" (ByVal hWnd As Long, _

假如SetHook和UnHook的本金不高,我们得以虚拟在MessageBox.Show()的地方实行联系和解钩。假若那样,那么只要您的程序里面传布着

ByVal nIndex As Long) As Long

MessageBox.show(),你就哭啊;TMS真是英明,把MessageBox.Show()的功力都收取到了八个大局静态类里面,作者如若改那几个大局方法就足以了。

Private Declare Function SetWindowLong Lib "user32" Alias _

足见抽出共用逻辑依旧很注重的!

"SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, _

敲定:就让大家的顺序傻傻的,傻傻要比傻B强得多。
      最少大家精晓了,那些标题有化解方案。

ByVal dwNewLong As Long) As Long

 

Private Const GWL_WNDPROC = (-4)

 

Private Declare Function GetProp Lib "user32" Alias "GetPropA" _

(ByVal hWnd As Long, ByVal lpString As String) As Long

Private Declare Function SetProp Lib "user32" Alias "SetPropA" _

(ByVal hWnd As Long, ByVal lpString As String, _

ByVal hData As Long) As Long

Private Declare Function RemoveProp Lib "user32" Alias _

"RemovePropA" (ByVal hWnd As Long, _

ByVal lpString As String) As Long

 

Private Declare Function CallWindowProc Lib "user32" Alias _

"CallWindowProcA" (ByVal lpPrevWndFunc As Long, _

ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, _

ByVal lParam As Long) As Long

 

Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _

(Destination As Any, Source As Any, ByVal Length As Long)

 

Owner draw constants

Private Const ODT_BUTTON = 4

Private Const ODS_SELECTED = &H1

Window messages were using

Private Const WM_DESTROY = &H2

Private Const WM_DRAWITEM = &H2B

 

Private Type DRAWITEMSTRUCT

CtlType As Long

CtlID As Long

itemID As Long

itemAction As Long

itemState As Long

hwndItem As Long

hDC As Long

rcItem As RECT

itemData As Long

End Type

 

Private Declare Function GetWindowText Lib "user32" Alias _

"GetWindowTextA" (ByVal hWnd As Long, ByVal lpString As String, _

ByVal cch As Long) As Long

Various GDI painting-related functions

Private Declare Function DrawText Lib "user32" Alias "DrawTextA" _

(ByVal hDC As Long, ByVal lpStr As String, ByVal nCount As Long, _

lpRect As RECT, ByVal wFormat As Long) As Long

Private Declare Function Se

Basic允许程序员改造三个CommandButton的背景象--简单的将样式设为Graphical然后更换BackColor就行了。但却未有提供多少个轻巧的措施去退换...

连锁作品

有关寻找:

今日看甚

检索本领库

再次来到首页

  • 【彻彻底底,从头到尾忘记了哪个人
  • 【彻头彻尾,原原本本忘记了何人
  • WPF学习(四) - 附加属性,wpf学习附加属性
  • Windows 上的 Jetty 小工具,windowsjetty工具
  • 【从头到尾,原原本本忘记了哪个人
  • C# web server的费用流程,

有关频道: Java编程  C#教程  C语言  C++教程  VC教程  Delphi教程  VB教程  工具软件  

本文由优德中文版发布于外国军情,转载请注明出处:[转]动态更动MessageBox的按键文本的言语

关键词: