944,111 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 18496
  • C RSS
Feb 5th, 2005
2

How can I change console application font size?

Expand Post »
I am writing a Win32 Console application and I need to change the font size to 18x10 pixels. I think this can be done with a function in windows.h but Im not sure which one or how to do it.
Similar Threads
Reputation Points: 11
Solved Threads: 0
Newbie Poster
f_escobar82 is offline Offline
4 posts
since Feb 2005
Feb 5th, 2005
0

Re: How can I change console application font size?

The function is called CreateFont(), not something for the faint at heart!

[php]
HFONT CreateFont(
int nHeight, // logical height of font
int nWidth, // logical average character width
int nEscapement, // angle of escapement
int nOrientation, // base-line orientation angle
int fnWeight, // font weight
DWORD fdwItalic, // italic attribute flag
DWORD fdwUnderline, // underline attribute flag
DWORD fdwStrikeOut, // strikeout attribute flag
DWORD fdwCharSet, // character set identifier
DWORD fdwOutputPrecision, // output precision
DWORD fdwClipPrecision, // clipping precision
DWORD fdwQuality, // output quality
DWORD fdwPitchAndFamily, // pitch and family
LPCTSTR lpszFace // pointer to typeface name string
);
[/php]
Moderator
Reputation Points: 1333
Solved Threads: 1404
DaniWeb's Hypocrite
vegaseat is offline Offline
5,792 posts
since Oct 2004
Feb 5th, 2005
0

Re: How can I change console application font size?

I dont think this function will work for console apps. The program Im writing runs in DOS window.
Reputation Points: 11
Solved Threads: 0
Newbie Poster
f_escobar82 is offline Offline
4 posts
since Feb 2005
Feb 5th, 2005
0

Re: How can I change console application font size?

Quote originally posted by f_escobar82 ...
I dont think this function will work for console apps. The program Im writing runs in DOS window.
There is a code snippet on DaniWeb called "Add WinBGI Graphics to your Console" at:
http://www.daniweb.com/code/snippet176.html
check the lines ...
[php]
setcolor(YELLOW);
settextstyle(DEFAULT_FONT, HORIZ_DIR, 2); // 2 = size
outtextxy(20, 320, "Press any key ... ");
getch(); // wait
[/php]
Maybe you can modify these to suit your needs.
Moderator
Reputation Points: 1333
Solved Threads: 1404
DaniWeb's Hypocrite
vegaseat is offline Offline
5,792 posts
since Oct 2004
Feb 7th, 2005
0

Re: How can I change console application font size?

thanks vegaseat, I dont think i explained what Im trying to do very well. I already have a working application that runs in a console window. But the default text is too small. This can be fixed by opening the console properties while the app is running and changing the font size to 18x10 and the screen buffer size to 79 characters wide by 25 characters high. I would like to be able to change these settings through to code. Windows.h includes a function called:

SetConsoleScreenBufferSize();

msdn describes it here:

http://www.symbolictools.de/public/p...nchar_7sv9.htm

the problem is that Im having trouble understanding how it works. I found a listing of various console functions here:

http://www.symbolictools.de/public/p...nchar_3vg3.htm

but the documentation is somewhat vague.
Reputation Points: 11
Solved Threads: 0
Newbie Poster
f_escobar82 is offline Offline
4 posts
since Feb 2005
Feb 7th, 2005
0

Re: How can I change console application font size?

heres a function that I wrote, but it seems to have no effect.

  1. void consoleResize(unsigned int x, unsigned int y)
  2. {
  3. COORD coord;
  4. HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
  5.  
  6. coord.X = x;
  7. coord.Y = y;
  8.  
  9. SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE),coord);
  10. }
Reputation Points: 11
Solved Threads: 0
Newbie Poster
f_escobar82 is offline Offline
4 posts
since Feb 2005
Feb 8th, 2005
0

Re: How can I change console application font size?

Quote originally posted by f_escobar82 ...
heres a function that I wrote, but it seems to have no effect.

  1. void consoleResize(unsigned int x, unsigned int y)
  2. {
  3. COORD coord;
  4. HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
  5.  
  6. coord.X = x;
  7. coord.Y = y;
  8.  
  9. SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE),coord);
  10. }
Check under InvalidateRect() to force an update your your screen.
Moderator
Reputation Points: 1333
Solved Threads: 1404
DaniWeb's Hypocrite
vegaseat is offline Offline
5,792 posts
since Oct 2004
Feb 8th, 2005
0

Re: How can I change console application font size?

Hi,

I wonder if you can go to your user community and just change the DOC in the README to change the environment defined by the icon. Right-click on the icon, change the properties to this x that, and then save. Yes, it is a user step. Or, maybe you alter your installer to do the configuration for you!

Christian
Team Colleague
Reputation Points: 121
Solved Threads: 57
Posting Virtuoso
kc0arf is offline Offline
1,629 posts
since Mar 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: needed recursion help
Next Thread in C Forum Timeline: what is "unresolved external..."???





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC