Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

Paramètres de la console en C

16 réponses
Avatar
vive-gauthier
Bonjour a vous tous!
J'aimerais savoir si il est possible de changer la police et sa
dimension avec un programme.
De la m=EAme mani=E8re que :
system("title ");
system("mode con cols=3D120");

Voila, merci d'avance.

10 réponses

1 2
Avatar
Christian ASTOR
wrote:

J'aimerais savoir si il est possible de changer la police



SetConsoleFont()

et sa dimension avec un programme.



http://msdn.microsoft.com/en-us/library/ms686044(VS.85).aspx
Avatar
vive-gauthier
On 18 juil, 21:04, Christian ASTOR wrote:
wrote:
> J'aimerais savoir si il est possible de changer la police

SetConsoleFont()

> et sa dimension avec un programme.

http://msdn.microsoft.com/en-us/library/ms686044(VS.85).aspx



Merci pour ta réponse mais, comment l'utiliser s'il te plait ?
Avatar
ByB
avait soumis l'idée :
On 18 juil, 21:04, Christian ASTOR wrote:
wrote:
J'aimerais savoir si il est possible de changer la police



SetConsoleFont()

et sa dimension avec un programme.



http://msdn.microsoft.com/en-us/library/ms686044(VS.85).aspx



Merci pour ta réponse mais, comment l'utiliser s'il te plait ?



Voir ici : http://tinyurl.com/m8f282
Avatar
vive-gauthier
On 18 juil, 21:47, ByB wrote:
avait soumis l'idée :

> On 18 juil, 21:04, Christian ASTOR wrote:
>> wrote:
>>> J'aimerais savoir si il est possible de changer la police

>> SetConsoleFont()

>>> et sa dimension avec un programme.

>>http://msdn.microsoft.com/en-us/library/ms686044(VS.85).aspx

> Merci pour ta réponse mais, comment l'utiliser s'il te plait ?

Voir ici :http://tinyurl.com/m8f282



:s
Je suis nul en anglais, vous pourriez me donner un petit exemple en C
s'il vous plait ?
Avatar
ByB
avait énoncé :
On 18 juil, 21:47, ByB wrote:
avait soumis l'idée :

On 18 juil, 21:04, Christian ASTOR wrote:
wrote:
J'aimerais savoir si il est possible de changer la police


SetConsoleFont()









Je suis nul en anglais, vous pourriez me donner un petit exemple en C
s'il vous plait ?



J'ai trouvé ça avec Google :
http://cboard.cprogramming.com/windows-programming/102187-console-font-size-2.html

/* A mettre en tête de votre fichier*/
struct CONSOLE_FONT
{
DWORD index;
COORD dim;
};/*CONSOLE_FONT*/


/*A mettre dans votre fonction main() */

const DWORD MAX_FONTS = 40;
DWORD num_fonts = GetNumberOfConsoleFonts();
HANDLE hOut = ::GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_FONT fonts[MAX_FONTS] = {0};
GetConsoleFontInfo(hOut, 0, num_fonts, fonts);
for (DWORD n = 0; n < num_fonts; ++n)
{
fonts[n].dim = GetConsoleFontSize(hOut, fonts[n].index);

if (fonts[n].dim.X == 6 &&
fonts[n].dim.Y == 8)
{
SetConsoleFont(hOut, fonts[n].index);
::InvalidateRect(hwnd, 0, FALSE);
::UpdateWindow(hwnd);
break;
}
}



Je n'ai jamais utilisé ces fonctions, je vous laisse donc les tester.
Avatar
robert
a écrit :
On 18 juil, 21:47, ByB wrote:
avait soumis l'idée :

On 18 juil, 21:04, Christian ASTOR wrote:
wrote:
J'aimerais savoir si il est possible de changer la police


SetConsoleFont()
et sa dimension avec un programme.


http://msdn.microsoft.com/en-us/library/ms686044(VS.85).aspx


Merci pour ta réponse mais, comment l'utiliser s'il te plait ?


Voir ici :http://tinyurl.com/m8f282



:s
Je suis nul en anglais, vous pourriez me donner un petit exemple en C
s'il vous plait ?



Une autre façon de t'aider serait de te conseiller de te mettre à
l'anglais, car la grande majorité des ressources dont tu pourra avoir
besoin ne sont disponibles qu'en cette langue.
Avatar
vive-gauthier
On 19 juil, 01:04, ByB wrote:
avait énoncé :

> On 18 juil, 21:47, ByB wrote:
>> avait soumis l'idée :

>>> On 18 juil, 21:04, Christian ASTOR wrote:
>>>> wrote:
>>>>> J'aimerais savoir si il est possible de changer la police
>>>> SetConsoleFont()
> Je suis nul en anglais, vous pourriez me donner un petit exemple en C
> s'il vous plait ?

J'ai trouvé ça avec Google :http://cboard.cprogramming.com/windows-pr ogramming/102187-console-fon...

/* A mettre en tête de votre fichier*/
struct CONSOLE_FONT
{
    DWORD index;
    COORD dim;

};/*CONSOLE_FONT*/

/*A mettre dans votre fonction main()  */

const DWORD MAX_FONTS = 40;
DWORD num_fonts = GetNumberOfConsoleFonts();
HANDLE hOut = ::GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_FONT fonts[MAX_FONTS] = {0};
GetConsoleFontInfo(hOut, 0, num_fonts, fonts);
for (DWORD n = 0; n < num_fonts; ++n)
    {
        fonts[n].dim = GetConsoleFontSize(hOut, fonts[n].index) ;

        if (fonts[n].dim.X == 6 &&
            fonts[n].dim.Y == 8)
        {
            SetConsoleFont(hOut, fonts[n].index);
            ::InvalidateRect(hwnd, 0, FALSE);
            ::UpdateWindow(hwnd);
            break;
        }
    }

Je n'ai jamais utilisé ces fonctions, je vous laisse donc les tester.



Merci beaucoup, je teste ça.

Sinon, j'apprends déjà l'anglais... Je suis en 4ème ;)
Avatar
vive-gauthier
On 19 juil, 09:16, wrote:
On 19 juil, 01:04, ByB wrote:



> avait énoncé :

> > On 18 juil, 21:47, ByB wrote:
> >> avait soumis l'idée :

> >>> On 18 juil, 21:04, Christian ASTOR wrot e:
> >>>> wrote:
> >>>>> J'aimerais savoir si il est possible de changer la police
> >>>> SetConsoleFont()
> > Je suis nul en anglais, vous pourriez me donner un petit exemple en C
> > s'il vous plait ?

> J'ai trouvé ça avec Google :http://cboard.cprogramming.com/windows- programming/102187-console-fon...

> /* A mettre en tête de votre fichier*/
> struct CONSOLE_FONT
> {
>     DWORD index;
>     COORD dim;

> };/*CONSOLE_FONT*/

> /*A mettre dans votre fonction main()  */

> const DWORD MAX_FONTS = 40;
> DWORD num_fonts = GetNumberOfConsoleFonts();
> HANDLE hOut = ::GetStdHandle(STD_OUTPUT_HANDLE);
> CONSOLE_FONT fonts[MAX_FONTS] = {0};
> GetConsoleFontInfo(hOut, 0, num_fonts, fonts);
> for (DWORD n = 0; n < num_fonts; ++n)
>     {
>         fonts[n].dim = GetConsoleFontSize(hOut, fonts[n].inde x);

>         if (fonts[n].dim.X == 6 &&
>             fonts[n].dim.Y == 8)
>         {
>             SetConsoleFont(hOut, fonts[n].index);
>             ::InvalidateRect(hwnd, 0, FALSE);
>             ::UpdateWindow(hwnd);
>             break;
>         }
>     }

> Je n'ai jamais utilisé ces fonctions, je vous laisse donc les tester.

Merci beaucoup, je teste ça.

Sinon, j'apprends déjà l'anglais... Je suis en 4ème ;)



Ben, j'ai quelques erreur avec ce code:

/*Copyright (C) 2009 MASSART GAUTHIER

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/

#ifdef WIN32
#include <winsock2.h>
#include <windows.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <CSLP/CSLP.h>
#include "fonctions.h"
#include "utilitaires.h"
#include "menus.h"
#include "gestionnaireSon.h"

CSLP_COLORTYPE CT = CYAN|LIGHT, CTS = BLACK, CBS = CYAN|LIGHT;
unsigned char volume = 150;
char prenom[100];
long toucheHaut = '5', toucheBas = '2', toucheDroite = '3',
toucheGauche = '1', typeMenu = 1, ok = 0, teste = 0;
const char versionJeu[] = "VERSION 1.0.0";

struct CONSOLE_FONT
{
DWORD index;
COORD dim;

};/*CONSOLE_FONT*/

int main(void)
{
long continuer = 1, iBienvenu = 0;
char *contenuMenu = "*Jeux :nJeu du plus ou moinsnJeu du pendunJeu
du pousse caissesnJeu du morpionnJeu du snakenJeu du chifuminJeu
des tours de hanoinJeu du bantumin*Autres :nCrx82"
"ditsnHistoriquesnOptionsnQuittern", *contenuTitre = "MENU
PRINCIPAL";

#ifdef WIN32

const DWORD MAX_FONTS = 40;

DWORD num_fonts = GetNumberOfConsoleFonts();
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_FONT fonts[MAX_FONTS] = {0};
GetConsoleFontInfo(hOut, 0, num_fonts, fonts);
for (DWORD n = 0; n < num_fonts; ++n)
{
fonts[n].dim = GetConsoleFontSize(hOut, fonts[n].index);

if (fonts[n].dim.X == 6 &&
fonts[n].dim.Y == 8)
{
SetConsoleFont(hOut, fonts[n].index);
::InvalidateRect(hwnd, 0, FALSE);
::UpdateWindow(hwnd);
break;
}
}
system("title Les jeux indémodables V1.0.0 Alpha");
system("mode con cols0");
CSLP_ColorText(WHITE|LIGHT);
printf("Initialisation de la console : ");
CSLP_ColorText(GREEN|LIGHT);
printf("OKn");
#endif
CSLP_ColorText(WHITE|LIGHT);
printf("nLecture des configurations : ");
LireConf();
srand(time(NULL));
CSLP_ColorText(WHITE|LIGHT);
printf("nChargement des sons : ");
if(InitGestSons() == false)
{
CSLP_ColorText(RED|LIGHT);
printf(" !!n");
CSLP_Sleep(500);
}
else
{
CSLP_ColorText(GREEN|LIGHT);
printf(" OKn");
CSLP_ColorText(WHITE|LIGHT);
printf("nRx82glage du volume de la musique :");
while(ok != 1)
{
if(ChangeVolume(volume) == true)
{
ok = 1;
CSLP_ColorText(GREEN|LIGHT);
printf(" OKn");
}
else
{
teste++;
CSLP_Sleep(20);
if(teste == 10)
{
CSLP_ColorText(RED|LIGHT);
printf(" !!n");
CSLP_Sleep(500);
ok = 1;
}
}
}
}
CSLP_ColorText(WHITE|LIGHT);
printf("nnCHARGEMENT TERMINE!n");

while (continuer)
{
long choixMenu = 0;

if(iBienvenu == 0)
{
CSLP_ClearScreen();
bienvenue1();
iBienvenu++;
}
else
{
CSLP_ClearScreen();
bienvenue2();
}

choixMenu = AfficherMenuJeu(contenuMenu, contenuTitre);

switch(choixMenu)
{
case 1 : MenuPlusOuMoins(); break;
case 2 : MenuPendu(); break;
case 3 : MenuPousseCaisses(); break;
case 4 : MenuMorpion(); break;
case 5 : MenuSnake(); break;
case 6 : MenuChifumi(); break;
case 7 : MenuToursHanoi(); break;
case 8 : MenuBantumi(); break;
case 9 : credit(); break;
case 10 : historiques(); break;
case 11 : options(); break;
case 12 : quitter(); continuer = 0; break;
}
}
CloseGestSons();
CSLP_ResetColors();
}

1>.main.c(54) : warning C4013: 'GetNumberOfConsoleFonts' non défini
(e) ; extern retournant int pris par défaut
1>.main.c(56) : error C2065: 'CONSOLE_FONT' : identificateur non
déclaré
1>.main.c(56) : error C2146: erreur de syntaxe : absence de ';' avant
l'identificateur 'fonts'
1>.main.c(56) : error C2065: 'fonts' : identificateur non déclaré
1>.main.c(56) : error C2109: un indice requiert un type tableau ou
pointeur
1>.main.c(56) : error C2059: erreur de syntaxe : '{'
1>.main.c(57) : warning C4013: 'GetConsoleFontInfo' non défini(e) ;
extern retournant int pris par défaut
1>.main.c(57) : error C2065: 'fonts' : identificateur non déclaré
1>.main.c(58) : error C2143: erreur de syntaxe : absence de ';' avant
'type'
1>.main.c(58) : error C2143: erreur de syntaxe : absence de ';' avant
'type'
1>.main.c(58) : error C2143: erreur de syntaxe : absence de ')' avant
'type'
1>.main.c(58) : error C2143: erreur de syntaxe : absence de ';' avant
'type'
1>.main.c(58) : error C2065: 'n' : identificateur non déclaré
1>.main.c(58) : warning C4018: '<' : incompatibilité signed/unsigned
1>.main.c(58) : warning C4552: '<' : opérateur sans effet ; opérat eur
avec effet secondaire attendu
1>.main.c(58) : error C2059: erreur de syntaxe : ')'
1>.main.c(59) : error C2065: 'n' : identificateur non déclaré
1>.main.c(59) : error C2143: erreur de syntaxe : absence de ';' avant
'{'
1>.main.c(60) : error C2065: 'fonts' : identificateur non déclaré
1>.main.c(60) : error C2065: 'n' : identificateur non déclaré
1>.main.c(60) : error C2109: un indice requiert un type tableau ou
pointeur
1>.main.c(60) : error C2065: 'fonts' : identificateur non déclaré
1>.main.c(60) : error C2065: 'n' : identificateur non déclaré
1>.main.c(60) : error C2109: un indice requiert un type tableau ou
pointeur
1>.main.c(60) : error C2198: 'GetConsoleFontSize' : pas assez
d'arguments pour un appel
1>.main.c(62) : error C2065: 'fonts' : identificateur non déclaré
1>.main.c(62) : error C2065: 'n' : identificateur non déclaré
1>.main.c(62) : error C2109: un indice requiert un type tableau ou
pointeur
1>.main.c(63) : error C2065: 'fonts' : identificateur non déclaré
1>.main.c(63) : error C2065: 'n' : identificateur non déclaré
1>.main.c(63) : error C2109: un indice requiert un type tableau ou
pointeur
1>.main.c(65) : warning C4013: 'SetConsoleFont' non défini(e) ;
extern retournant int pris par défaut
1>.main.c(65) : error C2065: 'fonts' : identificateur non déclaré
1>.main.c(65) : error C2065: 'n' : identificateur non déclaré
1>.main.c(65) : error C2109: un indice requiert un type tableau ou
pointeur
1>.main.c(66) : error C2143: erreur de syntaxe : absence de ';' avant
':'
1>.main.c(67) : error C2143: erreur de syntaxe : absence de ';' avant
':'
1>.main.c(68) : error C2043: instruction break non conforme
Avatar
Christian ASTOR
wrote:

1>.main.c(54) : warning C4013: 'GetNumberOfConsoleFonts' non défini
(e) ; extern retournant int pris par défaut



Il faut les appeler dynamiquement (GetProcAddress())
(il ya aussi SetCurrentConsoleFontEx() pour Vista)
Un exemple =>

#include <windows.h>
#include <iostream>
#include <tchar.h>
#include <conio.h>

typedef BOOL (WINAPI*SCF)
(
IN HANDLE hConsoleOutput,
IN DWORD nFont
);
typedef DWORD (WINAPI*GNOCF)(void) ;
typedef DWORD (WINAPI*GCFI)
(
IN HANDLE hConsoleOutput,
IN BOOL bMaxSize,
IN DWORD dwLength,
OUT PCONSOLE_FONT_INFO lpConsoleFontInfo
) ;

int _tmain(int argc, _TCHAR* argv[])
{
HMODULE hDLL = LoadLibrary(TEXT("kernel32.dll"));
SCF pSetConsoleFont = (SCF)GetProcAddress(hDLL, "SetConsoleFont");
GNOCF pGetNumberOfConsoleFonts = (GNOCF)GetProcAddress(hDLL,
"GetNumberOfConsoleFonts");
GCFI pGetConsoleFontInfo = (GCFI)GetProcAddress(hDLL,
"GetConsoleFontInfo");
if (!pSetConsoleFont || !pGetNumberOfConsoleFonts || !pGetConsoleFontInfo)
return 1;
HANDLE hStdOut;
hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
DWORD dwNbFonts = pGetNumberOfConsoleFonts();
printf ("Number of Fonts = %drn", dwNbFonts);
CONSOLE_FONT_INFO cfi[50];
DWORD dwFonts = pGetConsoleFontInfo(hStdOut, FALSE, dwNbFonts, cfi) ;
for (int i = 0; i<dwFonts; i++)
{
pSetConsoleFont(hStdOut, i);
printf ("Font number %d - X=%d-Y=%drn", i, cfi[i].dwFontSize.X,
cfi[i].dwFontSize.Y);
getch();
}
return 0;
}
Avatar
ByB
a couché sur son écran :
On 19 juil, 09:16, wrote:
On 19 juil, 01:04, ByB wrote:



avait énoncé :
On 18 juil, 21:47, ByB wrote:
avait soumis l'idée :
On 18 juil, 21:04, Christian ASTOR wrote:
wrote:
J'aimerais savoir si il est possible de changer la police


SetConsoleFont()






Je suis nul en anglais, vous pourriez me donner un petit exemple en C
s'il vous plait ?










Lorsque vous avez un problème à résoudre, faites plutot un petit
programme pour tester la fonction qui pose problème avant d'intégrer
cela dans votre programme principale, sinon vous allez tout mélanger.
1 2