【问题标题】:Change win app labels and text更改 win 应用程序标签和文本
【发布时间】:2012-11-07 08:22:03
【问题描述】:

我记得在VB6 中,我能够获取当前正在运行的软件形式的句柄,并使用一些 API 函数从外部对其进行更改。 可以用c#做吗?如何?问题是该软件使用不同的语言。我想把它改成英文。

【问题讨论】:

标签: c# winforms


【解决方案1】:

尝试使用 Win32 API 中的 FindWindowSetWindowText

FindWindow c#签名:

[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

SetWindowText c#签名:

[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern bool SetWindowText(IntPtr hwnd, String lpString);

和一个样本鳕鱼:

SetWindowText(Process.GetCurrentProcess().MainWindowHandle, "Hello W");

【讨论】:

    【解决方案2】:

    1) 在 WinForms 中,Control 类中有一个“Handle”属性(所有控件和 Form 类都派生自它 (MSDN article)

    2) 在 WPF 中没有暴露 HWND 句柄,但您可以使用 WindowInteropHelper 类获取它。
    您可以这样获取它:

            WindowInteropHelper wih = new WindowInteropHelper(YourWindow);
            IntPtr hwndHandle = wih.Handle;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-05-13
      • 2017-10-28
      • 1970-01-01
      • 1970-01-01
      • 2013-08-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多