cpubbs论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

LabVIEW+单片机学习套件全套教程资料下载[免费]LabVIEW论坛精华列表贴USB0816数据采集卡《LabVIEW宝典》
LabWindows/CVI论坛精华贴NET0816以太网数据采集卡RC0210远程设备授权系统 关闭关停锁定打开设备 户外分布式数据采集
NET1624低速高精度以太网数据采集卡WIFI0824SD无线WIFI网络数据采集卡脱机运行 SD存储 小尺寸微型 串口采集远程采集 安卓 手持移动采集 纪录仪
查看: 1195|回复: 6

VB拷屏

[复制链接]
发表于 2008-12-23 09:23:01 | 显示全部楼层 |阅读模式
我要用VB写个拷屏的程序,就是将屏幕拷屏,然后存入一个文件,整了好久没搞定,哪位兄弟可以帮忙啊?谢谢了!
发表于 2008-12-23 09:25:51 | 显示全部楼层
记得以前在一本书中看到过类似的文章,是远程拷屏的,有空再找一下吧.看看能不能找到.
发表于 2008-12-23 09:31:45 | 显示全部楼层
如果你用的是2005,.NET   Framework   2.0   版中是新增了Graphics.CopyFromScreen   方法。   
  试试看。
发表于 2008-12-23 09:33:26 | 显示全部楼层
再有就是调用API的方式,以下内容是从网上找到的,可以参考一下,是用C#写的.
struct   GetDeviceCapsIndex   
  {   
  public   static   readonly   int   DRIVERVERSION   =   0;   
  public   static   readonly   int   HORZSIZE   =   4;   
  public   static   readonly   int   VERTSIZE   =   6;   
  public   static   readonly   int   HORZRES   =   8;   
  public   static   readonly   int   VERTRES   =   10;   
   
  }   
   
  [StructLayout(LayoutKind.Sequential,   CharSet=CharSet.Auto)]     
  public   struct   LUID     
  {   
  public   uint   LowPart;     
  public   uint   HighPart;     
  }   
   
  [StructLayout(LayoutKind.Sequential,   CharSet=CharSet.Auto)]     
  public   struct   TOKEN_PRIVILEGES   
  {     
  public   uint   PrivilegeCount;     
  public   LUID   Luid;     
  public   uint   Attributes;     
  }   
   
  public   class   Win32API   
  {   
  [DllImport("Advapi32",   CharSet=CharSet.Auto)]     
  public   static   extern   bool   LookupPrivilegeValue   (string   sysname,string   privname,ref   LUID   luid);     
   
  [DllImport("advapi32",   CharSet=CharSet.Auto)]     
  public   static   extern   bool   AdjustTokenPrivileges(IntPtr   handle,   bool   dsall,ref   TOKEN_PRIVILEGES   newstate,int   len,   IntPtr   oldstate,IntPtr   retlen);     
   
  [DllImport("kernel32.dll")]      
  public   static   extern   int   GetLastError();      
   
  [DllImport("user32.dll")]   
  public   static   extern   bool   ExitWindowsEx(int   uFlags,   int   dwReason);      
  [DllImport("gdi32.dll")]   
  public   static   extern   IntPtr   CreateDC(   
  string   lpszDriver,                 //   driver   name   
  string   lpszDevice,                 //   device   name   
  string   lpszOutput,                 //   not   used;   should   be   NULL   
  Int64   lpInitData     //   optional   printer   data   
  );   
      
  [DllImport("gdi32.dll")]   
  public   static   extern   IntPtr   CreateCompatibleDC(   
  IntPtr   hdc   //   handle   to   DC   
  );   
      
  [DllImport("gdi32.dll")]   
  public   static   extern   int   GetDeviceCaps(   
  IntPtr   hdc,           //   handle   to   DC   
  int   nIndex       //   index   of   capability   
  );   
   
  [DllImport("gdi32.dll")]   
  public   static   extern   IntPtr   CreateCompatibleBitmap(   
  IntPtr   hdc,                 //   handle   to   DC   
  int   nWidth,           //   width   of   bitmap,   in   pixels   
  int   nHeight           //   height   of   bitmap,   in   pixels   
  );   
   
  [DllImport("gdi32.dll")]   
  public   static   extern   IntPtr   SelectObject(   
  IntPtr   hdc,                     //   handle   to   DC   
  IntPtr   hgdiobj       //   handle   to   object   
  );   
   
  [DllImport("gdi32.dll")]   
  public   static   extern   int   BitBlt(   
  IntPtr   hdcDest,   //   handle   to   destination   DC   
  int   nXDest,     //   x-coord   of   destination   upper-left   corner   
  int   nYDest,     //   y-coord   of   destination   upper-left   corner   
  int   nWidth,     //   width   of   destination   rectangle   
  int   nHeight,   //   height   of   destination   rectangle   
  IntPtr   hdcSrc,     //   handle   to   source   DC   
  int   nXSrc,       //   x-coordinate   of   source   upper-left   corner   
  int   nYSrc,       //   y-coordinate   of   source   upper-left   corner   
  UInt32   dwRop     //   raster   operation   code   
  );   
   
  [DllImport("gdi32.dll")]   
  public   static   extern   int   DeleteDC(   
  IntPtr   hdc                     //   handle   to   DC   
  );   
   
  }     
  public   class   GDI   
  {   
  public   static   Bitmap   GetScreen()   
  {   
  IntPtr   hscrdc,hmemdc;   
  IntPtr   hbitmap,holdbitmap;   
  int   nx,ny,nx2,ny2;   
  nx=ny=nx2=ny2=0;   
  int   nwidth,   nheight;   
  int   xscrn,   yscrn;   
  hscrdc   =   Win32API.CreateDC("DISPLAY",   null,   null,   0);//创建DC句柄   
  hmemdc   =   Win32API.CreateCompatibleDC(hscrdc);//创建一个内存DC   
  xscrn   =   Win32API.GetDeviceCaps(hscrdc,   GetDeviceCapsIndex.HORZRES);//获取屏幕宽度   
  yscrn   =   Win32API.GetDeviceCaps(hscrdc,   GetDeviceCapsIndex.VERTRES);//获取屏幕高度   
  nx   =   0;   
  ny   =   0;   
  nx2   =   xscrn;   
  ny2   =   yscrn;   
   
  nwidth   =   nx2   -   nx;//截取范围的宽度   
  nheight   =   ny2   -   ny;//截取范围的高度   
  hbitmap   =   Win32API.CreateCompatibleBitmap(hscrdc,   nwidth,   nheight);//从内存DC复制到hbitmap句柄   
  holdbitmap   =   Win32API.SelectObject(hmemdc,   hbitmap);   
  Win32API.BitBlt(hmemdc,   0,   0,   nwidth,   nheight,hscrdc,   nx,   ny,(UInt32)0xcc0020);   
  hbitmap   =   Win32API.SelectObject(hmemdc,   holdbitmap);   
  Win32API.DeleteDC(hscrdc);//删除用过的对象   
  Win32API.DeleteDC(hmemdc);//删除用过的对象   
  return   Bitmap.FromHbitmap(hbitmap);//用Bitmap.FromHbitmap从hbitmap返回Bitmap   
  }   
   
  }   

以上的调用的API声明,以下是主程序:
public   virtual   void   OnGetScreen()   
  {   
  Bitmap   bmp   =   GDI.GetScreen();   
  Sender   sender   =   new   Sender();   
  MemoryStream   mem   =   new   MemoryStream();   
  bmp.Save(mem   ,   System.Drawing.Imaging.ImageFormat.Jpeg);   
  bmp.Dispose();   
  byte[]   pic;   
  pic   =   mem.GetBuffer();   
  mem.Close();   
  sender.Send(pic);   
  }
发表于 2008-12-23 09:37:04 | 显示全部楼层
以下是一个网友写的VB拷屏的例子,你可以参考一下.

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
 楼主| 发表于 2008-12-26 09:03:24 | 显示全部楼层
谢谢兄弟们啊
 楼主| 发表于 2008-12-26 19:07:05 | 显示全部楼层
Ricken:
    我还想问一下:如果要将指定的窗口拷屏下来(比方说,现在应用程序正在运行,如果要将计算器的界面拷下来),该怎么整呢?如何将拷屏的图像存入文件呢?谢谢
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|cpubbs论坛. ( 粤ICP备09171248号 )

GMT+8, 2025-4-20 17:05 , Processed in 0.574926 second(s), 7 queries , Gzip On, File On.

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表