LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-24-2011, 05:27 PM   #1
toredo
Member
 
Registered: Feb 2009
Posts: 83

Rep: Reputation: 25
mingw; printscreen-tool


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
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Printscreen not working tv8dnguyen Linux - General 2 03-05-2009 02:48 PM
PrintScreen problem xennetwork Linux - Newbie 6 01-16-2005 05:13 PM
Printscreen - HOWTO ? blackx Linux - General 1 05-29-2003 11:10 AM
PrintScreen Shots in linux chrehmatali Linux - General 2 04-26-2003 02:12 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:55 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration