码迷,mamicode.com
首页 > Windows程序 > 详细

WPF 精修篇 调用Win32Api

时间:2019-12-21 09:35:53      阅读:177      评论:0      收藏:0      [点我收藏+]

标签: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. <Grid>
  2. <TextBox x:Name="Text_Path" HorizontalAlignment="Left" Height="25" Margin="0,34,0,0" TextWrapping="Wrap" Text="https://www.baidu.com" VerticalAlignment="Top" Width="251" />
  3. <Button x:Name="OPenButton" Content="打开" HorizontalAlignment="Left" Margin="10,86,0,0" VerticalAlignment="Top" Width="75" Click="OPenButton_Click"/>
  4. <Button x:Name="TOPButton" Content="前台" HorizontalAlignment="Left" Margin="10,123,0,0" VerticalAlignment="Top" Width="75" Click="TOPButton_Click"/>
  5. <Button x:Name="FlushButton" Content="刷新" HorizontalAlignment="Left" Margin="10,160,0,0" VerticalAlignment="Top" Width="75" Click="FlushButton_Click"/>
  6. </Grid>

  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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!