I need handle another running application by name, id, or process handle. I get the ID and Process handles but I don't know how get handle of window to change external program title.
There is my code:
BOOL CFindProcess::OnInitDialog()
{
CDialogEx::OnInitDialog();
CComboBox* pComboBox = (CComboBox*)GetDlgItem(IDC_COMBO_PROCESS);
HANDLE hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
PROCESSENTRY32 proc;
proc.dwSize = sizeof(PROCESSENTRY32);
if (Process32First(hSnap, &proc)){
pComboBox->AddString(proc.szExeFile);
while (Process32Next(hSnap, &proc)){
if (0!=wcscmp(proc.szExeFile, L"svchost.exe"))
pComboBox->AddString(proc.szExeFile);
if (wcscmp(proc.szExeFile, L"notepad.exe") == 0){
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, proc.th32ProcessID);
GetProcessId(hProcess);
AfxMessageBox(L"Handeled");
//SetWindowText(hProcess, L"Weather");
CloseHandle(hProcess);
}
}
}
CloseHandle(hSnap);
return TRUE;
}
my question is how get window handle of notepad.exe by name or ID, Process handles with MFC?
FindWindowcan find by name.EnumWindowswithGetWindowProcessIdcan match a window up with a process ID. - Jerry Coffin