Commit ed1f4165 authored by yiweiz's avatar yiweiz
Browse files

cap working

parent b36a86f1
#include "screen_cap.hpp"
#include <windows.h>
#include <Unknwn.h>
#include <objidl.h>
#include <WinUser.h>
#include <gdiplus.h>
#include <iostream>
#include <gdiplusbase.h>
using namespace std;
using namespace Gdiplus;
#pragma comment (lib,"Gdiplus.lib")
s_cap::s_cap() {
......@@ -15,45 +19,58 @@ int get_encoder_cls_id(const WCHAR* format, CLSID* pClsid)
UINT num = 0; // number of image encoders
UINT size = 0; // size of the image encoder array in bytes
Gdiplus::ImageCodecInfo* pImageCodecInfo = NULL;
Gdiplus::ImageCodecInfo* p_image_codec_info = NULL;
Gdiplus::GetImageEncodersSize(&num, &size);
if (size == 0)
return -1; // Failure
pImageCodecInfo = (Gdiplus::ImageCodecInfo*)(malloc(size));
if (pImageCodecInfo == NULL)
p_image_codec_info = (Gdiplus::ImageCodecInfo*)(malloc(size));
if (p_image_codec_info == NULL)
return -1; // Failure
GetImageEncoders(num, size, pImageCodecInfo);
GetImageEncoders(num, size, p_image_codec_info);
for (UINT j = 0; j < num; ++j)
{
if (wcscmp(pImageCodecInfo[j].MimeType, format) == 0)
if (wcscmp(p_image_codec_info[j].MimeType, format) == 0)
{
*pClsid = pImageCodecInfo[j].Clsid;
free(pImageCodecInfo);
*pClsid = p_image_codec_info[j].Clsid;
free(p_image_codec_info);
return j; // Success
}
}
free(pImageCodecInfo);
free(p_image_codec_info);
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);
// 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 = GetDeviceCaps(hScreenDC, HORZRES);
// int height = GetDeviceCaps(hScreenDC, VERTRES);
int width = 1000;
int height = 1000;
......@@ -63,7 +80,7 @@ void s_cap::cap_window() {
// get a new bitmap
HBITMAP hOldBitmap = (HBITMAP)SelectObject(hMemoryDC, hBitmap);
BitBlt(hMemoryDC, 0, 0, width, height, hScreenDC, 0, 0, SRCCOPY);
BitBlt(hMemoryDC, 100, 100, width, height, hScreenDC, 100, 100, SRCCOPY);
hBitmap = (HBITMAP)SelectObject(hMemoryDC, hOldBitmap);
// clean up
......
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