Click to See Complete Forum and Search --> : GDI+(GDI) performance problem


fragy153
March 8th, 2005, 02:57 AM
Hello

I have a GDI performance problem. I implemented a MDI application and a black background, a grid and text that shows the current mouse position within the document window.

I used GDI functions, for example to draw the GRID i did the following

DeleteObject(hbmMem_grid );
DeleteDC(hdcMem_grid );
RECT rc;
HBRUSH hbrBkGnd;
HPEN hpen;
GetClientRect(hWnd, &rc);
hdcMem_grid = CreateCompatibleDC(hdc);
hbmMem_grid = CreateCompatibleBitmap(hdc,rc.right-rc.left,rc.bottom-rc.top);
SelectObject(hdcMem_grid , hbmMem_grid );
hbrBkGnd = CreateSolidBrush(RGB(255, 255, 255));
FillRect(hdcMem_grid , &rc, hbrBkGnd);
DeleteObject(hbrBkGnd);
hpen = CreatePen(PS_SOLID, 0, RGB(225, 233, 233));
SelectObject(hdcMem_grid , hpen);

for(int i=1; i<5; i++)
{
MoveToEx(hdcMem_grid ,rc.left+((rc.right-rc.left)/5)*i,rc.top,NULL);
LineTo(hdcMem_grid ,rc.left+((rc.right-rc.left)/5)*i,rc.bottom );
MoveToEx(hdcMem_grid ,rc.left, rc.top+((rc.bottom-rc.top)/5)*i,NULL);
LineTo(hdcMem_grid , rc.right, rc.top+((rc.bottom-rc.top)/5)*i );
}

DeleteObject(hpen);

Everything is correctly drawn to the document area but the problem arises when I move the mouse over the document area. It is extremely slow! The mouse pointer
reacts really slow...

Have you got any ideas of what might be the problem?
I tried the same application in other machines ( more powerful ) and everything was ok. But my machine isn't that slow I have a 1.6Ghz pentium 4 with Nvidia 64Mb graphics card...And the application is quite simple...

Thanks

ovidiucucu
March 8th, 2005, 04:47 AM
You didn't specify where is located your piece of drawing code.
Somehow in WM_MOUSEMOVE message handler?

fragy153
March 8th, 2005, 06:46 AM
Yes you are right

this is called in OnMouseMove function

ovidiucucu
March 8th, 2005, 06:57 AM
So, move the code in WM_PAINT handler and in OnMouseMove invalidate only the rectangle you need to re-paint (in which you write the mouse coordinates).

BTW. It seems that your application uses MFC.
Right?

fragy153
March 8th, 2005, 07:35 AM
Yes it uses MFC

this is my OnMouseMove function

void CTestDrawView::OnMouseMove(UINT nFlags, CPoint point)
{

CTestDrawDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
pDoc->CurrentPosition=point;

Invalidate(FALSE);

CView::OnMouseMove(nFlags, point);
}

I guess after that, the OnDraw() function is called that calls the function I included in my previous message

so I think that I do what you say. Or not??

Anandforyou
March 15th, 2005, 01:57 AM
Don't call Invalidate(). this is the pronblem.
Call InvalidateRect() for partion only you need redraw.