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 : 65
    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 : 65
    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