Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

effective drawing 1

Status
Not open for further replies.

bubak

Programmer
Jun 25, 2001
208
SK
Hi
I have my object, derived from CWnd. It's an chceker with little rectangles. I have an data array, where I save color for each rectangle. When I push mouse button, I can coorize the rectangles with selected color (sth like drawing in grid) First I've made it with function ColorizeAt(x,y), which made getDC and drawn a Rect. Now I paint everything in OnPaint() and the ColorizeAt function does just InvalidateRect and updatewindow an selected rectangle.
Th Problem is, that when I now go somewhere into that checker, push lbutton down and drag, not every, but just every fith or sixth rect is filled with color. Like when the window will not be able to catch all the messages.
Where can be the problem? What's the best way to do that. Some example code somewhere? Thanx.
bubak
 
Can you post the code that makes the colorize from the OnPaint (eventully the call from InvalidateRect, too)?

It seem quite hard to realize the problem without some code... :(


s-)

Blessed is he who in the name of justice and goodwill, sheperds the weak through the valley of darkness...
 
---this is a part from onPaint() - the part of drawing checkers
diff_x=5;diff_y=5;y=6;x=6;
CBrush brush,*brush_old;
CPen pen,*pen_old;
for(int ix=0;ix<60;ix++)
for(int iy=0;iy<24;iy++)
{
brush.CreateSolidBrush(m_data[iy][ix]);
if(ix==0&&iy==0){brush_old=dc.SelectObject(&brush);}
else{dc.SelectObject(&brush);}
dc.Rectangle(diff_x+ix*x+ix*sx,diff_y+iy*y+iy*sy,diff_x+(ix+1)*x+ix*sx,diff_y+(iy+1)*y+iy*sy);
brush.DeleteObject();
}
......


-------quite well working colorizeAt(...
CDC *dc; //cdc, not cpaintdc, coz with cpaintdc it doesn't work
dc=GetDC();
brush.CreateSolidBrush(c);
pen.CreatePen(PS_SOLID,1,RGB(120,120,120));

old_pen=dc->SelectObject(&pen);
old_brush=dc->SelectObject(&brush);

dc->Rectangle(diff_x+min*x+min*sx,diff_y+hr*y+hr*sy,diff_x+(min+1)*x+min*sx,diff_y+(hr+1)*y+hr*sy);
.....

----------quite bad working colorizeAt
InvalidateRect(CRect(diff_x+min*x+min*sx+1,diff_y+hr*y+hr*sy+1,diff_x+(min+1)*x+min*sx-1,diff_y+(hr+1)*y+hr*sy-1));
UpdateWindow();

-----------OnMouseMove(UINT nFlags, CPoint point)
{
int hr=point.y/5-4;
int min=point.x/5-4;

if((MK_LBUTTON&nFlags)==0){}else{
colorizeAt(hr,min,m_Color1);
m_data
[min]=m_Color1;
}
 
I also had a few more functions, where I did GetDC, GetPainDC , etc. a drawn directly, but my chief told me to use just OnPaint and in that function just do InvalidateRect and UpdateWindow
 
--bubak.
Your chief is a wise men. Because if you are doing as he said you will not have problems with repainting when your window is overlapped or set to backgorund then again brought forth.

Just think that when you bring forth a window(also alt+tab) OnPaint is called. If in OnPaint you don't have samething to tell the window to colorize differently the piece of window where your mouse is, it won't colorize.

That's why you have to put some code in OnPaint that will:
- read the Mouse position
- map it to your window (maybe with MapWindowPoints)
- put some 'if' or 'switch' statement in your code to colorize the small rectangle where your mouse is (you can test it with PtInRect)

Then in other function you will just do an InvalidateRect(YourRect)

PS: That is the way I have done with my graphic program(is a game actually) - You can find the kit for download on my site and is called SeekAndDestroy, if you want to see it.

HTH, s-)

Blessed is he who in the name of justice and goodwill, sheperds the weak through the valley of darkness...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top