Sunil C

Sunil C

  • NA
  • 1
  • 1.2k

GetForegroundWindow(); with docs.ActiveWindow.Selection.Font

Jul 2 2016 8:52 AM
In my C# background (Tray) application, I am checking if foreground application is Office Word application, using following Function. It is working perfectly.
  1. bool WinWordApp()  
  2. {   
  3.    IntPtr hwnd = GetForegroundWindow();  
  4.    BringWindowToTop(hwnd);  
  5.    uint pid;  
  6.    GetWindowThreadProcessId(hwnd, out pid);  
  7.    Process p = Process.GetProcessById((int)pid);  
  8.    string AppName = null;  
  9.    AppName = p.ProcessName.ToString();  
  10.    if (AppName.IndexOf("WinWord", StringComparison.CurrentCultureIgnoreCase) != -1)  
  11.       return true;  
  12.    else  
  13.       return false;  
  14. }  
My query: Using this pid / p / AppName, I want to just set font in the foreground Word application, to say “Arial”, without touching other attributes like font size, underline, bold etc. On the net I got some clues like:
  1. objWord.Activewindow.Selection.Font.Name = "Arial"  
But I don’t know how to club these two.
 
Please help.