CGContextShowTextAtPoint() help

srajen1
Unregistered
 
Post: #1
hi,
I am a new user to Mac OS.I need to port a C project from Mac os 9 to Mac os 10.4.So while porting it to xcode I found that few API's which we used in our project has been deprecated.One such API is DrawString() to print text on the screen.In the Apple developer reference document they have asked to use ATSU or Quartz as an alternative.I used CGContextShowatPoint() API but it is not printing the text.Please help me with this.

Code I used is:
-------------
#include <ApplicationServices/ApplicationServices.h>

char str[100];
sprintf(str,"Press any key to exit");

CGContextRef context;
CGContextShowTextAtPoint(context,400,300,str,strle n(str)-1);

Please tell me what is wrong in the above code.
It is a carbon application.Please help me out.
Sage
Posts: 1,403
Joined: 2005.07
Post: #2

Sir, e^iπ + 1 = 0, hence God exists; reply!
⌘-R in Chief
Posts: 1,260
Joined: 2002.05
Post: #3
If you have a valid context (you don't in the pasted code, but I'm not sure if that's just short for brevity's sake), then you're on the right track.

http://developer.apple.com/documentation...ion_4.html


Where are you getting the context from?
srajen1
Unregistered
 
Post: #4
Hi,
How to get a valid context?
srajen1
Unregistered
 
Post: #5
void MakeTargets()
{
.....
//The following code is for Drawing Text
CGContextRef context;
CGContextSelectFont(context, "Helvetica", 16, kCGEncodingMacRoman);
CGContextSetTextDrawingMode (context, kCGTextFillStroke); CGContextSetRGBFillColor (context, 0, 5, 0, .5);
CGContextSetRGBStrokeColor (context, 0, 1, 1, 1);
CGContextShowTextAtPoint(context,20,440,stringTemp,strlen(stringTemp)-1);
........
}

How to create a valid graphics context?And what else should I add to this code to make it work?The text should be printed in a screen where I have loaded a few pictures(targets).
⌘-R in Chief
Posts: 1,260
Joined: 2002.05
Post: #6
You need to read these docs from the beginning:
http://developer.apple.com/documentation...-TPXREF101
Thread Closed