Click here to Skip to main content
12,997,042 members (129,431 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Hello All,

General Idea:- I am developing application win32 cleint server type (It is like desktop monitoring ).

On server side I am takeing screen shot. & sending it to client side.

On server side I have function code like
hdc1 = GetDC(NULL);
    hdc2 = CreateCompatibleDC(hdc1);
    GetWindowRect(GetDesktopWindow(), &rc);
    w = rc.right-rc.left;
    h =;
    bmih.biSize = sizeof(BITMAPINFOHEADER);
    bmih.biWidth = w;
    bmih.biHeight = h;
    bmih.biPlanes = 1;
    bmih.biBitCount = 24;
    bmih.biCompression = BI_RGB;
    bmih.biSizeImage = ((((bmih.biWidth * bmih.biBitCount) + 31) & ~31) >> 3) * bmih.biHeight;
    bi.bmiHeader = bmih;
    aBmp = CreateDIBSection(hdc1, &bi ,DIB_RGB_COLORS, (void**)&dibvalues, NULL, NULL);
    OldObj = SelectObject(hdc2, aBmp);
    BitBlt(hdc2, 0, 0, w, h, hdc1, 0, 0, SRCCOPY);


I have class like

class DesktopScreen
     unsigned char  dibvalues[lenght];


using above code I am filling Object of this class & sending it to other side

in binary formate (byte).

On Client side deserializing is also OK (I check all value at time of debuging )

Now at time WM_Paint:
hDC = BeginPaint(hWnd, &Ps);
i=  StretchDIBits(hDC,
                         // destination rectangle
                         0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN),
                         // source rectangle
                         0, 0,desktopObj.bmih.biWidth , desktopObj.bmih.biHeight,


StretchDIBits is returning 0 .

Application run properlly but image is not displying.

also if i call StretchDIBits on server side passing same info to that function.I mages is displaying.

Can you please tell me what should be the problem.

( sorry for posting code ,but I think it is necessary to get my Question to you )

Thanks ,
Posted 28-Jun-10 23:41pm
Updated 28-Jun-10 23:45pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Haven't try it myself.

First, make sure that you intialized BITMAPINFO and BITMAPINFOHEADER properly in client side code. ZeroMemory() them to make sure before you put values.

Second make sure that you properly reconstruct byte order of bitmap data in dibvalues. CMIIW, for BI_RGB 24 bit, each pixel is stored as BGR format rather than RGB.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170622.1 | Last Updated 28 May 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100