资源简介
使用C语言写远程屏幕监视程序,此处为关键代码,具体参考博文.

代码片段和文件信息
/*以下代码为服务器和客户端连接后的
*其中ImageSock为用来通信的socket
*/
// Get the Screen DC
HDC hDC = GetDC( GetDesktopWindow() );
// Create a compatible DC
HDC hCpDC = CreateCompatibleDC( hDC );
// Create a compatible bitmap
HBITMAP hBmp = CreateCompatibleBitmap( hDC nScreenX nScreenY );
// Select the compatible bitmap into the compatible DC and get the old bitmap handle
HBITMAP hOldBmp = (HBITMAP)Selectobject( hCpDC hBmp );
// Copy the screen to the compatible DC
StretchBlt( hCpDC 0 0 nScreenX nScreenY hDC 0 0 nScreenX nScreenY SRCCOPY);
// Fullfill the BITMAPINFOHEADER structure
Getobject( hBmp sizeof(BITMAP) &bmp );
bi.biSize = sizeof(BITMAPINFOHEADER);
bi.biPlanes = 1;
bi.biWidth = bmp.bmWidth;
bi.biHeight = bmp.bmHeight;
bi.biCompression = BI_RGB;
bi.biSizeImage = bmp.bmHeight * bmp.bmWidthBytes;
bi.biBitCount = bmp.bmPlanes * bmp.bmBitsPixel;
bi.biXPelsPerMeter = 0;
bi.biYPelsPerMeter = 0;
bi.biClrUsed = 0;
bi.biClrImportant = 0;
//为要传输的位图分配内存,计算所需内存大小
int nSize = sizeof(BITMAPINFOHEADER) + bi.biSizeImage;
// 分配内存
char *lp = (char *)( new byte[nSize] );
// 放位图的大小,用来通知客户端
char Buffer[1024] = {0};
while (1)
{
// Copy the screen to the compatible DC
StretchBlt( hCpDC 0 0 nScreenX nScreenY hDC 0 0 nScreenX nScreenY SRCCOPY);
// Fullfill the BITMAPINFOHEADER structure
Getobject( hBmp sizeof(BITMAP) &bmp );
bi.biSize = sizeof(BITMAPINFOHEADER);
bi.biPlanes = 1;
bi.biWidth = bmp.bmWidth;
bi.biHeight = bmp.bmHeight;
bi.biCompression = BI_RGB;
bi.biSizeImage = bmp.bmHeight * bmp.bmWidthBytes;
bi.biBitCount = bmp.bmPlanes * bmp.bmBitsPixel;
bi.biXPelsPerMeter = 0;
bi.biYPelsPerMeter = 0;
bi.biClrUsed = 0;
bi.biClrImportant = 0;
//复制BITMAPINFOHEADER信息到内存中
memcpy( lp &bi sizeof(BITMAPINFOHEADER) );
//复制具体的位图数据到内存中
if ( ERROR_INVALID_PARAMETER == GetDIBits( hCpDC hBmp 0 bmp.bmHeight lp + sizeof(BITMAPINFOHEADER) (LPBITMAPINFO) &bi DIB_RGB_COLORS ) )
{
printf( “[GetDIBits] error:ERROR_INVALID_PARAMETER\n“ );
continue;
}
// Receive the feedback
if ( 0 == recv( ImageSock Buffer 1024 0 ) )
break;
if ( strcmp( Buffer “200 OK“ ) )
break;
// Send the screen data
send( ImageSock lp nSize 0 );
}
ReleaseDC( GetDesktopWindow() hDC );
DeleteDC( hCpDC );
delete []lp;
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 2518 2009-02-14 19:59 CatchScreen.cpp
文件 456 2009-02-14 20:02 Client.cpp
----------- --------- ---------- ----- ----
2974 2
- 上一篇:C++写的SIS疾病传播模型模拟
- 下一篇:c/c++实现银行家算法模拟
相关资源
- 国际象棋的qt源代码
- 操作系统c语言模拟文件管理系统844
- C语言开发实战宝典
- C++中头文件与源文件的作用详解
- C语言代码高亮html输出工具
- 猜数字游戏 c语言代码
- C语言课程设计
- 数字电位器C语言程序
- CCS FFT c语言算法
- 使用C语言编写的病房管理系统
- 通信过程中的RS编译码程序(c语言)
- 计算机二级C语言上机填空,改错,编
- 用回溯法解决八皇后问题C语言实现
- 简易教务管理系统c语言开发文档
- 操作系统课设 读写者问题 c语言实现
- 小波变换算法 c语言版
- C流程图生成器,用C语言代码 生成C语
- 3des加密算法C语言实现
- 简单的C语言点对点聊天程序
- 单片机c语言源程序(51定时器 八个按
- 个人日常财务管理系统(C语言)
- c语言电子商务系统
- 小甲鱼C语言课件 源代码
- 将图片转换为C语言数组的程序
- C语言实现的一个内存泄漏检测程序
- DES加密算法C语言实现
- LINUX下命令行界面的C语言细胞游戏
- 用单片机控制蜂鸣器播放旋律程序(
- 学校超市选址问题(数据结构C语言版
- 电子时钟 有C语言程序,PROTEUS仿真图
评论
共有 条评论