How to draw a box around a third party window using c#?
How to draw a rectangle around a third party window? I have got the handle to that window and have the size of window. I am drawing a rectangle around window but that is not attached to the window when I open some other application the same rectangle appears on the top of that application. How to keep it in the background or attached with my window
Code which I am using now
IntPtr desktop = G开发者_开发百科etDC(IntPtr.Zero);
while (true)
{
using (Graphics g = Graphics.FromHdc(desktop))
{
RECT rct = new RECT();
GetWindowRect(wnd.hWnd, ref rct);
Rectangle rect = new Rectangle(rct.Left - 2, rct.Top - 2, (rct.Right - rct.Left) + 2, (rct.Bottom - rct.Top) + 2);
Pen myPen = new Pen(System.Drawing.Color.Red, 5);
g.DrawRectangle(myPen, rect);
g.Dispose();
}
}
Thanks
Handle of Main window of process wont help you always, as some application, like yahoo messenger shows secondary window. Probably you want to highlight the active window. You can get the handle of active window, once you have it, get the region it is covering, you can show your overlay at that location.
精彩评论