Commit b36a86f1 authored by yiweiz's avatar yiweiz
Browse files

working on screen shots

parent b3c7c7b8
#include <boost/lambda/lambda.hpp>
#include <iostream>
#include <iterator>
#include <algorithm>
int main()
{
using namespace boost::lambda;
typedef std::istream_iterator<int> in;
std::for_each(
in(std::cin), in(), std::cout << (_1 * 3) << " " );
}
#include "screen_cap.hpp"
int main() {
s_cap x;
x.cap_window();
return 0;
}
\ No newline at end of file
#include "screen_cap.hpp"
#include <windows.h>
#include <WinUser.h>
#include <gdiplus.h>
#include <iostream>
#include <gdiplusbase.h>
using namespace std;
s_cap::s_cap() {
}
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::GetImageEncodersSize(&num, &size);
if (size == 0)
return -1; // Failure
pImageCodecInfo = (Gdiplus::ImageCodecInfo*)(malloc(size));
if (pImageCodecInfo == NULL)
return -1; // Failure
GetImageEncoders(num, size, pImageCodecInfo);
for (UINT j = 0; j < num; ++j)
{
if (wcscmp(pImageCodecInfo[j].MimeType, format) == 0)
{
*pClsid = pImageCodecInfo[j].Clsid;
free(pImageCodecInfo);
return j; // Success
}
}
free(pImageCodecInfo);
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);
// 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;
// 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, 0, 0, width, height, hScreenDC, 0, 0, SRCCOPY);
hBitmap = (HBITMAP)SelectObject(hMemoryDC, hOldBitmap);
// clean up
DeleteDC(hMemoryDC);
DeleteDC(hScreenDC);
Gdiplus::GdiplusStartupInput gdiplusStartupInput;
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);
delete image;
Gdiplus::GdiplusShutdown(gdiplusToken);
}
\ No newline at end of file
#pragma once
#include <string>
// #include <boost/python.hpp>
// using namespace boost::python;
class s_cap {
public:
s_cap();
void cap_window();
};
/*
BOOST_PYTHON_MODULE(screen_manip)
{
class_<s_cap>("s_cap")
.def("cap_window", &s_cap::cap_window)
;
}
*/
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