日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

win7下 窗体玻璃效果的实现和WindowStyle None模式下的移动 wpf

發布時間:2025/3/14 编程问答 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 win7下 窗体玻璃效果的实现和WindowStyle None模式下的移动 wpf 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

這些技術在上一篇文章的介紹的軟件里有用到,現在單獨摘出來說明一下。

添加 using System.Runtime.InteropServices;

[StructLayout(LayoutKind.Sequential)]
public struct MARGINS
{
public int cxLeftWidth;
public int cxRightWidth;
public int cyTopHeight;
public int cyBottomHeight;
}
#region 引用 Dll
[DllImport("DwmApi.dll")] //玻璃
public static extern int DwmExtendFrameIntoClientArea(IntPtr hwnd, ref MARGINS pMarInset);
[DllImport("user32.dll", EntryPoint = "SendMessage")]// 移動
public static extern int SendMessage(int hWnd, int wMsg, int wParam, int lParam);
[DllImport("user32.dll", EntryPoint = "ReleaseCapture")]
public static extern int ReleaseCapture();
public const int WM_SysCommand = 0x0112;
public const int SC_MOVE = 0xF012;

#endregion

public MainWindow()
{
InitializeComponent();

this.Background = Brushes.Transparent;
ExtendAeroGlass(this);

}

private void ExtendAeroGlass(Window window)
{
try
{
// 為WPF程序獲取窗口句柄
IntPtr mainWindowPtr = new WindowInteropHelper(window).Handle;
HwndSource mainWindowSrc = HwndSource.FromHwnd(mainWindowPtr);
mainWindowSrc.CompositionTarget.BackgroundColor = Colors.Transparent;
// 設置Margins
MARGINS margins = new MARGINS();

// 擴展Aero Glass
margins.cxLeftWidth = -1;
margins.cxRightWidth = -1;
margins.cyTopHeight = -1;
margins.cyBottomHeight = -1;

int hr = DwmExtendFrameIntoClientArea(mainWindowSrc.Handle, ref margins);
if (hr < 0)
{
checkBox1.IsChecked = false;
MessageBox.Show("玻璃效果加載失敗!");
}
}
catch (DllNotFoundException)
{
Application.Current.MainWindow.Background = Brushes.White;
}
}
private void Window_MouseDown(object sender, MouseButtonEventArgs e) //鼠標按下時,移動
{
IntPtr mainWindowPtr = new WindowInteropHelper(this).Handle;
HwndSource mainWindowSrc = HwndSource.FromHwnd(mainWindowPtr);
ReleaseCapture();
SendMessage(mainWindowSrc.Handle.ToInt32(), WM_SysCommand, SC_MOVE, 0);
}

完成 。。

轉載于:https://www.cnblogs.com/wxdtk1989/archive/2011/08/11/2135383.html

總結

以上是生活随笔為你收集整理的win7下 窗体玻璃效果的实现和WindowStyle None模式下的移动 wpf的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。