Lei
You can use this to save a bitmap of the desktop. if you are using a mirror
driver, and you attach to the desktop, use the sample app in the ddk and it
shows you how to get a HDC to you driver. Hope this helps.
Jeff
int getDesktopImage()
{
//Source window handle
HWND hDesktopWnd = GetDesktopWindow();
if (!hDesktopWnd)
{ AfxMessageBox(“failed at hDesktopWnd”);
return 0;
}
int nScreenWidth = 0;
int nScreenHeight = 0;
WINDOWINFO windinfo;
windinfo.cbSize = sizeof(WINDOWINFO);
if (!GetWindowInfo(hDesktopWnd, &windinfo))
{ AfxMessageBox(“Error getting window info”);
return 0;
}
nScreenHeight = windinfo.rcClient.bottom - windinfo.rcClient.top;
nScreenWidth = windinfo.rcClient.right - windinfo.rcClient.left;
//Source window DC
HDC hDesktopDC = GetDC(hDesktopWnd);
if (!hDesktopDC)
{ AfxMessageBox(“failed at hDesktopDC”);
return 0;
}
//Output DC
HDC hCaptureDC = CreateCompatibleDC(hDesktopDC);
if (!hCaptureDC)
{ AfxMessageBox(“failed at hCaptureDC”);
return 0;
}
HBITMAP hCaptureBitmap = CreateCompatibleBitmap(hDesktopDC, nScreenWidth,
nScreenHeight);
if (!hCaptureBitmap)
{ AfxMessageBox(“failed at hCaptureBitmap”);
return 0;
}
if (SelectObject(hCaptureDC, hCaptureBitmap) == HGDI_ERROR)
{ AfxMessageBox(“failed at SelectObject”);
return 0;
}
SendMessage(hDesktopWnd, WM_PRINT, (WPARAM)hCaptureDC, PRF_CLIENT);
if
(!BitBlt(hCaptureDC,0,0,nScreenWidth,nScreenHeight,hDesktopDC,0,0,SRCCOPY))
{ AfxMessageBox(“failed at BitBlt”);
return 0;
}
SaveBitmap(_T(“theDesktop.bmp”), hCaptureBitmap);
ReleaseDC(hDesktopWnd,hDesktopDC);
DeleteDC(hCaptureDC);
DeleteObject(hCaptureBitmap);
return 1;
}
void SaveBitmap(char *szFilename,HBITMAP hBitmap)
{ HDC hdc=NULL;
FILE* fp=NULL;
LPVOID pBuf=NULL;
BITMAPINFO bmpInfo;
BITMAPFILEHEADER bmpFileHeader;
do
{ hdc = GetDC(NULL);
ZeroMemory(&bmpInfo, sizeof(BITMAPINFO));
bmpInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
int retget = GetDIBits(hdc, hBitmap, 0, 0, NULL, &bmpInfo,
DIB_RGB_COLORS);
//CString myMsg;
//myMsg.Format(“retget is %d \n bmpInfo.bmiHeader.biSizeImage %d”,
retget, bmpInfo.bmiHeader.biSizeImage);
//AfxMessageBox(myMsg);
if(bmpInfo.bmiHeader.biSizeImage <= 0)
{ bmpInfo.bmiHeader.biSizeImage = bmpInfo.bmiHeader.biWidth *
abs(bmpInfo.bmiHeader.biHeight) * (bmpInfo.bmiHeader.biBitCount + 7)/8;
}
//myMsg.Format(“bmpInfo.bmiHeader.biSizeImage %d”,
bmpInfo.bmiHeader.biSizeImage);
//AfxMessageBox(myMsg);
if((pBuf = malloc(bmpInfo.bmiHeader.biSizeImage))==NULL)
{ AfxMessageBox(TEXT(“Unable to Allocate Bitmap Memory”));
break;
}
bmpInfo.bmiHeader.biCompression = BI_RGB;
if (GetDIBits(hdc, hBitmap, 0, bmpInfo.bmiHeader.biHeight, pBuf,
&bmpInfo, DIB_RGB_COLORS) <= 0)
{
// /*
LPVOID lpMsgBuf;
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR) &lpMsgBuf,
0,
NULL
);
// Process any inserts in lpMsgBuf.
// …
// Display the string.
MessageBox(NULL, (LPCTSTR)lpMsgBuf, “Error”, MB_OK |
MB_ICONINFORMATION);
// Free the buffer.
LocalFree(lpMsgBuf);
// */
}
if((fp = fopen(szFilename,“wb”))==NULL)
{ AfxMessageBox(TEXT(“Unable to Create Bitmap File”));
break;
}
if (pBuf == (void*)0x00ffffff)
{ AfxMessageBox(TEXT(“pointer is invalid caught here”));
break;
}
bmpFileHeader.bfReserved1 = 0;
bmpFileHeader.bfReserved2 = 0;
bmpFileHeader.bfSize = sizeof(BITMAPFILEHEADER) +
sizeof(BITMAPINFOHEADER) + bmpInfo.bmiHeader.biSizeImage;
bmpFileHeader.bfType = ‘MB’;
bmpFileHeader.bfOffBits = sizeof(BITMAPFILEHEADER) +
sizeof(BITMAPINFOHEADER);
fwrite(&bmpFileHeader, sizeof(BITMAPFILEHEADER), 1, fp);
fwrite(&bmpInfo.bmiHeader, sizeof(BITMAPINFOHEADER), 1, fp);
fwrite(pBuf, bmpInfo.bmiHeader.biSizeImage, 1, fp);
} while(false);
if(hdc)
{ ReleaseDC(NULL,hdc);
}
if(pBuf)
{ if (pBuf != (void*)0x00ffffff)
{ free(pBuf);
}
}
if(fp)
{ fclose(fp);
}
}
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com]On Behalf Of Lei Zhang
Sent: Friday, March 18, 2005 10:24 AM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] How to name a device object in video miniport
driver?
I agree with Mats that the buffer in the driver should have limited
size. Otherwise the machine may crash easily as long as my user-mode
app never starts. It is an annoying problem.
But how about writing the user-mode app as a service? It can run
before the user logs in. However, I am not quite sure whether it will
starts before the drawing begins.
Can we capture the entire screen by simply using some Win32 API? If
yes, we can start intercepting drawing command after doing that.
Lei
On Fri, 18 Mar 2005 15:03:16 +0000, Mats PETERSSON
wrote:
>
>
> > One way may to do it be to use a circular buffer: you lose the
> > older stuff, but only when the system’s overloaded, and the
> > chucking is automatic. You can also allow the user to configure
> > the size of the buffer upfront.
> >
> > Or you can be a bit more aggressive and implement a chain of
> > buffers: if you run out of a buffer, you grab another one. The
> > problem of course is that if the app’s not running you risk
> > clogging the system pretty fast, specially with high performance
> > graphics.
>
> Not a particularly pleasing idea, filling the entire kernel space with
> buffers, eh? If the user-mode app isn’t responding, it’s highly possible
> that it will not do so for a while. It’s probably much better to have a
big
> buffer in the first place, than to dynamically expand the buffer(s). At
the
> very least, limit the number of buffers so that it doesn’t go too far.
>
> But one thing that I think might work is if there are later commands that
> entirely cover earlier commands (such as blits that don’t use the
> destination as an input, or fill’s), the older ones can be deleted [this
is
> probably better seen as an optimisation than a way to reduce the space].
> This culling should be done continually, so that the buffer is always
> “unique”. Unfortunately, a lot of drawing is done based on the previous
> surface, so it’s unlikely to give great gains in anything but special
cases
> (where it may well be very useful).
>
> –
> Mats
> >
> > Alberto.
> >
>
> —
> Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@gmail.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>
—
Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
You are currently subscribed to ntdev as: xxxxx@resolutions.ws
To unsubscribe send a blank email to xxxxx@lists.osr.com