用键盘keybd_event模拟PrintScreen键

解决方案 »

  1.   

    BOOL HardCopy( HBITMAP *phBitmap, RECT *pRect, int iType )
    { HWND hWnd = (HWND)0 ; HDC hDC = ::GetDC( hWnd ) ;
    HWND hWork ;
    RECT rectTaskBar ;
    int iX = 0 ;
    int iY = 0 ;
    int iWidth = 0 ;
    int iHeight = 0 ;
    switch( iType )
    {
    case CAPTURE_RECT : // 儐乕僓巜掕嬮宍椞堟
    iX = (*pRect).left ;
    iY = (*pRect).top ;
    iWidth =(*pRect).right - (*pRect).left ;
    iHeight =(*pRect).bottom - (*pRect).top ;
    break ;
    case CAPTURE_CLIENT : // 僋儔僀傾儞僩椞堟(僫價僎乕僔儑儞僶乕丒僐儅儞僪僶乕晹暘傪彍偔)
    ::ReleaseDC( hWnd, hDC ) ;
    hWnd = ::GetDesktopWindow() ;
    hDC = ::GetDC( hWnd ) ;
    ::GetWindowRect( hWnd, pRect ) ;
    if( (hWork = ::FindWindow( _T("HHTaskBar"), NULL)) )
    {
    ::GetWindowRect( hWork, &rectTaskBar ) ;
    pRect->bottom -= (rectTaskBar.bottom - rectTaskBar.top) ;
    }
    iX = 0 ;
    iY = 0 ;
    iWidth = pRect->right - pRect->left ;
    iHeight = pRect->bottom - pRect->top ;
    break ;
    case CAPTURE_DESKTOP : // 夋柺慡懱
    default :
    iX = 0 ;
    iY = 0 ;
    iWidth = GetDeviceCaps( hDC, HORZRES ) ;
    iHeight = GetDeviceCaps( hDC, VERTRES ) ;
    break ;
    } *phBitmap = CreateCompatibleBitmap( hDC, iWidth, iHeight ) ;
    if( !(*phBitmap) )
    {
    ::ReleaseDC( hWnd, hDC ) ;
    return( FALSE ) ;
    } // DSP儊儌儕 僨僶僀僗僐儞僥僉僗僩嶌惉
    HDC hmemDC ;
    hmemDC = CreateCompatibleDC( hDC ) ; HBITMAP hOldBitmap ;
    hOldBitmap = (HBITMAP)SelectObject( hmemDC, *phBitmap ) ; // 價僢僩儅僢僾暋幨
    BitBlt( hmemDC,0, 0, iWidth, iHeight, hDC, iX, iY , SRCCOPY ) ; SelectObject( hmemDC, hOldBitmap ) ;
    DeleteDC( hmemDC ) ;

    // 僉儍僾僠儍僒僀僘僙僢僩
    pRect->left = 0 ;
    pRect->top = 0 ;
    pRect->right = iWidth ;
    pRect->bottom = iHeight ; ::ReleaseDC( hWnd, hDC ) ;
    return( TRUE ) ;
    }