//ID--HANDLE--HWND三者之间的互相转换
//id->句柄 hWnd = ::GetDlgItem(hParentWnd, id);
//id->指针 CWnd::GetDlgItem();
//句柄->id id = GetWindowLong(hWnd, GWL_ID);
//句柄->指针 CWnd *pWnd = CWnd::FromHandle(hWnd);
//指针->ID id = GetWindowLong(pWnd->GetSafeHwnd, GWL_ID);
//GetDlgCtrlID();
//指针->句柄 hWnd = cWnd.GetSafeHandle() or mywnd->m_hWnd;
//句柄->指针
CWnd* GetCwndByHwnd(HWND hWnd)
{
CWnd *pWnd = CWnd::FromHandle(hWnd);
return pWnd;
}
//指针->句柄
HWND GetCwndByHwnd(CWnd cWnd)
{
HWND hWnd = cWnd.GetSafeHwnd(); // mywnd->m_hWndreturn hWnd;
}
//通过窗口标题名杀进程
BOOL FindProcessHandleAndKill(const CString &sWndName)
{
HWND hWnd;
DWORD ProcessID;
HANDLE hProcess;
hWnd = ::FindWindow(NULL, sWndName);
if (hWnd == NULL)
{
return FALSE;
}
else
{
if (GetWindowThreadProcessId(hWnd, &ProcessID) == 0)
{
return FALSE;
}
else
{
hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, ProcessID);
if (hProcess == NULL)
{
return FALSE;
}
else
{
if (TerminateProcess(hProcess, 0))
{
return TRUE;
}
else
{
return FALSE;
}
}
}
}
}
如果觉得《VC由进程ID获取窗口句柄的各种方》对你有帮助,请点赞、收藏,并留下你的观点哦!