VisualStudio/WPF

[WPF] Win32 api 사용하여 윈도우 창 제어하기 max창 드레그 및 축소화

usingsystem 2023. 1. 9. 15:35
728x90
   <!--Control bar-->
                    <StackPanel x:Name="pnlControlBar"
                                Grid.Row="0"
                                Orientation="Horizontal"
                                FlowDirection="RightToLeft"
                                Background="Transparent"
                                Margin="0 0 5 0"
                                MouseLeftButtonDown="pnlControlBar_MouseLeftButtonDown"
                                MouseEnter="pnlControlBar_MouseEnter">
                    </StackPanel>
 public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        [DllImport("user32.dll")]
        public static extern IntPtr SendMessage(IntPtr hWnd, int wMsg, int wParam, int lParam);
        private void pnlControlBar_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            WindowInteropHelper helper = new WindowInteropHelper(this);
            SendMessage(helper.Handle, 161, 2, 0);

            //DragMove();
        }

        private void pnlControlBar_MouseEnter(object sender, MouseEventArgs e)
        {
            this.MaxHeight = SystemParameters.MaximizedPrimaryScreenHeight;
        }
    }

pnlControlBar_MouseEnter - 사용자마다 화면의 크기가 다르기고 듀얼 모니터를 사용하기 때문에 enter가 일어날때마다 해당 화면의 max 사이즈를 알려준다.

 

728x90