Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
291 views
in Technique[技术] by (71.8m points)

c# - Making my console application invisible

I am developing a console application for my public library as a school project. The console application will run as soon as the user logs on and do some background work.

The thing is, I don't want the console application to actually appear. I need it invisible. The last thing I need is complaints because some people got freaked out that a CMD window opened and closed, besides that the library wants it as invisible as possible.

I tried following the code in this thread: http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/ea8b0fd5-a660-46f9-9dcb-d525cc22dcbd

but to no avail, I can still see the console application pop open and close after it has done all of its work.

Is there a better way to stop the console from appearing? Thanks.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The best thing to do is just don't compile it as a console application! Compile it as a Windows EXE and no console will show. Then you can just do whatever you need to do in the Main method without showing a UI.

But in any case, if you must hide/show the console window I would steer clear of using FindWindow for this task since there is a much more reliable API for this: GetConsoleWindow. This will give you the HWND of the console window and you can try passing that to ShowWindow.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...