Drawing on CodeWindow - AddIn

M

Mythran

I created an addin and wrote a class that inherits from
System.Windows.Forms.NativeWindow. In the Connect method, I created an
event handler to listen for DTE.Events.DocumentEvents.DocumentOpened. In
the handler for DocumentOpened, I call EnumChildWindows. In the callback
for EnumChildWindows, I compare the child window's text (using GetText API)
to the caption of the document being opened (Document.ActiveWindow.Caption).
All this works fine and dandy, when the caption of the doc = the child
window's text, the hWnd passed to the EnumChildWindows callback function is
the handle I use to create the NativeWindow derived class. I am overriding
the NativeWindow derived class' WndProc and listening for the WM_PAINT
message. The problem is, I can't seem to figure out how to paint a line on
the device context of the window. My WndProc code is modified from C++
version of the VSWallPaper WndProc code. The following is my WndProc
method:

protected override void WndProc(ref Message Message)
{
if (Message.Msg == (int) WindowMessage.Paint) {
// Save the update rectangle.
RECT rc;
rc = new RECT(1, 1, 1, 1);
bool result = GetUpdateRect(mWindowHandle, out rc, false);

IntPtr hdc = GetDC(mWindowHandle);

// Call the .Net handler.
base.WndProc(ref Message);

if (!IsRectEmpty(ref rc) && !mReEntry) {
HideCaret(mWindowHandle);

// Draw the line.
MoveToEx(hdc, rc.Left, rc.Top, IntPtr.Zero);
LineTo(hdc, rc.Width, rc.Height / 2);
}

// Cleanup.
ReleaseDC(mWindowHandle, hdc);
Message.Result = new IntPtr(1);
return;
}

base.WndProc(ref Message);
}


If any can help me get this working, it would be great! As of now, the
CodeWindow doesn't even refresh. When I alt-tab, then alt-tab back, the
code window doesn't get repainted and shows whatever I alt-tabbed to,
instead of being the code window.

Thanks! :)

Mythran
 
D

Dave

Have you tried using a Graphics object. I think you might get your
results your looking for by looking into that.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top