Screenshot vom aktuellen Fenster
-
Hi,
Ich möchte ein "Screenshot" vom aktuellen Fenster machen, aber auch nur von dem Inhalt des Fensters. So, dass ich z.b. nicht die Taskleiste unten sehe oder oben den roten "Schließen" Button.
Wichtig ist bei dem ganzen dass ich es in einem kommerziellen Programm nutzen darf, und dafür möglichst wenig oder garnichts zahlen muss (wobei mir garnix eig. besser gefällt). Also dass es nicht unter einer Lizenz steht.
Ich dachte mir das geht vllt. über die WinAPI, habs damit aber nicht hingekriegt, deshalb poste ich es mal hier und nicht im API Forum.
Schonma vielen dank,
BlitzBasic303
-
Da das Betriebssystem-spezifisch ist, gehört das schon in die WinAPI
Nichtsdestotrotz, so könnte es gehen: Du brauchst das Fenster-Handle und holst dir damit (GetDC) den Zeichnen-Kontext. Mit GetPixel bekommst du die Farbe jeden einzelnen Pixels im Fenster, da musst du die Daten dann nur noch weiterverarbeiten.
-
Kommt ganz auf dein System an. Windows? Dann wärst du bei der WinAPI richtig gewesen. Denn nur weil du es noch nicht geschafft hast, heißt das ja noch nicht, dass es keinen Weg gibt. In Standard-C++ gibts nämlich keinen, das kennt noch nicht mal Fenster.
Unter der WinAPI könnte man sich das Handle des Fensters besorgen, dann mittels GetDC(handle) den Device Context holen. Der DC hierbei betrifft nur die Client Area, d.h. Titelleiste, Rahmen und Buttons für Schließen (den "roten Button" den du meinst, gibst den in Vista?), Maximieren und Minimieren gibts nicht. Wenn du die trotzdem haben möchtest, hilft GetWindowDC(handle), das nimmt auch noch die Nonclientarea mit!
Naja, dann einfach ein kompatibles Bitmap mittels CreateCompatibleBitmap(dc, größe... genaue Parameter in MSDN) kreieren und den DeviceContext per BitBlt(..) reinblitten. Fertig!
gruß
MartinEdith sagt: Ein bisschen zu langsam, aber dafür ausführlicher

-
mad_martin schrieb:
den "roten Button" den du meinst, gibst den in Vista?
also den schließen button an sich ja, aber der ist da nicht rot

-
Keine Ahnung, hab kein Vista. War nur interessiert, welcher rote Button das denn sein mag... :p
-
sicher is der rot.
-
ähmm so ich hab das jetzt auch mal probiert, aber steh aufm schlauch, wie speichere ich jetzt mit dem handle das bitmap?
-
Dieser Thread wurde von Moderator/in HumeSikkins aus dem Forum C++ in das Forum WinAPI verschoben.
Im Zweifelsfall bitte auch folgende Hinweise beachten:
C/C++ Forum :: FAQ - Sonstiges :: Wohin mit meiner Frage?Dieses Posting wurde automatisch erzeugt.
-
Bin mir nicht ganz sicher, aber schau mal in der GDI+ bei der Bitmap-Klasse nach. Die nimmt iirc u.a. ein HBITMAP (also handle) im Konstruktor an, um ein Bitmap-Objekt zu erzeugen. Da müsste es eine Methode geben, die die ganze Sache recht einfach als Datei speichert. Aber alles erstmal ohne Gewähr!
-
Ok, ich bin jetzt so weit:
HWND hWnd=FindWindow(NULL, "Hello World"); HDC hDC = GetDC(hWnd); HBITMAP hBIT = CreateCompatibleBitmap(hDC, 640,480); BitBlt([b]"screenie.bmp"[/b],0,0,640,480,hBIT,0,0,PATINVERT);Sollte soweit gehen, außer das (fett markierte) "screenie.bmp", da erwartet er jetzt ein Handle eines Bitmaps, also meine Frage jetzt, wie kann ich ein hBITMAP abspeichern?
-
Mach erstmal aus
BitBlt("screenie.bmp",0,0,640,480,hBIT,0,0,PATINVERT);HDC dc_dest = CreateCompatibleDC(hDC); // kompatiblen zieldc anlegen HGDIOBJ old = SelectObject(dc_dest, hBit); // selektieren und altes objekt behalten BitBlt(dc_dest,0,0,640,480,hDC,0,0,SRCCOPY); // blitten SelectObject(dc_dest, old); // aufräumen DeleteDC(dc_dest); // aufräumenSo, jetzt solltest du das Bild in hBit haben. Gleich gehts hier weiter...
-
mad_martin schrieb:
Bin mir nicht ganz sicher, aber schau mal in der GDI+ bei der Bitmap-Klasse nach. Die nimmt iirc u.a. ein HBITMAP (also handle) im Konstruktor an, um ein Bitmap-Objekt zu erzeugen. Da müsste es eine Methode geben, die die ganze Sache recht einfach als Datei speichert. Aber alles erstmal ohne Gewähr!
ahh dann hatte ich das doch schon richtig gesehen, ok danke
-
So, nun noch das Speichern:
Hier ist der Konstruktor der Bitmap-Klasse aus GDI+, den ich meinte:
http://msdn2.microsoft.com/en-us/library/ms536314(VS.85).aspxÜber die benötigte Palette bin ich mir nicht mehr ganz im Klaren, da das schon einige Zeit her ist. Glaube, die kann man u.U. ignorieren. Wäre schön, wenn hierzu noch jemand eine Antwort hätte!
Naja, gespeichert wird auf jeden Fall mit:
http://msdn2.microsoft.com/en-us/library/ms535407(VS.85).aspxDen richtige Encoder auszuwählen überlasse ich dem geneigten Leser

-
Sorry dass ich erst so spät antworte, aber ich habe jetzt ne Zeit probiert und gesucht, doch wo kriege ich die gdiplus.h her die ich einbinden muss?
-
Zu finden z.B. im "Windows SDK" oder "Platform SDK"
-
Ok, ich mal wieder. Hab das Platform SDK runtergeladen, alles installiert usw. jetzt will ich kompilieren und:
..\..\..\..\..\Programme\Microsoft SDK\include\winnt.h|674|#error Must define a target architecture.| ..\..\..\..\..\Programme\Microsoft SDK\include\rpcnterr.h|4|warning: "/*" within comment| ..\..\..\..\..\Programme\Microsoft SDK\include\wtypes.h|17|warning: ignoring #pragma warning | ..\..\..\..\..\Programme\Microsoft SDK\include\wtypes.h|17|warning: ignoring #pragma warning | ..\..\..\..\..\Programme\Microsoft SDK\include\unknwn.h|17|warning: ignoring #pragma warning | ..\..\..\..\..\Programme\Microsoft SDK\include\objidl.h|17|warning: ignoring #pragma warning | ..\..\..\..\..\Programme\Microsoft SDK\include\objidl.h|6545|warning: ignoring #pragma warning | ..\..\..\..\..\Programme\Microsoft SDK\include\objidl.h|6561|warning: ignoring #pragma warning | ..\..\..\..\..\Programme\Microsoft SDK\include\urlmon.h|17|warning: ignoring #pragma warning | ..\..\..\..\..\Programme\Microsoft SDK\include\oaidl.h|442|pasting "/" and "/" does not give a valid preprocessing token| ..\..\..\..\..\Programme\Microsoft SDK\include\oaidl.h|442|error: expected unqualified-id before '/' token| ..\..\..\..\..\Programme\Microsoft SDK\include\oaidl.h|457|pasting "/" and "/" does not give a valid preprocessing token| ..\..\..\..\..\Programme\Microsoft SDK\include\oaidl.h|457|error: expected unqualified-id before '/' token| ..\..\..\..\..\Programme\Microsoft SDK\include\urlmon.h|277|warning: ignoring #pragma comment | ..\..\..\..\..\Programme\Microsoft SDK\include\propidl.h|17|warning: ignoring #pragma warning | ..\..\..\..\..\Programme\Microsoft SDK\include\propidl.h|310|pasting "/" and "/" does not give a valid preprocessing token| ..\..\..\..\..\Programme\Microsoft SDK\include\propidl.h|310|error: expected unqualified-id before '/' token| ..\..\..\..\..\Programme\Microsoft SDK\include\propidl.h|1423|warning: ignoring #pragma warning | ..\..\..\..\..\Programme\Microsoft SDK\include\propidl.h|1424|warning: ignoring #pragma warning | ..\..\..\..\..\Programme\Microsoft SDK\include\oaidl.h|17|warning: ignoring #pragma warning | ..\..\..\..\..\Programme\Microsoft SDK\include\oleidl.h|17|warning: ignoring #pragma warning | ..\..\..\..\..\Programme\Microsoft SDK\include\GdiplusEnums.h|534|error: use of enum `EmfPlusRecordType' without previous declaration| ..\..\..\..\..\Programme\Microsoft SDK\include\GdiplusEnums.h|548|error: invalid use of undefined type `enum Gdiplus::EmfPlusRecordType'| ..\..\..\..\..\Programme\Microsoft SDK\include\GdiplusEnums.h|543|error: forward declaration of `enum Gdiplus::EmfPlusRecordType'| ..\..\..\..\..\Programme\Microsoft SDK\include\GdiplusEnums.h|548|error: enumerator value for `WmfRecordTypeSetBkColor' not integer constant| ..\..\..\..\..\Programme\Microsoft SDK\include\GdiplusEnums.h|549|error: invalid use of undefined type `enum Gdiplus::EmfPlusRecordType'| ..\..\..\..\..\Programme\Microsoft SDK\include\GdiplusEnums.h|543|error: forward declaration of `enum Gdiplus::EmfPlusRecordType'| ..\..\..\..\..\Programme\Microsoft SDK\include\GdiplusEnums.h|549|error: enumerator value for `WmfRecordTypeSetBkMode' not integer constant| ..\..\..\..\..\Programme\Microsoft SDK\include\GdiplusEnums.h|550|error: invalid use of undefined type `enum Gdiplus::EmfPlusRecordType'| ..\..\..\..\..\Programme\Microsoft SDK\include\GdiplusEnums.h|543|error: forward declaration of `enum Gdiplus::EmfPlusRecordType'| ..\..\..\..\..\Programme\Microsoft SDK\include\GdiplusEnums.h|550|error: enumerator value for `WmfRecordTypeSetMapMode' not integer constant| ..\..\..\..\..\Programme\Microsoft SDK\include\GdiplusEnums.h|551|error: invalid use of undefined type `enum Gdiplus::EmfPlusRecordType'| ..\..\..\..\..\Programme\Microsoft SDK\include\GdiplusEnums.h|543|error: forward declaration of `enum Gdiplus::EmfPlusRecordType'| ..\..\..\..\..\Programme\Microsoft SDK\include\GdiplusEnums.h|551|error: enumerator value for `WmfRecordTypeSetROP2' not integer constant| ..\..\..\..\..\Programme\Microsoft SDK\include\GdiplusEnums.h|552|error: invalid use of undefined type `enum Gdiplus::EmfPlusRecordType'| ..\..\..\..\..\Programme\Microsoft SDK\include\GdiplusEnums.h|543|error: forward declaration of `enum Gdiplus::EmfPlusRecordType'| ..\..\..\..\..\Programme\Microsoft SDK\include\GdiplusEnums.h|552|error: enumerator value for `WmfRecordTypeSetRelAbs' not integer constant| ..\..\..\..\..\Programme\Microsoft SDK\include\GdiplusEnums.h|553|error: invalid use of undefined type `enum Gdiplus::EmfPlusRecordType'| ..\..\..\..\..\Programme\Microsoft SDK\include\GdiplusEnums.h|543|error: forward declaration of `enum Gdiplus::EmfPlusRecordType'| ..\..\..\..\..\Programme\Microsoft SDK\include\GdiplusEnums.h|553|error: enumerator value for `WmfRecordTypeSetPolyFillMode' not integer constant| ..\..\..\..\..\Programme\Microsoft SDK\include\GdiplusEnums.h|554|error: invalid use of undefined type `enum Gdiplus::EmfPlusRecordType'| ..\..\..\..\..\Programme\Microsoft SDK\include\GdiplusEnums.h|543|error: forward declaration of `enum Gdiplus::EmfPlusRecordType'| ..\..\..\..\..\Programme\Microsoft SDK\include\GdiplusEnums.h|554|error: enumerator value for `WmfRecordTypeSetStretchBltMode' not integer constant| ..\..\..\..\..\Programme\Microsoft SDK\include\GdiplusEnums.h|555|error: invalid use of undefined type `enum Gdiplus::EmfPlusRecordType'| ..\..\..\..\..\Programme\Microsoft SDK\include\GdiplusEnums.h|543|error: forward declaration of `enum Gdiplus::EmfPlusRecordType'| ..\..\..\..\..\Programme\Microsoft SDK\include\GdiplusEnums.h|555|error: enumerator value for `WmfRecordTypeSetTextCharExtra' not integer constant| ..\..\..\..\..\Programme\Microsoft SDK\include\GdiplusEnums.h|556|error: invalid use of undefined type `enum Gdiplus::EmfPlusRecordType'| ..\..\..\..\..\Programme\Microsoft SDK\include\GdiplusEnums.h|543|error: forward declaration of `enum Gdiplus::EmfPlusRecordType'| ..\..\..\..\..\Programme\Microsoft SDK\include\GdiplusEnums.h|556|error: enumerator value for `WmfRecordTypeSetTextColor' not integer constant| ..\..\..\..\..\Programme\Microsoft SDK\include\GdiplusEnums.h|557|error: invalid use of undefined type `enum Gdiplus::EmfPlusRecordType'| ..\..\..\..\..\Programme\Microsoft SDK\include\GdiplusEnums.h|543|error: forward declaration of `enum Gdiplus::EmfPlusRecordType'| ..\..\..\..\..\Programme\Microsoft SDK\include\GdiplusEnums.h|557|error: enumerator value for `WmfRecordTypeSetTextJustification' not integer constant| ..\..\..\..\..\Programme\Microsoft SDK\include\GdiplusEnums.h|558|error: invalid use of undefined type `enum Gdiplus::EmfPlusRecordType'| ..\..\..\..\..\Programme\Microsoft SDK\include\GdiplusEnums.h|543|error: forward declaration of `enum Gdiplus::EmfPlusRecordType'| ..\..\..\..\..\Programme\Microsoft SDK\include\GdiplusEnums.h|558|error: enumerator value for `WmfRecordTypeSetWindowOrg' not integer constant| ..\..\..\..\..\Programme\Microsoft SDK\include\GdiplusEnums.h|559|error: invalid use of undefined type `enum Gdiplus::EmfPlusRecordType'| ..\..\..\..\..\Programme\Microsoft SDK\include\GdiplusEnums.h|543|error: forward declaration of `enum Gdiplus::EmfPlusRecordType'| ..\..\..\..\..\Programme\Microsoft SDK\include\GdiplusEnums.h|559|error: enumerator value for `WmfRecordTypeSetWindowExt' not integer constant| ..\..\..\..\..\Programme\Microsoft SDK\include\GdiplusEnums.h|560|error: invalid use of undefined type `enum Gdiplus::EmfPlusRecordType'| ..\..\..\..\..\Programme\Microsoft SDK\include\GdiplusEnums.h|543|error: forward declaration of `enum Gdiplus::EmfPlusRecordType'| ..\..\..\..\..\Programme\Microsoft SDK\include\GdiplusEnums.h|560|error: enumerator value for `WmfRecordTypeSetViewportOrg' not integer constant| ..\..\..\..\..\Programme\Microsoft SDK\include\GdiplusEnums.h|561|error: invalid use of undefined type `enum Gdiplus::EmfPlusRecordType'| ..\..\..\..\..\Programme\Microsoft SDK\include\GdiplusEnums.h|543|error: forward declaration of `enum Gdiplus::EmfPlusRecordType'| ..\..\..\..\..\Programme\Microsoft SDK\include\GdiplusEnums.h|561|error: enumerator value for `WmfRecordTypeSetViewportExt' not integer constant| ||More errors follow but not being shown.| ||Edit the max errors limit in compiler options...| ||=== Build finished: 50 errors, 14 warnings ===|Jede Menge Fehler, woran liegts?
-
Weiß wirklich keiner woran es liegt?
-
BlitzBasic303 schrieb:
Wichtig ist bei dem ganzen dass ich es in einem kommerziellen Programm nutzen darf, und dafür möglichst wenig oder garnichts zahlen muss (wobei mir garnix eig. besser gefällt). Also dass es nicht unter einer Lizenz steht.
wieviel willste ausgeben
-
Evtl. falsche Header-Reihenfolge?
http://msdn2.microsoft.com/en-us/library/aa383745(VS.85).aspx beachtet?
-
Ok, den Link versteh ich nicht ganz ^^ Meine Header sind so eingebunden
#include <irrlicht.h> #include <math.h> #include <stdlib.h> #include <iostream> #include <windows.h> #include <winuser.h> #include <winreg.h> #include <time.h> #include <fstream> #include <ctime> #include <string.h> #include <stdio.h> #include <gdiplus.h>