-1
我需要編寫一個C#程序,它將識別光標下的一個窗口並在其上繪製邊框。C#。 WINAPI。在窗口上繪製
我可以很容易地得到一個窗口句柄:
...
Point point;
WinApi.GetCursorPos(out point);
WinApi.WindowFromPoint(point);
...
但我不能,該窗口上繪製...
public static void drawSelectionRectangle(IntPtr handler)
{
Rectangle rectangle;
WinApi.GetWindowRect(handler, out rectangle);
WinApi.PAINTSTRUCT paintProperties;
IntPtr paintContext = WinApi.BeginPaint(handler, out paintProperties);
IntPtr pen = WinApi.CreatePen(WinApi.PenStyle.PS_SOLID, 5, (uint) ColorTranslator.ToWin32(Color.Red));
WinApi.SelectObject(paintContext, pen);
WinApi.Rectangle(paintContext, rectangle.Left, rectangle.Top, rectangle.Right, rectangle.Bottom);
WinApi.ValidateRect(handler, IntPtr.Zero);
WinApi.EndPaint(handler, ref paintProperties);
}
我叫drawSelectionRectangle(IntPtr handler)
一次(通過點擊按鈕)和環(通過MyForm的onPaint()
方法,而不是我想要繪製的表單)。這似乎並不奏效。
請幫助我。我不知道該怎麼辦。
不工作。該窗口不屬於你。所有者將畫任何你可能成功繪畫的東西。您需要了解Win32繪畫的工作原理。無論問題是什麼,這都不是解決方案。 –