IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C++/CLI Discussion :

[C#/SetConsoleWindowInfo] Comment obtenir le positionnement voulue de la Console ?


Sujet :

C++/CLI

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Expert confirmé
    Avatar de neguib
    Profil pro
    Inscrit en
    Mai 2005
    Messages
    3 627
    Détails du profil
    Informations personnelles :
    Âge : 64
    Localisation : Suisse

    Informations forums :
    Inscription : Mai 2005
    Messages : 3 627
    Par défaut [C#/SetConsoleWindowInfo] Comment obtenir le positionnement voulue de la Console ?
    Bonjour à tous

    Voilà je poursuis ma reprise en main, et dans le cas présent par le pilotage implémenté d'une application Console. Malheureusement il semble que je ne maîtrise pas bien l'utilisation des dll 'SetConsoleScreenBufferSize' ainsi que 'SetConsoleWindowInfo'. En fait j'obtiens bien l'agrandissement maximal de l'écran Console, alors que le positionnement reste totalement aléatoire. Je voudrais obtenir un positionnement en haut à gauche (left=0,top=0), mais résultat stérile. Je dois louper quelque chose mais quoi ?
    Voici le code actuel qui donne un résultat correcte mais aléatoire :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
     
     [DllImport("kernel32.dll", EntryPoint = "GetStdHandle", SetLastError = true, CharSet = CharSet.Unicode)]
    extern static IntPtr GetStdHandle(Handles handle);
     [DllImport("kernel32.dll", EntryPoint = "SetConsoleScreenBufferSize", SetLastError = true, CharSet = CharSet.Unicode)]
    extern static bool SetConsoleScreenBufferSize(IntPtr handle, Coord newSize);
     [DllImport("kernel32.dll", EntryPoint = "SetConsoleWindowInfo", SetLastError = true, CharSet = CharSet.Unicode)]
    extern static bool SetConsoleWindowInfo(IntPtr handle, bool absolute, ref SmallRect rect);
     
    private static void EcranConsole()
    {
     Console.Clear();
     Console.Title = "ConsoleTest : db4oClassLibrarySample";
     Coord coord = new Coord(0,0);
     SetConsoleScreenBufferSize(GetStdHandle(Handles.STD_OUTPUT), coord);
    SmallRect rect = new SmallRect(0, 0, Console.LargestWindowWidth - 1, Console.LargestWindowHeight - 1);
     SetConsoleWindowInfo(GetStdHandle(Handles.STD_OUTPUT), true, ref rect);
     Console.SetWindowPosition(0, 0);
     Console.SetWindowSize(Console.LargestWindowWidth,  Console.LargestWindowHeight);
    }
    

  2. #2
    Rédacteur
    Avatar de nico-pyright(c)
    Profil pro
    Inscrit en
    Octobre 2003
    Messages
    6 414
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2003
    Messages : 6 414
    Par défaut
    Salut Neguib,

    content de te revoir par ici

    voilà ce que je ferais :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
            [DllImport("kernel32.dll", SetLastError = true)]
            static extern IntPtr GetConsoleWindow();
            [DllImport("user32.dll")]
            static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);
            const UInt32 SWP_NOSIZE = 0x0001;
     
            static void Main(string[] args)
            {
                IntPtr hwnd = GetConsoleWindow();
                SetWindowPos(hwnd, IntPtr.Zero, 0, 0, 0, 0, SWP_NOSIZE);
            }

  3. #3
    Expert confirmé
    Avatar de neguib
    Profil pro
    Inscrit en
    Mai 2005
    Messages
    3 627
    Détails du profil
    Informations personnelles :
    Âge : 64
    Localisation : Suisse

    Informations forums :
    Inscription : Mai 2005
    Messages : 3 627
    Par défaut
    Bonsoir, cher nico-pyright
    Comme il m'est agréable de te lire.
    je te remercie pour ta réponse.
    Et comme les grans esprits se rencontrent, j'ai également cherché de mon côté et je reviens pour mettre ma question en .
    Le résultat est quasiment parfait avec ceci :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
     
    [DllImport("kernel32")]
    private static extern IntPtr GetConsoleWindow();
     
    [DllImport("user32")]
    private static extern Boolean GetClientRect(IntPtr hWnd, ref Rectangle rect);
     
    [DllImport("user32")]
    private static extern Boolean SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, Int32 x, Int32 y, Int32 cx, Int32 cy, Int32 flags);
     
    private static int STD_OUTPUT_HANDLE = -11;
    private static int SWP_NOZORDER = 0x4;
    private static int SWP_NOACTIVATE = 0x10;
     
    //Configurer la fenêtre de la Console
    private static void FenêtreConsole()
    {    
        //   - le titre
        Console.Title = "ConsoleTest : db4oClassLibrarySample";
     
        //   - la position
        Int32 x; Int32 y; Int32 width; Int32 height;
        GetWindowPosition(out x, out y, out width, out height);
        SetWindowPosition(x, y, width, height);
     
        //   - le taille
        Console.SetWindowSize(Console.LargestWindowWidth - 3, Console.LargestWindowHeight - 3);
    }
     
    private static void GetWindowPosition(out Int32 x, out Int32 y, out Int32 width, out Int32 height)
    {
        Rectangle rect = new Rectangle();
        GetClientRect(GetConsoleWindow(), ref rect);
        x = rect.Top;
        y = rect.Left;
        width = rect.Right - rect.Left;
        height = rect.Bottom - rect.Top;
    }
     
    private static void SetWindowPosition(Int32 x, Int32 y, Int32 width, Int32 height)
    {
        SetWindowPos(GetConsoleWindow(), IntPtr.Zero, x, y, width, height, SWP_NOZORDER | SWP_NOACTIVATE);
    }
    Voilà à bientôt

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. comment obtenir un polynome de regression
    Par evariste_galois dans le forum Mathématiques
    Réponses: 17
    Dernier message: 19/01/2007, 15h06
  2. Réponses: 5
    Dernier message: 18/01/2004, 16h25
  3. Comment obtenir l'heure du serveur avec flash ?
    Par Michaël dans le forum Flash
    Réponses: 9
    Dernier message: 23/12/2003, 17h50
  4. Comment obtenir la liste des paramètres d'une SP ?
    Par Le Gritche dans le forum MS SQL Server
    Réponses: 2
    Dernier message: 14/03/2003, 16h54

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo