Click here to Skip to main content
15,886,639 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
--------------------------------------------
|
|
|
MIDL
hdc1 = GetDC(NULL);
    hdc2 = CreateCompatibleDC(hdc1);
    GetWindowRect(GetDesktopWindow(), &rc);
    w = rc.right-rc.left;
    h = rc.bottom-rc.top;

    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

CSS
class DesktopScreen
{
public:
    BITMAPINFOHEADER bmih ;
    BITMAPINFO bi;
     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);
VB
i=  StretchDIBits(hDC,
                         // destination rectangle
                         0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN),
                         // source rectangle
                         0, 0,desktopObj.bmih.biWidth , desktopObj.bmih.biHeight,
                         desktopObj.dibvalues,
                         &desktopObj.bi,
                         DIB_RGB_COLORS,
                         SRCCOPY);


//////////////////////////////////////////////////////////////////////////

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 ,
Ashish.
Posted
Updated 28-Jun-10 23:45pm
v2

1 solution

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.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900