开发者

How can I prevent windows from showing in .NET?

I'm currently working on an access control program in C# and I've come across the problem of blocking windows. The original idea I've come up with is rendering a plain black form over the position given by the IntPtr window handle of the process. The problem within that is updating the for开发者_StackOverflow社区m's position smoothly and z-index of the position (being I don't want it topmost). I've also noticed a ridiculously high resource use with my solution as I was using a loop to constantly check position.

Thus why I ask: What would be the best solution for this without eating major resources? The entry point is merely the name of the running process.

Presently the idea is only blocking off browsers (IE: a school application to prevent distraction when a lecture is active).

More Information:

  • I'm not looking to close a window in my own application, I'm trying to obscure windows from other processes.

  • My application is not a virus/annoying program, it's essentially meant to prevent uses of potentially distracting applications in a school environment. It's made for lectures in a school computer lab.

  • I'm presently pulling the main window from the process caught by the process name of browsers.

  • I can't completely disable the computers either.


I really hate hate hate any application trying to mess around with other application's windows. Sorry, this comes from very deep.

The only thing I can think of that is somewhat sensible is to lock the current user session, and swith the computer to another desktop belonging to another account with no rights to do anything except what's required under the circumstances.

Or if it is acceptable to disable the use of the computers entirely, you could put all the monitors on a single power switch on the teacher's desk.


If you are looking to hide your application window, I can suggest 3 things. First thing, try setting your form's visible property true and calling the hide() method. Second thing is to set your form's transparency to 100%, which will hide it. The third is, maybe consider your application should be a windows service instead of a windows form application.

If you are looking to hide other windows so that your application is always on top, set the TopMost property to true in your form: http://msdn.microsoft.com/en-us/library/system.windows.forms.form.topmost(VS.71).aspx

This might help too: http://www.codeproject.com/KB/cs/windowhider.aspx


   [DllImport("user32.dll")]
   static extern bool ShowWindow(IntPtr hWnd, int nCmdShow); 

   static void MinimizeProcess(string procName)
    {
        foreach (Process p in Process.GetProcesses())
        {
            if (p.ProcessName == procName)
            {
                ShowWindow(p.MainWindowHandle,11);

            }
        }
    }

If you have an array of process names you'd obviously want to refactor this to take in an array so that you're not looping through every process for everything you want to minimize, but you get the idea.


You could use the windows api to hide the offending window. user32.showwindow

Not exactly what you've asked for, but might be simpler.


You can do:

this.Hide()

this.Visible = false;

Or if this is the main for you dont want to show, simply dont run the forum when you start the app.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜