Monday, 15 February 2010

c++ - win32 redrawing after resizing -



c++ - win32 redrawing after resizing -

i have next problems

i have base of operations class "shape", cointains virtual function draw(hwnd), have kid class "line" contains same function draw(hwnd).

when draw line in wm_mousemove, ok, when minimize or alter window size, line disappear

what need do?

i have vector pointer base of operations class vector ff; shape *f;

case wm_lbuttondown: { isdrawing = true; startx = loword(lparam); starty = hiword(lparam); endx = loword(lparam); endy = hiword(lparam); switch(ishape) { case line: f=new line(); break; case rectangle: f=new myrectangle(); break; } f->setbrushwidth(5); f->setcolor(rgb(255,0,0)); f->setstartcoord(startx,starty); f->setendcoord(endx,endy); f->setmode(1); f->draw(hwnd); break; } case wm_mousemove: if( isdrawing == true ) { f->setendcoord(endx,endy); f->setmode(2); f->draw(hwnd); endx = loword(lparam); endy = hiword(lparam); f->setendcoord(endx,endy); f->setmode(2); f->draw(hwnd); } break; case wm_lbuttonup: endx = loword(lparam); endy = hiword(lparam); f->setendcoord(endx,endy); f->setmode(3); f->draw(hwnd); ff.push_back(f); isdrawing = false; break;

it drawing ok, when alter windows size

you drawing in wrong place. drawing on window should done in response receiving wm_paint message. windows can redrawn @ time , programme must able redraw itself.

you need move drawing code handling code wm_paint. in wm_mousemove handler need create note of line must drawn, , phone call invalidaterect. schedule paint cycle , window can repainted when paint cycle occurs.

this pretty much win32 101 , suggest that, if have not done so, hold of re-create of petzold's classic tome, programming windows.

c++ winapi

No comments:

Post a Comment