Detect when text is out of CStatic

How can I know when I am supposed to displauy a vertical scrollbar to my 
CStatic ?
I know how to do it for horizontal but not for vertical...


::GetTextExtentPoint32(pDCMem->GetSafeHdc(), s2, s2.GetLength(), &sz);
IF (sz.cx > pRect->Width())
{
	DO SOMETHING
}
In the vertical case do I need to count the number of lines displayed 
and to do somthing like


int nLines = some value; // Number of lines of text in my CStatic
for (int i =0, i < nLines; i++)
{
::GetTextExtentPoint32(pDCMem->GetSafeHdc(), s2, s2.GetLength(), &sz);
m_sz += sz;
}

m_sz.cy > pRect->Width()


But I am not sure because does it take in account space between lines ?
0
richom.v (84)
4/12/2006 10:11:38 PM
vc.mfc 33608 articles. 0 followers. Follow

10 Replies
713 Views

Similar Articles

[PageSpeed] 10

Wouldnt you be better off usng a Listbox instead which provides the
scrolling for free?

---
Ajay

0
ajaykalra (6842)
4/13/2006 3:42:30 AM
Ajay Kalra wrote:
> Wouldnt you be better off usng a Listbox instead which provides the
> scrolling for free?
> 
> ---
> Ajay
> 
the goal is to learn how to manage scrolling, I don't want the easy way.
0
richom.v (84)
4/13/2006 5:31:16 AM
>>> But I am not sure because does it take in account space between lines ?

Yes, it does.


"Vincent RICHOMME" <richom.v@free.fr> wrote in message news:443d7ac5$0$18991$626a54ce@news.free.fr...
> How can I know when I am supposed to displauy a vertical scrollbar to my CStatic ?
> I know how to do it for horizontal but not for vertical...
>
>
> ::GetTextExtentPoint32(pDCMem->GetSafeHdc(), s2, s2.GetLength(), &sz);
> IF (sz.cx > pRect->Width())
> {
> DO SOMETHING
> }
> In the vertical case do I need to count the number of lines displayed and to do somthing like
>
>
> int nLines = some value; // Number of lines of text in my CStatic
> for (int i =0, i < nLines; i++)
> {
> ::GetTextExtentPoint32(pDCMem->GetSafeHdc(), s2, s2.GetLength(), &sz);
> m_sz += sz;
> }
>
> m_sz.cy > pRect->Width()
>
>
> But I am not sure because does it take in account space between lines ? 


0
voidcoder (31)
4/13/2006 10:25:02 AM
> I don't want the easy way.

Why not start with a CWnd instead of CStatic?

Yet  another option would be to use Assembly language instead of C++
;-)

---
Ajay

0
ajaykalra (6842)
4/13/2006 10:52:38 AM
Hi Vincent,

I think the way to do this would be to keep track of how many lines of code 
you have in the control and the height and width of the characters using the 
GetTextExtent() routine in CDC and just turn the scrollbar on and off as 
needed (I.E., if the text all fits in the window without being truncated 
then you are OK, otherwise you may need to scroll.  You would also have to 
manage the scrolling by redrawing the window starting with the correct line 
of text.  IOW, you have to manage what is drawn in the window.

Tom

"Vincent RICHOMME" <richom.v@free.fr> wrote in message 
news:443d7ac5$0$18991$626a54ce@news.free.fr...
> How can I know when I am supposed to displauy a vertical scrollbar to my 
> CStatic ?
> I know how to do it for horizontal but not for vertical...
>
>
> ::GetTextExtentPoint32(pDCMem->GetSafeHdc(), s2, s2.GetLength(), &sz);
> IF (sz.cx > pRect->Width())
> {
> DO SOMETHING
> }
> In the vertical case do I need to count the number of lines displayed and 
> to do somthing like
>
>
> int nLines = some value; // Number of lines of text in my CStatic
> for (int i =0, i < nLines; i++)
> {
> ::GetTextExtentPoint32(pDCMem->GetSafeHdc(), s2, s2.GetLength(), &sz);
> m_sz += sz;
> }
>
> m_sz.cy > pRect->Width()
>
>
> But I am not sure because does it take in account space between lines ? 


0
tserface (3861)
4/13/2006 1:51:25 PM
Why not use a read-only multiline edit control?  This is usually simpler and doesn't
involve any additional complexity.
				joe

On Thu, 13 Apr 2006 00:11:38 +0200, Vincent RICHOMME <richom.v@free.fr> wrote:

>How can I know when I am supposed to displauy a vertical scrollbar to my 
>CStatic ?
>I know how to do it for horizontal but not for vertical...
>
>
>::GetTextExtentPoint32(pDCMem->GetSafeHdc(), s2, s2.GetLength(), &sz);
>IF (sz.cx > pRect->Width())
>{
>	DO SOMETHING
>}
>In the vertical case do I need to count the number of lines displayed 
>and to do somthing like
>
>
>int nLines = some value; // Number of lines of text in my CStatic
>for (int i =0, i < nLines; i++)
>{
>::GetTextExtentPoint32(pDCMem->GetSafeHdc(), s2, s2.GetLength(), &sz);
>m_sz += sz;
>}
>
>m_sz.cy > pRect->Width()
>
>
>But I am not sure because does it take in account space between lines ?
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
-- 
NewsGuy.Com 30Gb $9.95 Carry Forward and On Demand Bandwidth
0
newcomer (15974)
4/16/2006 4:09:26 AM
Hint: those of us with experience in Windows programming know that it is a waste of time
to re-invent the wheel.  One thing you learn to do is to be *effective*, and to do this
you should always take the easy way.  There are enough real challenges in GUI programming
without adding unnecessary challenges.  In any case, the selection of CStatic is probably
a serious mistake.  Start with a base CWnd, and since you will do your own TextOut calls
you will know *exactly* how high the lines are, so there is no question about how much
scrolling you need to do.  Otherwise, you are trying to outguess someone else's
implementation of text output.
				joe
On Thu, 13 Apr 2006 07:31:16 +0200, Vincent RICHOMME <richom.v@free.fr> wrote:

>Ajay Kalra wrote:
>> Wouldnt you be better off usng a Listbox instead which provides the
>> scrolling for free?
>> 
>> ---
>> Ajay
>> 
>the goal is to learn how to manage scrolling, I don't want the easy way.
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
-- 
NewsGuy.Com 30Gb $9.95 Carry Forward and On Demand Bandwidth
0
newcomer (15974)
4/16/2006 4:13:12 AM
Here's an interesting problem...

I can hold n lines in my edit control.  I only want to display a horizontal edit control
if there is a line being displayed that is wider than the window.  So each time I scroll,
I compute the width of each line, and show the horizontal scrollbar if needed.  Oops.  If
the long line is the last line on the window, then when I show the horizontal scrollbar,
it hides this line, and now all the lines are shorter, so I don't need the horizontal
scrollbar.  So I hide it.  Now the long line becomes visible, so I show the scrollbar,
which hides the last line, which...

(Yes, I did this around 1991in Windows 3.1.  There was this moment of insight as I watched
the scrollbar flicker in and out of existence).  These days, I try to implement the
simplest mechanism possible.  So I'll use a listbox or a read-only edit control if I want
something that scrolls text, and not waste time trying to reinvent it.
				joe

On Thu, 13 Apr 2006 06:51:25 -0700, "Tom Serface" <tserface@msn.com> wrote:

>Hi Vincent,
>
>I think the way to do this would be to keep track of how many lines of code 
>you have in the control and the height and width of the characters using the 
>GetTextExtent() routine in CDC and just turn the scrollbar on and off as 
>needed (I.E., if the text all fits in the window without being truncated 
>then you are OK, otherwise you may need to scroll.  You would also have to 
>manage the scrolling by redrawing the window starting with the correct line 
>of text.  IOW, you have to manage what is drawn in the window.
>
>Tom
>
>"Vincent RICHOMME" <richom.v@free.fr> wrote in message 
>news:443d7ac5$0$18991$626a54ce@news.free.fr...
>> How can I know when I am supposed to displauy a vertical scrollbar to my 
>> CStatic ?
>> I know how to do it for horizontal but not for vertical...
>>
>>
>> ::GetTextExtentPoint32(pDCMem->GetSafeHdc(), s2, s2.GetLength(), &sz);
>> IF (sz.cx > pRect->Width())
>> {
>> DO SOMETHING
>> }
>> In the vertical case do I need to count the number of lines displayed and 
>> to do somthing like
>>
>>
>> int nLines = some value; // Number of lines of text in my CStatic
>> for (int i =0, i < nLines; i++)
>> {
>> ::GetTextExtentPoint32(pDCMem->GetSafeHdc(), s2, s2.GetLength(), &sz);
>> m_sz += sz;
>> }
>>
>> m_sz.cy > pRect->Width()
>>
>>
>> But I am not sure because does it take in account space between lines ? 
>
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
-- 
NewsGuy.Com 30Gb $9.95 Carry Forward and On Demand Bandwidth
0
newcomer (15974)
4/16/2006 4:18:01 AM
Why not use a read-only multiline edit control?  This is usually simpler and doesn't
involve any additional complexity.
				joe
On 13 Apr 2006 03:52:38 -0700, "Ajay Kalra" <ajaykalra@yahoo.com> wrote:

>> I don't want the easy way.
>
>Why not start with a CWnd instead of CStatic?
>
>Yet  another option would be to use Assembly language instead of C++
>;-)
>
>---
>Ajay
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
-- 
NewsGuy.Com 30Gb $9.95 Carry Forward and On Demand Bandwidth
0
newcomer (15974)
4/17/2006 3:27:38 AM
Hint: those of us with experience in Windows programming know that it is a waste of time
to re-invent the wheel.  One thing you learn to do is to be *effective*, and to do this
you should always take the easy way.  There are enough real challenges in GUI programming
without adding unnecessary challenges.  In any case, the selection of CStatic is probably
a serious mistake.  Start with a base CWnd, and since you will do your own TextOut calls
you will know *exactly* how high the lines are, so there is no question about how much
scrolling you need to do.  Otherwise, you are trying to outguess someone else's
implementation of text output.
				joe
On Thu, 13 Apr 2006 07:31:16 +0200, Vincent RICHOMME <richom.v@free.fr> wrote:

>Ajay Kalra wrote:
>> Wouldnt you be better off usng a Listbox instead which provides the
>> scrolling for free?
>> 
>> ---
>> Ajay
>> 
>the goal is to learn how to manage scrolling, I don't want the easy way.
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
-- 
NewsGuy.Com 30Gb $9.95 Carry Forward and On Demand Bandwidth
0
newcomer (15974)
4/17/2006 3:29:30 AM
Reply:

Similar Artilces:

Outlook 2007 and hyperlinks in plain text messages
Hello all, Since I have installed Outlook 2007 URLs in plain text messages are not longer displayed as clickable hyperlinks. In HTML messages they are still working. What can I do that these URLs are also displayed as hyperlinks? Thank you an best regards! Markus ...

text box
I want a column of text boxes to automatically expand to fit the date (names) appearing in each row. The Microsoft assistance instructions tell me to click text box on the format menu and then click alignment. I do not get text box on the format menu when in Excell. Therefore, I cannot get to alignment. Can anyone give me an alternative? Thanks You could try selecting them all, and on the Draw menu on the Drawing toolbar, there is an align option . -- HTH Bob Phillips ... looking out across Poole Harbour to the Purbecks (remove nothere from the email address if mailing direct) ...

replying to plain text
Outlook 2003 SP 2 Word 2003 SP 2 How do I set Outlook to always reply in HTML or RTF? When replying to, or forwarding, an email that is in plain text format, it always uses plain text. I want to force it to use RTF or HTML. I understand why it works this way. It is assuming that the user is sending plain text, that they *can't* understand anything else. In my case, I know who I am sending to and know otherwise. I know I can change it every time, and I do, but it is getting very old. Thanks, Brad. Outlook doesn't not have such an option. You'll need to either change it m...

Converting text to dates
Hi I have inherited an Access 97 database which has the dates in text format eg '20040425'. Changing the data type in design view deletes all the records. Anyone know how I can convert these dates from text to date without data loss. Thanks GLS You can add a new field (of Date type) to your table and then do an Update query to fill it with the date value from your text field. Here is the SQL for an Update query using the DateValue() function to convert the text to a true date: UPDATE [MyTable] SET [MyTable].NewDateField = DateValue(Left([TextField],4) & "/" &...

Add text to slides in Power Point
Hello: For the first time I am atempting to create a slide show in Power Point. I already have all the slides, placed a label on each one and saved the .pps file. However, when I played the .pps it shows the pictures but not the text. Could you tell me what to do? Do I have to save each text and how? Thanks a lot. Which version of PPT are you using, and how did you add the labels? -- Echo [MS PPT MVP] http://www.echosvoice.com What's new in PPT 2010? http://www.echosvoice.com/2010.htm Fixing PowerPoint Annoyances http://tinyurl.com/36grcd PowerPoint 2007 Complete Makeover ...

Change a comma separated text file and save it.
Hello All, I need some help on comma separated text files, changing them and saving them. I have got two text files. The first file "ES_EF_AIG_20141440_105708_d.txt" has employee payment record exactly like below: "C0000000519","","","MR STEPHEN AGUTTER","10 COLCOKES ROAD","BANSTEAD","SURREY","","","","","","SM7 2EW","MAL","AGUTTER","NS686159A","0000153363","CDN","E","EMPLOYEE",&quo...

How to validate time format from a text field?
The goal is to normalize data before converting text fields to datetime fields. There are start times and end times stored in text fields of a table. The problem is that any criteria used in a query causes errors when any function causes text to be converted to a datetime type, and the text field does not contain a valid date or time. I'm familiar with some of the validation functions such as isNull(), but I can't find anything like isTime(). How can I test existing data for valid time format? IsDate works on time as well. -- Doug Steele, Microsoft Acce...

repeat text in same exact cells in multi worksheets
I have a workbook and have 20 worksheets in the book. example of what I would like to do. on the worksheet in the same exact numbered cells I want to put the text in once and then put a forumla to make it copy the info to 2-19 pages of the workbook. like 1 of 20 pages, 2 of 20 pages - I only want to put the "of 20 pages" once then have it when it's changed it would automatically change the other work books if I had 21 pages one time then it would change the others. I hope this makes sense. Thank you! One way This needs to be done once only, select the 2nd to the 20th she...

How do I change the text in a workbook from upper to lower case
Hi Please can anyone help with this one! I have a large workbook that I have created (just with text - no formulas) and I have done it in caps but now want to change all the text to lower case without having to re-type it all. Excel hslp is confusing so can anyone tell me how to do it please Thanks Mike Hi see: http://www.cpearson.com/excel/case.htm -- Regards Frank Kabel Frankfurt, Germany mike wrote: > Hi > > Please can anyone help with this one! > > I have a large workbook that I have created (just with text - no > formulas) and I have done it in caps but now...

How to detect clicks outside of a modal dialog
I have a modal dialog displaying a calendar. I want the dialog to cancel if the user clicks out side of the dialog. I have tried using SetCapture() in the dialogs OnInitDialog() but it mucks things up with the controls on the dialog no longer working. Has any one got any ideas how to achieve this. thanks I'm not 100% clear on your arrangement but the ideal approach seems to be for the dialog to cancel when it loses focus. One problem with implementing this is that the dialog itself won't have focus, a child control will. So you'd need to see how well this approach could be a...

Number stored as text
I have number stored as text. It has a small green triangle at the upper left of the cell. If I click on the cell it has a yellowsign with a ! and if I click on that a menu and "convert to number" This works fine one cell at a time. I need to convert columns the cell format has no effect on the column of cell I need to change. I did un click the protect on the last tab. Suggestions? Sueanne copy an empty cell. select your range of offending cells Edit|paste special|check Add sueanne wrote: > > I have number stored as text. It has a small green triangle at the ...

The message not display the body text
Some body help!!! In Ms Outlook 2003 I have 2 accounts set up, 1 with a POP3 access and 1 aol account using IMAP. Suddenly, both accounts are able to connect and download messages, but the messages don't have any body text. When the message is opened, all the information appears in the top of the message form, but the message body is blank. and alert the message box is "The Message not yet download try download and open again" Did something with my outlook 2003?? Best Regards, Chen ...

Dynamic Chart title and text formula?
I have a series of charts that I'd like to create a title for using the left function. I'd like the chart titles to be the result of =LEFT(B7,7). I know how to pull the full contents of a cell but thought of saving a step to avoid doing this as a separate cell formula and point the chart title to that. Any ideas? Thanks!!! The formulas in the chart's text elements can only be link formulas. Splurge and use the extra cell, it doesn't cost much. - Jon ------- Jon Peltier Peltier Technical Services, Inc. http://peltiertech.com/ On 4/15/2010 4:40 PM, Cec...

Text in a Formula
Hi, I once knew how to add text to a formula, which I'd use to explain the formula rather than using cell comments. I can't for the life of me remember how to do this. Any help would be greatly appreciated. James Hi James Try =Sum(A1:A100)+N("This adds the total Gross Amount") Change to suit. Regards Roger Govier James Hamilton wrote: > Hi, > > I once knew how to add text to a formula, which I'd use to explain the > formula rather than using cell comments. > > I can't for the life of me remember how to do this. > > Any help wou...

format in text boxes
In a sql server report service 2005 report, I need to format a few paragraphs before I displayed a chart. Thus, can you tell me is there a way to format messages in paragraphs foramt like you can in word? If this is not an option, do I need to use special carriage control and paragraph indicator characters like '\C'> Thanks! Hi Can you format by T-SQL? "midnight" <midnight@discussions.microsoft.com> wrote in message news:BCFF67CE-FC98-4E73-B814-2E485D2F0548@microsoft.com... > In a sql server report service 2005 report, I need to format a few...

Count first occurance of text
I have a row of 24 cells, some are blank and others have text. I am trying to create a formula that returns the first instance of text being used. I have tried using a match, but it gives me an error because I am trying to pull text not a number. thanks Here's one dart throw .. Assume your 24 source cells are A2:A25 Place in say, B2, normal ENTER to confirm: =INDEX(A2:A25,MATCH(TRUE,INDEX(ISTEXT(A2:A25),),0)) Bullseye? hit the YES below -- Max Singapore http://savefile.com/projects/236895 Downloads:27,000 Files:200 Subscribers:70 xdemechanik --- "Chad Wods...

detecting which control has focus
I have an application that I am writing and I need to be able to detect which control has focus (I am using edit controls). I figured out how to set the focus by creating a member control variable and using the setfocus() function, but how do detect which control has focus? There is a getfocus() in the control member variable, but I have been unsuccessful in using it? I am using the PreTranslateMessage(MSG* pMsg) function to detect when the Return key is pressed and then I automatically go the the next edit control, but I want to do different code depending on which Edit control has focus a...

Auto Text
How do I have Excel enter the path of a workbook like the auto text function does in Wrod? Howard Assuming you want the path and name in a cell you must enter a formula in that cell. See Bob Phillips' site for various combinations. http://www.xldynamic.com/source/xld.xlFAQ0002.html OR use a macro assigned to a button or shortcut key. Sub PathInCell() ActiveCell.Value = ActiveWorkbook.FullName End Sub Gord Dibben Excel MVP On Wed, 16 Mar 2005 12:13:06 -0800, Howard <Howard@discussions.microsoft.com> wrote: >How do I have Excel enter the path of a workbook like the au...

code for text to columns
Let's say I want a worksheet to do "text to columns" (delimited) ever time it opens? For example: Text to columns, delimited, by space for column A. Thanks again all...Vat -- Message posted from http://www.ExcelForum.com Hi, Vato, Add this code to your main sheet module1.bas.(In VB editor, menu Insert->Module) Sub auto_open() Columns("A:A").Select Selection.TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, _ TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=True, Tab:=False, _ Semicolon:=False, Comma:=False, S...

Extract text strings
To all: I have looked throughout the forum and cannot find the solution to my problem. I have a document that has text strings within single quotes (e.g. 'this is sample text') I need to pull all of these out and place them in another document (or preferrably an excel spreadsheet). If someone could point me to some VBA code, that would be much appreciated. If you have Word 2003 or above, you can use the "Find All" feature to do this; see http://sbarnhill.mvps.org/WordFAQs/SpecialFind.htm#CopyingSelectedText (scroll up from that section to get the ...

Put a variable into text ?
I have 60 lines like this one TextBox01.Text = .. TextBox02.Text = .... .... .... Now I would like to make it more simple by setting a variable - X - into the TextBox-text and then do a loop 60 time instead of writing 60 lines. My id´┐Że was to do it like this - TextBox & X &.Text But it does not work. What is wrong ? -- My Photoalbum www.photo.activewebsite.dk If userform controls Dim ctl As msforms.Control For Each ctl In Me.Controls If TypeName(ctl) = "TextBox" Then ctl.Value = X End If Next ctl -- HTH Bob Phi...

Combo box and text box dependency
I have a combo box 'cboRepairType' where the Rowsource is: SELECT * FROM tblGrips ORDER BY GripType 'tblGrips' has three fields GripType -Text BuyPrice -Currency SellPrice -Currency I have a text box 'txtSellPrice' and the following code to accompany it "Private Sub cboRepairType_AfterUpdate() Me.txtSellPrice = cboRepairType.Column(2) End Sub" Why does the value from 'tblGrips.SellPrice' not show in the text box. If I change the .Column(2) to .Column(1) I get the BuyPrice field value. Ideally I would like to use both of these values Any adv...

Converting an INI text file to a dll resource
I have an MFC application which opens a text file and uses its content. I want to use it as a resouce - like a compiled dll that the application will load and use. Is it possible and how? Any reference would be appreciated. Greg Just store it as a binary or string resource, dump it to file. You cannot use it internall without your own INI parser. -- - Mark Randall http://www.temporal-solutions.co.uk http://zetech.swehli.com "Those people that think they know everything are a great annoyance to those of us who do" Isaac Asimov "Greg" <greg@ranger.com> wr...

Link Excel cell data to Powerpoint text boxes
Hi there I am using Excel 2002. On cell A1, I have text "Apple", On cell A2, I have text "Banana". I also have a powerpoint file with two text boxes What i wanna do: 1) To create a link between this Excel file and this Powerpoint files. So, that, "Apple" will appear in one text box in Powerpoint, and "Banana" will appear in another text box. 2) Also, whatever i change or update the Excel cell e.g. "Apple", it will be changed in Powerpoint automatically. Any tips? Thanks a lot. cheers:) Jon Peltier a Excel MVP has a macro that will d...

Prompted to convert the file's text encoding...
When I try to open any excel file from my second computer (Office 2003) it prompts me to convert the file because it can't recognize the text encoding. The file preview is all junk characters and no other encoding makes it readable. I can open these files fine on my laptop, which is also running Office 2003. Any insight would be appreciated! ...