I'm still quite new to how handles works and need some help to understand this a bit more.
I have this method in my class, "cbxWebsite" is a combobox.
public IntPtr GetCurrentHandle()
{
foreach (Process process in Process.GetProcesses())
{
if (process.ProcessName.Contains("chrome")
&& process.MainWindowTitle.Contains(cbxWebsite.SelectedValue.ToString()))
{
return process.MainWindowHandle;
}
}
return IntPtr.Zero;
}
And I'm trying to implement this: Capture screen of Window by handle
My question is about these lines:
IntPtr hwnd = GetCurrentHandle();
User32.GetWindowRect(new HandleRef(null, hwnd), ref rc);
When I call GetWindowRect, the HandleRef() complains about "Cannot convert from HandleRef to IntPtr".
MS docs says this about process.MainWindowHandle: The system-generated window handle of the main window of the associated process.
So I guess I don't understand from here. I thought I was returning the handle of the current window I want to work with from GetCurrentHandle(). But is it returning the handle of the process of that window and not the actual window-handle itself?
Can someone please clarify.