procedure ScreenCap(LeftPos,TopPos,RightPos,BottomPos:integer);
var
  RectWidth,RectHeight:integer;
  SourceDC,DestDC,Bhandle:integer;
  Bitmap:TBitmap;
  Stream:TMemoryStream;
begin
  RectWidth:=RightPos-LeftPos;
  RectHeight:=BottomPos-TopPos;
  SourceDC:=CreateDC('DISPLAY','','',nil);
  DestDC:=CreateCompatibleDC(SourceDC);
  Bhandle:=CreateCompatibleBitmap(SourceDC,RectWidth,RectHeight);
  SelectObject(DestDC,Bhandle);
  BitBlt(DestDC,0,0,RectWidth,RectHeight,SourceDC,LeftPos,TopPos,SRCCOPY);
  Bitmap:=TBitmap.Create;
  Bitmap.Handle:=BHandle;
  Stream := TMemoryStream.Create;
  Bitmap.SaveToStream(Stream);
  Bitmap.PixelFormat := pf24bit;
  Stream.Free;
  try
    FORM1.Image1 .Picture .Bitmap :=Bitmap;
    Bitmap.SaveToFile('C:\Documents and Settings\'+pchar(GetCurrentUserName)+'\桌面\2.bmp');
  finally
    Bitmap.Free;
    DeleteDC(DestDC);
    ReleaseDC(Bhandle,SourceDC);
  end;
end;用上面这个函数能正常截图,但是我如果切换电脑用户时(WIN+L)他截出来的就是黑色的,
请问各位大大们有没有办法让他不黑屏!

解决方案 »

  1.   

    这个似乎是没什么办法,我一直理解为无解, 程序运行在那个用户下就截图那个用户,而且是活动用户。 
    所以这么一来在登录界面,所以猜测当前是system, 所以屏幕无东西可以截。 
    因为就算你当前用户也是不能有其它窗口挡住,所以非活动的用户也无法吧。
      

  2.   

    注入到System用户下的那个WinLogon.exe中进行解屏,需要相应的权限及程序中申请特权才能完成.
      

  3.   

    按了WIN+L之后,不同的桌面,不黑才怪
      

  4.   

    OpenInputDesktop
    GetUserObjectInformation
    CreateProcessAsUser