Running word but in Background

  • Thread starter Thread starter ahmad.humyn
  • Start date Start date
A

ahmad.humyn

I have made an application in which I want to take a printout of a word
document after changing some bookmarks in it. The issue is I dont want
ot make it apparent ot the user that Microsoft Word has opened up.

Word.Application word = new Word.Application();
word.Visible = true;
word.Activate();

And it doesn't activate window until you make it visible.
Can somebody tell a work-around?

Thanks

Regards
 
I have made an application in which I want to take a printout of a word
document after changing some bookmarks in it. The issue is I dont want
ot make it apparent ot the user that Microsoft Word has opened up.

Word.Application word = new Word.Application();
word.Visible = true;
word.Activate();

And it doesn't activate window until you make it visible.
Can somebody tell a work-around?

I'm not quite clear on what the problem is. You say you don't want the
user to know Word has opened, but you want it active? Just setting
visible to false will "hide" the Word window, and then you can do
whatever
you want (i.e. create a document, print it, whatever).

Matt
 
That's the problem Matt, you somehow can't activate it until you make
it visible. Setting visible to false gives you an error.

Thanks for helping out
 
So why do you need to activate it? Is there a reason for this? You should be
able to use the object model (loading a document, printing etc) without
forcing the app into focus...

Marc
 
Well found a work around....set the form to full screen size. Set its
property this.topMost to true. And hid the taskbar which gave a clean
UI not showing a sign of MS Word

Well for anybody's interest here is how you hide the windows taskbar:

---------------------------------------------------------------------------
//Define inside the class
[DllImport("User32")]
public static extern int ShowWindow(int hwnd, int nCmdShow);

[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr FindWindow(string lpClassName, string
lpWindowName);

private const int SW_HIDE = 0;
private const int SW_SHOWNA = 8;

public void Foo()
{
ShowWindow(FindWindow("Shell_TrayWnd", "").ToInt32(), SW_HIDE);

this.TopMost = true; //Runs only if function belongs to a form class

//Form is on top of all apps running now, with the taskbar now
completely hidden

//To show Windows taskbar again
ShowWindow(FindWindow("Shell_TrayWnd", "").ToInt32(), SW_SHOWNA);
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top