Edit box class...

Started by
5 comments, last by ziplux 23 years, 11 months ago
I am in the process of creating an edit box class using GDI for my game engine, and everything works except that I can''t figure out how to find how big it should be. Right now, I am calling GetTextMetrics and using the tmMaxCharWidth times the max number of characters, but this makes the box way too big. If I use tmAveCharWidth, it is way too small. So...my question is, how can I figure out how big the text box should be? Is there some GDI call I haven''t thought of? Thanks in advance. Visit our web site: Asylum Entertainment
My Geekcode: "GCS d s: a14 C++$ P+(++) L+ E-- W+++$ K- w++(+++) O---- M-- Y-- PGP- t XR- tv+ b++ DI+(+++) D- G e* h!"Decode my geekcode!Geekcode.com
Visit our web site:Asylum Entertainment
Advertisement
Could someone please help? I'll give you a glass of Sprite if you can help me, so here you go:
\_/

Visit our web site:
Asylum Entertainment

Edited by - ziplux on May 21, 2000 7:39:20 PM
My Geekcode: "GCS d s: a14 C++$ P+(++) L+ E-- W+++$ K- w++(+++) O---- M-- Y-- PGP- t XR- tv+ b++ DI+(+++) D- G e* h!"Decode my geekcode!Geekcode.com
Visit our web site:Asylum Entertainment
They do it in web browers like IE5, so it MUST be possible! Someone must know how!

Visit our web site:
Asylum Entertainment
My Geekcode: "GCS d s: a14 C++$ P+(++) L+ E-- W+++$ K- w++(+++) O---- M-- Y-- PGP- t XR- tv+ b++ DI+(+++) D- G e* h!"Decode my geekcode!Geekcode.com
Visit our web site:Asylum Entertainment
You could set your font to a fixed-pitch font then use the tmMaxCharWidth I suppose. The reason it''s so huge when you use tmMaxCharWidth on a variable-pitch font is that it uses either W or M (can''t remember which) to calculate, and M is a lot wider than say, i, in variable-pitched font. Same problem in reverse for average calculation. So unless you want to get the width of every char in the string you want to put in the edit box, I believe you have to use fixed-pitch.

-fel
~ The opinions stated by this individual are the opinions of this individual and not the opinions of her company, any organization she might be part of, her parrot, or anyone else. ~
Thanks, felisandria. I may have to do what you said, but, and I may be wrong, I think IE5 can use variable width fonts in its edit boxes, and in HTML you specify the field width in number of chars...so wonder how they do it...very interesting.

Visit our web site:
Asylum Entertainment
My Geekcode: "GCS d s: a14 C++$ P+(++) L+ E-- W+++$ K- w++(+++) O---- M-- Y-- PGP- t XR- tv+ b++ DI+(+++) D- G e* h!"Decode my geekcode!Geekcode.com
Visit our web site:Asylum Entertainment
According to the HTML book sitting on my desk, the SIZE attribute of the TEXT type of INPUT (edit boxes in HTML) is based on average character width. Testing this, I find that if I type lowercase letters alphabetically into the text box, I can fit approximately 12 characters into an edit box with a SIZE=9 parameter, using IE5.

-fel
~ The opinions stated by this individual are the opinions of this individual and not the opinions of her company, any organization she might be part of, her parrot, or anyone else. ~
Ok, I guess I''ll make the text scroll as it does in IE5 and use the average character width to calculate the width. Thanks for all your help.

Visit our web site:
Asylum Entertainment
My Geekcode: "GCS d s: a14 C++$ P+(++) L+ E-- W+++$ K- w++(+++) O---- M-- Y-- PGP- t XR- tv+ b++ DI+(+++) D- G e* h!"Decode my geekcode!Geekcode.com
Visit our web site:Asylum Entertainment

This topic is closed to new replies.

Advertisement