当前位置:必发365电子游戏 > 操作系统 > 就会遇到英文版应用程序下的MessageBox的按钮显示,本模块可让你改变命令按钮的文本颜色
就会遇到英文版应用程序下的MessageBox的按钮显示,本模块可让你改变命令按钮的文本颜色
2019-12-19

本文转自:


 

必发365登录, 

通过安装CultureUIInfo不能够改换MessageBox的按键的文书语言,因为那么些文件是基于你所设置的操作系统的语言决定的:你装的保加黎波里语操作系统,

 

这正是说便是"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卡塔尔(英语:State of Qatar);//设置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

hInstance, int threadID卡塔尔(قطر‎;//设置挂钩

        [DllImport("user32.dll")]
        static extern IntPtr CallNextHookEx(IntPtr handle, int code, IntPtr wparam, IntPtr lparam卡塔尔国;//实行下一个牵连,若是有个别话

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

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(卡塔尔(英语:State of Qatar)正是值得寻思的四个难点,你也足以在前后相继运维就

 

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_就会遇到英文版应用程序下的MessageBox的按钮显示,本模块可让你改变命令按钮的文本颜色。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就能够了。但却没有提供八个简约的不二等秘书籍去退换...

相关文章

有关寻觅:

今日看什么

检索技能库

归来首页

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