我写了个抓屏的程序,代码在windows application模式下可以抓屏,后来我把这个程序改成了系统服务程序,结果抓出的图全是黑的.不知道问题出在哪儿?奇怪的是这个服务程序在DEBUG时候也可以抓,但是其release版本运行成服务后就不行

解决方案 »

  1.   

    关注一下!如果Debug下都可以的话,那么肯定是你的Release中有问题了,呵呵,这很可能是变量的初始化的问题,Debug和Release不同的是:在未显式初始化时默认的初始化值不同,尤其是BOOL型和指针。最好你能将所有的指针等变量先显式初始化一下!
      

  2.   

    set your service "Interact with desktop".
    if capture media,try DirectDraw.
      

  3.   

    是Release版不行还是做成服务之后不行?
      

  4.   

    to pomelowu(羽战士) :服务的release不行!
    to liufeng24(流枫) : 在release下,绘图句柄没有值 ?
    to kingzai(stevenzhu) :在啥地方设置?
    代码如下:
    bool save_screen(BYTE *&pScreen, DWORD &nLength)
    {
    int nScreenX = GetSystemMetrics(SM_CXSCREEN);
    int nScreenY = GetSystemMetrics(SM_CYSCREEN);
    HDC hDC = GetDC(GetDesktopWindow());
    HDC hMemDC = CreateCompatibleDC(hDC);
    HBITMAP hBitmap = CreateCompatibleBitmap(hDC, nScreenX, nScreenY);
    HBITMAP hOldBitmap = (HBITMAP)SelectObject(hMemDC, hBitmap);
    // 保存整个屏幕内容 保存在bitmap中了
    BitBlt(hMemDC, 0, 0, nScreenX, nScreenY, hDC, 0, 0, SRCCOPY);
    SelectObject(hMemDC, hOldBitmap);
    DIBSection.SetBitmap((HBITMAP)hBitmap);
    ReleaseDC(GetDesktopWindow(), hDC);

    BITMAPFILEHEADER   hdr;
    LPBITMAPINFOHEADER lpbi = DIBSection.GetBitmapInfoHeader();
    DWORD dwBitmapInfoSize = sizeof(BITMAPINFO) + DIBSection.m_iColorTableSize*sizeof(RGBQUAD);
    DWORD dwFileHeaderSize = dwBitmapInfoSize + sizeof(hdr);
    hdr.bfType       = DS_BITMAP_FILEMARKER;
    hdr.bfSize       = dwFileHeaderSize + lpbi->biSizeImage;
    hdr.bfReserved1  = 0;
    hdr.bfReserved2  = 0;
    hdr.bfOffBits    = dwFileHeaderSize; nLength = sizeof(hdr)+dwBitmapInfoSize+lpbi->biSizeImage ;
    pScreen = new BYTE [nLength];
    if ( pScreen )
    {
    memcpy( pScreen, &hdr, sizeof(hdr));
    memcpy( pScreen+sizeof(hdr), lpbi, dwBitmapInfoSize);
    memcpy( pScreen+sizeof(hdr)+dwBitmapInfoSize, DIBSection.GetDIBits(), lpbi->biSizeImage);
    }
    return TRUE;
    }
      

  5.   

    下面的程序是将整个桌面复制下来,从cur.x,cur.y位置开始复制一小块图象分析的过程,完全可以使用
    CDC dc;
    dc.CreateDC("DISPLAY",NULL,NULL,NULL);
    CBitmap bm;    BITMAP btm;
    char* lpData; int Width=20;
    int Height=25;
    bm.CreateCompatibleBitmap(&dc,Width,Height); CDC tdc;
    tdc.CreateCompatibleDC(&dc);
    CBitmap *pOld=tdc.SelectObject(&bm);
    tdc.BitBlt(0,0,Width,Height,&dc,cur.x,cur.y,SRCCOPY);
    tdc.SelectObject(pOld);

    bm.GetBitmap(&btm);
    int size=btm.bmWidthBytes*btm.bmHeight;

    if(btm.bmWidthBytes/btm.bmWidth == 1)
    return FALSE; lpData=new char[size]; 
    /////////////////////////////////////////////
    BITMAPINFOHEADER bih;
    bih.biBitCount=btm.bmBitsPixel;
    bih.biClrImportant=0;
    bih.biClrUsed=0;
    bih.biCompression=0;
    bih.biHeight=btm.bmHeight;
    bih.biPlanes=1;
    bih.biSize=sizeof(BITMAPINFOHEADER);
    bih.biSizeImage=size;
    bih.biWidth=btm.bmWidth;
    bih.biXPelsPerMeter=0;
    bih.biYPelsPerMeter=0;
    ///////////////////////////////////
    GetDIBits(dc,bm,0,bih.biHeight,lpData,(BITMAPINFO*)&bih,DIB_RGB_COLORS);         //在这里分析LPDATA中的数据 delete lpData;