Double Buffering technique in MFC for Flicker Free drawing

Visual Programming

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:


2.   Create the bitmap in memory…

View original post 78 more words


This is a replica of the code that caused a major disruption of AT&T phone service throughout the U.S. AT&T’s network was in large part unusable for about nine hours starting on the afternoon of January 15, 1990. Telephone exchanges are all computer systems these days, and this code was running on a model 4ESS Central Office Switching System.
It demonstrates that it is too easy in C to overlook exactly which control constructs are affected by a “break” statement.
network code()
switch (line) {
case THING1:
case THING2:
if (x == STUFF) {
if (y == OTHER_STUFF)
} /* coder meant to break to here… */
} /* …but actually broke to here! */
use_modes_pointer();/* leaving the modes_pointer
uninitialized */
This is a simplified version of the code, but the bug was real enough. The programmer wanted to break out of the “if” statement, forgetting that “break” actually gets you out of the nearest enclosing iteration or switch statement. Here, it broke out of the switch, and executed the call to use_modes_pointer() —but the necessary initialization had not been done, causing a failure further on.
This code eventually caused the first major network problem in AT&T’s 114-year history. The saga is described in greater detail on page 11 of the January 22, 1990 issue of Telephony magazine. The supposedly fail-safe design of the network signaling system
actually spread the fault in a chain reaction, bringing down the entire long distance network.
And it all rested on a C switch statement.

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!/c-ps001/l-207152500/m-206819111


View original post

Beginner’s Guide to Linkers

This article is intended to help C & C++ programmers understand the essentials of what the linker does.


The Virtual Internship: Take Control of Your Future by Becoming an Open Source Developer

The Virtual Internship: Take Control of Your Future by Becoming an Open Source Developer.

A Primer on Object-Oriented Concepts

A Primer on Object-Oriented Concepts.

C 11 Regular-Expression Library | 20.1. Overview of C 11 Regular Expressions

C 11 Regular-Expression Library | 20.1. Overview of C 11 Regular Expressions.

Project Euler Problem#14 solution in C++

Longest Collatz sequence

The following iterative sequence is defined for the set of positive integers:

n → n/2 (n is even)
n → 3n + 1 (n is odd)

Using the rule above and starting with 13, we generate the following sequence:

13 → 40 → 20 → 10 → 5 → 16 → 8 → 4 → 2 → 1

It can be seen that this sequence (starting at 13 and finishing at 1) contains 10 terms. Although it has not been proved yet (Collatz Problem), it is thought that all starting numbers finish at 1.

Which starting number, under one million, produces the longest chain?

NOTE: Once the chain starts the terms are allowed to go above one million.


#include <iostream>

int main ()
int N           = 1000000;
int CHECKPOINT  = 800000;
long long nTemp = N;
int chainCount  = 1;
int check       = 0;
long long myNum = 0;

for (int i = N; i > CHECKPOINT; --i)
while (nTemp != 1)
if ((nTemp%2) == 0)
nTemp = nTemp/2;
nTemp = (nTemp*3) + 1;

nTemp = N;

if (check < chainCount)
check = chainCount;
myNum = nTemp;
chainCount = 1;

std::cout << "The number " << myNum << " has longest chain of " << check << std::endl;


Machine Learning, Deep Learning and Scientific Understanding

Simant Dube

Machine learning is super hot in silicon valley these days! It has emerged as a very useful discipline in computer science and statistics. If you have skills in Machine Learning, you are likely to get a nice job. But what exactly is machine learning? With growing popularity of the field, engineers and scientists know the technical answer, but can it be explained to everyone in simple language? What are current trends in machine learning and what could come next?

In this article, we will focus on statistical learning and discuss state-of-the-art, trends and future directions.

Decisions, Decisions, Decisions!

Why is machine learning hot? Well, there are so many decisions to be made everywhere. Suppose you want to predict, recommend, classify or rank something in an automated data driven manner. Then your best bet is to use statistical machine learning.

Netflix wants to recommend movies to you which you may like…

View original post 2,913 more words