vertical text not drawn at correct location

The code below illustrates the problem I am having.  A rectangle is drawn in
the center of the display.  Text is suppose to be drawn at a 270 degree
angle and centered in the middle of the rectangle.   Instead, the text is
always drawn to the far to the left of the rectangle.  If I change text
escapement to 0 degrees then the text is correctly centered.  Can someone
suggest what mistake I am making?  Thanks in advance.

Ian


CMyView::OnDraw( CDC *pDC )
{
    // create font
    CFont oFont;
    LOGFONT oLF;
    memset( &oLF, 0, sizeof(oLF) );
    oLF.lfHeight = 25;
    oLF.lfOrientation = 2700; // 270 degrees
    oLF.lfEscapement = 2700;
    VERIFY( oFont.CreateFontIndirect( &oLF ) );
    CFont *pOldFont = pDC->SelectObject( &oFont );
    ASSERT( pOldFont );

    // set drawing rectangle
    CRect oCR;
    GetClientRect( &oCR );
    CRect oR(
        oCR.CenterPoint().x-30, oCR.top,
        oCR.CenterPoint().x+30, oCR.bottom
    );
    pDC->DPtoLP( &oR );

    // draw rectangle
    CBrush oBrush( RGB(0,0,0) );
    pDC->FrameRect( &oR, &oBrush );

    // draw text
    pDC->SetTextColor( RGB(0,0,0) );
    UINT uFormat = DT_SINGLELINE | DT_TOP | DT_CENTER | DT_NOCLIP;
    pDC->DrawTextEx( _T("sample text"), &oR, uFormat, NULL );

    // clean up
    pDC->SelectObject( pOldFont );
}



0
ibnospam (19)
1/3/2005 5:49:51 AM
vc.mfc 33608 articles. 0 followers. Follow

2 Replies
778 Views

Similar Articles

[PageSpeed] 54

    Your 'oFont' object gets destroyed once the function exits. Make 'oFont'
a member variable of your 'CMyView' class.

-- 
Cheers
Check Abdoul [VC++ MVP]
-----------------------------------

"Ian" <ibnospam@yahoo.com> wrote in message
news:725Cd.7945$7z.535168@weber.videotron.net...
> The code below illustrates the problem I am having.  A rectangle is drawn
in
> the center of the display.  Text is suppose to be drawn at a 270 degree
> angle and centered in the middle of the rectangle.   Instead, the text is
> always drawn to the far to the left of the rectangle.  If I change text
> escapement to 0 degrees then the text is correctly centered.  Can someone
> suggest what mistake I am making?  Thanks in advance.
>
> Ian
>
>
> CMyView::OnDraw( CDC *pDC )
> {
>     // create font
>     CFont oFont;
>     LOGFONT oLF;
>     memset( &oLF, 0, sizeof(oLF) );
>     oLF.lfHeight = 25;
>     oLF.lfOrientation = 2700; // 270 degrees
>     oLF.lfEscapement = 2700;
>     VERIFY( oFont.CreateFontIndirect( &oLF ) );
>     CFont *pOldFont = pDC->SelectObject( &oFont );
>     ASSERT( pOldFont );
>
>     // set drawing rectangle
>     CRect oCR;
>     GetClientRect( &oCR );
>     CRect oR(
>         oCR.CenterPoint().x-30, oCR.top,
>         oCR.CenterPoint().x+30, oCR.bottom
>     );
>     pDC->DPtoLP( &oR );
>
>     // draw rectangle
>     CBrush oBrush( RGB(0,0,0) );
>     pDC->FrameRect( &oR, &oBrush );
>
>     // draw text
>     pDC->SetTextColor( RGB(0,0,0) );
>     UINT uFormat = DT_SINGLELINE | DT_TOP | DT_CENTER | DT_NOCLIP;
>     pDC->DrawTextEx( _T("sample text"), &oR, uFormat, NULL );
>
>     // clean up
>     pDC->SelectObject( pOldFont );
> }
>
>
>


0
CheckAbdoul
1/3/2005 6:47:56 PM
Hello Check,

Thank you.  Your suggestions works in the sample code but not my 
application.  I'll put on the coffee and donuts and try to work through this 
tonight.   Thanks again.

Ian



"CheckAbdoul" <checkabdoul at mvps dot org> wrote in message 
news:%23mKd%23Sc8EHA.2788@TK2MSFTNGP15.phx.gbl...
>    Your 'oFont' object gets destroyed once the function exits. Make 
> 'oFont'
> a member variable of your 'CMyView' class.
>
> -- 
> Cheers
> Check Abdoul [VC++ MVP]
> -----------------------------------
>
> "Ian" <ibnospam@yahoo.com> wrote in message
> news:725Cd.7945$7z.535168@weber.videotron.net...
>> The code below illustrates the problem I am having.  A rectangle is drawn
> in
>> the center of the display.  Text is suppose to be drawn at a 270 degree
>> angle and centered in the middle of the rectangle.   Instead, the text is
>> always drawn to the far to the left of the rectangle.  If I change text
>> escapement to 0 degrees then the text is correctly centered.  Can someone
>> suggest what mistake I am making?  Thanks in advance.
>>
>> Ian
>>
>>
>> CMyView::OnDraw( CDC *pDC )
>> {
>>     // create font
>>     CFont oFont;
>>     LOGFONT oLF;
>>     memset( &oLF, 0, sizeof(oLF) );
>>     oLF.lfHeight = 25;
>>     oLF.lfOrientation = 2700; // 270 degrees
>>     oLF.lfEscapement = 2700;
>>     VERIFY( oFont.CreateFontIndirect( &oLF ) );
>>     CFont *pOldFont = pDC->SelectObject( &oFont );
>>     ASSERT( pOldFont );
>>
>>     // set drawing rectangle
>>     CRect oCR;
>>     GetClientRect( &oCR );
>>     CRect oR(
>>         oCR.CenterPoint().x-30, oCR.top,
>>         oCR.CenterPoint().x+30, oCR.bottom
>>     );
>>     pDC->DPtoLP( &oR );
>>
>>     // draw rectangle
>>     CBrush oBrush( RGB(0,0,0) );
>>     pDC->FrameRect( &oR, &oBrush );
>>
>>     // draw text
>>     pDC->SetTextColor( RGB(0,0,0) );
>>     UINT uFormat = DT_SINGLELINE | DT_TOP | DT_CENTER | DT_NOCLIP;
>>     pDC->DrawTextEx( _T("sample text"), &oR, uFormat, NULL );
>>
>>     // clean up
>>     pDC->SelectObject( pOldFont );
>> }
>>
>>
>>
>
> 


0
ibnospam (19)
1/3/2005 10:42:06 PM
Reply:

Similar Artilces:

text flow
Is there a way to have text flow around the outline of a graphic so the text takes the form of the image? A small child turns to Ed, and exclaims: "Look! Look! A post from Brian Lubroth <blubroth@communityschool.us>!"... > Is there a way to have text flow around the outline of a > graphic so the text takes the form of the image? Use the "Tight" wrapping option? -- Ed Bennett - MVP Microsoft Publisher http://www.mvps.org/the_nerd/ Before reading this message, view the disclaimer: http://mvps.org/the_nerd/disclaim.htm I'm not really looking to wrap the...

FW: Try on that corrective update which came from the MS Corporation
--gjfddephpnoh Content-Type: multipart/related; boundary="cmcuzvsszmxe"; type="multipart/alternative" --cmcuzvsszmxe Content-Type: multipart/alternative; boundary="mgemxkfvi" --mgemxkfvi Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Microsoft Consumer this is the latest version of security update, the "October 2003, Cumulative Patch" update which resolves all known security vulnerabilities affecting MS Internet Explorer, MS Outlook and MS Outlook Express as well as three newly discovered vulnerabilities. Install now to continu...

MS ACCESS REPORT EXPORT TO TEXT FILE
I have an Access Report which I am using to create a text file for upload into a 3rd party application. When Access exports the text file it is creating a carriage return (i.e., empty row) in the first row of the created text file thereby making the file incompatible for upload to the 3rd party. Is there a setting I need to select to prevent this from happening? Any suggestion you may have would be appreciated. Thanks in advance for your help! Regards Thanks Eric. "Eric Blitzer" wrote: > If you are creating a file for import you would be better of exporting the > que...

I want to display a graph vertically
Hello, I have a problem with displaying a graph in excel. It seems like the default way of displaying a graph is from left to right, that is, the longer part stretches out to the right. On my graph, dates are on the left (vertically) and an other factor is on the right (horisontally). I want the dates tp be horisontally and the other factor vertically, and the curve/graph should go from top to bottom, like a waterfall if that better explains it. That is, I would like to rotate the graph, but not by saving the graph as a gif-file and rotate it in Visio for instance, but as a real excel-graph, ...

Text to Column Function Rejects Zeros
Hello, As part of a project, I was conducting a survey (administered online) using Snap survey software. Snap automatically sends results into an Excel file, which is great. However, several of the questions allowed participants to select more than one item ("Check the top 3 things..." etc.). These responses were coded in Excel into a 10101 format, where 1=checked and 0=not checked, all in one cell. Since 0 represents a response, I selected the cell formatting of these columns as Custom (Format->Cell->Number tab->Custom), so any 0s before the first 1 would not drop o...

Formula to increment sequence only if text in a particular cell
Hi, I'm new to this, and not sure how to do this, I'd like to increment a field by one only if there's text in a particular cell. This is what I have, so I'm trying to write a formula that automatically populates column A...this is what I have tried =IF(C4<>"","Test_"&TEXT(ROW(A1),"000"), "") --- but this formula increments even when no text in B, so I end up with a value of Test_003 in A3, where I need to have Test_002 A B 1 Test_001 some text 2 ...

Visio
I have started to learn UML class diagram design and am using Visio 2003 (SP1) with Software > UML Model Diagram template as by base for design. My biggest frustration right now trying to model i cannot change the Type to anything expect for the items already in the list. Is there any way to add custom text to this? Help would be appreciated. ...

Text Wrap
I have text wrap on a cell with lots of text and I use "Alt Enter" to create new lines within the cell. The last two entries in the cell are not wrapping though the first four entries within the cell wrap just fine. Is there a way to get the last two entries within the cell to text wrap? Thanks! Is the rowheight big enough? And if those last two entries are really long, then maybe a few more alt-enters to break them up???? Craig wrote: > > I have text wrap on a cell with lots of text and I > use "Alt Enter" to create new lines within the cell. The > l...

Repeating a formula in text
I'm concatenating two columns in an excel data file. The formula works, but won't replicate in the column to subsequent rows, all it will do is copy. I'm tearing my hair out - I've done it before but all of the sudden it won't work. Can you help? 1) What happens if you hit [F9] ? If this recalculates the correct results - then your Calculation option is set to "Manual". 2) Did you, by mistake, fix the References of the concatenated cells with $ [like: $A$1] ? Micky "Lyn" wrote: > I'm concatenating two columns in an ex...

how to draw text vertically?
for example, some software like Microsoft Word, when docking a toolbar to left or right, the text on button will be drawn vertically. In article <eShIl7FZGHA.3704@TK2MSFTNGP03.phx.gbl>, Bill Gates says... > for example, some software like Microsoft Word, when docking a toolbar to > left or right, the text on button will be drawn vertically. Basically you specify the angle in lfEscapement of the LOGFONT structure. Then call CreateFontIndirect with this structure and you'll get a rotated font of type HFONT. Use SelectObject to select the font and then you can use TextO...

Text running
Hello I don't know if there is a code that keeps a word ( for example FOOTBALL) running from left to the right of the cell. I appriciate even a small help. Thanks in advance Where would you like it to run to? English and most other languages run left to right. Middle East countries usually run right to left. There are various methods of text alignment in cell formatting>alignment. Gord Dibben MS Excel MVP On Thu, 15 Apr 2010 09:39:01 -0700, MAX <MAX@discussions.microsoft.com> wrote: >Hello >I don't know if there is a code that keeps a wor...

hyperlink an excel cell to a specific location wthin application f
how can I hyperlink an excel cell to a specific outlook contact? ...

vertical text
Any one help me with displaying text vertically, without expanding the row height? Dan, Do you have exceptional eyesight? Bernard "Dan" <hemidan@aol.com> wrote in message news:27b301c38367$5ae76490$a101280a@phx.gbl... > Any one help me with displaying text vertically, without > expanding the row height? ...

Export auto correct dictionary
I frequently add to the custom dictionary, and enter auto correct words as well. How do I copy the data over to another computer as well? Dave Peterson gave the following advice recently: http://groups.google.ca/groups?selm=422B4F03.314FF9DB%40netscapeXSPAM.com ====================== I like to do it this way. Old pc. Open excel. Make a minor change to the autocorrection list. close excel. search for *.acl and copy the one with the latest date. New pc. Open excel. Make a minor change to the autocorrection list. close excel. search for *.acl. Make note of the path/filename for that lat...

I would like the tabs in Excel to be listed vertically on left.
There's no option setting that will move the sheet tabs to the left. You can send suggestions to: mswish@microsoft.com Put "Excel" in the subject line, so your suggestion will be forwarded to the Excel product managers. Suzy wrote: -- Debra Dalgleish Excel FAQ, Tips & Book List http://www.contextures.com/tiptech.html ...

Advice about correct object casting
Hi all.. I have a class derived from CDialog that has this method: int CTabCtrlSSL::AddSSLPage (LPCTSTR pszTitle, int nPageID, CTabPageSSL* pTabPage); CTabCtrSSL class is part of a class that encapsulates tab control functionality. On the other hand, I have created a dialog resource that will contain the subclassed tab control, and other child dialog controls to be placed for each tab. Using classwizard I have created, for example, for the dialog to be shown when tab 0 is selected, a class named CHistoryWorkflowDlg. In OnInitDialog of the dialog that contains the tab control I have ...

Changing Text Box Size and Location on a form, at run time with Access Xp
Hello All, Is it possible to change the size of the text box (or any other control) on a form at run time, by Drag and drop or resizing borders using the mouse events. (Just like the design mode but the user will use it at run time on form view). Thanks in advance... You should be able to resize in your code if necessary. Me.control.Visible = True Me.control.Height = 1000 Me.control.Width = 1000 Don't forget to set them back when you are done. "Developer" wrote: > Hello All, > Is it possible to change the size of the text box (or any other control) on > a ...

Inserting text in a CEdit/CeditView
I've been working on this for a week, and did a scan of this NG. That pointed me to SetWindowText, but as expected that simply replaces the text in the Notepad like window with the string passed to SetWindowText. What I want to do is take a string of text I have assembled in a CDialog and insert in the current position of the main CEdit window. -- Gary G. Little Gary G. Little wrote: > I've been working on this for a week, and did a scan of this NG. That > pointed me to SetWindowText, but as expected that simply replaces the text > in the Notepad like window with the stri...

Forms and linking text Boxes
Good morning, I am not new to word or Basic forms for that matter how ever I am unable to work out one facet of forms that I wish to use. I have been sent a form in word 2003 which is 8 pages long. I have copied these eight pages and am able to edit my copy. 30 - 40 % of each page has the same information boxes, Name, address etc etc. I would like to know how I can link all the "address" text boxes on each page so that when I write info in the first address box it will also appear in the other address boxes -- Michele On Sun, 15 Nov 2009 15:20:01 -0800, Michele ...

Text box
When I print the Text box, I must have several lines in the Text box below the last line, otherwise the last few lines in the Text box do not print. So how can I shrink the Text box without losing the last few lines. Thanks. -- Ed In article <0BFC6F3F-3915-4C52-AD49-E87B605AD29D@microsoft.com>, Ed <Ed@discussions.microsoft.com> wrote: > When I print the Text box, I must have several lines in the Text box below > the last line, otherwise the last few lines in the Text box do not print. So > how can I shrink the Text box without losing the last few lines. Which ap...

Data Connection with Text Import Problem
Using Excel 2007, I've configured a data connection using a text file. In the text file's first column, there is a value of TRUE (a company's actual name). When the data connection imports the text file, Excel sees TRUE not as a text value, but as a binary value. The problem is when the first column is sorted in ascending order, TRUE gets put at the bottom of the column and is centered. Placing an apostrophe before TRUE in the text file doesn't work, nor does formatting the first column as text. What can I do to make TRUE be sorted as a text value ? - ...

Printing just vertical gridlines
Is there any way to print out the data in a worksheet showing vertical gridlines only? Virginia One way is to format the cells and add vertical borders. Then whe printing, uncheck the print gridlines box. -- kkkni ----------------------------------------------------------------------- kkknie's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=754 View this thread: http://www.excelforum.com/showthread.php?threadid=26513 Thanks very much. That's just what I needed! Virginia kkknie wrote: > One way is to format the cells and add vertical borders. The...

Excel -- Wrapped text disappears
A user here is having the same problem as described in a previous topic (http://groups.google.com/group/microsoft.public.excel/browse_thread/thread/b32b50c3e69981d/dc8adb6c01616d70%23dc8adb6c01616d70). Windows XP Pro, SP2 Office 2003 Pro, SP2 New machine with plenty of resources. Was originally working properly, then mysteriously developed a strange symptom: Any text that is in an Excel cell in which the "wrap text" option has been selected no longer shows up. I have checked it with 1 character, 1 word, and multiple lines of text. It has been repeated with spreadsheets created on...

Convert vertical data to horizontal data
I have a listing of 6 performance ratings for each employee. The ratings appear vertically. How do I convert the ratings data to a single row for each employee? Copy - paste special - transpose -- Russell Dawson Excel Student Please hit "Yes" if this post was helpful. "Kiley" wrote: > I have a listing of 6 performance ratings for each employee. The ratings > appear vertically. How do I convert the ratings data to a single row for > each employee? I think I need more information. I tried what you suggested but I got the following me...

Vertical font
Can a line of font be turned from horizontal to vertical. I've been known to use tables and/or columns to create the effect of a vertical font. If you make the column narrow enough and get the margins right if will move all the text into a vertical line. It is far from foolproof though, some letters, i.e. l, are narrower than others and so frustrate this work around. I am sure someone will be along soon with a much cleverer answer. Good luck. "Jonka" wrote: > Can a line of font be turned from horizontal to vertical. The only way I know is nothing autom...