Application don't have lpszName when HCBT_CREATEWND

Mai Co Zo Xop 21 Reputation points
2021-01-02T14:22:26.603+00:00

Is there any other way to get title of window before it create or active?
I've tried with "SendMessageW(hWnd, WM_GETTEXT, length, (WPARAM)buffer)" and GetWindowTextW(hWnd, buffer, length) when HCBT_ACTIVATE fired. Only works with the first one, the second one is always null.
https://youtu.be/uv0wFnftWgY

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,585 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,690 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Rita Han - MSFT 2,161 Reputation points
    2021-01-04T09:30:47.153+00:00

    Hello @Mai Co Zo Xop ,

    My question is some windows and child windows don't have lpszName parameter when HCBT_CREATEWND fired and any other way to get it, not how to get window title.

    If you mean that the lpszName parameter is empty string or NULL, it is possible because the window name may be not set when creating window but set at later time after the window has been created.

    One possible solution is hooking APIs that can be used to set window name after the window created, like SetWindowText(). Detours is most commonly used to intercept Win32 APIs calls within an application.

    Thank you!


    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


  2. RLWA32 45,236 Reputation points
    2021-01-05T12:08:19.37+00:00

    Another way to obtain window text when a window is created or subsequently if text is changed is to use WinEvents.

    EVENT_OBJECT_CREATE is fired when a window is created and EVENT_OBJECT_NAMECHANGE is fired when the text is changed (windows title changed subsequent to creation).

    An example of using WinEvents is at Using accessibility to monitor windows as they come and go

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.