截屏软件 我想做一个截屏软件,可以全屏与局部.并保存到剪贴板.应该怎样做啊 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 参考代码:void C***Dlg::OnCaptureSave() { // TODO: Add your control notification handler code here //获得输入的保存路径 CFileDialog savePath(FALSE ,NULL,"save.bmp",OFN_HIDEREADONLY,"Bitmap Files(*.bmp)|*.bmp||",NULL); savePath.m_ofn.lpstrTitle="请选择保存路径并输入文件名"; if(savePath.DoModal()==IDOK) { CString fullName; fullName=savePath.GetPathName(); m_tip="屏幕成功拷贝"; //m_tip是一个编辑框的CString变量 UpdateData(FALSE); //获得屏幕窗口的对象句柄 CWnd *pWnd=GetDesktopWindow(); //对话框窗口最小化,使截到的屏幕不包含对话框窗口 this->ShowWindow(SW_SHOWMINIMIZED); //将屏幕窗口拷贝到DIB位图中 HANDLE hDib=DIBFromWindow(pWnd,NULL); CFile file; file.Open(fullName,CFile::modeCreate|CFile::modeWrite); SaveToFile(hDib,file);//将位图存为指定名字的文件 file.Close(); GlobalFree(hDib); }} 给你点源码:HBITMAP CopyScreenToBitmap(LPRECT lpRect) //lpRect 代表选定区域{ HDC hScrDC, hMemDC; // 屏幕和内存设备描述表 HBITMAP hBitmap,hOldBitmap; // 位图句柄 int nX, nY, nX2, nY2; // 选定区域坐标 int nWidth, nHeight; // 位图宽度和高度 int xScrn, yScrn; // 屏幕分辨率 // 确保选定区域不为空矩形 if (IsRectEmpty(lpRect)) return NULL; //为屏幕创建设备描述表 hScrDC = CreateDC("DISPLAY", NULL, NULL, NULL); //为屏幕设备描述表创建兼容的内存设备描述表 hMemDC = CreateCompatibleDC(hScrDC); // 获得选定区域坐标 nX = lpRect->left; nY = lpRect->top; nX2 = lpRect->right; nY2 = lpRect->bottom; // 获得屏幕分辨率 xScrn = GetDeviceCaps(hScrDC, HORZRES); yScrn = GetDeviceCaps(hScrDC, VERTRES); //确保选定区域是可见的 if (nX < 0) nX = 0; if (nY < 0) nY = 0; if (nX2 > xScrn) nX2 = xScrn; if (nY2 > yScrn) nY2 = yScrn; nWidth = nX2 - nX; nHeight = nY2 - nY; // 创建一个与屏幕设备描述表兼容的位图 hBitmap=CreateCompatibleBitmap(hScrDC,nWidth,nHeight); // 把新位图选到内存设备描述表中 hOldBitmap=(HBITMAP)SelectObject(hMemDC,hBitmap); // 把屏幕设备描述表拷贝到内存设备描述表中 BitBlt(hMemDC,0,0, nWidth,nHeight,hScrDC, nX, nY, SRCCOPY); //得到屏幕位图的句柄 hBitmap=(HBITMAP)SelectObject(hMemDC,hOldBitmap); //清除 DeleteDC(hScrDC); DeleteDC(hMemDC); // 返回位图句柄 return hBitmap;}HBITMAP CopyBitmap(HBITMAP hBitmapSrc){ BITMAP bitmap; HBITMAP hBitmapDst; HDC hdcSrc,hdcDst; GetObject(hBitmapSrc,sizeof(BITMAP),&bitmap); hBitmapDst = CreateBitmapIndirect(&bitmap); hdcSrc = CreateCompatibleDC(NULL); hdcDst = CreateCompatibleDC(NULL); SelectObject(hdcSrc,hBitmapSrc); SelectObject(hdcDst,hBitmapDst); BitBlt(hdcDst,0,0,bitmap.bmWidth,bitmap.bmHeight, hdcSrc,0,0,SRCCOPY); DeleteDC(hdcSrc); DeleteDC(hdcDst); return hBitmapDst;}BOOL CopyBitmapToClipboard(HWND hWnd,HBITMAP hBitmap){ HBITMAP hBitmapClip; if(hBitmap == NULL) return FALSE; hBitmapClip = CopyBitmap(hBitmap); if(hBitmapClip == NULL) return FALSE; if( !OpenClipboard(hWnd)) return FALSE; EmptyClipboard(); SetClipboardData(CF_BITMAP,hBitmapClip); CloseClipboard(); return TRUE;}HBITMAP PasteBitmapFromClipboard(HWND hWnd){ HBITMAP hBitmapClip,hBmp; if(IsClipboardFormatAvailable(CF_BITMAP)) { if( !OpenClipboard(hWnd)) return FALSE; hBitmapClip = (HBITMAP)GetClipboardData(CF_BITMAP); if(hBitmapClip == NULL){ CloseClipboard(); return FALSE; } hBmp = CopyBitmap(hBitmapClip); CloseClipboard(); return hBmp; } return NULL;} 找了一个别人写的函数:(http://blog.chinaunix.net/u1/38762/showart_301546.html)HBITMAP CMyBitmapDlg::CopyScreenToBitmap(LPRECT lpRect){ HDC hScrDC, hMemDC; HBITMAP hOldBitmap; int nX, nY, nX2, nY2; int nWidth, nHeight; int xScrn, yScrn; if (IsRectEmpty(lpRect)) return NULL; hScrDC = CreateDC("DISPLAY", NULL, NULL, NULL); hMemDC = CreateCompatibleDC(hScrDC); nX = lpRect->left; nY = lpRect->top; nX2 = lpRect->right; nY2 = lpRect->bottom; xScrn = GetDeviceCaps(hScrDC, HORZRES); yScrn = GetDeviceCaps(hScrDC, VERTRES); if (nX < 0) nX = 0; if (nY < 0) nY = 0; if (nX2 > xScrn) nX2 = xScrn; if (nY2 > yScrn) nY2 = yScrn; nWidth = nX2 - nX; nHeight = nY2 - nY; hBitmap = CreateCompatibleBitmap(hScrDC, nWidth, nHeight); hOldBitmap = (HBITMAP)SelectObject(hMemDC, hBitmap); ShowWindow(SW_HIDE); BitBlt(hMemDC, 0, 0, nWidth, nHeight,hScrDC, nX, nY, SRCCOPY); hBitmap =(HBITMAP)SelectObject(hMemDC, hOldBitmap); DeleteDC(hScrDC); DeleteDC(hMemDC); ShowWindow(SW_SHOW); return hBitmap;}//开始截图void CExampleDlg::OnBtnCopyscreen() { CRect rc; GetDesktopWindow()->GetWindowRect(&rc); hBitmap=CopyScreenToBitmap(&rc);}//复制到剪贴板if (OpenClipboard()) { EmptyClipboard(); SetClipboardData(CF_BITMAP, hBitmap); CloseClipboard(); } http://download.csdn.net/source/295362 自己在 baidu 里搜关键字 vc 截屏一大把 QueryInterface为什么不能成功呢? 两台机器直连,一台发送组播时,为什么在另一台机器上抓不到包? VC 对话框 C++如何定义事件 DLLMAIN 中的 HINSTANCE 参数是什么? 为何我不能在头文件中声明CxImage对象啊?而在cpp文件中就可以? 那个scrollwindow函数到底是干什么的 使用VC连接到Oracle MFC给bmp图像加噪声并用picture控件显示 翻出旧贴,关于DeviceIoControl()控制光驱,高手请看。。。(shines求救) DCT变换算法谁能帮忙解释一下switch是什么意思 怎么在vc里面做柱状图???有例子吗?
{
// TODO: Add your control notification handler code here
//获得输入的保存路径
CFileDialog savePath(FALSE ,NULL,"save.bmp",OFN_HIDEREADONLY,"Bitmap Files(*.bmp)|*.bmp||",NULL);
savePath.m_ofn.lpstrTitle="请选择保存路径并输入文件名";
if(savePath.DoModal()==IDOK)
{
CString fullName;
fullName=savePath.GetPathName();
m_tip="屏幕成功拷贝"; //m_tip是一个编辑框的CString变量
UpdateData(FALSE);
//获得屏幕窗口的对象句柄
CWnd *pWnd=GetDesktopWindow();
//对话框窗口最小化,使截到的屏幕不包含对话框窗口
this->ShowWindow(SW_SHOWMINIMIZED);
//将屏幕窗口拷贝到DIB位图中
HANDLE hDib=DIBFromWindow(pWnd,NULL);
CFile file;
file.Open(fullName,CFile::modeCreate|CFile::modeWrite);
SaveToFile(hDib,file);//将位图存为指定名字的文件
file.Close();
GlobalFree(hDib);
}
}
{
HDC hScrDC, hMemDC;
// 屏幕和内存设备描述表
HBITMAP hBitmap,hOldBitmap;
// 位图句柄
int nX, nY, nX2, nY2;
// 选定区域坐标
int nWidth, nHeight;
// 位图宽度和高度
int xScrn, yScrn;
// 屏幕分辨率
// 确保选定区域不为空矩形
if (IsRectEmpty(lpRect))
return NULL;
//为屏幕创建设备描述表
hScrDC = CreateDC("DISPLAY", NULL, NULL, NULL);
//为屏幕设备描述表创建兼容的内存设备描述表
hMemDC = CreateCompatibleDC(hScrDC);
// 获得选定区域坐标
nX = lpRect->left;
nY = lpRect->top;
nX2 = lpRect->right;
nY2 = lpRect->bottom;
// 获得屏幕分辨率
xScrn = GetDeviceCaps(hScrDC, HORZRES);
yScrn = GetDeviceCaps(hScrDC, VERTRES);
//确保选定区域是可见的
if (nX < 0)
nX = 0;
if (nY < 0)
nY = 0;
if (nX2 > xScrn)
nX2 = xScrn;
if (nY2 > yScrn)
nY2 = yScrn;
nWidth = nX2 - nX;
nHeight = nY2 - nY;
// 创建一个与屏幕设备描述表兼容的位图
hBitmap=CreateCompatibleBitmap(hScrDC,nWidth,nHeight);
// 把新位图选到内存设备描述表中
hOldBitmap=(HBITMAP)SelectObject(hMemDC,hBitmap);
// 把屏幕设备描述表拷贝到内存设备描述表中
BitBlt(hMemDC,0,0, nWidth,nHeight,hScrDC, nX, nY, SRCCOPY);
//得到屏幕位图的句柄
hBitmap=(HBITMAP)SelectObject(hMemDC,hOldBitmap);
//清除
DeleteDC(hScrDC);
DeleteDC(hMemDC);
// 返回位图句柄
return hBitmap;
}
HBITMAP CopyBitmap(HBITMAP hBitmapSrc)
{
BITMAP bitmap;
HBITMAP hBitmapDst;
HDC hdcSrc,hdcDst; GetObject(hBitmapSrc,sizeof(BITMAP),&bitmap);
hBitmapDst = CreateBitmapIndirect(&bitmap); hdcSrc = CreateCompatibleDC(NULL);
hdcDst = CreateCompatibleDC(NULL); SelectObject(hdcSrc,hBitmapSrc);
SelectObject(hdcDst,hBitmapDst); BitBlt(hdcDst,0,0,bitmap.bmWidth,bitmap.bmHeight,
hdcSrc,0,0,SRCCOPY); DeleteDC(hdcSrc);
DeleteDC(hdcDst); return hBitmapDst;
}
BOOL CopyBitmapToClipboard(HWND hWnd,HBITMAP hBitmap)
{
HBITMAP hBitmapClip; if(hBitmap == NULL)
return FALSE; hBitmapClip = CopyBitmap(hBitmap); if(hBitmapClip == NULL)
return FALSE;
if( !OpenClipboard(hWnd))
return FALSE;
EmptyClipboard();
SetClipboardData(CF_BITMAP,hBitmapClip); CloseClipboard();
return TRUE;
}
HBITMAP PasteBitmapFromClipboard(HWND hWnd)
{
HBITMAP hBitmapClip,hBmp; if(IsClipboardFormatAvailable(CF_BITMAP))
{
if( !OpenClipboard(hWnd))
return FALSE; hBitmapClip = (HBITMAP)GetClipboardData(CF_BITMAP); if(hBitmapClip == NULL){
CloseClipboard();
return FALSE;
}
hBmp = CopyBitmap(hBitmapClip); CloseClipboard(); return hBmp; }
return NULL;
}
HBITMAP CMyBitmapDlg::CopyScreenToBitmap(LPRECT lpRect)
{
HDC hScrDC, hMemDC;
HBITMAP hOldBitmap;
int nX, nY, nX2, nY2;
int nWidth, nHeight;
int xScrn, yScrn;
if (IsRectEmpty(lpRect))
return NULL;
hScrDC = CreateDC("DISPLAY", NULL, NULL, NULL);
hMemDC = CreateCompatibleDC(hScrDC);
nX = lpRect->left;
nY = lpRect->top;
nX2 = lpRect->right;
nY2 = lpRect->bottom;
xScrn = GetDeviceCaps(hScrDC, HORZRES);
yScrn = GetDeviceCaps(hScrDC, VERTRES);
if (nX < 0) nX = 0;
if (nY < 0) nY = 0;
if (nX2 > xScrn) nX2 = xScrn;
if (nY2 > yScrn) nY2 = yScrn;
nWidth = nX2 - nX;
nHeight = nY2 - nY;
hBitmap = CreateCompatibleBitmap(hScrDC, nWidth, nHeight);
hOldBitmap = (HBITMAP)SelectObject(hMemDC, hBitmap);
ShowWindow(SW_HIDE);
BitBlt(hMemDC, 0, 0, nWidth, nHeight,hScrDC, nX, nY, SRCCOPY);
hBitmap =(HBITMAP)SelectObject(hMemDC, hOldBitmap);
DeleteDC(hScrDC);
DeleteDC(hMemDC);
ShowWindow(SW_SHOW);
return hBitmap;
}
//开始截图
void CExampleDlg::OnBtnCopyscreen()
{
CRect rc;
GetDesktopWindow()->GetWindowRect(&rc);
hBitmap=CopyScreenToBitmap(&rc);
}
//复制到剪贴板
if (OpenClipboard())
{
EmptyClipboard();
SetClipboardData(CF_BITMAP, hBitmap);
CloseClipboard();
}
一大把