Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem with caret movement 1

Status
Not open for further replies.

Raywall

Programmer
Oct 1, 2003
51
RO
Hello...
I have to do a text editor and I have a problem with the caret.I tryed this:
/*
TEXTMETRIC tm;
GetTextMetric(hwnd,&tm);
charwidth=tm.AveCharWidth;
*/
When a button is pressed the new caret position will be:
//xpos=xpos+charwidth
It works for a few characthers like 'a,s' but for others the caret moves to far on right and I don't now if I made a mistake in the code(probably no) or there is a problem caused by the width of the characther.Please tell me what should stand for my variable 'charwidth'.
 
Moving by the average width is not good (unless you've got a monospaced font in your editor). You must either use the call to get the metric length of a string (can't remember the function name off-hand, sorry) or switch to a monospaced font in the text editor (but, I assume the display font is under the user's control and they may want a propotional font, so this is probably out of the question).

Hope this helps.

________________________________________
[hippy]Roger J Coult; Grimsby, UK
In the game of life the dice have an odd number of sides.
 
Do you mean GetTextExtent() and GetTabbedTextExtent() and in mfc I believe there is similar functions declared in the CDC class.
 
Yes, in MFC we use CDC.GetTextExtent() for finding the caret position. CodingNovice, is GetTextExtent() also simply a API function as well? (that's what RayWall needs to know)

-Bones
 
They're the ones!

________________________________________
[hippy]Roger J Coult; Grimsby, UK
In the game of life the dice have an odd number of sides.
 
It doesn't work.
Please tell me, how do I switch to a monospaced font?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top