728x90
반응형
728x170
▶ MainWindow.xaml
<Window x:Class="TestProject.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
WindowStartupLocation="CenterScreen"
Width="800"
Height="600"
WindowStyle="None"
AllowsTransparency="True"
BorderThickness="1"
BorderBrush="Black"
Background="#12000000"
FontFamily="나눔고딕코딩"
FontSize="16">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock Grid.Row="0"
HorizontalAlignment="Left"
VerticalAlignment="Center"
Margin="5"
Foreground="RoyalBlue">
반투명 윈도우 사용하기
</TextBlock>
<Button Name="closeButton" Grid.Row="2"
HorizontalAlignment="Right"
VerticalAlignment="Center"
Margin="5"
Width="100"
Height="30"
Content="종료" />
</Grid>
</Window>
728x90
▶ MainWindow.xaml.cs
using System;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Interop;
namespace TestProject
{
/// <summary>
/// 메인 윈도우
/// </summary>
public partial class MainWindow : Window
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Import
////////////////////////////////////////////////////////////////////////////////////////// Static
//////////////////////////////////////////////////////////////////////////////// Private
#region 윈도우 합성 어트리뷰트 설정하기 - SetWindowCompositionAttribute(windowHandle, data)
/// <summary>
/// 윈도우 합성 어트리뷰트 설정하기
/// </summary>
/// <param name="windowHandle">윈도우 핸들</param>
/// <param name="data">데이터</param>
/// <returns>처리 결과</returns>
[DllImport("user32.dll")]
private static extern int SetWindowCompositionAttribute(IntPtr windowHandle, ref WindowCompositionAttributeData data);
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 생성자 - MainWindow()
/// <summary>
/// 생성자
/// </summary>
public MainWindow()
{
InitializeComponent();
Loaded += Window_Loaded;
this.closeButton.Click += closeButton_Click;
}
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Private
//////////////////////////////////////////////////////////////////////////////// Event
#region 윈도우 로드시 처리하기 - Window_Loaded(sender, e)
/// <summary>
/// 윈도우 로드시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void Window_Loaded(object sender, RoutedEventArgs e)
{
ApplyGlassEffect(this);
}
#endregion
#region 종료 버튼 클릭시 처리하기 - closeButton_Click(sender, e)
/// <summary>
/// 종료 버튼 클릭시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void closeButton_Click(object sender, RoutedEventArgs e)
{
Close();
}
#endregion
//////////////////////////////////////////////////////////////////////////////// Function
#region 글래스 효과 적용하기 - ApplyGlassEffect(window)
/// <summary>
/// 글래스 효과 적용하기
/// </summary>
/// <param name="window">윈도우</param>
private void ApplyGlassEffect(Window window)
{
WindowInteropHelper helper = new WindowInteropHelper(window);
AccentPolicy accentPolicy = new AccentPolicy();
accentPolicy.AccentState = AccentState.ACCENT_ENABLE_BLURBEHIND;
int accentPolicySize = Marshal.SizeOf(accentPolicy);
IntPtr memoryHandle = Marshal.AllocHGlobal(accentPolicySize);
Marshal.StructureToPtr(accentPolicy, memoryHandle, false);
WindowCompositionAttributeData data = new WindowCompositionAttributeData();
data.Attribute = WindowCompositionAttribute.WCA_ACCENT_POLICY;
data.Data = memoryHandle;
data.DataSize = accentPolicySize;
SetWindowCompositionAttribute(helper.Handle, ref data);
Marshal.FreeHGlobal(memoryHandle);
}
#endregion
}
}
728x90
반응형
그리드형(광고전용)
'C# > WPF' 카테고리의 다른 글
[C#/WPF] 가상 키보드 사용하기 (0) | 2019.06.23 |
---|---|
[C#/WPF] BlurEffect 클래스 사용하기 (0) | 2019.06.22 |
[C#/WPF] 반투명 윈도우 사용하기 (0) | 2019.06.16 |
[C#/WPF] 실시간 스트리밍 프토로콜(RTSP)을 사용해 동영상 재생하기 (0) | 2019.06.15 |
[C#/WPF] 웹 카메라 사용하기 (0) | 2019.06.14 |
[C#/WPF] 반투명 윈도우 사용하기 (0) | 2019.06.10 |
[C#/WPF] TreeView 클래스 : 데이터 바인딩시 부모 노드 사전 설정하기 (0) | 2019.06.02 |
[C#/WPF] TreeView 클래스 : ItemContainerGenerator 속성을 사용해 바인딩 데이터의 트리 노드 구하기 (0) | 2019.06.02 |
[C#/WPF] ComponentDispatcher 클래스 : ThreadFilterMessage 정적 이벤트를 사용해 윈도우 이벤트 가로채기 (0) | 2019.06.02 |
[C#/WPF] HwndSource 클래스 : AddHook 메소드를 사용해 윈도우 이벤트 가로채기 (0) | 2019.06.02 |
[C#/WPF] Dispatcher 클래스 : UnhandledExceptionFilter/UnhandledException 이벤트를 사용해 비정상 종료 방지하기 (0) | 2019.06.02 |
댓글을 달아 주세요