Windows Azure Cloud Storage ermöglicht es Ihnen bereits ab 0,10€ pro GB/Monat die Vorteile der Cloud zu nutzen.
Willkommen bei dotnet-snippets.de! Snippet hinzufügen Login Registrieren
Snippets in der Datenbank: 1551 | Anzahl registrierter User: 1841 | Besucher online: 170
Hauptmenü
Home
Top Ten
Zufälliger Snippet
FAQs
.NET Community
dotnet-forum.de
dotnet-kicks.de
Social

RSS Feeds
Rss Alle Snippets
Rss C#
Rss VB.NET
Rss C++
Rss ASP.NET
Partner
Member of Microsoft Community Leader/Insider Program (CLIP)

Fenster wirklich in den Vordergrund des Desktops bringen


Autor: Rüdiger Vossel
Sprache: C#
Bewertung:
noch nicht bewertet
Anzahl der Aufrufe: 15252
  
Kick it on dotnet-kicks.de  

Beschreibung:

Diese Funktion bringt ein Fenster (Übergabeparameter = System.Windows.Forms.Form) in den Vordergrund des Desktops, auch wenn sich andere Programme zur Zeit im Vordergrund befinden.

using System.Runtime.InteropServices;


Achso .. Lauffähig ab Framework 2


Abgelegt unter: Fenster, Vordergrund, SetForegroundWindow, AttachThreadInput, GetForegroundWindow, GetWindowThreadProcessId, Desktop.



C#
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
[DllImport("User32.dll")]
static extern bool SetForegroundWindow(IntPtr hWnd);

[DllImport("User32.dll")]
public static extern int AttachThreadInput(IntPtr idAttach, IntPtr idAttachTo, bool fAttach);

[DllImport("User32.dll")]
public static extern IntPtr GetForegroundWindow();

[DllImport("User32.dll")]
public static extern IntPtr GetWindowThreadProcessId(IntPtr hwnd, IntPtr lpdwProcessId);

public static void SetForegroundWindowEx(Form window)
{
	IntPtr hndl = window.Handle;
	IntPtr threadID1 = GetWindowThreadProcessId(GetForegroundWindow(), IntPtr.Zero);
	IntPtr threadID2 = GetWindowThreadProcessId(hndl, IntPtr.Zero);
	window.TopMost = true;

	if (threadID1 == threadID2)
	{
		SetForegroundWindow(hndl);
	}
	else
	{
		AttachThreadInput(threadID2, threadID1, true);
		SetForegroundWindow(hndl);;
		AttachThreadInput(threadID2, threadID1, false);
	}
}
Sie haben Fragen zu diesem Snippet oder brauchen Hilfe bei der .NET Entwicklung?
Freundliche und kompetente Entwickler helfen Ihnen gern weiter im Forum für .NET Entwicklung.



Kommentare:
(Zum Schreiben von Kommentaren bitte anmelden.)



schlecht sehr gut
1 2 3 4 5 6 7 8 9 10
Nur angemeldete User können Snippets bewerten.