Hello,
I try to write a tool. Target plattforms are Windows and Linux.
I use only Linux (XUbuntu) for development. There i use gcc and i586-mingw32msvc-gcc to create my x86 binaries for both plattforms.
I try now to implement the functionality to take a screenshot for windows. Ok, that sounds easy. And it is easy i think.
This screenshot i would like to save as a PNG-File (preferred) or as a JPEG-File. It should be compressed.
My problem is now, that i can't compile my code with mingw.
Currently i have only a test-code:
Code:
#include <stdio.h>
#include <windows.h>
#include <GdiPlus.h>
#include <GdiPlusFlat.h>
#include <GdiPlusBitmap.h>
//#include <wingdi.h>
int main() {
// 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);
// maybe worth checking these are positive values
HBITMAP 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);
GdipSaveImageToFile(hBitmap, "image01.png",
"{557CF406-1A04-11D3-9A73-0000F81EF32E}", 0);
return 0;
}
The function "GdiSaveImageToFil" is only in GDI available, which is defaultly not available in mingw.
So i downloaded some header and lib-files for mingw. But mingw doesn't find the function "GdipSaveImageToFile". I use the following command to compile this file:
Code:
i586-mingw32msvc-g++ screenshot.c -lgdi32 -lgdiplus
The normal code without the "GdipSaveImageToFile" works. So maybe i can use a small lib to save the HBITMAP as png? I don't like to use a dynamik linked library on Windows, so is there a "simple" c-file to save a bitmap as png or jpeg?
It is very circular to do this easy thing. I like to build all my binaries on linux. I don't like to compile a small Screenshot-Tool on Windows and copy it to linux to continue the build-process. That's ugly.
Isn't there another easy way to do this??
best regards
toredo