Click here to Skip to main content
15,902,492 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Array of Buttons Pin
picander7711-Jan-05 3:49
picander7711-Jan-05 3:49 
GeneralRe: Array of Buttons Pin
Maximilien11-Jan-05 2:38
Maximilien11-Jan-05 2:38 
GeneralRe: Array of Buttons Pin
picander7711-Jan-05 4:09
picander7711-Jan-05 4:09 
GeneralRe: Array of Buttons SOLUTION Pin
picander7711-Jan-05 4:10
picander7711-Jan-05 4:10 
Generalrtf help Pin
Mohammad Daba'an10-Jan-05 22:22
Mohammad Daba'an10-Jan-05 22:22 
Generalread data from line in Pin
gecool10-Jan-05 22:21
gecool10-Jan-05 22:21 
GeneralRe: read data from line in Pin
KaЯl10-Jan-05 23:20
KaЯl10-Jan-05 23:20 
Generalincrease the max length of SETWINDOWTEXT Pin
Member 147966910-Jan-05 21:43
Member 147966910-Jan-05 21:43 
hello,

I have a problem. the call SETWINDOWTEXT truncates the length of the displayed text to 259 characters (dialog based, ansi mode) (somebody else reported 159), i don't see any dots, also a lot of space is left on the bar. A getwindowtext will return the full original string.

I try to set a titlebar of my dialog with 3 strings which are left, center and right justified. I do this by inserting a lot of spaces between the strings

Things i can do, but don't wan't to:
- Change the active title bar font.
- Draw my own titlebar.

The following code will work on a 800x600 mode maximized dialog, but not on a 1600x1200.

<code>
void SetWindowText3(CWnd* TargetWnd, CString LeftText, CString MidText, CString RightText)
{
CRect Rect;
int CaptionWidth;
CFont font;
CDC dc;
NONCLIENTMETRICS ncm;
int LeftWidth;
int MidWidth;
int RightWidth;
int SpaceWidth;
int FillWidth;
int FillLeftWidth;
int FillRightWidth;
int PosCenter;
CString CaptionText;

/****************************************************************************
Figure out the maximum width of the caption text
****************************************************************************/
TargetWnd->GetWindowRect(Rect);
CaptionWidth = Rect.Width(); // get width of whole window
CaptionWidth -= 2*GetSystemMetrics(SM_CXBORDER); // Remove left and right the border width
CaptionWidth -= 2*GetSystemMetrics(SM_CXFRAME); // Remove left and right the frame width
if (TargetWnd->GetStyle() & WS_SYSMENU)
CaptionWidth -= 2*GetSystemMetrics(SM_CXSIZE); // Remove the icon and close button
else
CaptionWidth -= 5; // Remove extra edge if no close button
PosCenter = CaptionWidth/2;
if ( (TargetWnd->GetStyle() & WS_MAXIMIZEBOX)
|| (TargetWnd->GetStyle() & WS_MINIMIZEBOX) )
CaptionWidth -= (2*GetSystemMetrics(SM_CXSIZE)) - 1; // Remove the width of the minimizebutton

/****************************************************************************
Prepare the GetTextExtent function.
****************************************************************************/
ncm.cbSize = sizeof(NONCLIENTMETRICS); // i don't why this is used.
SystemParametersInfo(SPI_GETNONCLIENTMETRICS,
sizeof(NONCLIENTMETRICS), &ncm, 0); // get the pointer to the nonclientmetrics struct
font.CreateFontIndirect(&ncm.lfCaptionFont); // Create a copy of the font used title bar
dc.CreateCompatibleDC(NULL); // Create an DC
CFont* pOldFont = (CFont*)dc.SelectObject(&font); // Make sure that gettextextent uses the correct font.
dc.SetMapMode(MM_TEXT); // Make sure that gettextextent returns PIXELS.

/****************************************************************************
Get various width in pixels of the thext
****************************************************************************/
LeftWidth = dc.GetTextExtent(LeftText).cx; // Get the text width of the left text.
MidWidth = dc.GetTextExtent(MidText).cx; // Get the text width of the mid text.
RightWidth = dc.GetTextExtent(RightText).cx; // Get the text width of the right text.
SpaceWidth = dc.GetTextExtent(_T(" ")).cx; // How many pixels does a space take
FillWidth = (CaptionWidth - LeftWidth -
MidWidth - RightWidth)/SpaceWidth; // How much space is left on the title bar?

/****************************************************************************
Bug Work around. Make sure text is never longer as 259 characters
****************************************************************************/
// if ((LeftText.GetLength()+MidText.GetLength()+RightText.GetLength()+FillWidth)>259)
// FillWidth = 259 - (LeftText.GetLength()+MidText.GetLength()+RightText.GetLength());

/****************************************************************************
Fill in the spaces between the text and write the text to the title bar
****************************************************************************/

FillLeftWidth = (PosCenter-LeftWidth-(MidWidth/2))/SpaceWidth; // Space (in characters) between left and middle
//FillLeftWidth = FillWidth/2; // Same as above, but midtext in middle of empty area
FillRightWidth = FillWidth - FillLeftWidth; // space (in characters) between middle and right

CaptionText = LeftText;

for (int loopy=0;loopy<FillLeftWidth;loopy++) // How many space are needed between left and middle?
CaptionText += _T(" "); // Add a space to the caption text

CaptionText += MidText; // Add the middle text to the caption text

for (int loopy=0;loopy<FillRightWidth;loopy++) // How many space are needed between middle and right?
CaptionText += _T(" "); // Add a space to the caption text

CaptionText += RightText; // Add the right text tot the caption text
TargetWnd->SetWindowText(CaptionText); // now actually set the windows text


/****************************************************************************
Delete temperary objects
****************************************************************************/
dc.SelectObject(pOldFont);
font.DeleteObject(); // Delete the font.
dc.DeleteDC(); // Delete the DC
}
</code>

GeneralRe: increase the max length of SETWINDOWTEXT Pin
Roger Allen10-Jan-05 23:19
Roger Allen10-Jan-05 23:19 
GeneralCRectTracker and scrolling problems Pin
Maverick10-Jan-05 21:38
Maverick10-Jan-05 21:38 
GeneralFIFO thread synchronizing Pin
Menny Even Danan10-Jan-05 20:53
Menny Even Danan10-Jan-05 20:53 
GeneralRe: FIFO thread synchronizing Pin
Blake Miller11-Jan-05 4:03
Blake Miller11-Jan-05 4:03 
GeneralRe: FIFO thread synchronizing Pin
Menny Even Danan11-Jan-05 21:39
Menny Even Danan11-Jan-05 21:39 
GeneralRe: FIFO thread synchronizing Pin
Blake Miller12-Jan-05 5:00
Blake Miller12-Jan-05 5:00 
GeneralRe: FIFO thread synchronizing Pin
Menny Even Danan12-Jan-05 0:52
Menny Even Danan12-Jan-05 0:52 
GeneralFile Directory Table Pin
LiYS10-Jan-05 20:20
LiYS10-Jan-05 20:20 
GeneralRe: File Directory Table Pin
David Crow11-Jan-05 6:42
David Crow11-Jan-05 6:42 
GeneralRe: File Directory Table Pin
LiYS11-Jan-05 13:37
LiYS11-Jan-05 13:37 
GeneralRe: File Directory Table Pin
David Crow12-Jan-05 1:55
David Crow12-Jan-05 1:55 
GeneralCreating Property Sheet Run Time. Pin
Anonymous10-Jan-05 20:05
Anonymous10-Jan-05 20:05 
Generalsoftware package Pin
vc-programmer-10-Jan-05 19:31
vc-programmer-10-Jan-05 19:31 
GeneralRe: software package Pin
ThatsAlok11-Jan-05 0:34
ThatsAlok11-Jan-05 0:34 
GeneralConverting UNICODE to Str Pin
dSolariuM10-Jan-05 18:44
dSolariuM10-Jan-05 18:44 
QuestionI need to do some clean-up on exit, how do I break in? Pin
fklldsvs10-Jan-05 18:22
fklldsvs10-Jan-05 18:22 
AnswerRe: I need to do some clean-up on exit, how do I break in? Pin
Cedric Moonen10-Jan-05 19:50
Cedric Moonen10-Jan-05 19:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.