Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make the text length of the title of a WPF Window greater 255 characters?

Tags:

c#

windows

wpf

xaml

Created WPF application in VS2015. Set the Window's title to a string of length 290.

Title = "123456789 223456789 323456789 423456789 523456789 623456789 723456789 823456789 923456789 133456789 233456789 333456789 433456789 533456789 633456789 733456789 833456789 933456789 143456789 243456789 343456789 443456789 543456789 643456789 743456789 843456789 943456789 153456789 253456789 ";

When the application is run, the title is truncated to 255 characters (maximised window and window extended across 2 screens).

Stretched Window

  1. How to increase the number of displayed characters?
  2. What is the maximum allowed length for a WPF Window title?

I tried

  • How to set WPF Window's width equal to the content in its Title Bar?
  • Setting title bar text in code and in XAML.
like image 298
robor Avatar asked Nov 11 '16 12:11

robor


1 Answers

It seems that 255 chars is an internal limitation in the DefWindowProc() native window function.

WPF changes the windows's title using a call to a native method:

UnsafeNativeMethods.SetWindowText(new HandleRef(this, CriticalHandle), title);

This method accepts strings of any length, so that should actually work. This is not a WPF problem.

But...

Even if you create a standard and native Win32 window that uses the DefWindowProc() function, you will observe the same behavior - maximum 255 characters in the window title.

Windows paints the title bar in response to a WM_NCPAINT message (along with the window frames, the system button, and so on). Inside the DefWindowProc() code that handles WM_NCPAINT messages, the code calls GetWindowText() to get the window's title string. In this call to GetWindowText(), the size of the buffer seems to be 255 chars (in old Windows, the buffer was only 79 bytes). This limits the length of a window's title to 255 characters.

like image 168
dymanoid Avatar answered Sep 20 '22 00:09

dymanoid