Commit eba02431 authored by yiweiz's avatar yiweiz
Browse files

screencap done

parent e881e72b
screen_cap/screen_cap/output.bmp

3.81 MB | W: | H:

screen_cap/screen_cap/output.bmp

707 KB | W: | H:

screen_cap/screen_cap/output.bmp
screen_cap/screen_cap/output.bmp
screen_cap/screen_cap/output.bmp
screen_cap/screen_cap/output.bmp
  • 2-up
  • Swipe
  • Onion skin
......@@ -44,43 +44,23 @@ int get_encoder_cls_id(const WCHAR* format, CLSID* pClsid)
return -1; // Failure
}
void s_cap::cap_window() {
// resize window
HWND handle = ::FindWindow(NULL, TEXT("Messenger - Mozilla Firefox"));
::SetWindowPos(handle, 0, 0, 0, 1000, 1000, SWP_NOMOVE
| SWP_NOOWNERZORDER | SWP_NOZORDER);
// active window
HWND hCurWnd = ::GetForegroundWindow();
DWORD dwMyID = ::GetCurrentThreadId();
DWORD dwCurID = ::GetWindowThreadProcessId(hCurWnd, NULL);
::AttachThreadInput(dwCurID, dwMyID, TRUE);
::SetWindowPos(handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
::SetWindowPos(handle, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
::SetForegroundWindow(handle);
::AttachThreadInput(dwCurID, dwMyID, FALSE);
::SetFocus(handle);
::SetActiveWindow(handle);
// min console
::ShowWindow(GetConsoleWindow(), SW_MINIMIZE);
void save_cap(int x_1, int x_2, int y_1, int y_2, const wchar_t f_name[10]) {
// get the device context of the screen
HDC hScreenDC = CreateDC("DISPLAY", NULL, NULL, NULL);
// and a device context to put it in
HDC hMemoryDC = CreateCompatibleDC(hScreenDC);
int width = 1000;
int height = 1000;
int width = x_2 - x_1;
int height = y_2 - y_1;
// maybe worth checking these are positive values
HBITMAP hBitmap = CreateCompatibleBitmap(hScreenDC, width, height);
// get a new bitmap
HBITMAP hOldBitmap = (HBITMAP)SelectObject(hMemoryDC, hBitmap);
BitBlt(hMemoryDC, 100, 100, width, height, hScreenDC, 100, 100, SRCCOPY);
// x, x, ... ,leftx, topy...... no ignore that
BitBlt(hMemoryDC, 0, 0, width, height, hScreenDC, x_1, y_1, SRCCOPY);
hBitmap = (HBITMAP)SelectObject(hMemoryDC, hOldBitmap);
// clean up
......@@ -91,14 +71,39 @@ void s_cap::cap_window() {
ULONG_PTR gdiplusToken;
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
// HBITMAP hBitmap = (HBITMAP)LoadImage(GetModuleHandle(NULL), "babe.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
Gdiplus::Bitmap *image = new Gdiplus::Bitmap(hBitmap, NULL);
CLSID my_cls_id;
int retVal = get_encoder_cls_id(L"image/bmp", &my_cls_id);
image->Save(L"output.bmp", &my_cls_id, NULL);
image->Save(f_name, &my_cls_id, NULL);
delete image;
Gdiplus::GdiplusShutdown(gdiplusToken);
}
void s_cap::cap_window() {
// resize window
HWND handle = ::FindWindow(NULL, TEXT("Messenger - Mozilla Firefox"));
::SetWindowPos(handle, 0, 0, 0, 650, 1000, SWP_NOMOVE
| SWP_NOOWNERZORDER | SWP_NOZORDER);
// active window
HWND hCurWnd = ::GetForegroundWindow();
DWORD dwMyID = ::GetCurrentThreadId();
DWORD dwCurID = ::GetWindowThreadProcessId(hCurWnd, NULL);
::AttachThreadInput(dwCurID, dwMyID, TRUE);
::SetWindowPos(handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
::SetWindowPos(handle, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
::SetForegroundWindow(handle);
::AttachThreadInput(dwCurID, dwMyID, FALSE);
::SetFocus(handle);
::SetActiveWindow(handle);
// min console
::ShowWindow(GetConsoleWindow(), SW_MINIMIZE);
save_cap(2, 427, 795, 826, L"tiles.bmp");
save_cap(2, 427, 323, 749, L"board.bmp");
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment