dialog caption

Posted on 2006-03-27
Last Modified: 2013-11-20

How do I make a dialog caption in the center of the dialog?
The problem we are having if we manually center the caption of the dialog it works in windows XP however, in NT it's
moving to the right.

Question by:pbsmbc
    LVL 7

    Expert Comment

    How are you manually drawing it at the moment? And what do you mean by it doesn't work under NT, it's not really centered, won't draw at all, etc?

    Here's a draw text function for drawing centered text within a rect:

    void DrawText(CDC* pdc, const CString& strText, CRect& rcRect)
         CRect rcSavedRect = rcRect;
         CRect rcNewRect = rcRect;
         CRgn rgn;

         rgn.CreateRectRgn(rcRect.left,, rcRect.right, rcRect.bottom);

         // Call DrawText with DT_WORDBREAK | DT_CALCRECT flags, this will adjust the rectagle size
         // after breaking it into lines but without drawing

         pdc->DrawText(strText, &rcSavedRect,  DT_WORDBREAK | DT_CALCRECT | DT_CENTER | DT_VCENTER);

         // Modify the caption rectagle according to the new coordinates = + (rcRect.Height() - rcSavedRect.Height()) / 2;
         rcNewRect.bottom = + rcSavedRect.Height();
         HRGN hrgnOld = NULL;
         ::GetClipRgn(pdc->m_hDC, hrgnOld);

         pdc->SelectClipRgn(&rgn, RGN_COPY);

         // Draw the caption
         pdc->DrawText(strText, &rcNewRect, DT_WORDBREAK | DT_CENTER | DT_VCENTER);

         ::SelectClipRgn(pdc->m_hDC, hrgnOld);

    LVL 7

    Accepted Solution


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Suggested Solutions

    Title # Comments Views Activity
    Whole sheet autoscrub still needed 19 41
    substring method in java 1 59
    format the code in java 6 60
    sum28 challenge 31 82
    Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
    Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
    This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
    how to add IIS SMTP to handle application/Scanner relays into office 365.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now