多显示器,拷屏 ( 积分: 100 )

  • 主题发起人 主题发起人 anni9977
  • 开始时间 开始时间
A

anni9977

Unregistered / Unconfirmed
GUEST, unregistred user!
我现在把程序投到第二个显示器上,想拷第二个显示器的桌面怎么拷啊,急
 
void
vncDesktop::Checkmonitors()
{
nr_monitors=GetNrMonitors();
DEVMODE devMode;
if (nr_monitors>0)
{
if(OSVersion()!=3 && OSVersion()!=5)GetPrimaryDevice();
devMode.dmSize = sizeof(DEVMODE);
if(OSVersion()!=3 && OSVersion()!=5) EnumDisplaySettings(mymonitor[0].device, ENUM_CURRENT_SETTINGS, &devMode);
else EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &devMode);
mymonitor[0].offsetx=devMode.dmPosition.x;
mymonitor[0].offsety=devMode.dmPosition.y;
mymonitor[0].Width=devMode.dmPelsWidth;
mymonitor[0].Height=devMode.dmPelsHeight;
mymonitor[0].Depth=devMode.dmBitsPerPel;
}
if (nr_monitors>1)
{
GetSecondaryDevice();
devMode.dmSize = sizeof(DEVMODE);
EnumDisplaySettings(mymonitor[1].device, ENUM_CURRENT_SETTINGS, &devMode);
mymonitor[1].offsetx=devMode.dmPosition.x;
mymonitor[1].offsety=devMode.dmPosition.y;
mymonitor[1].Width=devMode.dmPelsWidth;
mymonitor[1].Height=devMode.dmPelsHeight;
mymonitor[1].Depth=devMode.dmBitsPerPel;
}
mymonitor[2].offsetx=GetSystemMetrics(SM_XVIRTUALSCREEN);
mymonitor[2].offsety=GetSystemMetrics(SM_YVIRTUALSCREEN);
mymonitor[2].Width=GetSystemMetrics(SM_CXVIRTUALSCREEN);
mymonitor[2].Height=GetSystemMetrics(SM_CYVIRTUALSCREEN);
mymonitor[2].Depth=mymonitor[0].Depth;//depth primary monitor is used
}

Checkmonitors();
asked_display=m_buffer.GetDisplay();
current_monitor=1;
if (asked_display==2 && nr_monitors>1) current_monitor=2;
if (asked_display==3 && nr_monitors>1) current_monitor=3;
if (current_monitor==3) current_monitor=1;

if (current_monitor==1)
{
m_hrootdc = CreateDC(("DISPLAY"),mymonitor[0].device,NULL,NULL);
m_ScreenOffsetx=mymonitor[0].offsetx;
m_ScreenOffsety=mymonitor[0].offsety;
}
if (current_monitor==2)
{
m_hrootdc =CreateDC(("DISPLAY"),mymonitor[1].device,NULL,NULL);
m_ScreenOffsetx=mymonitor[1].offsetx;
m_ScreenOffsety=mymonitor[1].offsety;
}
if (current_monitor==3)
{
m_hrootdc = GetDC(NULL);
m_ScreenOffsetx=mymonitor[2].offsetx;
m_ScreenOffsety=mymonitor[2].offsety;;
}
if (m_hrootdc == NULL) {
vnclog.Print(LL_INTERR, VNCLOG("Failed m_rootdc /n"));
return FALSE;
}
 
没看明白,有没有用delphi弄过的,我要存成JPG文件,谢谢了
 
暈,這都看不懂,那真沒辦法了。
 
是想要拷图部分又不是要你检显示器的部分
 
服了你了,在你面前都看不明白,还说代码不对。
 
uses
Jpeg;

//拷贝监视器屏幕到Jpg,
//参数:JpG,Jpg图形对象.MonitorIndex监视器编号
Procedure MonitorToJpg(JpG : TJPEGImage; MonitorIndex : Integer);
var
DC : HDC;
Bmp : TBitmap;
begin
if (MonitorIndex >= Screen.MonitorCount)or(MonitorIndex <0) then
begin
ShowMessage('指定的显示器序号超出显示器数量范围');
Exit;
end;
Bmp := TBitmap.Create;
Bmp.Width := Screen.Monitors[MonitorIndex].Width;
Bmp.Height := Screen.Monitors[MonitorIndex].Height;
DC := GetDC(0);
BitBlt(Bmp.Canvas.Handle, 0, 0, Bmp.Width, Bmp.Height,
DC, Screen.Monitors[MonitorIndex].Left, Screen.Monitors[MonitorIndex].Top,
SRCCOPY);

ReleaseDC(0, DC);
Jpg.Assign(Bmp);
Bmp.Free;
end;
//////////////////////////////
使用方法如下
procedure TForm1.Button1Click(Sender: TObject);
var
Jpg : TJPEGImage;
begin
Jpg := TJPEGImage.Create;
MonitorToJpg(Jpg, 0);

//Jpg.CompressionQuality := 50; //压缩比
Jpg.Compress();//压缩

Jpg.SaveToFile('c:/a.jpg');
Jpg.Free;
end;
 
后退
顶部