Tuesday 15 February 2011

c++ - MFC OnSize() issue with Invalidate -



c++ - MFC OnSize() issue with Invalidate -

i'm starting larn basics of mfc i've written little practice programme tracks coordinates relative window , screen on each move , resize, works great except this:

how can there no trailing paints left behind when resize window?

here onsize() code:

void cmainframe::onsize(uint ntype, int cx, int cy) { cframewnd::onsize(ntype, cx, cy); // todo: add together message handler code here // window cdc* dc; dc = getdc(); crect rect; getwindowrect(rect); invalidaterect(rect); // if statement makes sure new reddish text coordinates not printed upon starting programme if (numsizecalls > 1){ // set font future text output cfont myfont; verify(myfont.createfont( 20, // nheight in points 0, // nwidth 0, // nescapement 0, // norientation fw_normal, // nweight true, // bitalic false, // bunderline 0, // cstrikeout ansi_charset, // ncharset out_default_precis, // noutprecision clip_default_precis, // nclipprecision default_quality, // nquality default_pitch | ff_swiss, // npitchandfamily _t("arial"))); // lpszfacename dc->settextcolor(rgb(255, 0, 0)); dc->selectobject(myfont); deleteobject(myfont); // set window coordinates relative client area screentoclient(&rect); // format them textout cstring tl; tl.format(l"%d %d ; ", rect.top, rect.left); cstring tr; tr.format(l"%d %d ; ", rect.top, rect.right); cstring bl; bl.format(l"%d %d ; ", rect.bottom, rect.left); cstring br; br.format(l"%d %d", rect.bottom, rect.right); // position textout textoutyposition += 20; // print them dc->textout(5, textoutyposition, tl + tr + bl + br, _tcslen(tl) + _tcslen(tr) + _tcslen(bl) + _tcslen(br)); // set coords relative screen getwindowrect(&rect); // format them textout tl.format(l"%d %d ; ", rect.top, rect.left); tr.format(l"%d %d ; ", rect.top, rect.right); bl.format(l"%d %d ; ", rect.bottom, rect.left); br.format(l"%d %d", rect.bottom, rect.right); // position textout textoutyposition += 20; // print them dc->textout(5, textoutyposition, tl + tr + bl + br, _tcslen(tl) + _tcslen(tr) + _tcslen(bl) + _tcslen(br)); } numsizecalls++; }

invalidaterect takes rectangle in client coordinates. you're passing results of getwindowrect, returns screen coordinates. window isn't beingness invalidated properly, not beingness erased.

note when window erased, painting in onsize function erased too. should reserve painting onpaint function prevent problem.

c++ windows mfc invalidate

No comments:

Post a Comment