WPF finishing papers call Win32Api

Original: WPF finishing papers call Win32Api

Chestnut is the most front window to make calls WIn32API 

Background code


  
  
  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. }

Reception


  
  
  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}"); need to reference System.Windows.Forms.dll

Guess you like

Origin www.cnblogs.com/lonelyxmas/p/12075802.html