# Reading window title from external app

**URL:** <https://community.mp3tag.de/t/reading-window-title-from-external-app/51880>\
**Category:** Development\
**Created:** [February 6, 2021, 5:09pm UTC](https://community.mp3tag.de/t/reading-window-title-from-external-app/51880 "2021-02-06T17:09:50Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Wannastayunercover](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/w/977dab/32.png) [@Wannastayunercover](https://community.mp3tag.de/u/Wannastayunercover)\
**Post date:** [February 6, 2021, 5:09pm UTC](https://community.mp3tag.de/t/reading-window-title-from-external-app/51880/1 "2021-02-06T17:09:50Z")

</div>

Hello guys, Can you tell me which function you are using to create your Gui, cause I never manage to catch the full main windows title. I am developping an automatic tagger program in early stage at the moment it works in a standalone mode for now but I need to catch the full filename of the actual selected file. There is no hotkey assigned for file properties and I don't want to force users to add an extra tag containing the filemane ( which would be a pain in the b...on the user side).

In summary your window title gets truncated when calling GetWindowTextW with a returned string set to 1024 bytes ( or 2048 if unicode).

Thank you.

---

<div class="post-metadata">

**Author:** ![Florian](https://community.mp3tag.de/user_avatar/community.mp3tag.de/florian/32/5759_2.png) [@Florian](https://community.mp3tag.de/u/Florian)\
**Post date:** [February 6, 2021, 5:48pm UTC](https://community.mp3tag.de/t/reading-window-title-from-external-app/51880/2 "2021-02-06T17:48:59Z")

</div>

I'm just using `SetWindowText`, nothing special.

---

<div class="post-metadata">

**Author:** ![MP3Freak\_Peter](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/m/c68b51/32.png) [@MP3Freak\_Peter](https://community.mp3tag.de/u/MP3Freak_Peter)\
**Post date:** [February 6, 2021, 8:48pm UTC](https://community.mp3tag.de/t/reading-window-title-from-external-app/51880/3 "2021-02-06T20:48:23Z")

</div>

> [@](#):
>
> In summary your window title gets truncated when calling GetWindowTextW with a returned string set to 1024 bytes ( or 2048 if unicode).

You call getwindowtextlength frist?  
You set up your recieve Buffer correctly? (remember, doublebyte per char on unicode)  
You read hint's at msdn?

> **[GetWindowTextLengthW function (winuser.h) - Win32 apps](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getwindowtextlengthw)**
>
> Retrieves the length, in characters, of the specified window's title bar text (if the window has a title bar). (Unicode)

> **[GetWindowTextW function (winuser.h) - Win32 apps](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getwindowtextw)**
>
> Copies the text of the specified window's title bar (if it has one) into a buffer. If the specified window is a control, the text of the control is copied. However, GetWindowText cannot retrieve the text of a control in another application. (Unicode)

> [@](#):
>
> I'm just using `SetWindowText`, nothing special.

Get/SetWindowText/Length in all current unicode languages call W functions.

---

<div class="post-metadata">

**Author:** ![Wannastayunercover](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/w/977dab/32.png) [@Wannastayunercover](https://community.mp3tag.de/u/Wannastayunercover)\
**Post date:** [February 6, 2021, 10:58pm UTC](https://community.mp3tag.de/t/reading-window-title-from-external-app/51880/4 "2021-02-06T22:58:46Z")

</div>

> [@Wannastayunercover](#):
>
> GetWindowText

GetWindowText will return the same trunctated length. the exact same length with getwindowtextlength, and of course I've set the Lptrstring capacity to 1024 combined to IsWindowUnicode().

and of course I did read the manual and always did it since I first starting coding on z80 aged of 8 then 68k and so on. When You had coded on a commodore Amiga, you know those things.

Just to be sure are you creating the window using this ? :

```auto
if(IsWindowUnicode(hWnd))  
  return DefWindowProcW(hWnd, uMsg, wParam, lParam);  
else  
  return DefWindowProcA(hWnd, uMsg, wParam, lParam);

depending on this answer, this would be my last attempt,
 I am using my own tag reading function and audiogenie.dll as well . Not only targetting win32 code so mp3tag is not essential for my project.

thanks
```

---

<div class="post-metadata">

**Author:** ![MP3Freak\_Peter](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/m/c68b51/32.png) [@MP3Freak\_Peter](https://community.mp3tag.de/u/MP3Freak_Peter)\
**Post date:** [February 7, 2021, 11:25am UTC](https://community.mp3tag.de/t/reading-window-title-from-external-app/51880/5 "2021-02-07T11:25:17Z")

</div>

> [@Wannastayunercover](#):
>
> and of course I did read the manual and always

well, comodore and amiga don't know about multibyte strings - same as my early DOS versions running on my old 80286 😉  
Didn't like to diss you 😉

Just to find out what's going wrong:

Did you try to read windowtext inside an simple byte/char buffer array to verify if you really don't receive full text or may be a problem of your buffer datatype.  
Check if received string is null byte terminated.

Try something like that (tested with winamp, working fine)  
set up an buffer  
array[0.. length \* sizeof(char) + 1] of byte  
or  
array[0.. length + 1] of char

Receive WindowText to @buf[0]  
Copy (Decode) from buffer to string using an Encoding class
