惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Simon Willison's Weblog
Simon Willison's Weblog
P
Privacy International News Feed
www.infosecurity-magazine.com
www.infosecurity-magazine.com
T
Troy Hunt's Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
Attack and Defense Labs
Attack and Defense Labs
S
Secure Thoughts
V2EX - 技术
V2EX - 技术
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
O
OpenAI News
Cloudbric
Cloudbric
Google Online Security Blog
Google Online Security Blog
Schneier on Security
Schneier on Security
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Help Net Security
Help Net Security
Cyberwarzone
Cyberwarzone
G
GRAHAM CLULEY
L
Lohrmann on Cybersecurity
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Spread Privacy
Spread Privacy
NISL@THU
NISL@THU
N
News and Events Feed by Topic
T
Tenable Blog
S
Security @ Cisco Blogs
N
News and Events Feed by Topic
The Hacker News
The Hacker News
C
CXSECURITY Database RSS Feed - CXSecurity.com
宝玉的分享
宝玉的分享
月光博客
月光博客
酷 壳 – CoolShell
酷 壳 – CoolShell
美团技术团队
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google DeepMind News
Google DeepMind News
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
Tailwind CSS Blog
V
Visual Studio Blog
P
Proofpoint News Feed
Webroot Blog
Webroot Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
博客园 - 三生石上(FineUI控件)
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Jina AI
Jina AI
雷峰网
雷峰网
T
The Blog of Author Tim Ferriss
Hugging Face - Blog
Hugging Face - Blog
腾讯CDC
L
LangChain Blog
The Register - Security
The Register - Security
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 聂微东

博客园 - lmllouk

找nopcommerce兼职人员 ArachNode.Net 之配置 CS2001 CS2008 Adobe CS4 Dreamweaver 产品许可证已过期 CSS实现网页背景渐变 jQuery 多级下拉菜单解决方案 确保已安装类型(.aspx)的应用程序 sql server 行合并 灌水 的论坛 取消svn版本控制 - lmllouk - 博客园 fatal error C1083: Cannot open include file: 'ceconfig.h': No such file or directory PowerDesigner constraint name 长度限制问题 不同服务器数据库之间的数据操作 使用PowerDesigner进行代码生成(转) 怎样给 ActiveX 控件签名并打包发布 温州到杭州火车 通过CertEnroll在CA上(1创建证书请求2得到证书3安装证书) orcale 常见错误 C++ BUILDER AnsiString 用法 - lmllouk
抓屏 - lmllouk - 博客园
lmllouk · 2010-04-28 · via 博客园 - lmllouk

[DllImport("CoreDll.dll", EntryPoint = "GetDesktopWindow")]
  public static extern IntPtr GetDesktopWindow();

  [DllImport("CoreDll.dll", EntryPoint = "GetSystemMetrics")]
  public static extern int GetSystemMetrics(int abc);

  [DllImport("CoreDll.dll", EntryPoint = "GetWindowDC")]
  public static extern IntPtr GetWindowDC(IntPtr ptr);

  [DllImport("coredll.dll")]
  internal static extern IntPtr GetDC(IntPtr hWnd);

  [DllImport("coredll.dll")]
  internal static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC);

  [DllImport("coredll.dll")]
  internal static extern bool BringWindowToTop(IntPtr hWnd);

  [DllImport("coredll", EntryPoint = "ExtEscape")]
  private static extern int ExtEscape(
  IntPtr hdc,
  uint nEscape,
  uint cbInput,
  byte[] lpszInData,
  int cbOutput,
  IntPtr lpszOutData
  );
  [DllImport("CoreDLL.dll")]
  public static extern IntPtr SelectObject(IntPtr hDC, IntPtr hObject);
  [DllImport("CoreDLL.dll")]
  public static extern bool BitBlt(IntPtr hObject, int nXDest, int nYDest,
  int nWidth, int nHeight, IntPtr hObjectSource,
  int nXSrc, int nYSrc, int dwRop);

  // Window State and Position Functions.

  [DllImport("CoreDLL.dll")]
  private static extern IntPtr GetCapture();

  [DllImport("CoreDLL.dll")]
  public static extern IntPtr SetFocus(IntPtr hWnd);

  [DllImport("CoreDLL.dll")]
  private static extern bool SetWindowPos(IntPtr hWnd,
  IntPtr hWndInsertAfter,
  int X,
  int Y,
  int cx,
  int cy,
  int uFlags);

  [DllImport("CoreDLL.dll")]
  public static extern bool DeleteDC(IntPtr hDC);
  [DllImport("CoreDLL.dll")]
  public static extern bool DeleteObject(IntPtr hObject);

  [DllImport("CoreDLL.dll", EntryPoint = "SetForegroundWindow")]
  private static extern bool SetForegroundWindow(System.IntPtr hWnd);

  [DllImport("coredll.dll", EntryPoint = "GetForegroundWindow", SetLastError = true)]
  public static extern IntPtr GetForegroundWindow();

  [DllImport("CoreDLL.dll")]
  public static extern IntPtr FindWindow(string className, string WindowsName);

把上面的内容包装到Display类中,然后。

  public static Bitmap SnapShot()
  {
  Bitmap bmp = new Bitmap(240,320);
  IntPtr hwnd = Display.GetDesktopWindow();
  int width = Display.GetSystemMetrics(Display.SM_CXSCREEN);
  int height = Display.GetSystemMetrics(Display.SM_CYSCREEN);

  IntPtr hdcsrc = Display.GetWindowDC(hwnd);
  IntPtr hdcdes = Display.CreateCompatibleDC(hdcsrc);
  IntPtr hbitmap = Display.CreateCompatibleBitmap(hdcsrc, width, height);
  IntPtr hOld = Display.SelectObject(hdcdes, hbitmap);

  Display.BitBlt(hdcdes, 0, 0, width, height, hdcsrc, 0, -26, Display.SRCCOPY);
  Display.SelectObject(hdcdes, hOld);
  try
  {
  bmp = Bitmap.FromHbitmap(hbitmap);
  Display.DeleteObject(hbitmap);
  Display.DeleteObject(hOld);
  Display.DeleteDC(hdcdes);
  Display.DeleteDC(hdcsrc);
  Display.ReleaseDC(hwnd, hdcsrc);
  return bmp;
  }
  catch (OutOfMemoryException ome)
  {
  Debug.Write("MEM ERROR:"+ome.ToString());
  GC.Collect();
  }
  return bmp;

  }
  }

void ScreenCapture::SaveScreenToBmpFile(const char *filename)

HDC hScrDC, hMemDC;  
int width, height,pixel_cnt; 

//the pointer will save all pixel point's color value
BYTE *lpBitmapBits = NULL; 
//creates a device context for the screen device 
hScrDC = CreateDC(_T("DISPLAY"), NULL, NULL, NULL); 

//get the screen point size
width = GetDeviceCaps(hScrDC, HORZRES);
height = GetDeviceCaps(hScrDC, VERTRES); 
pixel_cnt = 3 * width * height;

//creates a memory device context (DC) compatible with the screen device(hScrDC)  
hMemDC = CreateCompatibleDC(hScrDC); 

//initialise the struct BITMAPINFO for the bimap infomation,
//in order to use the function CreateDIBSection
//on wince os, each pixel stored by 24 bits(biBitCount=24) 
//and no compressing(biCompression=0)
BITMAPINFO RGB24BitsBITMAPINFO; 
ZeroMemory(&RGB24BitsBITMAPINFO, sizeof(BITMAPINFO));
RGB24BitsBITMAPINFO.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
RGB24BitsBITMAPINFO.bmiHeader.biWidth = width;
RGB24BitsBITMAPINFO.bmiHeader.biHeight = height;
RGB24BitsBITMAPINFO.bmiHeader.biPlanes = 1;
RGB24BitsBITMAPINFO.bmiHeader.biBitCount = 24;

//use the function CreateDIBSection and SelectObject 
//in order to get the bimap pointer : lpBitmapBits
HBITMAP directBmp = CreateDIBSection(hMemDC, (BITMAPINFO*)&RGB24BitsBITMAPINFO, 
DIB_RGB_COLORS, (void **)&lpBitmapBits, NULL, 0);
HGDIOBJ previousObject = SelectObject(hMemDC, directBmp); 

// copy the screen dc to the memory dc
BitBlt(hMemDC, 0, 0, width, height, hScrDC, 0, 0, SRCCOPY);

//if you only want to get the every pixel color value, 
//you can begin here and the following part of this function will be unuseful;
//the following part is in order to write file; 
//bimap file header in order to write bmp file
BITMAPFILEHEADER bmBITMAPFILEHEADER;
ZeroMemory(&bmBITMAPFILEHEADER, sizeof(BITMAPFILEHEADER));
bmBITMAPFILEHEADER.bfType = 0x4D42; //bmp  
bmBITMAPFILEHEADER.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
bmBITMAPFILEHEADER.bfSize = bmBITMAPFILEHEADER.bfOffBits + (pixel_cnt); ///3=(24 / 8)

//if the screen does not have any change from last one, just return without saving the Bmp data.
if(! isScreenChanged(lpBitmapBits))
{
DeleteObject(hMemDC);
DeleteObject(hScrDC);
DeleteObject(directBmp);
DeleteObject(previousObject);
return;
}

//write into file 
FILE *mStream = NULL;
if((mStream = fopen(filename, "wb")))
{  
//write bitmap file header
fwrite(&bmBITMAPFILEHEADER, sizeof(BITMAPFILEHEADER), 1, mStream);

//write bitmap info 
fwrite(&(RGB24BitsBITMAPINFO.bmiHeader), sizeof(BITMAPINFOHEADER), 1, mStream);

//write bitmap pixels data
fwrite(lpBitmapBits, pixel_cnt, 1, mStream);
//close file
fclose(mStream);
}

//delete
DeleteObject(hMemDC);
DeleteObject(hScrDC);
//DeleteObject(directBmp);
DeleteObject(previousObject);
return;
}