|
I am not calling the base classes OnPaint. My OnPaint is as follows:
void CStaticColor::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
CString staticText = m_delimitedString;
if (staticText != "") {
//Set Font
CFont font;
CFont* pOldFont;
if (font.CreateFont(14, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET,
OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, PROOF_QUALITY,
DEFAULT_PITCH & FF_DONTCARE, "Courier")) {
pOldFont = dc.SelectObject(&font);
}
CRect rect;
GetClientRect(&rect);
//Data Sizing
int newLinePos = 0;
int oldLinePos = 0;
staticTextHeight = 0;
staticTextWidth = 0;
while(newLinePos != -1) {
staticTextHeight += 13;
oldLinePos = newLinePos;
newLinePos = staticText.Find("\r\n",newLinePos + 1);
if ( ( ( newLinePos - oldLinePos ) * 8) > staticTextWidth ) {
staticTextWidth = ( ( newLinePos - oldLinePos ) * 8 );
}
}
//Vertical Scroll Code
if (staticTextHeight > rect.Height()) {
this->EnableScrollBar(SB_VERT, ESB_ENABLE_BOTH);
this->ShowScrollBar(SB_VERT);
SCROLLINFO si = {0};
si.cbSize = sizeof(si); // size of this structure
si.fMask = SIF_RANGE | SIF_PAGE; // parameters to set
si.nMin = 0; // minimum scrolling position
si.nMax = (staticTextHeight); // maximum scrolling position
si.nPage = rect.Height(); // the page size of the scroll box
//si.nPos = 0; // initial position of the scroll box
//si.nTrackPos = 0; // immediate position of a scroll box that the user is dragging
this->SetScrollInfo(SB_VERT, &si, TRUE);
}
else {
ShowScrollBar( SB_VERT, FALSE ); // Hide it
SetScrollPos( SB_VERT, 0 );
}
//Horizontal Scroll Code
if (staticTextWidth > rect.Width()) {
this->EnableScrollBar(SB_HORZ, ESB_ENABLE_BOTH);
this->ShowScrollBar(SB_HORZ);
SCROLLINFO si = {0};
si.cbSize = sizeof(si); // size of this structure
si.fMask = SIF_RANGE | SIF_PAGE; // parameters to set
si.nMin = 0; // minimum scrolling position
si.nMax = (staticTextWidth); // maximum scrolling position
si.nPage = rect.Width(); // the page size of the scroll box
//si.nPos = 0; // initial position of the scroll box
//si.nTrackPos = 0; // immediate position of a scroll box that the user is dragging
this->SetScrollInfo(SB_HORZ, &si, TRUE);
}
else {
ShowScrollBar( SB_HORZ, FALSE ); // Hide it
SetScrollPos( SB_HORZ, 0 );
}
dc.SetBkMode(TRANSPARENT);
CRect outRect(0,0,rect.Width(),rect.Height());
// Create a rect above our target rect that will not allow drawing to.
RECT excluderect;
excluderect.top = outRect.top - GetScrollPos( SB_VERT);
excluderect.bottom = outRect.top;
excluderect.left = outRect.left;
excluderect.right = outRect.right;
dc.ExcludeClipRect(&excluderect);
// Create a rect to the left of our target rect that will not allow drawing to.
RECT excluderect2;
excluderect2.top = outRect.top;
excluderect2.bottom = outRect.bottom;
excluderect2.left = outRect.left - GetScrollPos( SB_HORZ);
excluderect2.right = outRect.left;
dc.ExcludeClipRect(&excluderect2);
//Create a rect to the right of our target rect that will not allow drawing to.
RECT excluderect3;
excluderect3.top = outRect.top;
excluderect3.bottom = outRect.bottom;
excluderect3.left = outRect.right;
excluderect3.right = max(outRect.right, ( outRect.right + (staticTextWidth - outRect.Width()) - GetScrollPos( SB_HORZ) ) );
dc.ExcludeClipRect(&excluderect3);
// Draw the text accounting for any scrolling of the vertical scroll bar.
outRect.top -= GetScrollPos( SB_VERT );
leftRect = outRect.left -= GetScrollPos( SB_HORZ );
outRect.right = max((staticTextWidth +2 - GetScrollPos( SB_HORZ) ), outRect.right);
DrawText(&dc, staticText, &outRect, DT_LEFT | DT_WORDBREAK);
}
// Do not call CStatic::OnPaint() for painting messages
}
Let me know if you need to see my DrawText() or if you have any other questions. I appreciate any help on this.
|
|
|
|
|
This seems awfully complicated for just changing a control's text color. Why not handle the WM_CTLCOLORSTATIC message instead?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I beleive that that message will change the color for all the text in a particular static window. With my program I just want to make certain words within the cstatic a different color. This derived class changes the color by looking for a particular character flag within the text and changing the color until the next flag. I do not want to change the text of the entire cstatic box or this would be a much simpler problem.
Thanks for the comment though. As I said before I can copy the entire string from within the cstatic using shortcut keys but I cannot select portions of the text with the mouse to do a copy. Any ideas on this?
-Derrick
|
|
|
|
|
Derrick Becker wrote: With my program I just want to make certain words within the cstatic a different color.
A richedit control would do this much, much easier.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
As I said I am new to Visual C++ programming. How might I go about this with a richedit control? Can I insert some character sequence into the string to tell the richedit to change colors? Or would I have to derive a class from richedit to do this? And if I did derive the class are you telling me that I would not need to override the OnPaint function of the richedit since it would have functions built in to change parts of the string?
Thanks,
Derrick
|
|
|
|
|
Derrick Becker wrote: ...are you telling me that I would not need to override the OnPaint function of the richedit since it would have functions built in to change parts of the string?
Correct.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Well I think I will look into using richedit then instead of cstatic. As I said I am new to visual c++ programming and I was informed I should use and overridden class of cstatic to get colors. The rich edit may be a better option though.
If possible to just make the cstatic selectable though I would like to find that information since I have it all set up with the cstatic derived class with everything working but the text selection.
|
|
|
|
|
Derrick Becker wrote: The rich edit may be a better option though.
Definitely.
Derrick Becker wrote: If possible to just make the cstatic selectable though I would like to find that information since I have it all set up with the cstatic derived class with everything working but the text selection.
Even if you did somehow manage to get it working, you'd still be stuck swimming upstream (i.e, going against the grain) from this point forward.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Alright you've convinced me to go ahead and try to make the rich edit's work. btw I think the two different conversations at the same time is somewhat funny.
Thanks
|
|
|
|
|
I just did some more testing and I noticed that if you have the cstatic window open and do a Control+A and Control+C to copy all text it will copy and I can paste the entire window to another App but I still cannot do specific text selections. Any help would be greatly appreciated.
|
|
|
|
|
Ok. You cannot do a selection in a static control. Instead, you can prepare a CEdit derived class and make it readonly. This will look like a static control but with a capability of selection. (You might also consider CRichEditCtrl class which has a functions to format its content).
--
=====
Arman
|
|
|
|
|
I tried to derive my class from CEdit instead and it seemed to have the same exact output and issues. You said earlier "the text selected is not shown as being selected", could this be the problem? The old version of this App used a CStatic control that was read only and allowed text selection. I would like this same ability only with color, so it should not be a limitation in the CStatic since the old one with a regular CStatic could do text selection.
Thanks for all your help, let me know what else you think please.
-Derrick
|
|
|
|
|
Derrick Becker wrote: The old version of this App used a CStatic control that was read only and allowed text selection.
Are you 100% sure about this? A read-only edit control with no border/edge will look exacly like a static control. The only difference being that you can select text from the edit control whereas you cannot from the static control.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Yes in the header file they were declared as CStatic and text could be highlighted. I think maybe the person that created the first one may have used an Edit box through the resource editor and then manually changed it to a CStatic if that makes a difference because if you go to the properties of the dialog through the resource editor it says "Edit Properties" at the top.
|
|
|
|
|
The way to find out definitely is to use Spy++ on the control itself. Just run the application, open the dialog that contains the control in question, run Spy++ and drag the finder tool over the control. Note the type of control and its styles.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
|
It's part of Visual Studio.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Found it, i'll check it out. Thanks
|
|
|
|
|
here,I want to create a roundRectange dialog,I think there are two chioces:
First,owner draw,using the function SetWindowRgn().But I could not set the text of the title when it is minimized to the desktop's bottom.
Second,process none-client area of the dialog.But I could not make the bottom of the dialog to round-conor.
How should I resolve this?
Thanks.
BEST REGARDS
|
|
|
|
|
|
Thanks.The article is good.
But the problem is that,when it runs,there is no text tip in the desktop's status bar.(I mean the bottom of the desktop);
|
|
|
|
|
in another word,we could not set the WS_CAPTION style.
So,the dialog would show appear with no title ,even it is minimized!
|
|
|
|
|
How do I disable Remote debugging setting I had done for a project? Now what is happening is for whichever new project I try to debug the application asks for the path of the remote application.
|
|
|
|
|
in VS 2005
under project -> property pages
(tab) Configuration Properties -> debugging, (drop down) Debugger to lauch -> select Local Windows Debugger
under VS6... something simliar i guess, cant remember though
|
|
|
|
|
Why does a list offer a faster search as compared to a vector while offers a slower lookup. Is the explanation to be given in terms of algorithms?
|
|
|
|