Comment afficher une fenêtre de premier plan à l'aide de c#?

Je suis en train d'essayer d'apporter une fenêtre de premier plan. Je suis l'aide de ce code. Mais sa ne fonctionne pas. Quelqu'un pourrait s'il vous plaît aider?

ShowWindowAsync(wnd.hWnd, SW_SHOW);

SetForegroundWindow(wnd.hWnd);
//Code from Karl E. Peterson, www.mvps.org/vb/sample.htm
//Converted to Delphi by Ray Lischner
//Published in The Delphi Magazine 55, page 16
//Converted to C# by Kevin Gale
IntPtr foregroundWindow = GetForegroundWindow();
IntPtr Dummy = IntPtr.Zero;

uint foregroundThreadId = GetWindowThreadProcessId(foregroundWindow, Dummy);
uint thisThreadId = GetWindowThreadProcessId(wnd.hWnd, Dummy);

 if (AttachThreadInput(thisThreadId, foregroundThreadId, true))
 {
    BringWindowToTop(wnd.hWnd); //IE 5.5 related hack
    SetForegroundWindow(wnd.hWnd);
    AttachThreadInput(thisThreadId, foregroundThreadId, false);
 }

 if (GetForegroundWindow() != wnd.hWnd)
 {
     //Code by Daniel P. Stasinski
     //Converted to C# by Kevin Gale
    IntPtr Timeout = IntPtr.Zero;
    SystemParametersInfo(SPI_GETFOREGROUNDLOCKTIMEOUT, 0, Timeout, 0);
    SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, Dummy, SPIF_SENDCHANGE);
    BringWindowToTop(wnd.hWnd); //IE 5.5 related hack
    SetForegroundWindow(wnd.hWnd);
    SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, Timeout, SPIF_SENDCHANGE);
 }

Code Expliqué

Faire une fenêtre de la fenêtre de premier plan
exige plus que juste l'appel de la
SetForegroundWindow API. Vous devez
d'abord déterminer le thread de premier plan
et le joindre à votre fenêtre, à l'aide de
AttachThreadInput, puis d'appeler
SetForegroundWindow. De cette façon, ils peuvent
part des entrées.

J'ai d'abord appel à GetForegroundWindow
obtenir le handle de l'actuel
fenêtre de premier plan. Puis, quelques appels à
GetWindowThreadProcessId récupérer le
les threads associés avec le courant
de premier plan de la fenêtre et de la fenêtre, je
voulez apporter à l'avant-plan. Si
ces fils sont même un simple
appel à SetForegroundWindow est tout
ce qui est nécessaire. Sinon, l'
thread de premier plan est joint à l'
fenêtre que je porte à l'avant
et détaché de ce qui était l'actuel
fenêtre de premier plan. L'
AttachThreadInput API gère cela.

Du contenu provenant de ici
Merci.

InformationsquelleAutor Nikil | 2011-02-01