c++ - InvalidateRect in Windows API, Charles Petzold checker4.c program -


full program here:

http://examples.oreilly.com/9781572319950/cd_contents/chap07/checker4/checker4.c

the code in childwndproc confuses me:

 case wm_lbuttondown :       setwindowlong (hwnd, 0, 1 ^ getwindowlong (hwnd, 0)) ;       setfocus (hwnd) ;       invalidaterect (hwnd, null, false) ;       return 0 ;             // focus messages, invalidate window repaint   case wm_setfocus:       idfocus = getwindowlong (hwnd, gwl_id) ;             // fall through   case wm_killfocus:       invalidaterect (hwnd, null, true) ;       return 0 ; 

why in childwndproc in case of message wm_lbuttondown:

the last statement before return 0 invalidaterect, since right before program sends wm_setfocus message setfocus function, falls through wm_killfocus, has invalidaterect, last argument true, instead of false.

in understanding program should work without invalidaterect in wm_lbuttondown since calls setfocus, makes invalidate window, when comment out invalidaterect wm_lbuttondown, program doesn't repaint window after mouse clicks or button presses.

why , why in wm_lbuttondown invalidaterect last argument false , in wm_killfocus true?

i running ms visual studio c++ 2010 express in windows xp 32bit.

calling setfocus() doesn't unconditionally send wm_setfocus message. if window has focus before call, setfocus() not anything.

put way, wm_setfocus message sent if focus changed.

as true/false parameter, that's berase, whether erase whole window before re-drawing it, or whether paint on what's there. is, in book, performance hack. if know can away not erasing window (because updating small part of it), can pass true here.

i don't think in 2015 there's value in optimization. if need high performance display updates, you'd use opengl or directx anyway.


Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -