By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,067 Members | 1,818 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,067 IT Pros & Developers. It's quick & easy.

GUI Interop problem

P: n/a

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)
m_WaveForm.Time.Render(pbTimeView.Handle, 0);

Unmanaged Render call implementation:
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 *

double* pPCM = m_Container.m_pWaveData.m_p + (int)(fPosition *

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.

Mar 17 '06 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.