Monthly Archives: August 2013
Double Buffering technique in MFC for Flicker Free drawing
Flickering is caused in a window, by painting, in two steps.
(1) Erasing the window contents in OnEraseBkgnd. By default MFC does this.
(2) Painting new contents in OnPaint or OnDraw.
Double buffering eliminates this two-step process by overriding OnEraseBkgnd and including the erase in OnPaint/OnDraw to an off-screen image.
1. Overriding the OnEraseBkgnd function:
- Add a message handler for WM_ERASEBKGND in your Windows application.
- Once added it looks like the below one:
BOOL CExampleView::OnEraseBkgnd(CDC* pDC) { // TODO: Add your message handler code here and/or call default return CView::OnEraseBkgnd(pDC); } Now change the return value to any non-zero value and comment the default proced-ure. BOOL CExampleView::OnEraseBkgnd(CDC* pDC) { return TRUE; }
2. Now In the OnPaint/OnDraw do the following steps:
1. Create a Memory DC for the View DC as below:
CreateCompatibleDC(pDC);
2. Create the bitmap in memory…
View original post 78 more words
Break…?
Const Keyword in C and C++ (A few interesting points)
Consider following code snippet. Does it even compile?
foo (const char **conChar) {}
main (int argc, char **argv)
{
foo (argv);
}
This code will not compile with an error message of incompatible type. This is true in both c and c++. (don’t forget to add return type to foo in c++)
Now consider below snippet,
char * cp ;
const char * ccp;
ccp = cp;
- The left operand is a pointer to “char qualified by const”.
- The right operand is a pointer to “char” unqualified.
- The type char is a compatible type with char, and the type pointed to by the left operand has all the qualifiers of the type pointed to by the right operand (none), plus one of its own (const).
(Note that the assignment cannot be made the other way around. Try it if you don’t believe me.
cp = ccp; /* results in a compilation warning */)
here apparently we are doing the same thing while assigning a non const qualified pointer to to a const qualified pointer but it run without an error for both c and c++.
So why the first code is not compiling and second one does?
const char ** denotes a pointer to an unqualified type. Its type is a pointer to a pointer to a qualified type.
Since the types char ** and const char ** are both pointers to unqualified types that are not the same type, they are not compatible types. Therefore, a call with an argument of type char ** corresponding to a parameter of type const char ** is not allowed.
Now what will happen, if I don’t use * or **….?
Consider below code,
int cp ;
const int ccp;
ccp = cp;
You will have compile error in both c and c++ compilers… as you cannot assign a new value to a variable declared const…
Is it really so?
Consider following C code,
int cp = 12;
const int ccp = 10;
int * alter;
alter = &ccp;
*alter = cp;
printf(“value is %d”, ccp);
We can always take address of a const variable in C and can assign it to another pointer variable, which is not a constant pointer. Now we have the access of memory location of the constant variable and can change the value using our pointer.
This is not true in C++ as it prohibits, any kind of assignment to a constant variable.
“Genetics is complicated”
“Genetics is complicated”
Introduction to psychology.
Lesson 03. Biology of Behavior.
August 5, 2013
San Jose State University
https://www.udacity.com/course/viewer#!/c-ps001/l-207152500/m-206819111
related: