Getting character widths in Win32--for centering and such
I am working on a progress bar routine thing for **WIN32**, and am
figuring out a way to find the length **in pixels** of a string to be
posted in the progress bar (63 %). I have looked through the Win32
API help file from Inprise (Borland), and I have tried 2 methods, both
not working (I think). First I tried in GDI32.DLL GetCharWidth32(),
and when all was said and done, I got numbers like 88 and 0 and 32.
It may be the type of memory I allocate()d, or the way I'm peek()ing
into memory. Anyway, I have all that I've done in a TEST.EXW file.
First, you need to make a <slight> modification to win32lib.ew (.15c)
-- winspool=linkDLL("winspool.dll")
--below is code added by me
global constant Length32=
linkProc(gdi32,"GetCharWidth32A", {C_POINTER,C_UINT,C_UINT,C_POINTER})
--below here is normal
Second, here is the .exw file I used to test this.
--TEST.EXW
without warning
include win32lib.ew
include machine.e
--the below window is used for a dummy for the getDC()
constant win=create(Window,"",0,0,0,10,10,0),
--allocate the buffer of 10 bytes
buffer=allocate(10)
--put into memory the widths for numbers 0(zero)-9
c_proc(Length32,{getDC(win),'0','9',buffer})
sequence w
--get from memory widths of the numbers 0(zero)-9
w=peek({buffer,10})
for x=1 to 10 do
--use the console window to display widths with
--a space between them.
print(1,w[x])--show the width
puts(1," ")--add a space
end for
include get.e --for wait_key()
if wait_key() then end if --end program at keypress
**I'm sorry if the program doesn't get shown right. The editor I'm
using this at YAHOO is showing me this in a monospaced font. you may
see it kinda wavy.
Thanks,
Mike Hurley
_________________________________________________________
DO YOU YAHOO!?
Get your free @yahoo.com address at http://mail.yahoo.com
|
Not Categorized, Please Help
|
|