Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

WIN32 API Big Help Documentation

[es] :: C/C++ programiranje :: C/C++ za početnike :: WIN32 API Big Help Documentation

[ Pregleda: 1406 | Odgovora: 0 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

JoeBullet
Skola
Zagreb

Član broj: 227996
Poruke: 1
*.adsl.net.t-com.hr.

Sajt: www.hak5.com


Profil

icon WIN32 API Big Help Documentation14.07.2009. u 08:37 - pre 180 meseci
Eto i ja sam trazio ovo i nikako nisam mogao naci. Pa sam nasao slucajno jednom. Eto ako vas zanima link je: OVDJE
Znaci ima pokriven cijeli WIN32 API, winsock, mapi, tapi itd.

I jos nesto... isto sam trazio i funkciju koja bi napravila screenshoot i spremila u BMP.. pa evo:
Code:

int CaptureScreen(char szFileName[])
{
    HDC hdcScreen, hdcMemory;
    int cxScreen, cyScreen;
    HBITMAP hbmMemory, hbmOld;
    BITMAPINFO bi;
    void* data;

    // get the HDC of the screen
    hdcScreen = GetDC(NULL);

    // get the screen size
    cxScreen = GetSystemMetrics(SM_CXSCREEN);
    cyScreen = GetSystemMetrics(SM_CYSCREEN);

    // create a compatible memory dc/bitmap pair
    hdcMemory = CreateCompatibleDC(hdcScreen);
    hbmMemory = CreateCompatibleBitmap(hdcScreen, cxScreen, cyScreen);
    hbmOld = (HBITMAP)SelectObject(hdcMemory, hbmMemory);
    
    // "capture" the screen into this pair
    if(!BitBlt(hdcMemory, 0, 0, cxScreen, cyScreen, hdcScreen, 0, 0, SRCCOPY))
    {
        reportError("BitBlt didn't capture screen.");
        return 0;
    }

    // now that we got the screen into the HBITMAP, get its bits

    // we want to get it as 24-bpp
    ZeroMemory(&bi, sizeof(BITMAPINFO));
    bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
    bi.bmiHeader.biWidth = cxScreen;
    bi.bmiHeader.biHeight = cyScreen;
    bi.bmiHeader.biBitCount = 24;
    bi.bmiHeader.biPlanes = 1;

    // first call with a NULL pointer to fill in rest of bi.bmiHeader 
    if(!GetDIBits(
        hdcMemory,
        hbmMemory,
        0,
        cyScreen,
        NULL,
        &bi,
        DIB_RGB_COLORS))
    {
        reportError("GetDIBits failed(filling bi.bmiHeader).");
        return 0;
    }

    // allocate memory (size is in bi.bmiHeader.biSizeImage)
    if((data = malloc(bi.bmiHeader.biSizeImage)) == NULL)
    {
        reportError("malloc failed(bi.bmiHeader.biSizeImage).");
        return 0;
    }
    // now get the data
    if(!GetDIBits(
        hdcMemory,
        hbmMemory,
        0,
        cyScreen,    
        data,
        &bi,
        DIB_RGB_COLORS))
    {
        reportError("GetDIBits failed(while getting data).");
        return 0;
    }
    // clean-up
    if(!SaveBitmapFile(hdcScreen, szFileName))
    {
        reportError("SaveBitmapFile failed.");
        return 0;
    }
    SelectObject(hdcMemory, hbmOld);
    DeleteDC(hdcMemory);
    DeleteObject(hbmMemory);
    return 1;
    // thats it.
    // data = the data
    //    1. 24 bpp BGR format
    //    2. 32-bit padded scanlines
    //    3. upside down
    // cxScreen = width
    // cyScreen = height
}

BOOL SaveBitmapFile(HDC p_hDC, LPCTSTR p_pchFileName)
{

    HBITMAP hBmp = (HBITMAP)GetCurrentObject( p_hDC, OBJ_BITMAP );
    
    BITMAPINFO stBmpInfo; 
    stBmpInfo.bmiHeader.biSize = sizeof( stBmpInfo.bmiHeader );
    stBmpInfo.bmiHeader.biBitCount = 0;
    if(!GetDIBits( p_hDC, hBmp, 0, 0, NULL, &stBmpInfo, DIB_RGB_COLORS ))
    {
        reportError("GetDIBits failed(SaveBitmapFile).");
        return 0;
    }    
    
    ULONG iBmpInfoSize; 
    switch( stBmpInfo.bmiHeader.biBitCount )
    { 
        case 24:
            iBmpInfoSize = sizeof(BITMAPINFOHEADER); 
        break;
        
        case 16: 
        case 32:
            iBmpInfoSize = sizeof(BITMAPINFOHEADER)+sizeof(DWORD)*3; 
        break;
        
        default:
        iBmpInfoSize = sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * ( 1 << stBmpInfo.bmiHeader.biBitCount ); 
        break;
    } 
    
    PBITMAPINFO pstBmpInfo;
    if( iBmpInfoSize != sizeof(BITMAPINFOHEADER) ) 
    { 
        pstBmpInfo = (PBITMAPINFO)GlobalAlloc( GMEM_FIXED | GMEM_ZEROINIT, iBmpInfoSize );
        PBYTE pbtBmpInfoDest = (PBYTE)pstBmpInfo; 
        PBYTE pbtBmpInfoSrc = (PBYTE)&stBmpInfo; 
        ULONG iSizeTmp = sizeof( BITMAPINFOHEADER );

        while(iSizeTmp--) 
        { 
            *( ( pbtBmpInfoDest )++ ) = *( ( pbtBmpInfoSrc )++ ); 
        } 
    } 

    HANDLE hFile = CreateFile( p_pchFileName, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_ARCHIVE , NULL );

    BITMAPFILEHEADER stBmpFileHder; 
    stBmpFileHder.bfType = 0x4D42; // 'BM' 
    stBmpFileHder.bfSize = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + iBmpInfoSize + pstBmpInfo->bmiHeader.biSizeImage; 
    stBmpFileHder.bfReserved1 = 0;
    stBmpFileHder.bfReserved2 = 0; 
    stBmpFileHder.bfOffBits = sizeof(BITMAPFILEHEADER) + iBmpInfoSize; 

    DWORD dRet;
    WriteFile( hFile, (LPCVOID)&stBmpFileHder, sizeof(BITMAPFILEHEADER), &dRet, NULL );
    
    PBYTE pBits = (PBYTE)GlobalAlloc( GMEM_FIXED | GMEM_ZEROINIT, stBmpInfo.bmiHeader.biSizeImage );

    HBITMAP hBmpOld; 
    HBITMAP hTmpBmp = CreateCompatibleBitmap( p_hDC, pstBmpInfo->bmiHeader.biWidth, pstBmpInfo->bmiHeader.biHeight );
    hBmpOld = (HBITMAP)SelectObject( p_hDC, hTmpBmp ); 
    GetDIBits( p_hDC, hBmp, 0, pstBmpInfo->bmiHeader.biHeight, (LPSTR)pBits, pstBmpInfo, DIB_RGB_COLORS );

    WriteFile( hFile, (LPCVOID)pstBmpInfo, iBmpInfoSize, &dRet, NULL );
    
    WriteFile( hFile, (LPCVOID)pBits, pstBmpInfo->bmiHeader.biSizeImage, &dRet, NULL );

    SelectObject(p_hDC, hBmpOld); 
    DeleteObject(hTmpBmp); 
    CloseHandle(hFile); 
    GlobalFree(pstBmpInfo); 
    GlobalFree(pBits); 
    return 1;
}

- reportError je custom funkcija pa slobdno zamijenite sa svojom...
- bmp je uncompressed i ispada normalno oko 5mb zato ako hocete manje proguglajte za algoritam kompresije ;)

I jos nesto... ako koristite MingW kompajler vjerovatno ste upali u probleme tipa "Undefined reference to **neka win32 api funkcija**" - rijesenje:
Code:
gcc -mwindows source.c -o output.exe


Isti problem sa winsock-om, i morate jako dobro traziti po Google-u da biste nasli, jer obicno se preporuca stavljanje potrebne komande na krivo mjesto.. Znaci eto kako to treba:
Code:
gcc source.c -o output.exe -lws2_32


Moze li sticky ako nije problem da se ne pita za win32 api dokumentaciju nego da se zna ;)
"UNIX is basically a simple operating
system, but you have to be a genius
to understand the simplicity."

C & PHP|MYSQL Programmer
 
Odgovor na temu

[es] :: C/C++ programiranje :: C/C++ za početnike :: WIN32 API Big Help Documentation

[ Pregleda: 1406 | Odgovora: 0 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.