积极答复者
C#中如何编写一个能隐藏或显示其他程序的程序?

问题
答案
-
我是新手,多多交流.
首先我想到的是用API函数来解决.
方法如下
绝对做到隐藏窗口,到你看不到...
Code Snippetusing System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;namespace ConsoleApplication1
{
class Program
{
const int SW_HIDE = 0;
const int SW_SHOWNORMAL = 1;
const int SW_SHOWMINIMIZED = 2;
const int SW_SHOWMAXIMIZED = 3;[DllImport("User32.dll")]
public static extern bool ShowWindow(IntPtr HWND, int MSG);
[DllImport("User32.dll")]
public static extern IntPtr FindWindow(string ClassN, string WindN);
[DllImport("User32.dll")]
public static extern IntPtr GetTopWindow(IntPtr Phwnd);
static void Main(string[] args)
{
Console.WriteLine("Hide!");
Console.ReadLine();
ShowWindow(FindWindow(null, "新建文本文档.txt - 记事本"),SW_HIDE);
Console.WriteLine("Show!");
Console.ReadLine();
ShowWindow(FindWindow(null, "新建文本文档.txt - 记事本"), SW_SHOWNORMAL);
}}
}另外,我目前定义的是隐藏一个标题为 新建文本文档.txt - 记事本。也就是默认的记事本打开时出现的字样,API函数Findwindow是根据窗体标题来获取句柄的,所以你还可能需要完善EnumWindow函数。
在copy完代码后,请这样测试:
桌面-新建一个文本文档,双击打开。
然后运行我的程序。敲一下回车,记事本消失,再敲恢复。
2008年8月19日 2:39
全部回复
-
我是新手,多多交流.
首先我想到的是用API函数来解决.
方法如下
绝对做到隐藏窗口,到你看不到...
Code Snippetusing System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;namespace ConsoleApplication1
{
class Program
{
const int SW_HIDE = 0;
const int SW_SHOWNORMAL = 1;
const int SW_SHOWMINIMIZED = 2;
const int SW_SHOWMAXIMIZED = 3;[DllImport("User32.dll")]
public static extern bool ShowWindow(IntPtr HWND, int MSG);
[DllImport("User32.dll")]
public static extern IntPtr FindWindow(string ClassN, string WindN);
[DllImport("User32.dll")]
public static extern IntPtr GetTopWindow(IntPtr Phwnd);
static void Main(string[] args)
{
Console.WriteLine("Hide!");
Console.ReadLine();
ShowWindow(FindWindow(null, "新建文本文档.txt - 记事本"),SW_HIDE);
Console.WriteLine("Show!");
Console.ReadLine();
ShowWindow(FindWindow(null, "新建文本文档.txt - 记事本"), SW_SHOWNORMAL);
}}
}另外,我目前定义的是隐藏一个标题为 新建文本文档.txt - 记事本。也就是默认的记事本打开时出现的字样,API函数Findwindow是根据窗体标题来获取句柄的,所以你还可能需要完善EnumWindow函数。
在copy完代码后,请这样测试:
桌面-新建一个文本文档,双击打开。
然后运行我的程序。敲一下回车,记事本消失,再敲恢复。
2008年8月19日 2:39 -
我是新手,多多交流.
首先我想到的是用API函数来解决.
方法如下
绝对做到隐藏窗口,到你看不到...
Code Snippetusing System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;namespace ConsoleApplication1
{
class Program
{
const int SW_HIDE = 0;
const int SW_SHOWNORMAL = 1;
const int SW_SHOWMINIMIZED = 2;
const int SW_SHOWMAXIMIZED = 3;[DllImport("User32.dll")]
public static extern bool ShowWindow(IntPtr HWND, int MSG);
[DllImport("User32.dll")]
public static extern IntPtr FindWindow(string ClassN, string WindN);
[DllImport("User32.dll")]
public static extern IntPtr GetTopWindow(IntPtr Phwnd);
static void Main(string[] args)
{
Console.WriteLine("Hide!");
Console.ReadLine();
ShowWindow(FindWindow(null, "新建文本文档.txt - 记事本"),SW_HIDE);
Console.WriteLine("Show!");
Console.ReadLine();
ShowWindow(FindWindow(null, "新建文本文档.txt - 记事本"), SW_SHOWNORMAL);
}}
}另外,我目前定义的是隐藏一个标题为 新建文本文档.txt - 记事本。也就是默认的记事本打开时出现的字样,API函数Findwindow是根据窗体标题来获取句柄的,所以你还可能需要完善EnumWindow函数。
在copy完代码后,请这样测试:
桌面-新建一个文本文档,双击打开。
然后运行我的程序。敲一下回车,记事本消失,再敲恢复。
2008年8月19日 2:40