अपडेट करें:
@Donovan के अनुसार, आधुनिक दिन WPF मूल रूप से, सेटिंग के माध्यम से ShowInTaskbar="False"और Visibility="Hidden"XAML में इसका समर्थन करता
है। (मैंने अभी तक इसका परीक्षण नहीं किया है, लेकिन फिर भी टिप्पणी की दृश्यता को टक्कर देने का फैसला किया है)
मूल उत्तर:
Win32 API में कार्य स्विचर से विंडो छिपाने के दो तरीके हैं:
WS_EX_TOOLWINDOWविस्तारित विंडो शैली जोड़ने के लिए - यह सही तरीका है।
- इसे दूसरी विंडो का चाइल्ड विंडो बनाने के लिए।
दुर्भाग्य से, WPF Win32 के रूप में विंडो शैली पर लचीले नियंत्रण का समर्थन नहीं करता है, इस प्रकार WindowStyle=ToolWindowडिफ़ॉल्ट WS_CAPTIONऔर WS_SYSMENUशैलियों के साथ एक विंडो समाप्त हो जाती है , जिसके कारण यह एक कैप्शन और एक बंद बटन होता है। दूसरी ओर, आप सेटिंग करके इन दो शैलियों को हटा सकते हैं WindowStyle=None, हालांकि यह WS_EX_TOOLWINDOWविस्तारित शैली सेट नहीं करेगा और विंडो को कार्य स्विचर से छिपाया नहीं जाएगा।
WPF विंडो को WindowStyle=Noneउस कार्य स्विचर से भी छिपाया जाता है, जिसमें से कोई दो तरीके हो सकते हैं:
- ऊपर दिए गए सैंपल कोड के साथ जाएं और खिड़की को एक छोटे से छिपे हुए उपकरण की खिड़की का बच्चा बनाएं
WS_EX_TOOLWINDOWविस्तारित शैली में विंडो शैली को भी संशोधित करें ।
मैं व्यक्तिगत रूप से दूसरे दृष्टिकोण को पसंद करता हूं। फिर फिर से, मैं कुछ उन्नत सामान करता हूं जैसे कि क्लाइंट क्षेत्र में ग्लास का विस्तार करना और वैसे भी कैप्शन में WPF ड्राइंग को सक्षम करना, इसलिए थोड़ा सा इंटरॉप एक बड़ी समस्या नहीं है।
यहाँ Win32 इंटरॉप सॉल्यूशन दृष्टिकोण के लिए नमूना कोड है। सबसे पहले, XAML हिस्सा:
<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Height="300" Width="300"
ShowInTaskbar="False" WindowStyle="None"
Loaded="Window_Loaded" >
कुछ भी नहीं यहाँ फैंसी, हम सिर्फ WindowStyle=Noneऔर साथ एक खिड़की की घोषणा करते हैं ShowInTaskbar=False। हम लोड की गई घटना में एक हैंडलर भी जोड़ते हैं जहां हम विस्तारित विंडो शैली को संशोधित करेंगे। हम उस काम को कंस्ट्रक्टर में नहीं कर सकते हैं, क्योंकि उस बिंदु पर अभी तक कोई विंडो हैंडल नहीं है। ईवेंट हैंडलर स्वयं बहुत सरल है:
private void Window_Loaded(object sender, RoutedEventArgs e)
{
WindowInteropHelper wndHelper = new WindowInteropHelper(this);
int exStyle = (int)GetWindowLong(wndHelper.Handle, (int)GetWindowLongFields.GWL_EXSTYLE);
exStyle |= (int)ExtendedWindowStyles.WS_EX_TOOLWINDOW;
SetWindowLong(wndHelper.Handle, (int)GetWindowLongFields.GWL_EXSTYLE, (IntPtr)exStyle);
}
और Win32 इंटरॉप घोषणाएं। मैंने एनम से सभी अनावश्यक शैलियों को हटा दिया है, बस यहाँ नमूना कोड रखने के लिए। इसके अलावा, दुर्भाग्य से SetWindowLongPtrप्रवेश बिंदु विंडोज एक्सपी पर user32.dll में नहीं मिला है, इसलिए SetWindowLongइसके बजाय कॉल को रूट करने के साथ चाल ।
#region Window styles
[Flags]
public enum ExtendedWindowStyles
{
// ...
WS_EX_TOOLWINDOW = 0x00000080,
// ...
}
public enum GetWindowLongFields
{
// ...
GWL_EXSTYLE = (-20),
// ...
}
[DllImport("user32.dll")]
public static extern IntPtr GetWindowLong(IntPtr hWnd, int nIndex);
public static IntPtr SetWindowLong(IntPtr hWnd, int nIndex, IntPtr dwNewLong)
{
int error = 0;
IntPtr result = IntPtr.Zero;
// Win32 SetWindowLong doesn't clear error on success
SetLastError(0);
if (IntPtr.Size == 4)
{
// use SetWindowLong
Int32 tempResult = IntSetWindowLong(hWnd, nIndex, IntPtrToInt32(dwNewLong));
error = Marshal.GetLastWin32Error();
result = new IntPtr(tempResult);
}
else
{
// use SetWindowLongPtr
result = IntSetWindowLongPtr(hWnd, nIndex, dwNewLong);
error = Marshal.GetLastWin32Error();
}
if ((result == IntPtr.Zero) && (error != 0))
{
throw new System.ComponentModel.Win32Exception(error);
}
return result;
}
[DllImport("user32.dll", EntryPoint = "SetWindowLongPtr", SetLastError = true)]
private static extern IntPtr IntSetWindowLongPtr(IntPtr hWnd, int nIndex, IntPtr dwNewLong);
[DllImport("user32.dll", EntryPoint = "SetWindowLong", SetLastError = true)]
private static extern Int32 IntSetWindowLong(IntPtr hWnd, int nIndex, Int32 dwNewLong);
private static int IntPtrToInt32(IntPtr intPtr)
{
return unchecked((int)intPtr.ToInt64());
}
[DllImport("kernel32.dll", EntryPoint = "SetLastError")]
public static extern void SetLastError(int dwErrorCode);
#endregion