Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. GetWindowText API?

GetWindowText API?

Scheduled Pinned Locked Moved C#
csharpdotnetadobejsonquestion
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    wbjohnson
    wrote on last edited by
    #1

    ooooook guys heres a little tinker for ya! im trying to read some fields from Flash FXP (in c#) using the Windows User32 API... GetWindowText is what il be using... so i use Microsoft Spy++ to get the Handle for one of the input boxes, lets say for arguments sake its 4134644.. (thats the handle to the text box...) Spy++ reports this as an EDIT class, good so far! so i use GetWindowText to try get the text from the text box.... empty string?? mmmmm so im stratching my head... i know ill test my code and use: static extern int GetWindowTextLength(IntPtr hWnd) this has got to work! i should get a length back now!! NOPE! nothing is coming back from ANY EDIT class field HOWEVER if i use GetWindowText on anything else, Labels, Window Titles it works!! What am i doing wrong here? Am i using the wrong API call to get data from an Edit Field? its driving me mad!!! lol

    D 1 Reply Last reply
    0
    • W wbjohnson

      ooooook guys heres a little tinker for ya! im trying to read some fields from Flash FXP (in c#) using the Windows User32 API... GetWindowText is what il be using... so i use Microsoft Spy++ to get the Handle for one of the input boxes, lets say for arguments sake its 4134644.. (thats the handle to the text box...) Spy++ reports this as an EDIT class, good so far! so i use GetWindowText to try get the text from the text box.... empty string?? mmmmm so im stratching my head... i know ill test my code and use: static extern int GetWindowTextLength(IntPtr hWnd) this has got to work! i should get a length back now!! NOPE! nothing is coming back from ANY EDIT class field HOWEVER if i use GetWindowText on anything else, Labels, Window Titles it works!! What am i doing wrong here? Am i using the wrong API call to get data from an Edit Field? its driving me mad!!! lol

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      wbjohnson wrote:

      this has got to work!

      No, it doesn't! Just because the control derives from EDIT does NOT mean that you can use this, or any other method you want for getting the text out of the control. It will only work if the control responds to WM_GETTEXT, which not every EDIT control does.

      Dave Kreskowiak Microsoft MVP - Visual Basic

      W 1 Reply Last reply
      0
      • D Dave Kreskowiak

        wbjohnson wrote:

        this has got to work!

        No, it doesn't! Just because the control derives from EDIT does NOT mean that you can use this, or any other method you want for getting the text out of the control. It will only work if the control responds to WM_GETTEXT, which not every EDIT control does.

        Dave Kreskowiak Microsoft MVP - Visual Basic

        W Offline
        W Offline
        wbjohnson
        wrote on last edited by
        #3

        ah hah!! that explains alot! thanks! can i send the WM_GETTEXT command and then read the message buffer? assuming the control supports this command? Cheers dude!:-D

        D 1 Reply Last reply
        0
        • W wbjohnson

          ah hah!! that explains alot! thanks! can i send the WM_GETTEXT command and then read the message buffer? assuming the control supports this command? Cheers dude!:-D

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          Yes. You might want to try these[^]. You might also want to look at the limitations of GetWindowText[^].

          Dave Kreskowiak Microsoft MVP - Visual Basic

          W 1 Reply Last reply
          0
          • D Dave Kreskowiak

            Yes. You might want to try these[^]. You might also want to look at the limitations of GetWindowText[^].

            Dave Kreskowiak Microsoft MVP - Visual Basic

            W Offline
            W Offline
            wbjohnson
            wrote on last edited by
            #5

            [DllImport("user32.dll")] public static extern int SendMessage(IntPtr hWnd, IntPtr Msg, IntPtr wParam, [MarshalAs(UnmanagedType.LPArray)] byte[] lParam); int __titleLength = SendMessage(hWnd, WM_GETTEXTLENGTH, IntPtr.Zero, null); byte[] __data = new byte[__titleLength]; SendMessage(hWnd, WM_GETTEXT, new IntPtr(__data.Length), __data); foreach (byte __b in __data) Console.Write((char)__b); this loks like its working!!!

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups