<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      記錄一下WPF 調用 窗口自帶的Hide() 方法,用 Win32 的ShowWindow 顯示窗口異常的問題

      最近有小伙伴的應用里邊,需要跨進程的方式,顯示隱藏窗口。

      在WPF 自身的應用中,使用的最多的就是 窗口自帶的 Hide()Show() 方法

      1、創建一個HideWindow的窗口,添加按鈕,在點擊按鈕的時候,調用Hide()方法。

      image

       

      public partial class MainWindow : Window
      {
          public MainWindow()
          {
              InitializeComponent();
          }
      
      
          private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
          {
               this.Hide();
          }
      }

       

      2、創建一個激活的窗口,添加按鈕,在點擊按鈕的時候,將HideWindow的窗口激活并顯示

      image

       

      public partial class MainWindow : Window
      {
          public MainWindow()
          {
              InitializeComponent();
          }
      
      
          [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
          public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
      
          [DllImport("user32.dll")]
          private static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
      
          [DllImport("user32.dll")]
          private static extern bool SetForegroundWindow(IntPtr hWnd);
      
      
          [DllImport("user32.dll")]
          private static extern bool SetActiveWindow(IntPtr hWnd);
      
          [DllImport("user32.dll", SetLastError = true)]
          private static extern bool IsWindowVisible(IntPtr hWnd);
          [DllImport("user32.dll", SetLastError = true)]
          private static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter,
              int X, int Y, int cx, int cy, uint uFlags);
          // 窗口顯示狀態常量
          private const int SW_SHOWNOACTIVATE = 4;  // 顯示窗口但不激活
          private const int SW_SHOWNA = 8;           // 顯示窗口但不激活
          private const int SW_SHOWMINIMIZED = 2;    // 顯示最小化窗口
       
          // 窗口定位常量
          private const uint SWP_NOACTIVATE = 0x0010;
          private const uint SWP_NOZORDER = 0x0004;
          private const uint SWP_NOSIZE = 0x0001;
          private const uint SWP_NOMOVE = 0x0002;
          private const uint SWP_SHOWWINDOW = 0x0040;
          // 定義窗口狀態常量
          private const int SW_RESTORE = 9; // 激活并顯示窗口。如果窗口最小化或最大化,系統將其還原到原始大小和位置。
      
          private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
          {
              var intptr = FindWindow(null, "HideWindow");
      
              if (intptr != IntPtr.Zero)
              { 
                  var isVisible = IsWindowVisible(intptr);
                  var showResult = ShowWindow(intptr, SW_RESTORE);
      
                  //uint flags = SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOSIZE | SWP_NOMOVE | SWP_SHOWWINDOW;
                  //SetWindowPos(intptr, IntPtr.Zero, 0, 0, 0, 0, flags);
      
                  isVisible = IsWindowVisible(intptr);
                  var setResult = SetForegroundWindow(intptr);
              }
      
          }
      }

      結果如下:

      在設置ShowWindow的方法,返回的是False,并且HideWindow的窗口是黑屏的

      image

       

      image

       

       解決方法:

      1、修改HideWindow 窗口的隱藏方式:

      通過調用Win32的  ShowWindow(handle, SW_Hide); 

       public partial class MainWindow : Window
       {
           public MainWindow()
           {
               InitializeComponent();
           }
      
      
           private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
           {
               Win32Hide();
               // this.Hide();
           }
      
           private void Win32Hide()
           {
               var handle = new WindowInteropHelper(this).Handle;
      
               ShowWindow(handle, SW_Hide);
           }
      
           private int SW_Hide = 0;
      
           [DllImport("user32.dll")]
           private static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
       }

      2、ActiveWindow 的窗口的方法保持不變

      結果如下:

      ActiveWindow 的 窗口var showResult = ShowWindow(intptr, SW_RESTORE); 返回之為True,并且窗口可以激活并顯示

      image

      image

       

      代碼Demo 鏈接 :wutangyuan/wutyDemo: Demo代碼備份

      posted @ 2025-08-09 22:37  wuty007  閱讀(81)  評論(0)    收藏  舉報
      主站蜘蛛池模板: 97人妻中文字幕总站| 无码一区二区三区视频| 漂亮人妻中文字幕丝袜| 亚洲大尺度无码专区尤物| 亚洲熟少妇一区二区三区| 真实国产乱子伦视频| 亚洲精品成人综合色在线| 国产AV影片麻豆精品传媒| 国产精品久久久天天影视| 中文字幕成熟丰满人妻| 欧美日韩一线| 蜜臀精品视频一区二区三区| 狠狠躁夜夜躁人人爽天天5| 国产日韩av二区三区| 国产成人精品久久一区二区 | 18禁黄无遮挡网站免费| 精品国产午夜福利在线观看| 国产在线一区二区不卡| 国产999久久高清免费观看| 不卡在线一区二区三区视频| 中文字字幕在线中文乱码| 丝袜老师办公室里做好紧好爽| 国产伦码精品一区二区| 亚洲欧美日韩在线码| 亚洲精品一区二区妖精| 小污女小欲女导航| 精品人妻伦一二三区久久| www夜片内射视频日韩精品成人| 女人喷水高潮时的视频网站| 免费观看在线A级毛片| 国产亚洲精品久久77777| 国产美女MM131爽爽爽| 国产乱色国产精品免费视频| 亚洲最大成人av免费看| 性高湖久久久久久久久| 日韩精品中文字一区二区| 久久av高潮av喷水av无码| 国产美女久久精品香蕉| 漂亮人妻中文字幕丝袜| 亚洲av成人免费在线| 免费看亚洲一区二区三区|