トップ回答者
WPFアプリでタイトルバーのみの表示方法?

質問
回答
-
FullTrust で動かしてもいいのなら,
よくある SetWindowLong (Windows API)でやるパターンですけどね。
そうでない場合は,簡単にはやれないでしょうね。たぶん。
(http://pavanpodila.spaces.live.com/blog/cns!9C9E888164859398!345.entry
にあるような "自分で描画&イベント処理" になるような気がします)
cf.
WindowInteropHelper 経由でウィンドウハンドルを取得できるので,
後は,検索などで見つかるSetWindowLong/SetWindowLongPtrパターンと同じです。
Code Snippetusing System;
using System.Windows;
using System.Runtime.InteropServices;
using System.Windows.Interop;namespace MyWpfControlBoxTest
{
/// <summary>
/// Interaction logic for Window1.xaml
/// </summary>
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
}public override void OnApplyTemplate()
{
base.OnApplyTemplate();
WindowInteropHelper helper = new WindowInteropHelper(this);
SetWindowStyle(helper.Handle, GetWindowStyle(helper.Handle) & ~WindowStyles.WS_SYSMENU);
}public static readonly Int32 GWL_STYLE = -16;
public static readonly UInt32 WS_CHILD = 0x40000000;[Flags]
internal enum WindowStyles : uint
{
WS_OVERLAPPED = 0x00000000,
WS_POPUP = 0x80000000,
WS_CHILD = 0x40000000,
WS_MINIMIZE = 0x20000000,
WS_VISIBLE = 0x10000000,
WS_DISABLED = 0x08000000,
WS_CLIPSIBLINGS = 0x04000000,
WS_CLIPCHILDREN = 0x02000000,
WS_MAXIMIZE = 0x01000000,
WS_BORDER = 0x00800000,
WS_DLGFRAME = 0x00400000,
WS_VSCROLL = 0x00200000,
WS_HSCROLL = 0x00100000,
WS_SYSMENU = 0x00080000,
WS_THICKFRAME = 0x00040000,
WS_GROUP = 0x00020000,
WS_TABSTOP = 0x00010000,WS_MINIMIZEBOX = 0x00020000,
WS_MAXIMIZEBOX = 0x00010000,WS_CAPTION = WS_BORDER | WS_DLGFRAME,
WS_TILED = WS_OVERLAPPED,
WS_ICONIC = WS_MINIMIZE,
WS_SIZEBOX = WS_THICKFRAME,
WS_TILEDWINDOW = WS_OVERLAPPEDWINDOW,WS_OVERLAPPEDWINDOW = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX,
WS_POPUPWINDOW = WS_POPUP | WS_BORDER | WS_SYSMENU,
WS_CHILDWINDOW = WS_CHILD,
}
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
internal static extern IntPtr SetParent(IntPtr hWnd, IntPtr hWndParent);
[DllImport("user32.dll")]
internal static extern WindowStyles GetWindowLong(IntPtr hWnd, Int32 nIndex);
[DllImport("user32.dll")]
internal static extern UInt32 SetWindowLong(IntPtr hWnd, Int32 nIndex, UInt32 dwNewLong);internal WindowStyles GetWindowStyle(IntPtr hWnd)
{
return (WindowStyles)GetWindowLong(hWnd, GWL_STYLE);
}internal void SetWindowStyle(IntPtr hWnd, WindowStyles windowStyle)
{
SetWindowLong(hWnd, GWL_STYLE, (UInt32)windowStyle);
}
}
}// GetWindowStyle でラップする感じのところは,
// http://shevaspace.spaces.live.com/blog/cns!FD9A0F1F8DD06954!522.entry
// を参考にしています。
すべての返信
-
FullTrust で動かしてもいいのなら,
よくある SetWindowLong (Windows API)でやるパターンですけどね。
そうでない場合は,簡単にはやれないでしょうね。たぶん。
(http://pavanpodila.spaces.live.com/blog/cns!9C9E888164859398!345.entry
にあるような "自分で描画&イベント処理" になるような気がします)
cf.
WindowInteropHelper 経由でウィンドウハンドルを取得できるので,
後は,検索などで見つかるSetWindowLong/SetWindowLongPtrパターンと同じです。
Code Snippetusing System;
using System.Windows;
using System.Runtime.InteropServices;
using System.Windows.Interop;namespace MyWpfControlBoxTest
{
/// <summary>
/// Interaction logic for Window1.xaml
/// </summary>
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
}public override void OnApplyTemplate()
{
base.OnApplyTemplate();
WindowInteropHelper helper = new WindowInteropHelper(this);
SetWindowStyle(helper.Handle, GetWindowStyle(helper.Handle) & ~WindowStyles.WS_SYSMENU);
}public static readonly Int32 GWL_STYLE = -16;
public static readonly UInt32 WS_CHILD = 0x40000000;[Flags]
internal enum WindowStyles : uint
{
WS_OVERLAPPED = 0x00000000,
WS_POPUP = 0x80000000,
WS_CHILD = 0x40000000,
WS_MINIMIZE = 0x20000000,
WS_VISIBLE = 0x10000000,
WS_DISABLED = 0x08000000,
WS_CLIPSIBLINGS = 0x04000000,
WS_CLIPCHILDREN = 0x02000000,
WS_MAXIMIZE = 0x01000000,
WS_BORDER = 0x00800000,
WS_DLGFRAME = 0x00400000,
WS_VSCROLL = 0x00200000,
WS_HSCROLL = 0x00100000,
WS_SYSMENU = 0x00080000,
WS_THICKFRAME = 0x00040000,
WS_GROUP = 0x00020000,
WS_TABSTOP = 0x00010000,WS_MINIMIZEBOX = 0x00020000,
WS_MAXIMIZEBOX = 0x00010000,WS_CAPTION = WS_BORDER | WS_DLGFRAME,
WS_TILED = WS_OVERLAPPED,
WS_ICONIC = WS_MINIMIZE,
WS_SIZEBOX = WS_THICKFRAME,
WS_TILEDWINDOW = WS_OVERLAPPEDWINDOW,WS_OVERLAPPEDWINDOW = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX,
WS_POPUPWINDOW = WS_POPUP | WS_BORDER | WS_SYSMENU,
WS_CHILDWINDOW = WS_CHILD,
}
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
internal static extern IntPtr SetParent(IntPtr hWnd, IntPtr hWndParent);
[DllImport("user32.dll")]
internal static extern WindowStyles GetWindowLong(IntPtr hWnd, Int32 nIndex);
[DllImport("user32.dll")]
internal static extern UInt32 SetWindowLong(IntPtr hWnd, Int32 nIndex, UInt32 dwNewLong);internal WindowStyles GetWindowStyle(IntPtr hWnd)
{
return (WindowStyles)GetWindowLong(hWnd, GWL_STYLE);
}internal void SetWindowStyle(IntPtr hWnd, WindowStyles windowStyle)
{
SetWindowLong(hWnd, GWL_STYLE, (UInt32)windowStyle);
}
}
}// GetWindowStyle でラップする感じのところは,
// http://shevaspace.spaces.live.com/blog/cns!FD9A0F1F8DD06954!522.entry
// を参考にしています。