![]() |
| | #1 |
| Registered User Join Date: Apr 2008
Posts: 610
| Using TextOut() to align positive & negative numbers Is there a way i can achieve this? I believe i may opt to use a number designated function like SetDlgItemInt().. but need one for floating numbers |
| csonx_p is offline | |
| | #2 |
| Kernel hacker Join Date: Jul 2007 Location: Farncombe, Surrey, England
Posts: 15,686
| The normal way to deal with "number alignment" is by a left-justification - so you have a "left-hand edge" that is straight, and the right-hand side wherever it needs to be to achieve that. So let's say you want your right-hand edge to be at x=200. Then you get the length (in the current font) of the string using GetTextExtentPoint32, and you then start drawing at 200-size.cx - that will make the string END at 200. You may also be able to change the alignment of TextOut itself to use "right justified" and set the clipping rectangle to indicate where your text should go. -- Mats
__________________ Compilers can produce warnings - make the compiler programmers happy: Use them! Please don't PM me for help - and no, I don't do help over instant messengers. |
| matsp is offline | |
| | #3 | |
| Registered User Join Date: Apr 2008
Posts: 610
| Quote:
| |
| csonx_p is offline | |
| | #4 |
| Kernel hacker Join Date: Jul 2007 Location: Farncombe, Surrey, England
Posts: 15,686
| Because you want to know how many pixels the text is, not how many characters it is. This is for two reasons: 1. You need to move a number of pixels to the right from your left margin - you need to know that number of pixels. 2. You may think "well, just multiply the width of a character with a the length of the string". But not all characters are the same width, so you can't just multiply by a fixed number, you have to walk the string and add up the width of each character (e.g. iiii is not as wide as wwww, and in numbers, at least . and - are likely to be different from the width of the 0..9 digits). -- Mats
__________________ Compilers can produce warnings - make the compiler programmers happy: Use them! Please don't PM me for help - and no, I don't do help over instant messengers. |
| matsp is offline | |
| | #5 | |
| Registered User Join Date: Apr 2008
Posts: 610
| Quote:
| |
| csonx_p is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| the definition of a mathematical "average" or "mean" | DavidP | A Brief History of Cprogramming.com | 7 | 12-03-2002 11:15 AM |
| Homework help | Jigsaw | C++ Programming | 2 | 03-06-2002 05:56 PM |
| A (complex) question on numbers | Unregistered | C++ Programming | 8 | 02-03-2002 06:38 PM |
| negative numbers in a edit box | Isometric | Windows Programming | 2 | 12-19-2001 09:51 PM |
| can anyone help me give a code about a program that will input positive numbers... | vigen00 | C Programming | 1 | 10-01-2001 10:39 AM |