0

I'm trying to modify an existing dialog based program written in C++ under Visual Studio.

The title bar on the dialog is showing centered text. I need that to be left justified. But I cannot figure out why it is centered in the first place. I've written another sample program and the title text is left justified by default. An option in the properties for the dialog is to Right Alight Text. That works in my sample program, but changing it in the existing program shows no effect.

It seems like someone must have gone to some effort to center the text, but I don't see anything in the code, and if fact, the centering (or right justifying in my sample/test program) shows up in the dialog editor. So it must be in the properties there. But where!?!?!

This is one of those things that just has to be easy and I'm not seeing it!

So how do I left justify that title text? I'd even be happy to do it in code, since I'm already modifying the title to add a program version number in there. BTW, when I add to the title, or swap in a new title, that text ends up centered.

El Ronaldo
  • 383
  • 1
  • 3
  • 11
  • Can this reference help? https://stackoverflow.com/questions/13159545/justify-text-with-setw – CraftedGaming Oct 31 '17 at 01:12
  • It looks like you may want to be looking for code that handles the [`WM_NCPAINT` message](https://msdn.microsoft.com/en-us/library/vs/alm/dd145212(v=vs.85).aspx). Here's an (albeit relatively older) article where they have customized a dialog title bar: [Custom Titlebar](https://www.catch22.net/tuts/custom-titlebar). – Phil Brubaker Oct 31 '17 at 01:53
  • @CraftedGaming, setw does not seem to apply in this case. – El Ronaldo Oct 31 '17 at 19:17
  • @PhilBrubaker, yeah, that's probably the "right" approach but more effort than warranted. Thanks though! – El Ronaldo Oct 31 '17 at 19:18
  • @ElRonaldo You're welcome, glad you found an acceptable workaround anyway. – Phil Brubaker Nov 01 '17 at 02:00

2 Answers2

2

The trick to make the text center is by overriding the WM_NCPAINT event as given in this link

If you don't want to make the text center, remove the override and it should work.

0

So this isn't really an answer, but my "problem" was that I was comparing programs running on Win10 and Win8. It turns out the default for Win10 must be to left justify titles while the default for Win8 is to Center.

Programmatically I'm tacking on a version number to a title, and the centering process in Win8 apparently is not dynamic, so the result is skewed to the right. My solution is to simply add the number of chars in the version number to the original title, and when I tack the version number on, I'll trim off those spaces.

WM_NCPAINT is probably the "right" answer, but perhaps too expensive in terms of time.

El Ronaldo
  • 383
  • 1
  • 3
  • 11