Tech
Forums
Jobs
Books
Events
Interviews
Live
More
Learn
Training
Career
Members
Videos
News
Blogs
Login
Sign Up
Ask Question
0
Reply
GetForegroundWindow(); with docs.ActiveWindow.Selection.Font
Sunil C
Jul 2 2016 8:52 AM
503
Reply
In my C# background (Tray) application, I am checking if foreground application is Office Word application, using following Function. It is working perfectly.
bool
WinWordApp()
{
IntPtr hwnd = GetForegroundWindow();
BringWindowToTop(hwnd);
uint
pid;
GetWindowThreadProcessId(hwnd,
out
pid);
Process p = Process.GetProcessById((
int
)pid);
string
AppName =
null
;
AppName = p.ProcessName.ToString();
if
(AppName.IndexOf(
"WinWord"
, StringComparison.CurrentCultureIgnoreCase) != -1)
return
true
;
else
return
false
;
}
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:
objWord.Activewindow.Selection.Font.Name =
"Arial"
But I don’t know how to club these two.
Please help.
Upload Source Code
Select only zip and rar file.
Post
Reset
Cancel
Answers (
0
)
Next Recommended Forum
[C#] Processing on Data (Excel)
Microsoft Access Query in a Word Document