I want to check whether a form has a Form Border by its handle. And, the handle is from the another Application.
How can I handle this? Please help me.. Thanks!
I want to check whether a form has a Form Border by its handle. And, the handle is from the another Application.
How can I handle this? Please help me.. Thanks!
[DllImport("user32.dll")]
extern static int GetWindowLong(IntPtr hWnd, int nIndex);
const int GWL_STYLE = -16;
const int WS_BORDER = 0x00800000; // thin border
const int WS_THICKFRAME = 0x00040000; // sizing (thick) border
public static bool NativeWindowHasBorder(IntPtr hWnd)
{
return (GetWindowLong(hWnd, GWL_STYLE) & (WS_BORDER | WS_THICKFRAME)) != 0;
}
Control
s themselves don't actually have a handle. Control.Handle
actually returns it's parent window's .Handle
.
From MSDN for Control.Handle
:
Gets the window handle that the control is bound to.
If you look at the decompiled source for Control
, you'll see:
internal IntPtr HandleInternal
{
get
{
return this.window.Handle;
}
}
Edit
What I've stated above is completely incorrect. I'm leaving it for historical sake.
One can prove this very easily by putting a Button
on a Form
, and looking at the IntPtr Handle
value for them. They are different.