Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. center text in title bar of app.

center text in title bar of app.

Scheduled Pinned Locked Moved C / C++ / MFC
c++helpquestion
8 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    JensB
    wrote on last edited by
    #1

    Hi I want to center the title text of my application (mfc) in the title bar. Now it is positioned left. Anyone can help? Greetings Jens

    D R J H 4 Replies Last reply
    0
    • J JensB

      Hi I want to center the title text of my application (mfc) in the title bar. Now it is positioned left. Anyone can help? Greetings Jens

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      Good question. I suspect it's somewhat difficult, if it's even possible. You might end up creating a caption-less dialog (i.e., a dialog without the WS_CAPTION style), and then drawing your own caption in the client area of the dialog.

      J 1 Reply Last reply
      0
      • D David Crow

        Good question. I suspect it's somewhat difficult, if it's even possible. You might end up creating a caption-less dialog (i.e., a dialog without the WS_CAPTION style), and then drawing your own caption in the client area of the dialog.

        J Offline
        J Offline
        JensB
        wrote on last edited by
        #3

        Good question.... Thank you for the appreciation ;) I'll see if i can fix the problem. If i have working code, i'll send it to you or post it somewhere on forum here. Best regards Jens

        1 Reply Last reply
        0
        • J JensB

          Hi I want to center the title text of my application (mfc) in the title bar. Now it is positioned left. Anyone can help? Greetings Jens

          R Offline
          R Offline
          Renjith Ramachandran
          wrote on last edited by
          #4

          i hav some idea.. title bar length = widhth of ur dialog/window u alos get the indent/width of the text then find the half of width find the haif of string place the string from halfof titlebar - half of text you can add the spaces in fornt of the string to place the text in the appropriate position. hope u got it.. CodeTheDreams();

          L 1 Reply Last reply
          0
          • J JensB

            Hi I want to center the title text of my application (mfc) in the title bar. Now it is positioned left. Anyone can help? Greetings Jens

            J Offline
            J Offline
            Joan M
            wrote on last edited by
            #5

            I have not done it... never... but...

            **1.**filling the beggining of the string with spaces is not good if you change the font... because spaces size and font size changes also.

            **2.**Deleting the caption and placing a label centered... is also a not standard thing that will make your app. to seem strange...

            **3.**I'm sure that I've seen here in CP some pieces of code that show how to paint over the Caption bar (the typical thing of adding additional buttons and so on...).

            I think that the best approach would be to leave the caption text blank and painting the desired text calculating the width of the text that will be displayed in pixels and... Take a look at the articles that show how to draw in the caption bar... then you can search for how to find the width of a outputted text via GDI calls. then it's only a matter of time, dividing in order to get the coordinate where to start painting and so on... Well, I have not done this and this is only theory, but it sounds good to me... PS: my english is not my best... Hope this helps...

            https://www.robotecnik.com freelance robots, PLC and CNC programmer.

            1 Reply Last reply
            0
            • J JensB

              Hi I want to center the title text of my application (mfc) in the title bar. Now it is positioned left. Anyone can help? Greetings Jens

              H Offline
              H Offline
              Hari Krishnan Noida
              wrote on last edited by
              #6

              Hi, there was a working code on the net called "shadcap", originally written by "Paul DiLascia", Q&A author of MSJ Magaizine. Please search it on the net. Actually, I downloaded the code, just few days back. I couldnt find the link now. Please search it on the net. Otherwise, I can send u the code.

              H 1 Reply Last reply
              0
              • R Renjith Ramachandran

                i hav some idea.. title bar length = widhth of ur dialog/window u alos get the indent/width of the text then find the half of width find the haif of string place the string from halfof titlebar - half of text you can add the spaces in fornt of the string to place the text in the appropriate position. hope u got it.. CodeTheDreams();

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                This is the way I would do it as well.

                1 Reply Last reply
                0
                • H Hari Krishnan Noida

                  Hi, there was a working code on the net called "shadcap", originally written by "Paul DiLascia", Q&A author of MSJ Magaizine. Please search it on the net. Actually, I downloaded the code, just few days back. I couldnt find the link now. Please search it on the net. Otherwise, I can send u the code.

                  H Offline
                  H Offline
                  Hari Krishnan Noida
                  wrote on last edited by
                  #8

                  Hi, As, other members were suggested, its bit of complex coding. If you really want to do it, here is the link, and download "C++0697.exe" http://www.microsoft.com/msj/0697/c0697.aspx regards ~Hari~

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups