<bdo id='IWo23'></bdo><ul id='IWo23'></ul>
    1. <i id='IWo23'><tr id='IWo23'><dt id='IWo23'><q id='IWo23'><span id='IWo23'><b id='IWo23'><form id='IWo23'><ins id='IWo23'></ins><ul id='IWo23'></ul><sub id='IWo23'></sub></form><legend id='IWo23'></legend><bdo id='IWo23'><pre id='IWo23'><center id='IWo23'></center></pre></bdo></b><th id='IWo23'></th></span></q></dt></tr></i><div id='IWo23'><tfoot id='IWo23'></tfoot><dl id='IWo23'><fieldset id='IWo23'></fieldset></dl></div>
      <tfoot id='IWo23'></tfoot>
      <legend id='IWo23'><style id='IWo23'><dir id='IWo23'><q id='IWo23'></q></dir></style></legend>

        <small id='IWo23'></small><noframes id='IWo23'>

        如何更改 win32 窗口上的文本?

        时间:2023-09-14
      1. <tfoot id='Gc8QY'></tfoot>
          <tbody id='Gc8QY'></tbody>

      2. <legend id='Gc8QY'><style id='Gc8QY'><dir id='Gc8QY'><q id='Gc8QY'></q></dir></style></legend>
          <bdo id='Gc8QY'></bdo><ul id='Gc8QY'></ul>
            • <small id='Gc8QY'></small><noframes id='Gc8QY'>

                  <i id='Gc8QY'><tr id='Gc8QY'><dt id='Gc8QY'><q id='Gc8QY'><span id='Gc8QY'><b id='Gc8QY'><form id='Gc8QY'><ins id='Gc8QY'></ins><ul id='Gc8QY'></ul><sub id='Gc8QY'></sub></form><legend id='Gc8QY'></legend><bdo id='Gc8QY'><pre id='Gc8QY'><center id='Gc8QY'></center></pre></bdo></b><th id='Gc8QY'></th></span></q></dt></tr></i><div id='Gc8QY'><tfoot id='Gc8QY'></tfoot><dl id='Gc8QY'><fieldset id='Gc8QY'></fieldset></dl></div>
                1. 本文介绍了如何更改 win32 窗口上的文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  寻找从 C# 更改 win32 窗口上的文本的提示、技巧和搜索词.

                  Looking for hints, tips and search terms for changing the text on a win32 window from C#.

                  更具体地说,我正在尝试将打印对话框上的文本从打印"更改为确定",因为我正在使用该对话框来创建打印票而不进行任何打印.

                  More specifically, I'm trying to change the text on the print dialog from "Print" to "OK", as I am using the dialog to create a print ticket and not do any printing.

                  如何找到对话框的窗口句柄?一旦我得到它,我将如何在表单的子窗口中找到按钮?一旦我发现,我将如何更改按钮上的文本?在显示对话框之前我怎样才能做到这一切?

                  How can I find the dialog's window handle? Once I've got it, how would I go about finding the button in the child windows of the form? Once I've found that, how would I change the text on the button? And how can I do all this before the dialog is shown?

                  这里有一个类似的问题,但它指向的 CodeProject 文章比需要的要复杂得多,而且我花费的时间比我想花的时间要长一些.TIA.

                  There's a similar question here, but it points to a CodeProject article that is waaay more complex than needed and is taking me a bit longer to parse through than I'd like to spend on this. TIA.

                  推荐答案

                  您应该使用 Spy++ 来查看对话框.类名和按钮的控件 ID 很重要.如果它是本机 Windows 对话框,则类名应为#32770".在这种情况下,您将在 this线程.这是C#中的另一个.您可以通过 P/Invoking SetWindowText() 在按钮句柄上更改按钮文本.

                  You should use Spy++ to take a look at the dialog. The class name is important and the control ID of the button. If it is a native Windows dialog then the class name should be "#32770". In which case you'll have a lot of use for my post in this thread. Here is another in C#. You change the button text by P/Invoking SetWindowText() on the button handle.

                  using System;
                  using System.Text;
                  using System.Drawing;
                  using System.Windows.Forms;
                  using System.Runtime.InteropServices;
                  
                  class SetDialogButton : IDisposable {
                      private Timer mTimer = new Timer();
                      private int mCtlId;
                      private string mText;
                  
                      public SetDialogButton(int ctlId, string txt) {
                          mCtlId = ctlId;
                          mText = txt;
                          mTimer.Interval = 50;
                          mTimer.Enabled = true;
                          mTimer.Tick += (o, e) => findDialog();
                      }
                  
                      private void findDialog() {
                          // Enumerate windows to find the message box
                          EnumThreadWndProc callback = new EnumThreadWndProc(checkWindow);
                          if (!EnumThreadWindows(GetCurrentThreadId(), callback, IntPtr.Zero)) mTimer.Enabled = false;
                      }
                      private bool checkWindow(IntPtr hWnd, IntPtr lp) {
                          // Checks if <hWnd> is a dialog
                          StringBuilder sb = new StringBuilder(260);
                          GetClassName(hWnd, sb, sb.Capacity);
                          if (sb.ToString() != "#32770") return true;
                          // Got it, get the STATIC control that displays the text
                          IntPtr hCtl = GetDlgItem(hWnd, mCtlId);
                          SetWindowText(hCtl, mText);
                          // Done
                          return true;
                      }
                      public void Dispose() {
                          mTimer.Enabled = false;
                      }
                  
                      // P/Invoke declarations
                      private const int WM_SETFONT = 0x30;
                      private const int WM_GETFONT = 0x31;
                      private delegate bool EnumThreadWndProc(IntPtr hWnd, IntPtr lp);
                      [DllImport("user32.dll")]
                      private static extern bool EnumThreadWindows(int tid, EnumThreadWndProc callback, IntPtr lp);
                      [DllImport("kernel32.dll")]
                      private static extern int GetCurrentThreadId();
                      [DllImport("user32.dll")]
                      private static extern int GetClassName(IntPtr hWnd, StringBuilder buffer, int buflen);
                      [DllImport("user32.dll")]
                      private static extern IntPtr GetDlgItem(IntPtr hWnd, int item);
                      [DllImport("user32.dll", CharSet = CharSet.Auto)]
                      private static extern bool SetWindowText(IntPtr hWnd, string txt);
                  }
                  

                  用法:

                          using (new SetDialogButton(1, "Okay")) {
                              printDialog1.ShowDialog();
                          }
                  

                  这篇关于如何更改 win32 窗口上的文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:使用 ShowDialog 显示对话框时如何控制对话框的位置? 下一篇:Windows 窗体中是否有内置确认对话框?

                  相关文章

                    <tfoot id='njhl1'></tfoot>

                    <i id='njhl1'><tr id='njhl1'><dt id='njhl1'><q id='njhl1'><span id='njhl1'><b id='njhl1'><form id='njhl1'><ins id='njhl1'></ins><ul id='njhl1'></ul><sub id='njhl1'></sub></form><legend id='njhl1'></legend><bdo id='njhl1'><pre id='njhl1'><center id='njhl1'></center></pre></bdo></b><th id='njhl1'></th></span></q></dt></tr></i><div id='njhl1'><tfoot id='njhl1'></tfoot><dl id='njhl1'><fieldset id='njhl1'></fieldset></dl></div>
                  1. <legend id='njhl1'><style id='njhl1'><dir id='njhl1'><q id='njhl1'></q></dir></style></legend>
                        <bdo id='njhl1'></bdo><ul id='njhl1'></ul>
                    1. <small id='njhl1'></small><noframes id='njhl1'>