Hi,
Introduction:
I have developed an interop project built of an unmanaged COM object and a
..NET WinForm application, the WinForm Application implement the user
interface while the unmanaged COM implements a collection of mathematical
calculations and algorithms.
The COM object, when requested, should be able to render a graph
representing it’s calculations to a window, to achieve that it expose a
‘Render’ method that receive a window handle as an argument, this window
handle represent am PictureBox window created by the WinForm application, the
handle to this window is then being passed to the unmanaged COM and used to
draw a graph using Win32 GDI API ( MoveToEx, LineTo, … ).
The actual rendering is performed through the OnPaint event of the
PictureBox control.
The problem:
The data is being rendered to the desired window by the unmanaged COM,
still, it seem as if the .NET Framework draw the control background over it (
although the rendering was performed through the control Paint event ), the
resulting image is a gray rectangle with a one pixel width frame of the
original picture drawn by the unmanaged COM.
Why does this happen?
Why does the image rendered by the unmanaged COM was overwritten ?
How can this be resolved? ( I can’t do the drawing with managed code )
Code snippets:
Managed OnPaint event implementation:
private void pbTimeView_Paint(object sender, PaintEventArgs e)
{
if (0 == m_WaveForm.FileName.Length)
return;
m_WaveForm.Time.Render(pbTimeView.Handle, 0);
}
Unmanaged Render call implementation:
HRESULT STDMETHODCALLTYPE CWaveForm::Time::Render(VARIANT hWindow, FLOAT
fPosition)
{
RECT rc;
HWND hWnd = (HWND)hWindow.byref;
::GetClientRect(hWnd, &rc);
rc.right -= 1;
float fWidthInSecondsResolution = (float)rc.right / rc.bottom / 2.0f;//
Assumming the amount of higth pixels represent half second
int iWidthInSamplesResolution = (int)(m_Container.m_wfex.nSamplesPerSec *
fWidthInSecondsResolution);
double* pPCM = m_Container.m_pWaveData.m_p + (int)(fPosition *
m_Container.m_ulSamplesCount);
HDC hdc = ::GetDC(hWnd);
::MoveToEx(hdc, 1, rc.bottom / 2, 0);
for(int i = 0; i < iWidthInSamplesResolution; i++)
LineTo(hdc, i, (int)(pPCM[i]*rc.bottom));
::ReleaseDC(hWnd, hdc);
return S_OK;
}
Any help would be appreciated.
--
Nadav
http://www.sophin.com