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# Discussion :

Superposer deux fenetres


Sujet :

C#

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Futur Membre du Club
    Profil pro
    Inscrit en
    Février 2010
    Messages
    4
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2010
    Messages : 4
    Par défaut Superposer deux fenetres
    Bonsoir,

    J'ai besoin de superposer deux fenêtres (qui ne sont pas issues de mon application). Il faut qu'une fenêtre 2 reste toujours au dessus de fenetre 1 et suivent toutes ses actions. Quand on cache la fenetre 1 la fenetre 2 se cache aussi...

    J'ai mis au point un code C# en mode console, qui grace au DLL de la WinAPI me permet de faire quasiement ce que je souhaite, je seul problème est que lorsque l'on donne le focus sur la fenetre 1, la fenetre 2 passse derrière pour quelques seconde(le temps de faire un tour de boucle) et ce n'est pas bon pour moi j'aimerai que la fenetre 2 reste toujours devant et que la fenetre 1 reste cliquable ( ma fenetre 2 est transparente )

    De plus la fenetre 2 doit etre au dessus de la fenetre 1 mais pas au dessus des autres fenetres ( donc pas de Always In Front)...

    Voici mon code, vos idées sont les bienvenus :

    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
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
     
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Runtime.InteropServices;
    using System.Text.RegularExpressions;
     
    namespace winamax_winapi
    {
        class Program
        {
            #region WINApi function
     
            public const int WM_SYSCOMMAND = 0x0112;
            public const int SC_CLOSE = 0xF060;
     
     
            [DllImport("user32.dll")]
            public static extern bool SetForegroundWindow(IntPtr hWnd);
     
            [DllImport("user32.dll")]
            public static extern IntPtr GetForegroundWindow();
     
            [return: MarshalAs(UnmanagedType.Bool)]
            [DllImport("user32.dll", SetLastError = true)]
            private static extern bool GetWindowInfo(IntPtr hwnd, ref WINDOWINFO pwi);
     
            [DllImport("user32.dll", CharSet = CharSet.Auto)]
            public static extern int GetWindowText(HandleRef hWnd, StringBuilder lpString, int nMaxCount);
     
            [DllImport("user32.dll", SetLastError = true)]
            static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
     
            [DllImport("user32.dll", SetLastError = true)]
            [return: MarshalAs(UnmanagedType.Bool)]
            internal static extern bool GetWindowPlacement(IntPtr hWnd, out WINDOWPLACEMENT lpwndpl);
     
            [DllImport("user32.dll", SetLastError = true)]
            [return: MarshalAs(UnmanagedType.Bool)]
            static extern bool SetWindowPlacement(IntPtr hWnd, [In] ref WINDOWPLACEMENT lpwndpl);
     
            [DllImport("user32.dll")]
            [return: MarshalAs(UnmanagedType.Bool)]
            static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, SetWindowPosFlags uFlags);
     
            [DllImport("user32.dll")]
            public static extern int SendMessage(int hWnd, uint Msg, int wParam, int lParam);
     
            public delegate bool CallBackPtr(int hwnd, int lParam);
            private CallBackPtr callBackPtr;
     
            public class EnumReport
            {
                [DllImport("user32.dll")]
                public static extern int EnumWindows(CallBackPtr callPtr, int lPar);
                private delegate bool EnumWindowsProc(IntPtr hWnd, IntPtr lParam);
            }
            #endregion
     
            static void Main(string[] args)
            {
                String patternFenetre1 = "([0-9]*)#";
                Regex rgx = new Regex(patternFenetre1, RegexOptions.IgnoreCase);
     
     
                List<String> AllId = new List<String>();
     
                while (true)
                {
                    //On récupère la fenetre en front 
                    IntPtr windowForeground = GetForegroundWindow();
     
                    //On récupère le titre de cette fenetre
                    StringBuilder windowTitle = new StringBuilder(256);
                    GetWindowText(new HandleRef(null, windowForeground), windowTitle, windowTitle.Capacity);
     
                    // On regarde si le type de fenetre que l'on veut suivre est devant (foreground)
                    MatchCollection matches = rgx.Matches(windowTitle.ToString());
                    if (matches.Count > 0)
                    {
                        String identifiant = null;
                        // On selection l'identifiant de la fenetre 1 qui va nous permettre de trouver la fenetre 2
                        identifiant = windowTitle.ToString().Substring(windowTitle.ToString().IndexOf("("), windowTitle.ToString().IndexOf(")") - windowTitle.ToString().IndexOf("(") + 1);
     
                        //On check si la fenetre 2 correpondante est ouverte
                        IntPtr fenetre2Handle = WndSearcher.SearchForWindow("ApolloRuntimeContentWindow", identifiant);
                        if (fenetre2Handle != new IntPtr(0))
                        {
                            // On garde en mémoire le tournamentID
                            if (!AllId.Contains(identifiant))
                                AllId.Add(identifiant);
     
                            //On passe notre fenetre 2 devat
                            Boolean resultSetForeground = SetForegroundWindow(fenetre2Handle);
     
                            //Et On la place par dessus la fenetre 1
                            WINDOWPLACEMENT info = new WINDOWPLACEMENT();
                            GetWindowPlacement(windowForeground, out info);
                            info.NormalPosition.top -= 20;
     
                            SetWindowPlacement(fenetre2Handle, ref info);
                        }
                    }
                    //Si notre fenetre 1 n est pas devant
                    else
                    {
                        if (AllId.Count > 0)
                        {
                            //On boucle sur les ID en mémoire donc ouvert
                            foreach (String currentID in AllId)
                            {
                                IntPtr currentHandle = WndSearcher.SearchForWindow("ApolloRuntimeContentWindow", currentID);
     
                                #region Si ma fenetre 1 n'existe plus on ferme la fenetre 2 associée
                                if (currentHandle == new IntPtr(0))
                                {
                                    AllId.Remove(currentID);
     
                                    IntPtr currentFenetre2Handle = WndSearcher.SearchForWindow("ApolloRuntimeContentWindow", currentID);
                                    SendMessage(int.Parse(currentFenetre2Handle.ToString()), WM_SYSCOMMAND, SC_CLOSE, 0);
                                    break;
                                }
                                #endregion
     
                                #region Si elle existe mais pas en premier plan on la replace correctement par dessus la fenetre 1
                                else
                                {
                                    WINDOWPLACEMENT info = new WINDOWPLACEMENT();
                                    GetWindowPlacement(currentHandle, out info);
     
                                    IntPtr currentFenetre2Handle = WndSearcher.SearchForWindow("ApolloRuntimeContentWindow", currentID);
                                    SetWindowPlacement(currentFenetre2Handle, ref info);
                                }
                                #endregion
                            }
                        }
                    }
                    //Stop
                    System.Threading.Thread.Sleep(1300);
                }
            }
     
        }
     
     
     
     
        #region Struct
        struct Point
        {
            public int x;
            public int y;
     
            public override string ToString()
            {
     
                return (String.Format("({0}, {1})",
                  x, y));
            }
        }
        [Flags()]
        enum SetWindowPosFlags : uint
        {
            AsynchronousWindowPosition = 0x4000,
            DeferErase = 0x2000,
            DrawFrame = 0x0020,
            FrameChanged = 0x0020,
            HideWindow = 0x0080,
            DoNotActivate = 0x0010,
            DoNotCopyBits = 0x0100,
            IgnoreMove = 0x0002,
            DoNotChangeOwnerZOrder = 0x0200,
            DoNotRedraw = 0x0008,
            DoNotReposition = 0x0200,
            DoNotSendChangingEvent = 0x0400,
            IgnoreResize = 0x0001,
            IgnoreZOrder = 0x0004,
            ShowWindow = 0x0040,
        }
        [Serializable]
        [StructLayout(LayoutKind.Sequential)]
        internal struct WINDOWPLACEMENT
        {
            public int Length;
            public int Flags;
            public ShowWindowCommands ShowCmd;
            public Point MinPosition;
            public Point MaxPosition;
            public Rect NormalPosition;
            public static WINDOWPLACEMENT Default
            {
                get
                {
                    WINDOWPLACEMENT result = new WINDOWPLACEMENT();
                    result.Length = Marshal.SizeOf(result);
                    return result;
                }
            }
        }
        struct Rect
        {
            public int left;
            public int top;
            public int right;
            public int bottom;
     
            public override string ToString()
            {
                return (String.Format("({0}, {1})\n ({2}, {3})",
                       left, top, right, bottom));
            }
        }
     
        struct WindowPlacement
        {
            public uint length;
            public uint flags;
            public uint showCmd;
            public Point minPosition;
            public Point maxPosition;
            public Rect normalPosition;
     
            public override string ToString()
            {
                return (String.Format("min, max, normal:\n{0}\n{1}\n{2}", minPosition, maxPosition, normalPosition));
            }
        }
        enum ShowWindowCommands : int
        {
            Hide = 0,
            Normal = 1,
            ShowMinimized = 2,
            Maximize = 3, // is this the right value?
            ShowMaximized = 3,
            ShowNoActivate = 4,
            Show = 5,
            Minimize = 6,
            ShowMinNoActive = 7,
            ShowNA = 8,
            Restore = 9,
            ShowDefault = 10,
            ForceMinimize = 11
        }
        struct WINDOWINFO
        {
            public uint cbSize;
            public Rect rcWindow;
            public Rect rcClient;
            public uint dwStyle;
            public uint dwExStyle;
            public uint dwWindowStatus;
            public uint cxWindowBorders;
            public uint cyWindowBorders;
            public ushort atomWindowType;
            public ushort wCreatorVersion;
     
            public WINDOWINFO(Boolean? filler)
                : this()   // Allows automatic initialization of "cbSize" with "new WINDOWINFO(null/true/false)".
            {
                cbSize = (UInt32)(Marshal.SizeOf(typeof(WINDOWINFO)));
            }
        }
     
        [StructLayout(LayoutKind.Sequential)]
        struct TITLEBARINFO
        {
            public const int CCHILDREN_TITLEBAR = 5;
            public uint cbSize;
            public Rect rcTitleBar;
            [MarshalAs(UnmanagedType.ByValArray, SizeConst = CCHILDREN_TITLEBAR + 1)]
            public uint[] rgstate;
        }
        #endregion
     
        #region WndSearcher
        public class WndSearcher
        {
            public static IntPtr SearchForWindow(string wndclass, string title)
            {
                SearchData sd = new SearchData { Wndclass = wndclass, Title = title };
                EnumWindows(new EnumWindowsProc(EnumProc), ref sd);
                Console.WriteLine("__________________________________________________________________");
                return sd.hWnd;
            }
     
            public static bool EnumProc(IntPtr hWnd, ref SearchData data)
            {
                // Check classname and title 
                // This is different from FindWindow() in that the code below allows partial matches
                StringBuilder sb = new StringBuilder(1024);
                GetClassName(hWnd, sb, sb.Capacity);
                if (sb.ToString().StartsWith(data.Wndclass))
                {
                    sb = new StringBuilder(1024);
                    GetWindowText(hWnd, sb, sb.Capacity);
                    String currentResult = sb + "";
     
                    Console.WriteLine(currentResult);
     
                    if (currentResult.Contains(data.Title))
                    {
                        data.hWnd = hWnd;
                        return false;
                    }
                }
                return true;
            }
     
            public class SearchData
            {
                public string Wndclass;
                public string Title;
                public IntPtr hWnd;
            }
     
            private delegate bool EnumWindowsProc(IntPtr hWnd, ref SearchData data);
     
            [DllImport("user32.dll")]
            [return: MarshalAs(UnmanagedType.Bool)]
            private static extern bool EnumWindows(EnumWindowsProc lpEnumFunc, ref SearchData data);
     
            [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
            public static extern int GetClassName(IntPtr hWnd, StringBuilder lpClassName, int nMaxCount);
     
            [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
            public static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount);
        }
        #endregion
     
    }

    Merci d'avance pour votre aide précieux

  2. #2
    Membre chevronné
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2008
    Messages
    231
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : Finance

    Informations forums :
    Inscription : Avril 2008
    Messages : 231
    Par défaut
    Alors en dehors de la possibilité de faire ou de ne pas faire ce que tu demandes... ça sert à quoi ? si tu veux pas qu'on voit la seconde fenêtre et bien tu l'a rend visible = false et suivant un comportement tu l'affiches ou non ...
    c'est plus simple quand même

  3. #3
    Futur Membre du Club
    Profil pro
    Inscrit en
    Février 2010
    Messages
    4
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2010
    Messages : 4
    Par défaut
    La fenetre qui est positionner par dessus est transparente a 90%.

  4. #4
    Membre chevronné
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2008
    Messages
    231
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : Finance

    Informations forums :
    Inscription : Avril 2008
    Messages : 231
    Par défaut
    Je suis désolé mais je ne vois pas le principe de ce que tu veux faire ...
    Peux tu nous dire clairement ce que tu voudrais faire non pas techniquement mais fonctionnellement.

Discussions similaires

  1. superpose deux fenetre
    Par beraaa dans le forum AWT/Swing
    Réponses: 4
    Dernier message: 13/01/2008, 08h17
  2. Imbriquer deux fenêtres ?
    Par Eldered dans le forum wxWidgets
    Réponses: 3
    Dernier message: 16/05/2006, 23h32
  3. [css]superposer deux DIVs / opacity
    Par narkhor dans le forum Mise en page CSS
    Réponses: 1
    Dernier message: 13/03/2006, 02h38
  4. superposer deux images ?
    Par terminoz dans le forum Balisage (X)HTML et validation W3C
    Réponses: 7
    Dernier message: 20/08/2005, 09h04
  5. FOP: Superposer deux <fo:external-graphic>
    Par JeanLeDébutant dans le forum XML/XSL et SOAP
    Réponses: 7
    Dernier message: 14/06/2005, 15h44

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