Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

dialog caption

Posted on 2006-03-27
4
Medium Priority
?
804 Views
Last Modified: 2013-11-20
Hi,

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.

Thanks
pbsmbc
0
Comment
Question by:pbsmbc
  • 2
2 Comments
 
LVL 7

Expert Comment

by:minnirok
ID: 16305615
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.top, 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
     rcNewRect.top = rcRect.top + (rcRect.Height() - rcSavedRect.Height()) / 2;
     rcNewRect.bottom = rcRect.top + 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);

     DeleteObject(rgn);
}

http://www.experts-exchange.com/Programming/Programming_Languages/MFC/Q_21375994.html?query=center+caption&clearTAFilter=true
0
 
LVL 7

Accepted Solution

by:
minnirok earned 500 total points
ID: 16305640
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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 can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…
Suggested Courses

571 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