Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Displaying text with an angle

Posted on 2002-05-15
8
Medium Priority
?
514 Views
Last Modified: 2008-02-01
Id like to display text on a canvas in a certain angle with VCL (not MFC). I've looked around and all i can find is just real big functions and loads of code.

Is there a simple way to display the way i want to?
tnx all
0
Comment
Question by:rvlokven
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 2

Expert Comment

by:mirtol
ID: 7011129
Unless you can find a control somewhere which allows you to set angles, nope.

Simplest way is to call the windows CreateFontIndirect function and set the Font->Handle to this.

If you're going to do it alot then create a descendant of TFont which has an Escapement/Orientation property so you can easily create angled fonts. Then you can just pass the handle over and not worry each time about creating the font structure etc etc.
0
 
LVL 32

Expert Comment

by:jhance
ID: 7011165
See the Windows SDK docs section titled:

Rotating Lines of Text

But the relevant portion of the code is quite simple:


// Draw the string 36 times, rotating 10 degrees
// counter-clockwise each time.
 
for (angle = 0; angle < 3600; angle += 100)
{
    plf->lfEscapement = angle;
    hfnt = CreateFontIndirect(plf);
    hfntPrev = SelectObject(hdc, hfnt);
    TextOut(hdc, rc.right / 2, rc.bottom / 2,
        lpszRotate, lstrlen(lpszRotate));
    SelectObject(hdc, hfntPrev);
    DeleteObject(hfnt);
}
0
 
LVL 6

Accepted Solution

by:
DrDelphi earned 200 total points
ID: 7011609
a Delphi example (Same VCL) from my website:

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

  public
    { Public declarations }
   HF:Hfont;



procedure TForm1.FormCreate(Sender: TObject);
var
  LF: TLogFont;
begin
  FillChar(LF, SizeOf(LF), 0);
  with LF do begin
   lfWidth:=10;
   lfheight:=14;
   lfEscapement:=450; //45.0 degrees
   lfOrientation:=450;//45.0 degrees
   lfWeight:=FW_BOLD;
   lfCharSet:=DEFAULT_CHARSET;
   lfOutPrecision:=OUT_DEFAULT_PRECIS;
   lfClipPrecision:=CLIP_DEFAULT_PRECIS;
   lfQuality:=DEFAULT_QUALITY;
   lfPitchAndFamily:=DEFAULT_PITCH or FF_DONTCARE;
   lfFaceName:='Times New Roman';
  end;
  HF:=CreateFontIndirect(LF);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  SelectObject(canvas.Handle, HF);
  TextOut(canvas.handle, 200, 200, 'Testline', 8);
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  SelectObject(canvas.handle, GetStockObject(DEFAULT_GUI_FONT));
  DeleteObject(HF);

end;



Good luck!!
www.drdelphi.com

0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 32

Expert Comment

by:jhance
ID: 7011643
Why would a Delphi example be useful in the C++ topic area?  Just asking....
0
 
LVL 6

Expert Comment

by:DrDelphi
ID: 7011693
Because the question was how to do this using VCL, meaning that he is using Borland C++ Builder, which is based on the exact same VCL as Delphi. The beauty of this is that I can take Delphi code and plug into BCB directly. And BCB code is usually easily adapted to Delphi, as well. That is why, though an ardent Delphian, I also have BCB code examples on my website...www.drdelphi.com (shameless plug).

Good luck!!
0
 
LVL 32

Expert Comment

by:jhance
ID: 7011699
I guess I'm not sure what VCL is.  But in any case, this is really not a C++ or Delphi question at all but rather more suited to the Windows Programming topic.
0
 
LVL 6

Expert Comment

by:DrDelphi
ID: 7011738
VCL is an acronym for "Visual Component Library"... Borland's answer to MFC (Microsoft Foundation Classes). Every object in BCB and Delphi is ultimately derived from the VCL.As for whether this is the right area for the question... I am inclined to think that this is. rvlokven
is looking for a VCL C++ solution to his/her quaestion. Windows Programming is much too general for this. I mean, a PowerBuilder(or any other tool)  solution (if one even exists), isn't going to do him any good , would it?


Good luck!!
0
 
LVL 1

Expert Comment

by:wolfpackinc
ID: 7012299
heres what I use from a label component:

 LOGFONT LogRec;
GetObject(Font->Handle,sizeof(LogRec),&LogRec);

LogRec.lfEscapement = 900;//90% angle
LogRec.lfOrientation = 900;

Canvas->Font->Handle=CreateFontIndirect(&LogRec);
//Writes a string on the canvas, starting at the point (X,Y), and then updates the PenPos to the end of the string.

//void __fastcall TextOut(int X, int Y, const System::AnsiString Text);
Canvas->TextOut(0,w,Caption);

which is same as DrDelphi but in C++ Builder
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

721 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