In the following code, anytime CreateCompatibleDC is called, the resulting device context only has two colors: black and white.
case WM_PAINT:
{
Change this:
HBITMAP membm=CreateCompatibleBitmap(memdc,width,height);
To this:
HBITMAP membm=CreateCompatibleBitmap(hdc,width,height);
When you create a compatible DC, it's created with a bitmap--but that bitmap is always a 1x1 monochrome bitmap (i.e., a single pixel that's either black or white), regardless of what sort of DC it's compatible with.
As a result, if you create a bitmap compatible with that DC, you'll get a larger monochrome bitmap.
If, however, you create a bitmap compatible with the original DC, then you'll get a bitmap of the requested size and the color depth of the original DC.