banner



How To Change Number Size In C++

  1. #1

    piczim is offline

    Registered User


    changing font size and colour

    I would like to know how I change the colour of font and the size. The simple lawmaking beneath would be nice to see displayed on a white groundwork and the text red and bigger. Is this possible in the control prompt window and if so how

    Lawmaking:

                            
    ane 2 3 4 five 6 7 viii 9 10 11 12 #include<stdio.h>int main(){printf("\due north"); printf("------------\due north"); printf("HELLO World\north"); printf("------------\n"); printf("\n");render (0);}


  2. #ii

    Crossfire is offline

    Registered User


    the easiest manner i found to modify WINDOWS CONSOLE font and background colors is past including WINDOWS.H, then using the command One time like whne yous declare a variable

    Lawmaking:

                          HANDLE hConsole;  hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
    then everytime y'all desire a color change use

    Code:

    SetConsoleTextAttribute(hConsole, NUMBER);
    NUMBER is a number 0-255, there arranged in "blocks"

    groups of 16

    outset 16, black background, then sixteen colors of text
    second sixteen, side by side color background, then 16 colors of text
    etc

    prepare a number, then print text so run across what colors it is, then change number and run again till yous get the desired colors!

    this does Not change the entire background to a color, if you print "HELLO" the groundwork volition be the colour for Simply the 5 spaces that the messages are, and then the text would exist the reg colour.

    hope this helps, and have fun!


  3. #3

    Salem is offline

    and the hat of int overfl Salem's Avatar



  4. #4

    piczim is offline

    Registered User


    am I right in assuming I need to run my code in a WINDOWS CONSOLE currently I compile it in the command prompt which windows console do y'all recommend I use.


  5. #v

    Crossfire is offline

    Registered User


    command prompt IS the windows panel............

    as command.exe (or CMD.exe depending on which windows you use) is what handles your "msdos" programs for console style, wither you telephone call the prompt first, or your program calls it to run.

    Last edited by Crossfire; 06-thirty-2013 at 12:29 PM.


  6. #half dozen

    piczim is offline

    Registered User


    and then the CMD.exe I deceit modify the color or text size. stumped I am where do I write lawmaking and compile in c and be able to modify colour and size of text


  7. #vii

    Adak is offline

    Registered User


    Ordinarily, you write the code in an editor that comes with your compiler - that's what they hateful past "IDE" - Integrated Evolution Surroundings. And then, when you run your code, your console program volition automatically open a panel window - a DOS type window, aka "Command Prompt window", and that window will take it's own color for background and text, and font settings.

    The IDE will also accept other tools for helping y'all code better and faster - typically all key words in C are highlighted for y'all in a dissimilar color, it will accept a debugger yous can use to stride through your code and sentry variable values, set up breakpoints you can run to, etc. It may even have a profiler.

    You change the console window, by opening it, and then correct clicking on the acme bar of the window, and choosing either "Properties" or "Default". They both take the same settings for both color and font, simply any change you make will be temporary, (one fourth dimension merely), if you lot choose "Backdrop". For permanent changes, choose "Default", and make your changes there, and save them.

    I'm old fashioned, so I similar the bluish background and white letters, and 8x12 font size.

    Concluding edited by Adak; 06-30-2013 at 03:42 PM.


  8. #eight

    std10093 is offline

    SAMARAS std10093's Avatar



  9. #ix

    Crossfire is offline

    Registered User


    Quote Originally Posted past piczim View Post

    so the CMD.exe I cant modify the colour or text size. stumped I am where practice I write lawmaking and compile in c and be able to change colour and size of text

    Practice yous non read what people respond??? i broke it downwards to the easiest way for a 3rd grader to understand.....and your response, "so i cant do it?"

    i surrender, no more than help from me


  10. #x

    piczim is offline

    Registered User


    Quote Originally Posted by Crossfire View Post

    Do you not read what people answer??? i bankrupt information technology down to the easiest way for a 3rd grader to understand.....and your response, "then i cant do information technology?"

    i surrender, no more help from me

    I read your post and tried it and could not get it to work. nor did I empathise it. Give thanks you for your help but I nevertheless cant change font size !!


  11. #xi

    sonjared is offline

    Registered User


    Quote Originally Posted by piczim View Post

    I read your post and tried it and could not get information technology to work. nor did I empathize information technology. Thanks for your help but I still cant change font size !!

    Here is a unproblematic example of setting the panel'due south font size:

    Code:

    #include <stdio.h> #include <stdlib.h> #include <Windows.h>  int GetFontSize(HANDLE windowHandle, COORD *size)     {     CONSOLE_FONT_INFOEX font = { sizeof(CONSOLE_FONT_INFOEX) };      if (!GetCurrentConsoleFontEx(windowHandle, 0, &font))         {         return 0;         }      *size = font.dwFontSize;      return 1;     }  int SetFontSize(HANDLE windowHandle, COORD size)     {     CONSOLE_FONT_INFOEX font = { sizeof(CONSOLE_FONT_INFOEX) };      if (!GetCurrentConsoleFontEx(windowHandle, 0, &font))         {         return 0;         }      font.dwFontSize = size;      if (!SetCurrentConsoleFontEx(windowHandle, 0, &font))         {         render 0;         }      return 1;     }  int main(void)     {     HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE);     COORD size;      if (GetFontSize(h, &size))         {         /* Grow by 50% */         size.10 += (SHORT)(size.10 * .5);         size.Y += (Brusk)(size.Y * .5);         SetFontSize(h, size);         }      puts("Blah blah text");      return EXIT_SUCCESS;     }
    Just note that the console is not rich text. Setting the font size with modify everything.
    Final edited past sonjared; 07-01-2013 at 11:12 AM.


  12. #12

    Malcolm McLean is offline

    Registered User


    Colours are quite easy. Just use the conio.h fucntions.

    Changing fonts is much more than difficult. Basically the console isn't designed to handle mixed fonts. You tin can write your own console (medium hard), on elevation of the Windows GDI functions, or yous can hack into the console (very difficult), or you can just display text in a normal windows (relatively easy).

    I'chiliad the author of MiniBasic: How to write a script interpreter and Bones Algorithms
    Visit my website for lots of associated C programming resources.
    https://github.com/MalcolmMcLean


  13. #thirteen

    piczim is offline

    Registered User


    Quote Originally Posted past sonjared View Post

    Here is a simple instance of setting the console'due south font size:

    Code:

    #include <stdio.h> #include <stdlib.h> #include <Windows.h>  int GetFontSize(HANDLE windowHandle, COORD *size)     {     CONSOLE_FONT_INFOEX font = { sizeof(CONSOLE_FONT_INFOEX) };      if (!GetCurrentConsoleFontEx(windowHandle, 0, &font))         {         render 0;         }      *size = font.dwFontSize;      return i;     }  int SetFontSize(HANDLE windowHandle, COORD size)     {     CONSOLE_FONT_INFOEX font = { sizeof(CONSOLE_FONT_INFOEX) };      if (!GetCurrentConsoleFontEx(windowHandle, 0, &font))         {         return 0;         }      font.dwFontSize = size;      if (!SetCurrentConsoleFontEx(windowHandle, 0, &font))         {         return 0;         }      render i;     }  int main(void)     {     HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE);     COORD size;      if (GetFontSize(h, &size))         {         /* Grow by 50% */         size.X += (SHORT)(size.X * .5);         size.Y += (Brusk)(size.Y * .5);         SetFontSize(h, size);         }      puts("Blah blah text");      return EXIT_SUCCESS;     }

    But note that the console is not rich text. Setting the font size with change everything.

    many thanks for this case. I cutting and pasted the vim text editor and saved it as a C file. when I tried to compile it in the command prompt I got several errors in function get font size CONSOLE_FONT_INFOEX un declared not actually sure where to become from here


  14. #14

    sonjared is offline

    Registered User


    Quote Originally Posted by piczim View Post

    many thank you for this case. I cut and pasted the vim text editor and saved information technology as a C file. when I tried to compile information technology in the control prompt I got several errors in office get font size CONSOLE_FONT_INFOEX un alleged non really certain where to go from hither

    Are yous linking with Kernel32.lib or Kernel32.dll? The example uses the Windows API to hook into the panel, and if you lot're edifice manually from the command line y'all'll need to link with the appropriate libraries.


  15. #15

    piczim is offline

    Registered User


    Quote Originally Posted by sonjared View Post

    Are y'all linking with Kernel32.lib or Kernel32.dll? The instance uses the Windows API to hook into the console, and if yous're building manually from the command line you'll need to link with the appropriate libraries.

    Thank you for your answer! I don't retrieve I am using a windows API. This has e'er been a question and a business organisation of mine! I would similar some advice and guidance here. I am using the text editor Vim vii.3 and and so manually compiling the code in the windows CMD PROMPT. I save the lawmaking in Vim with the extension c. (Example salvage every bit code.c) I then go to the CMD PROMPT go to the correct directory and type gcc code.c -o code once the code is compiled I blazon code in the prompt line and the programme runs. So getting back to your advice or question I have no thought if I am linking with kernel32.lib or kernel32.dll I recollect I am building from the control line but volition stand corrected. I will also stand guided on recommendation of other software to write and compile code.. Many thanks Rodney


Source: https://cboard.cprogramming.com/c-programming/157954-changing-font-size-colour.html

Posted by: dennisalannow.blogspot.com

0 Response to "How To Change Number Size In C++"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel