On Windows: This function captures from the desktop image. Quickly. This function does the output to the clipboard, doesn't write to file. But it works.
Limitations: If another window is over your Quake window, this is a capture of the desktop and then limited the Quake client area.
Mostly based on what I found modification of from http://cboard.cprogramming.com/windows- ... ure-c.html and DirectQ's method of limiting the mouse cursor region. Call the function and give it "mainwindow" or "dibwindow" or whatever you are using for your primary window.
At some point, I may try to speed up Quake video capture by using the results instead of sluggish glReadPixels.
Code: Select all
#if _MSC_VER <=1200 // MSVC6 ONLY
// These are in <winuser.h> except I can't get them to work in MSVC6
typedef struct tagWINDOWINFO {
DWORD cbSize;
RECT rcWindow;
RECT rcClient;
DWORD dwStyle;
DWORD dwExStyle;
DWORD dwWindowStatus;
UINT cxWindowBorders;
UINT cyWindowBorders;
ATOM atomWindowType;
WORD wCreatorVersion;
} WINDOWINFO, *PWINDOWINFO, *LPWINDOWINFO;
BOOL WINAPI GetWindowInfo(HWND hwnd, PWINDOWINFO pwi);
#endif
void Sys_Window_To_Clipboard (HWND srchwnd)
{
// Baker: A modification of from http://cboard.cprogramming.com/windows-programming/34818-screen-capture-c.html
#define RectWidth(lprc) ((lprc)->right-(lprc)->left)
#define RectHeight(lprc) ((lprc)->bottom-(lprc)->top)
HWND desktophwnd = GetDesktopWindow ();
HDC hdc = GetWindowDC (desktophwnd);
HDC hdcMem = CreateCompatibleDC(hdc);
HBITMAP hbm = NULL;
HBITMAP oldbm = NULL;
RECT rcClient, rcWindow, rcCrop, rcCapture;
SelectObject (hdcMem,oldbm);
// GetWindowRect (srchwnd, &rcWindow); // Gets the entire window area in screen coordinates
// GetClientRect (srchwnd, &rcClient); // This is mostly useless, isn't in screen coordinates. Aero messes with it (it's wrong)
{
// MH of course has the "right" answer in DirectQ so we use that ....
WINDOWINFO windowinfo;
windowinfo.cbSize = sizeof (WINDOWINFO);
GetWindowInfo (srchwnd, &windowinfo); // windowinfo.rcClient
rcCapture = rcClient = windowinfo.rcClient;
}
SetRect (&rcCrop, 0, 0, RectWidth(&rcCapture), RectHeight(&rcCapture));
hbm = CreateCompatibleBitmap (hdc, RectWidth(&rcCrop), RectHeight (&rcCrop));
oldbm = SelectObject (hdcMem, hbm);
BitBlt (hdcMem, 0, 0, RectWidth(&rcCrop), RectHeight(&rcCrop), hdc, rcCapture.left, rcCapture.top, SRCCOPY);
// Clipboard
OpenClipboard(NULL);
EmptyClipboard();
SetClipboardData (CF_BITMAP, hbm);
CloseClipboard();
ReleaseDC (desktophwnd, hdc);
DeleteDC (hdcMem);
DeleteObject (oldbm);
}