Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VC6 C++ Win32
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 = 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
 
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);
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 29-Jun-10 0:41am
Edited 29-Jun-10 0:45am
v2

1 solution

Rate this: bad
good
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.
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 545
1 OriginalGriff 285
2 Shweta N Mishra 244
3 BillWoodruff 230
4 Mathew Soji 225
0 OriginalGriff 6,153
1 Sergey Alexandrovich Kryukov 5,758
2 DamithSL 4,958
3 Manas Bhardwaj 4,539
4 Maciej Los 3,735


Advertise | Privacy | Mobile
Web03 | 2.8.1411019.1 | Last Updated 28 May 2013
Copyright © CodeProject, 1999-2014
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