Now I have something like this. It is within a loop. It should show the window but it shows only black screen. When I'm using analogical code but with loading a bitmap from file everthing works fine.
1.
HDC WinDC;
HDC CopyDC;
HBITMAP hBitmap;
RECT rt;
HWND Wnd=FindWindow(NULL,"WINDOW");
if(Wnd==0) {MessageBox(0,"didnt found the window!",0,0);}
GetWindowRect (Wnd, &rt);
WinDC = GetDC (Wnd);
CopyDC = CreateCompatibleDC (global_hdc);
std::cout<<rt.right - rt.left<<std::endl;
std::cout<<rt.bottom - rt.top<<std::endl;
hBitmap = CreateCompatibleBitmap (WinDC,
800, //width
600);//height
SelectObject (CopyDC, hBitmap);
BitBlt (global_hdc, //destination
0,0,
800, //width
600, //height
CopyDC, //source
0, 0,
SRCCOPY);
DeleteObject((HBITMAP)hBitmap);
DeleteDC(CopyDC);
2.Analogical code with loading from file:
HBITMAP image;
BITMAP bm;
HDC hdcMem;
//load the bitmap image
image = (HBITMAP)LoadImage(0,"asteroid.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
//read the bitmap's properties
GetObject(image, sizeof(BITMAP), &bm);
//create a device context for the bitmap
hdcMem = CreateCompatibleDC(global_hdc);
SelectObject(hdcMem, image);
//draw the bitmap to the window (bit block transfer)
BitBlt(
global_hdc, //destination device context
0, 0, //x,y location on destination
bm.bmWidth, bm.bmHeight, //width,height of source bitmap
hdcMem, //source bitmap device context
0, 0, //start x,y on source bitmap
SRCCOPY); //blit method
//delete the device context and bitmap
DeleteDC(hdcMem);
DeleteObject((HBITMAP)image);