[C#]一段如何調用Button.Click事件的故事
轉貼自 http://www.dotblogs.com.tw/chou/archive/2009/06/04/8666.aspx
一、前言
由於小朱與BillChung的啟發,想寫一個故事,讓大家瞭解如何調用 Button.Click 事件,而故事的好壞,由看戲的客官去評判,假如說的不好,請不要罵太兇,因為我只是個寫程式菜鳥,並不是說書的
[Flags]
public enum ThreadAccess : int
{
TERMINATE = (0x0001),
SUSPEND_RESUME = (0x0002),
GET_CONTEXT = (0x0008),
SET_CONTEXT = (0x0010),
SET_INFORMATION = (0x0020),
QUERY_INFORMATION = (0x0040),
SET_THREAD_TOKEN = (0x0080),
IMPERSONATE = (0x0100),
DIRECT_IMPERSONATION = (0x0200)
}
[DllImport("kernel32.dll")]
static extern IntPtr OpenThread(ThreadAccess dwDesiredAccess, bool bInheritHandle, uint dwThreadId);
[DllImport("kernel32.dll")]
static extern uint SuspendThread(IntPtr hThread);
[DllImport("kernel32.dll")]
static extern int ResumeThread(IntPtr hThread);
private void SuspendProcess(int PID)
{
Process proc = Process.GetProcessById(PID);
if (proc.ProcessName == string.Empty)
return;
foreach (ProcessThread pT in proc.Threads)
{
IntPtr pOpenThread = OpenThread(ThreadAccess.SUSPEND_RESUME, false, (uint)pT.Id);
if (pOpenThread == IntPtr.Zero)
{
break;
}
SuspendThread(pOpenThread);
}
}
public void ResumeProcess(int PID)
{
Process proc = Process.GetProcessById(PID);
if (proc.ProcessName == string.Empty)
return;
foreach (ProcessThread pT in proc.Threads)
{
IntPtr pOpenThread = OpenThread(ThreadAccess.SUSPEND_RESUME, false, (uint)pT.Id);
if (pOpenThread == IntPtr.Zero)
{
break;
}
ResumeThread(pOpenThread);
}
}
Copyright © 2010 紀錄實用心得 | Blogger Templates by Splashy Templates | Design by Free CSS Templates