调用外部应用程序 代码如下
try
{
ProcessStartInfo p = null;
Process Proc;
p = new ProcessStartInfo("Setup.exe", "-update");
p.WorkingDirectory = Path.GetTempPath() + "\\RavUp";//设置此外部程序所在windows目录
Proc = Process.Start(p);//调用外部程序
}
catch (Exception err)
{
MessageBox.Show("启动更新程序出错\n\r"+err.ToString(), "RavUp提示");
}setup.exe 窗口有四个按钮 “上一步(p)”“下一步(n)”“完成(f)”“取消(c)”我想把“取消(C)”设成不可用状态(灰色)
请问各位大虾们怎么用api HOOK设置
try
{
ProcessStartInfo p = null;
Process Proc;
p = new ProcessStartInfo("Setup.exe", "-update");
p.WorkingDirectory = Path.GetTempPath() + "\\RavUp";//设置此外部程序所在windows目录
Proc = Process.Start(p);//调用外部程序
}
catch (Exception err)
{
MessageBox.Show("启动更新程序出错\n\r"+err.ToString(), "RavUp提示");
}setup.exe 窗口有四个按钮 “上一步(p)”“下一步(n)”“完成(f)”“取消(c)”我想把“取消(C)”设成不可用状态(灰色)
请问各位大虾们怎么用api HOOK设置
我自己先试一个,然后发一段代码上来。
定义一个函数: [DllImport("User32.dll")]
public static extern bool EnableWindow(IntPtr hWnd, bool bEnable);
第一个参数是窗口句柄,第二个窗口是设置是窗口有效或者无效,传入false即可。问题在于如何取得窗口句柄,我在测试程序中是用spy++直接查找窗口句柄,在实际中你可以用:
[DllImport("User32.dll")]
public static extern int FindWindow(string strClassName, string strWindowName);
[DllImport("User32.dll")]
public static extern int FindWindowEx(int hwndParent, int hwndChildAfter, string strClassName, string strWindowName);
[DllImport("User32.dll", SetLastError = true)]
public static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr childAfter, string className, string windowTitle);
这两个函数的均是返回窗口句柄,比如:
IntPtr k = (IntPtr)FindWindowEx("ClassName","WindowsName");
第一种调用方法中第一个参数是窗口的类名,可以为空(null),第二个参数是窗口的标题栏名称。必须至少有一个有效。
public static extern int FindWindowEx(int hWnd1, int hWnd2, string lpsz1, string lpsz2);
[DllImport("User32.dll")]
public static extern int FindWindow(string lpClassName, string lpWindowName);
[DllImport("User32.dll")]
public static extern int EnableWindow(int hwnd, bool fEnable); private void button1_Click(object sender, EventArgs e)
{
int h1 = 0, h2 = 0;
bool bEnable = true;
h1 = FindWindow(null, "任务栏和「开始」菜单属性"); //这要修改为窗口标题
if (h1 != 0)
{
h2 = FindWindowEx(h1, 0, null, "应用(&A)"); //这要修改为按钮文本
if (h2 != 0)
{
EnableWindow(h2, false);
}
else
{
MessageBox.Show("h2==0");
}
}
else
{
MessageBox.Show("h1==0");
}
}
private static int GetSysTrayWnd()
{
OSName osn = OS.GetVersion();
int k = Windows.FindWindow("Shell_TrayWnd", null);
k = Windows.FindWindowEx(k, 0, "TrayNotifyWnd", null); if (osn == OSName.Win2000 || osn == OSName.WinXP || osn == OSName.Win2003)
{
if (osn == OSName.Win2000)
{
k = Windows.FindWindowEx(k, 0, "ToolbarWindow32", null);
return k;
}
else
{
k = Windows.FindWindowEx(k, 0, "SysPager", null);
k = Windows.FindWindowEx(k, 0, "ToolbarWindow32", null);
return k;
}
}
else
{
return k;
}
}