fixed width (mono spaced) font

Started by tpekar, November 14, 2013, 03:48:00 PM

Previous topic - Next topic

tpekar

Does anyone know of a good fixed width (mono spaced) font that I can use to output a window out of Pelles C?  Courier wants to cut off the top of the letters and sometimes puts extraneous dots on the window (also is too light).  Courier New doesn't seem to be true monospaced (the headings do not line up over the data).  I think some of the monospaced fonts have spaces that are not the same width as its characters.  Any help would be greatly appreciated!

jj2007

Normally, with SendMessage(hWin, WM_SETFONT, GetStockObject(SYSTEM_FIXED_FONT), 0); the OS provides you with a decent font...

tpekar

Thanks for the info.  I tried this and it worked.  It is pretty ugly, though.  I am still looking for an attractive mono spaced font that has blank spaces the same width as the letters and numbers.

jj2007


colepc

I want my window to use mono-spaced text so tried the following suggestion:
SendMessage(hwnd, WM_SETFONT, GetStockObject(ANSI_FIXED_FONT), 0);

I get the following error:
Building main.obj.
(file location and line number): error #2140: Type error in argument 3 to 'SendMessageA'; expected 'unsigned long long int' but found 'void *'.
*** Error code: 1 ***

The 3rd parameter of SendMessage() is a WPARAM (whatever that is - why did it call it 'SendMessageA'?) and GetStockObject() returns a HGDIOBJ (whatever that is) with description "If the function succeeds, the return value is a handle to the requested logical object. If the function fails, the return value is NULL."

So why did the suggestion work with Pelles C a year ago and today it gives an error?

TimoVJL

You should cast that to (WPARAM) as SendMessage needs that.
SendMessage is actually a macro for SendMessageA (ANSI) and SendMessageW (UNICODE) versions.
May the source be with you

frankie

#6
In PellesC has changed nothing.
In the window headers something has changed, but you are using 64bits version I suppose, and in this case an handler, returned by GetStockObject, has not the same dimension of a WPARAM (a void pointer when WPARAM is a 64 bits integer).
Simply cast the function to a WPARAM and you'll solve the problem.
SendMessage(hwnd, WM_SETFONT, (WPARAM)GetStockObject(ANSI_FIXED_FONT), 0);
Anyway it is always a good habit to cast the parameters of a SendMessage to the correct type.
"It is better to be hated for what you are than to be loved for what you are not." - Andre Gide

colepc

Casting stopped the error but the font in my window didn't change. It's still the standard variable length font instead of the mono-length font that I wanted. Working with a Window is complicated and I have a lot to learn.