Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

BitBlt problems with Aero

Status
Not open for further replies.

Jimbom2k

Programmer
Mar 18, 2007
1
GB
Im playing around with an application which uses BitBlt with the SRCCOPY flag to capture a full screen window (a game) and save it as a BMP.

This works fine in XP and Vista with Aero turned off but on with Aero enabled im having problems. Either the captures come out completely black or the desktop underneath the fullscreen window is captured.


Has anyone else had this problem? Ive had a look through the MSDN BitBlt entry and it mentions nothing about any Vista pitfalls.
 
try this:

Code:
const 
  CAPTUREBLT = $40000000; 

var 
  hdcScreen     : DWORD; 
  hdcCompatible : DWORD; 
  hbmScreen     : DWORD; 
  bmp           : TBitmap; 

begin 
  bmp := TBitmap.Create; 
  try 
    hdcScreen     := CreateDC('DISPLAY', nil, nil, nil); 
    if hdcScreen = 0 then begin 
      ShowMessage('CreateDC: '+SysErrorMessage(GetLastError)); 
      Exit; 
    end; 
    try 
      hdcCompatible := CreateCompatibleDC(hdcScreen); 
      if hdcCompatible = 0 then begin 
        ShowMessage('CreateCompatibleDC: '+SysErrorMessage(GetLastError)); 
        Exit; 
      end; 
      try 
        hbmScreen := CreateCompatibleBitmap(hdcScreen,GetDeviceCaps(hdcScreen, HORZRES),GetDeviceCaps(hdcScreen, VERTRES)); 
        if hbmScreen = 0 then begin 
          ShowMessage('CreateCompatibleBitmap: '+SysErrorMessage(GetLastError)); 
          Exit; 
        end; 
        try 
          SelectObject(hdcCompatible, hbmScreen); 
          bmp.Handle := hbmScreen; 
          BitBlt(hdcCompatible, 
            0, 0, 
            bmp.Width, bmp.Height, 
            hdcScreen, 
            0, 0, 
            SRCCOPY or CAPTUREBLT); 
            bmp.SaveToFile('c:\temp\Screenshot.bmp'); 
          finally 
            DeleteObject(hbmScreen); 
          end; 
      finally 
        DeleteDC(hdcCompatible); 
      end; 
    finally 
      DeleteDC(hdcScreen); 
    end; 
  finally 
    FreeAndNil(bmp); 
  end; 
end;

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top