::GetWindowRect(hDlg,&rc); int Width = rc.Width(); int Height = rc.Height(); 看看宽高对不对》 另外: memDC.BitBlt(0,0,Width,Height,pDC,0,0,SRCCOPY); 应该是rc.left,rc.top
int Width = rc.Width(); int Height = rc.Height(); 这两句是rc的实际宽度还是像素? 原来的语句 int Width = pDC->GetDeviceCaps(HORZRES); int Height = pDC->GetDeviceCaps(VERTRES); 好像是像素吧,要是pDC指向rc的像素的话怎么写? 会不会是这里的问题?
出现这个提示Run-Time Check Failure #2 - Stack around the variable 'bih' was corrupted. 程序中断
int Width = rc.Width(); int Height = rc.Height(); 是像素 pixel int Width = pDC->GetDeviceCaps(HORZRES); int Height = pDC->GetDeviceCaps(VERTRES); 是全屏大小, 你只要 bitblt 从 vega 左上起的 宽高 到 memDC。
LPCTSTR lpClassName, // pointer to class name Vega的类名,可以 用SPY++ 找到
LPCTSTR lpWindowName // pointer to window name Vega的窗口标题
);
类名和标题有一个就行
HWND hDlg=(HWND)::FindWindow("#32770","Dialog");
HWND hWnd=::FindWindow(_T("360se_Frame"),NULL);
HDC hdc = ::GetDC(hVege);
CDC *pDC=CDC::FromSafeHandle(hDC);
有了win handle (hDlg)什么都可做。
RECT rc;
::GetClientRect(hDlg,&rc);
DeleteObject(hDC);//Vege DC
RECT rc;
::GetClientRect(hDlg,&rc);
CDC *pDC=CDC::FromHandle(hDC);这样子?
窗口是隐藏的,
你叫他不隐藏。
ShowWindow(hdlg,SW_SHOW)
while(PeekMessage(&msg,(HWND)NULL,0,0,PM_REMOVE) )
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
Spleep(1);
你要让有运行的时间,不能不断的截取。2.而且截取的仍然是全屏幕的图。
就是说全屏幕的包含vega的图?
用你findwindow得到的hwnd,
RECT rc;
GetWindowRect(hVega,&rc);
按 rc的范围值 截取屏幕
到底是什么图,你得到的屏幕 包不包含你要的图? 如果包含的话,只要知道Hwnd可以得到这窗口位置 rc。
截图时 要在 rc 的范围内 ,就得到你要的了
GetClientRect(hDlg,&rect);
int Width = rect.Width();
int Height = rect.Height();
LPDIRECTDRAW lpDD = NULL;
LPDIRECTDRAWSURFACE lpDDSPrime = NULL;
LPDIRECTDRAWSURFACE lpDDSBack = NULL;
LPDIRECTDRAWSURFACE lpDDSGdi = NULL;
LPDIRECTDRAWSURFACE lpSurf = NULL;DDSURFACEDESC DDSdesc;
BOOL m_b24=TRUE;
//rfbServerInitMsg m_scrinfo;
RECT m_bmrect;struct _BMInfo {
BITMAPINFO bmi ;
BOOL truecolour;
RGBQUAD cmap[256] ;
} m_bminfo; // 用来保存位图信息的结构int DX_Init() {// DirectX初始化。返回当前表面获取一张屏幕位图的存储空间大小
HRESULT hr; // 初始化directX
hr = DirectDrawCreate(0, &lpDD, 0);
if (FAILED(hr)) return FALSE; hr = lpDD->SetCooperativeLevel(NULL, DDSCL_NORMAL);
if (FAILED(hr)) return FALSE; ZeroMemory(&DDSdesc, sizeof(DDSdesc));
DDSdesc.dwSize = sizeof(DDSdesc);
DDSdesc.dwFlags = DDSD_CAPS;
DDSdesc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
hr = lpDD->CreateSurface(&DDSdesc, &lpDDSPrime, 0);
if (FAILED(hr)) return FALSE; hr = lpDD->GetGDISurface(&lpDDSGdi);
if (FAILED(hr)) return FALSE; ZeroMemory(&DDSdesc, sizeof(DDSdesc));
DDSdesc.dwSize = sizeof(DDSdesc);
DDSdesc.dwFlags = DDSD_ALL;
hr = lpDDSPrime->GetSurfaceDesc(&DDSdesc);
if (FAILED(hr)) return FALSE; // 初始化位图信息
if ((DDSdesc.dwFlags & DDSD_WIDTH) && (DDSdesc.dwFlags & DDSD_HEIGHT)) {
m_bmrect.left = m_bmrect.top = 0;
m_bmrect.right = DDSdesc.dwWidth;
m_bmrect.bottom = DDSdesc.dwHeight;
} else return FALSE; m_bminfo.bmi.bmiHeader.biCompression = BI_RGB;//BI_BITFIELDS;
m_bminfo.bmi.bmiHeader.biBitCount = DDSdesc.ddpfPixelFormat.dwRGBBitCount; // m_bminfo.truecolour = DDSdesc.ddpfPixelFormat.dwFlags & DDPF_RGB;
if (m_bminfo.bmi.bmiHeader.biBitCount > 8)
m_bminfo.truecolour = TRUE;
else
m_bminfo.truecolour = FALSE; ZeroMemory(&DDSdesc, sizeof(DDSdesc));
DDSdesc.dwSize = sizeof(DDSdesc);
DDSdesc.dwFlags = DDSD_CAPS | DDSD_HEIGHT |DDSD_WIDTH;
DDSdesc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
DDSdesc.dwHeight = m_bmrect.bottom - m_bmrect.top;
DDSdesc.dwWidth = m_bmrect.right - m_bmrect.left;
hr = lpDD->CreateSurface(&DDSdesc, &lpDDSBack, 0);
if (FAILED(hr)) return FALSE;
// hr = lpDDSPrime->QueryInterface( IID_IDirectDrawSurface3, (LPVOID *)&lpSurf);
// if (FAILED(hr)) return FALSE; switch (m_bminfo.bmi.bmiHeader.biBitCount) {
case 32:
case 24:
// Update the bitmapinfo header
m_b24 = TRUE;
m_bminfo.bmi.bmiHeader.biSize = sizeof( BITMAPINFOHEADER );
m_bminfo.bmi.bmiHeader.biWidth = 1024;
m_bminfo.bmi.bmiHeader.biHeight = 768;
m_bminfo.bmi.bmiHeader.biPlanes = 1;
// m_bminfo.bmi.bmiHeader.biBitCount = 24;
m_bminfo.bmi.bmiHeader.biCompression = BI_RGB;
m_bminfo.bmi.bmiHeader.biSizeImage = abs((m_bminfo.bmi.bmiHeader.biWidth * m_bminfo.bmi.bmiHeader.biHeight * m_bminfo.bmi.bmiHeader.biBitCount)/8);
m_bminfo.bmi.bmiHeader.biXPelsPerMeter = (1024*1000)/1024;
m_bminfo.bmi.bmiHeader.biYPelsPerMeter = (768*1000)/768;
m_bminfo.bmi.bmiHeader.biClrUsed = 0;
m_bminfo.bmi.bmiHeader.biClrImportant = 0;
break;
} return m_bminfo.bmi.bmiHeader.biSizeImage;
}BOOL CaptureScreen(RECT &rect, BYTE *scrBuff, UINT scrBuffSize) {// 捕捉屏幕。rect: 区域。scrBuff: 输出缓冲。scrBuffSize: 缓冲区大小
HRESULT hr=0; hr = lpDDSBack->BltFast(rect.left,rect.top,lpDDSPrime,&rect,DDBLTFAST_NOCOLORKEY | DDBLTFAST_WAIT);
if (FAILED(hr)) return FALSE; DDSURFACEDESC surfdesc;
ZeroMemory(&surfdesc, sizeof(surfdesc));
surfdesc.dwSize = sizeof(surfdesc); hr = lpDDSBack->Lock(&rect, &surfdesc, DDLOCK_READONLY | DDLOCK_WAIT | DDLOCK_SURFACEMEMORYPTR /*|DDLOCK_NOSYSLOCK*/, NULL);
// hr = lpDDSPrime->Lock(&rect, &surfdesc, DDLOCK_READONLY | DDLOCK_WAIT | DDLOCK_SURFACEMEMORYPTR /*|DDLOCK_NOSYSLOCK*/, NULL);
if (FAILED(hr)) return FALSE; // copy the data into our buffer
BYTE * destbuffpos, * srcbuffpos;
// m_scrinfo.format.bitsPerPixel = 24;
srcbuffpos = (BYTE *) surfdesc.lpSurface;
destbuffpos = scrBuff; memcpy( destbuffpos, srcbuffpos,m_bminfo.bmi.bmiHeader.biSizeImage); // unlock the primary surface
// lpDDSPrime->Unlock(surfdesc.lpSurface);
lpDDSBack->Unlock(surfdesc.lpSurface);
return TRUE;
}int SaveBitmapToFile(BITMAP *bitmap, LPSTR lpFileName,char *lpBuf) {
DWORD dwWritten;
BITMAPFILEHEADER bmfHdr;
BITMAPINFOHEADER bi;
HANDLE fh=NULL;
bi.biSize = sizeof(BITMAPINFOHEADER);
bi.biWidth= bitmap->bmWidth;
bi.biHeight = bitmap->bmHeight;
bi.biPlanes = 1;
bi.biBitCount = bitmap->bmBitsPixel*8;
bi.biCompression = BI_RGB;
bi.biSizeImage = 0;
bi.biXPelsPerMeter = 0;
bi.biYPelsPerMeter = 0;
bi.biClrUsed = 0;
bi.biClrImportant = 0;
fh = CreateFile(lpFileName, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL);
if (fh == INVALID_HANDLE_VALUE) return FALSE;
bmfHdr.bfType = 0x4D42; // "BM"
bmfHdr.bfSize = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER)+bitmap->bmWidth*bitmap->bmHeight*bitmap->bmBitsPixel;
bmfHdr.bfReserved1 = 0;
bmfHdr.bfReserved2 = 0;
bmfHdr.bfOffBits = (DWORD)sizeof(BITMAPFILEHEADER) + (DWORD)sizeof(BITMAPINFOHEADER);
WriteFile(fh, (LPSTR)&bmfHdr, sizeof(BITMAPFILEHEADER), &dwWritten, NULL);
WriteFile(fh, (char *)&bi,sizeof(BITMAPINFOHEADER), &dwWritten, NULL);
WriteFile(fh, (char *)lpBuf,bitmap->bmWidth*bitmap->bmHeight*bitmap->bmBitsPixel, &dwWritten, NULL);
FlushFileBuffers(fh);
CloseHandle(fh);
return true;
}//(1)获取屏幕绘图设备
//(2)创建一个与屏幕绘图设备相兼容的内存绘图设备
//(2)在内存中创建一个与屏幕绘图设备相兼容的图像对象
//(3)将屏幕设备中的图像复制到内存绘图设备中
//(4)将内存图像保存到文件中
//相关函数:
//GetDIBits:按位的方式返回指定的BITMAP,并按指定的格式存储到内存中
int GetBitmapFromScreen(char *lpFileName) {
char *lpBuf;
HBITMAP hBitmap,hOld ;
HDC hDC,hcDC;
BITMAP bb;
BITMAPINFO b;
HANDLE hp,fh=NULL;
DWORD dwX,dwY; dwX=GetSystemMetrics(SM_CXSCREEN);
dwY=GetSystemMetrics(SM_CYSCREEN);
hDC=GetDC(NULL);
hcDC=CreateCompatibleDC(hDC);
hBitmap=CreateCompatibleBitmap(hDC,dwX,dwY);
hOld=(HBITMAP)SelectObject(hcDC,hBitmap);
BitBlt(hcDC,0, 0,dwX,dwY, hDC, 0, 0, SRCCOPY);
bb.bmWidth=dwX;
bb.bmHeight =dwY;
bb.bmPlanes = 1;
bb.bmWidthBytes=bb.bmWidth*3;
bb.bmBitsPixel=3;
bb.bmType=0;
b.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
b.bmiHeader.biWidth =dwX;
b.bmiHeader.biHeight =dwY;
b.bmiHeader.biPlanes =1;
b.bmiHeader.biBitCount =3*8;
b.bmiHeader.biCompression =BI_RGB;
b.bmiHeader.biSizeImage =0;
b.bmiHeader.biXPelsPerMeter=0;
b.bmiHeader.biYPelsPerMeter=0;
b.bmiHeader.biClrUsed =0;
b.bmiHeader.biClrImportant =0;
b.bmiColors[0].rgbBlue =8;
b.bmiColors[0].rgbGreen =8;
b.bmiColors[0].rgbRed =8;
b.bmiColors[0].rgbReserved =0;
hp=GetProcessHeap();
lpBuf=(char *)HeapAlloc(hp,HEAP_ZERO_MEMORY,bb.bmHeight*bb.bmWidth*4);
GetDIBits(hcDC,hBitmap,0,dwY,lpBuf,&b,DIB_RGB_COLORS);
SaveBitmapToFile(&bb,lpFileName,lpBuf);
ReleaseDC(NULL,hDC);
DeleteDC(hcDC);
DeleteObject(hBitmap);
DeleteObject(hOld);
HeapFree(hp,0,lpBuf);
return true;
}
CRect rc;
::GetClientRect(hDlg,&rc); 这样子对吗?
HWND hDlg=(HWND)::FindWindow("Vega Prime",NULL);
CRect rect;
::GetClientRect(hDlg,&rect);
HDC hDC=::GetDC(hDlg);//屏幕DC
pDC=CDC::FromHandle(hDC);哪里有问题??
这个rc是要用的,现在你可以用
CDC*pDC=GetDC();
这个DC包含了你要的图。把这个DC中的 rc 范围内容,复制到一个 MemDC
pDC->Bitblt(MemDC,0,0,rc.width(),rc.height(),rc.left,rc.top);
就是你要的图
CRect rc;
::GetWindowRect(hDlg,&rc); HDC hDC=::GetDC(hDlg);//屏幕DC
CDC *pDC=GetDC();
int Width = pDC->GetDeviceCaps(HORZRES);
int Height = pDC->GetDeviceCaps(VERTRES); CDC memDC;//内存DC
memDC.CreateCompatibleDC(pDC);
CBitmap memBitmap, *oldmemBitmap;//建立和屏幕兼容的bitmap
memBitmap.CreateCompatibleBitmap(pDC,Width,Height); oldmemBitmap = memDC.SelectObject(&memBitmap);//将memBitmap选入内存DC
pDC->BitBlt(memDC,0,0,rc.Width,rc.Height,rc.left,rc.top);报错CDC::BitBlt 不接受7个参数??
什么状况?
pDC->BitBlt(memDC,0,0,rc.Width,rc.Height,rc.left,rc.top,SRCCOPY);
这样写的话还是会报错的
HDC hDC=::GetDC(hDlg);
CDC *pDC=CDC::FromHandle(hDC);
CRect rc;
::GetWindowRect(hDlg,&rc);
int Width = pDC->GetDeviceCaps(HORZRES);
int Height = pDC->GetDeviceCaps(VERTRES);
CDC memDC;//内存DC
memDC.CreateCompatibleDC(pDC);
CBitmap memBitmap, *oldmemBitmap;//建立和屏幕兼容的bitmap
memBitmap.CreateCompatibleBitmap(pDC,Width,Height);
oldmemBitmap = memDC.SelectObject(&memBitmap);//将memBitmap选入内存DC
pDC->BitBlt(memDC,0,0,rc.Width,rc.Height,rc.left,rc.top,SRCCOPY);错误 CDC::Biblt不能讲参数1从CDC转换为int
HDC hDC=::GetDC(hDlg);
CDC *pDC=CDC::FromHandle(hDC);
::GetWindowRect(hDlg,&rc);
int Width = rc.Width();
int Height = rc.Height();
CDC memDC;//内存DC
memDC.CreateCompatibleDC(pDC);
CBitmap memBitmap, *oldmemBitmap;//建立和屏幕兼容的bitmap memBitmap.CreateCompatibleBitmap(pDC,Width,Height);
oldmemBitmap = memDC.SelectObject(&memBitmap);//将memBitmap选入内存DC
memDC.BitBlt(0,0,Width,Height,pDC,0,0,SRCCOPY);这样写倒是可以编译,但是运行的时候会出现超出内存,也给看一下吧
int Width = rc.Width();
int Height = rc.Height();
看看宽高对不对》
另外:
memDC.BitBlt(0,0,Width,Height,pDC,0,0,SRCCOPY);
应该是rc.left,rc.top
int Height = rc.Height();
这两句是rc的实际宽度还是像素?
原来的语句
int Width = pDC->GetDeviceCaps(HORZRES);
int Height = pDC->GetDeviceCaps(VERTRES);
好像是像素吧,要是pDC指向rc的像素的话怎么写?
会不会是这里的问题?
int Height = rc.Height();
是像素 pixel int Width = pDC->GetDeviceCaps(HORZRES);
int Height = pDC->GetDeviceCaps(VERTRES);
是全屏大小,
你只要 bitblt 从 vega 左上起的 宽高 到 memDC。
HDC hDC=::GetDC(hDlg);
CDC *pDC=CDC::FromHandle(hDC);
::GetWindowRect(hDlg,&rc);
int Width = pDC->GetDeviceCaps(HORZRES);
int Height = pDC->GetDeviceCaps(VERTRES);
CDC memDC;//内存DC
memDC.CreateCompatibleDC(pDC);
CBitmap memBitmap, *oldmemBitmap;//建立和屏幕兼容的bitmap memBitmap.CreateCompatibleBitmap(pDC,Width,Height);
oldmemBitmap = memDC.SelectObject(&memBitmap);//将memBitmap选入内存DC
memDC.BitBlt(0,0,Width,Height,pDC,rc.left,rc.top,0,SRCCOPY);为什么这样写截取下来的图是整个黑色屏幕 什么都没有?
你要的其实就是:
atl+“prtsc”
你可以试试
让vega窗口 显示区 小于 屏幕,然后按:
atl+“prtsc”
打开‘画图’paste进来,可以看到只有 Vega 被截图了。
截取“拖拉机大赛”://
HBITMAP CopyScreenToBitmap(CRect &Rect,HWND hwnd)
{
HDC hScrDC, hMemDC;
HBITMAP hOldBitmap,hBitmap;
int xScrn, yScrn;
hScrDC = CreateDC("DISPLAY", NULL, NULL, NULL);
hMemDC = CreateCompatibleDC(hScrDC);
//
xScrn = GetDeviceCaps(hScrDC, HORZRES);
yScrn = GetDeviceCaps(hScrDC, VERTRES);
//
if (Rect.left < 0) Rect.left = 0;
if (Rect.top < 0) Rect.top = 0;
if (Rect.right > xScrn) Rect.right = xScrn;
if (Rect.bottom > yScrn) Rect.bottom = yScrn;
//
hBitmap = CreateCompatibleBitmap(hScrDC, Rect.Width(),Rect.Height());
hOldBitmap = (HBITMAP)SelectObject(hMemDC, hBitmap);
BitBlt(hMemDC,0,0,Rect.Width(),Rect.Height(),hScrDC,Rect.left,Rect.top,SRCCOPY);
hBitmap =(HBITMAP)SelectObject(hMemDC,hOldBitmap);
//
DeleteDC(hScrDC);
DeleteDC(hMemDC);
//
return hBitmap;
}
//
BOOL SaveBitmapToFile(HBITMAP hBitmap, LPCSTR lpszFileName)
{
HDC hDC; //设备描述表
int iBits; //当前显示分辨率下每个像素所占字节数
WORD wBitCount; //位图中每个像素所占字节数
//定义调色板大小, 位图中像素字节大小 , 位图文件大小 , 写入文件字节数
DWORD dwPaletteSize=0,dwBmBitsSize,dwDIBSize, dwWritten;
BITMAP Bitmap; //位图属性结构
BITMAPFILEHEADER bmfHdr; //位图文件头结构
BITMAPINFOHEADER bi;//位图信息头结构
LPBITMAPINFOHEADER lpbi; //指向位图信息头结构
HANDLE fh, hDib, hPal;
HPALETTE hOldPal=NULL;//定义文件,分配内存句柄,调色板句柄 //计算位图文件每个像素所占字节数
hDC = CreateDC("DISPLAY",NULL,NULL,NULL);
iBits = GetDeviceCaps(hDC, BITSPIXEL) *
GetDeviceCaps(hDC, PLANES); //?
DeleteDC(hDC);
if (iBits <= 1) wBitCount = 1;
else if (iBits <= 4) wBitCount = 4;
else if (iBits <= 8) wBitCount = 8;
else if (iBits <= 24) wBitCount = 24;
else wBitCount = 32;
//计算调色板大小
if (wBitCount <= 8) dwPaletteSize=(1 << wBitCount)*sizeof(RGBQUAD); //设置位图信息头结构
GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&Bitmap);
bi.biSize = sizeof(BITMAPINFOHEADER);
bi.biWidth = Bitmap.bmWidth;
bi.biHeight = Bitmap.bmHeight;
bi.biPlanes = 1;
bi.biBitCount = wBitCount;
bi.biCompression = BI_RGB;
bi.biSizeImage = 0;
bi.biXPelsPerMeter = 0;
bi.biYPelsPerMeter = 0;
bi.biClrUsed = 0;
bi.biClrImportant = 0; dwBmBitsSize = ((Bitmap.bmWidth*wBitCount+31)/32)*4*Bitmap.bmHeight;
//为位图内容分配内存
hDib = GlobalAlloc(GHND,dwBmBitsSize+dwPaletteSize+sizeof(BITMAPINFOHEADER));
lpbi = (LPBITMAPINFOHEADER)GlobalLock(hDib);
*lpbi = bi;
// 处理调色板
hPal = GetStockObject(DEFAULT_PALETTE);
if (hPal)
{
hDC = ::GetDC(NULL);
hOldPal=SelectPalette(hDC,(HPALETTE)hPal,FALSE);
RealizePalette(hDC);
}
// 获取该调色板下新的像素值
GetDIBits(hDC,hBitmap,0,(UINT)Bitmap.bmHeight,(LPSTR)lpbi+sizeof(BITMAPINFOHEADER)+dwPaletteSize, (BITMAPINFO *)lpbi,DIB_RGB_COLORS);
//恢复调色板
if (hOldPal)
{
SelectPalette(hDC, hOldPal, TRUE);
RealizePalette(hDC);
::ReleaseDC(NULL, hDC);
}
//创建位图文件
fh=CreateFile(lpszFileName, GENERIC_WRITE,0, NULL, CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL);
if (fh==INVALID_HANDLE_VALUE) return FALSE;
// 设置位图文件头
bmfHdr.bfType = 0x4D42; // "BM"
dwDIBSize=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)+dwPaletteSize+dwBmBitsSize;
bmfHdr.bfSize = dwDIBSize;
bmfHdr.bfReserved1 = 0;
bmfHdr.bfReserved2 = 0;
bmfHdr.bfOffBits = (DWORD)sizeof(BITMAPFILEHEADER)+(DWORD)sizeof(BITMAPINFOHEADER)+dwPaletteSize;
// 写入位图文件头
WriteFile(fh, (LPSTR)&bmfHdr, sizeof(BITMAPFILEHEADER), &dwWritten, NULL);
// 写入位图文件其余内容
WriteFile(fh, (LPSTR)lpbi, sizeof(BITMAPINFOHEADER)+dwPaletteSize+dwBmBitsSize , &dwWritten, NULL);
//清除
GlobalUnlock(hDib);
GlobalFree(hDib);
CloseHandle(fh);
return TRUE;
}
// Button1 "AltPrtsc"
void CAltPrtscDlg::OnButton1()
{
// TODO: Add your control notification handler code here
HWND hWnd=::FindWindow(0,"拖拉机大赛");
if(hWnd)
{
CRect rc;
::GetWindowRect(hWnd,&rc);
HBITMAP hBmp=CopyScreenToBitmap(rc,hWnd);
BOOL ret=SaveBitmapToFile(hBmp, "Tmp.bmp");
}
}CAltPrtscDlg 是个只有一个按钮的对话框。
我的 在“AltPrtsc”下,不知道你做了对话框没,还是只用了几个函数。
搜索看看吧
1。hScrDC = CreateDC("DISPLAY", NULL, NULL, NULL); // '桌面DC'
即上次给你的。HBITMAP CopyScreenToBitmap(CRect &Rect) // hWnd 已删除2。hScrDC = ::GetDC(hwnd);// '拖拉机大赛的DC'
用2时的程序:
//
HBITMAP CopyWinToBitmap(CRect &Rect,HWND hwnd)
{
HDC hScrDC, hMemDC;
HBITMAP hOldBitmap,hBitmap;
hScrDC = ::GetDC(hwnd);// '拖拉机大赛的DC'
hMemDC = CreateCompatibleDC(hScrDC);
//
hBitmap = CreateCompatibleBitmap(hScrDC, Rect.Width(),Rect.Height());
hOldBitmap = (HBITMAP)SelectObject(hMemDC, hBitmap);
//
BitBlt(hMemDC,0,0,Rect.Width(),Rect.Height(),hScrDC,Rect.left,Rect.top,SRCCOPY);
hBitmap =(HBITMAP)SelectObject(hMemDC,hOldBitmap);
//
::ReleaseDC(hwnd,hScrDC);
DeleteDC(hMemDC);
//
return hBitmap;
}
// "AltPrtsc"
void CAltPrtscDlg::OnButton1()
{
// TODO: Add your control notification handler code here
HWND hWnd=::FindWindow(0,"拖拉机大赛");
if(hWnd)
{
CRect rc;
::GetWindowRect(hWnd,&rc);
#ifdef USE_SCREEN
HBITMAP hBmp=CopyScreenToBitmap(rc);
#else
::MapWindowPoints(0,hWnd,(CPoint*)&rc,2);
HBITMAP hBmp=CopyWinToBitmap(rc,hWnd);
#endif
BOOL ret=SaveBitmapToFile(hBmp, "Tmp.bmp");
}
}
你试试可以到多快。
对,本来就是一个 Bitmap 。
名可以是给定的。
再拖一个按钮。
加上按钮响应。
// "AltPrtsc"
void CAltPrtscDlg::OnButton1()
把我给你的代码复制进来。
如果没有‘拖拉机大赛’改‘计算器’
编译运行。
那个tmp.bmp就在工程目录下。
void CAltPrtscDlg::OnButton1() // OnTimer
{
static int count=0;
char filename[40];
count ++;
sprintf(filename,"E:\\my\\%d.bmp",count);
// TODO: Add your control notification handler code here
HWND hWnd=::FindWindow(0,"拖拉机大赛");
if(hWnd)
{
CRect rc;
::GetWindowRect(hWnd,&rc);
HBITMAP hBmp=CopyScreenToBitmap(rc,hWnd);
BOOL ret=SaveBitmapToFile(hBmp, filename);
}
}