Pelles C forum

C language => Windows questions => Topic started by: tpekar on November 14, 2013, 03:48:00 PM

Title: fixed width (mono spaced) font
Post by: tpekar on November 14, 2013, 03:48:00 PM
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!
Title: Re: fixed width (mono spaced) font
Post by: jj2007 on November 14, 2013, 04:43:29 PM
Normally, with SendMessage(hWin, WM_SETFONT, GetStockObject(SYSTEM_FIXED_FONT), 0); the OS provides you with a decent font...
Title: Re: fixed width (mono spaced) font
Post by: tpekar on November 20, 2013, 05:06:54 PM
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.
Title: Re: fixed width (mono spaced) font
Post by: jj2007 on November 20, 2013, 09:23:53 PM
Try ANSI_FIXED_FONT, or go straight to this site: http://hivelogic.com/articles/top-10-programming-fonts
Title: Re: fixed width (mono spaced) font
Post by: colepc on January 23, 2015, 04:22:58 AM
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?
Title: Re: fixed width (mono spaced) font
Post by: TimoVJL on January 23, 2015, 09:06:57 AM
You should cast that to (WPARAM) as SendMessage needs that.
SendMessage is actually a macro for SendMessageA (ANSI) and SendMessageW (UNICODE) versions.
Title: Re: fixed width (mono spaced) font
Post by: frankie on January 23, 2015, 09:10:18 AM
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.
Code: [Select]
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.
Title: Re: fixed width (mono spaced) font
Post by: colepc on January 23, 2015, 03:28:50 PM
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.