WPF 精修篇 调用Win32Api

2021-01-23 00:14

阅读:737

标签:filename   form   data-   ram   tps   func   ber   rgs   div   

原文:WPF 精修篇 调用Win32Api

技术图片

栗子是 调用WIn32API 让窗口最前 

后台代码

  1. [DllImport("user32.dll")]
  2. private static extern bool SetForegroundWindow(IntPtr hWnd);
  3. //
  4. Process process = null;
  5. private void OPenButton_Click(object sender, RoutedEventArgs e)
  6. {
  7. process = new Process();
  8. process.StartInfo.FileName = "iexplore.exe";
  9. process.StartInfo.Arguments = Text_Path.Text;
  10. process.Start();
  11. }
  12. private void TOPButton_Click(object sender, RoutedEventArgs e)
  13. {
  14. if (process != null)
  15. {
  16. var ptr = process.MainWindowHandle;
  17. SetForegroundWindow(ptr);
  18. }
  19. }
  20. private void FlushButton_Click(object sender, RoutedEventArgs e)
  21. {
  22. if (process != null)
  23. {
  24. var ptr = process.MainWindowHandle;
  25. SetForegroundWindow(ptr);
  26. SendKeys.SendWait("{F5}");
  27. }
  28. }

前台

  1. "Text_Path" HorizontalAlignment="Left" Height="25" Margin="0,34,0,0" TextWrapping="Wrap" Text="https://www.baidu.com" VerticalAlignment="Top" Width="251" />

  SendKeys.SendWait("{F5}"); 需要引用System.Windows.Forms.dll

WPF 精修篇 调用Win32Api

标签:filename   form   data-   ram   tps   func   ber   rgs   div   

原文地址:https://www.cnblogs.com/lonelyxmas/p/12075802.html


评论


亲,登录后才可以留言!