Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8699559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:58:43+00:00 2026-06-13T01:58:43+00:00

I have a window with two text fields inside it. How can I get

  • 0

I have a window with two text fields inside it.

How can I get the handles of both text fields using WinAPI calls?

Note: Both text boxes belong to a different application (I make the WinAPI calls in application A and the text boxes are located in application B).

Update 1:

I get Invalid window handle message when invoking GetClassName.

I suppose that something is wrong with my declaration of the callback function.

EnumChildWindows is invoked from one of the methods of TMyClass like this:

EnumChildWindows(handle, @TMyClass.CBList, 0);

Here’s the code of the callback function.

function TMyClass.CBList(Win: THandle; lp: LPARAM): Boolean; stdcall;
var
  ClassName:array [1..1024] of Char;
begin
  GetClassName(Win, PChar(@ClassName), 1024);
  OutputDebugString(PChar('SysErrorMessage(GetLastError): '));

  result := true;
end;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T01:58:44+00:00Added an answer on June 13, 2026 at 1:58 am
    1. Use FindWindow or EnumWindows to find the top level window of the target application.
    2. Call EnumChildWindows to enumerate all children of the top level window.
    3. In the enumeration callback use GetClassName to check for the desired window class. It would be EDIT for a raw Win32 edit window, for example.

    Use a tool like Spy++ to understand the structure of the target app, and find out the precise window class names that it uses.


    Your questions in the comments about how to call GetClassName got me thinking. If you are using XE3, you could write a simple type record helper for HWND to make it syntactically cleaner to get hold of the class name:

    type
      THWNDHelper = record helper for HWND
      private
        function GetClassName: string;
      public
        property ClassName: string read GetClassName;
      end;
    
    function THWNDHelper.GetClassName: string;
    var
      Buffer: array [0..255] of Char;
    begin
      if Winapi.Windows.GetClassName(Self, @Buffer, Length(Buffer))=0 then
        RaiseLastOSError;
      Result := Buffer;
    end;
    

    And then you can write hwnd.ClassName to obtain the window class name. Of course, if you are not using XE3 you can do it like this:

    function GetWindowClassName(hwnd: HWND): string;
    var
      Buffer: array [0..255] of Char;
    begin
      if GetClassName(hwnd, @Buffer, Length(Buffer))=0 then
        RaiseLastOSError;
      Result := Buffer;
    end;
    

    Note that I am using a buffer length of 256 since window class name lengths are limited to be no longer than that.


    Regarding the code in the update, you must not use an instance method for the callback. The callback must be declared like this:

    function EnumChildWindowsCallback(hwnd: HWND; lParam: LPARAM): BOOL; stdcall;
    begin
      OutputDebugString(PChar(GetWindowClassName(hwnd)));
      Result := True;
    end;
    

    This is made clear in the documentation. Unfortunately the declaration of EnumChildWindows in Windows.pas completely abandons type safety of the callback function. So you have to get it right without help from the compiler.

    Note also that HWND and THandle are not the same thing. Don’t mix them up.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two text boxes on the same window. They are both set to
I have two text input fields: Name:<input id=name type=text value= name=username> Age:<input id=age type=text
I have a simple ExtJS 4 (xtype form) inside a window. It has two
I have a window with two columns of fields. On the left, there is
I have a layout where i have two text fields one is for alphabetic
I have two window form applications written in C, one holds a struct consisting
I have the following code which creates a simple window with two buttons which
I have a winforms app that initially displays a window with two file dialog
I have the following extJs window which has two tabs in it. One of
I have two images on a WPF window that are on top of each

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.