Click here to Skip to main content
16,011,570 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Visual C++ STLPort question Pin
Christian Graus15-Sep-04 11:43
protectorChristian Graus15-Sep-04 11:43 
Generalscreen capture to jpg Pin
Spiritofamerica5-Jul-04 12:21
Spiritofamerica5-Jul-04 12:21 
GeneralRe: screen capture to jpg Pin
Johann Gerell5-Jul-04 21:15
Johann Gerell5-Jul-04 21:15 
GeneralRe: screen capture to jpg Pin
Johann Gerell5-Jul-04 21:15
Johann Gerell5-Jul-04 21:15 
Generalslider Pin
Anonymous5-Jul-04 12:19
Anonymous5-Jul-04 12:19 
GeneralRe: slider Pin
Roger Allen6-Jul-04 4:28
Roger Allen6-Jul-04 4:28 
GeneralGet process terminated another process Pin
Cobra4Ever5-Jul-04 11:54
Cobra4Ever5-Jul-04 11:54 
Generalscreen capture to jpg Pin
Anonymous5-Jul-04 11:40
Anonymous5-Jul-04 11:40 
Hi
I wanna capture the desktop and save it to a jpg file, I know how to save it to a bmp file uncompressed but that file is to large 3 megs!!.

So I try to modify the code for capturing to an bmp

and I can not view the jpgs I create

what is wrong?

where am I wrong

here is the code:
[code]

#include <windows.h>
// C RunTime Header Files
#include <stdlib.h>
#include <malloc.h>
#include <memory.h>
#include <tchar.h>

// TODO: reference additional headers your program requires here
#include <shellapi.h>
#include <commdlg.h>

int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
static HBITMAP hDesktopCompatibleBitmap=NULL;
static HDC hDesktopCompatibleDC=NULL;
static HDC hDesktopDC=NULL;
static HWND hDesktopWnd=NULL;

hDesktopWnd=GetDesktopWindow();
hDesktopDC=GetDC(hDesktopWnd);
hDesktopCompatibleDC=CreateCompatibleDC(hDesktopDC);
hDesktopCompatibleBitmap=CreateCompatibleBitmap(hDesktopDC,GetSystemMetrics(SM_CXSCREEN),GetSystemMetrics(SM_CYSCREEN));
SelectObject(hDesktopCompatibleDC,hDesktopCompatibleBitmap);

OPENFILENAME ofn;
char szFileName[512]; szFileName[0]='\0';
ZeroMemory(&ofn,sizeof(ofn));
ofn.lStructSize=sizeof(OPENFILENAME);
ofn.Flags=OFN_HIDEREADONLY|OFN_PATHMUSTEXIST;
ofn.lpstrFilter="JPEG Files (*.jpg)\0*.jpg\0";
ofn.lpstrDefExt="jpg";
ofn.lpstrFile=szFileName;
ofn.nMaxFile=512;
if(!GetSaveFileName(&ofn));

BitBlt(hDesktopCompatibleDC,0,0,GetSystemMetrics(SM_CXSCREEN),GetSystemMetrics(SM_CYSCREEN),hDesktopDC,0,0,SRCCOPY);

BITMAPINFO bi;
void *pBits=NULL;
int nWidth=GetSystemMetrics(SM_CXSCREEN);
int nHeight=GetSystemMetrics(SM_CYSCREEN);
ZeroMemory(&bi,sizeof(bi));
bi.bmiHeader.biSize=sizeof(bi.bmiHeader);
bi.bmiHeader.biHeight=nHeight;
bi.bmiHeader.biWidth=nWidth;
bi.bmiHeader.biPlanes=1;
bi.bmiHeader.biBitCount=0;
bi.bmiHeader.biCompression=BI_JPEG;
bi.bmiHeader.biSizeImage=3*nWidth*nHeight;


HDC hBmpFileDC=CreateCompatibleDC(hDesktopCompatibleDC);

StretchDIBits(hBmpFileDC,
// destination rectangle
0,0 ,GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN),
// source rectangle
0, 0, nWidth, nHeight,
pBits,
&bi,
DIB_RGB_COLORS,
SRCCOPY);




HANDLE hFile=CreateFile(szFileName,GENERIC_WRITE,FILE_SHARE_WRITE,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
if(hFile!=INVALID_HANDLE_VALUE)
{
DWORD dwRet=0;
BITMAPFILEHEADER bmfHeader;
ZeroMemory(&bmfHeader,sizeof(bmfHeader));
bmfHeader.bfOffBits=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER);
bmfHeader.bfSize=bi.bmiHeader.biSizeImage+bmfHeader.bfOffBits;
bmfHeader.bfType='MB';

WriteFile(hFile,&bmfHeader,sizeof(bmfHeader),&dwRet,NULL);
WriteFile(hFile,&bi.bmiHeader,sizeof(bi.bmiHeader),&dwRet,NULL);
WriteFile(hFile,pBits,bi.bmiHeader.biSizeImage,&dwRet,NULL);
CloseHandle(hFile);
}

DeleteDC(hBmpFileDC);




return 0;
}

[/code]
GeneralRe: screen capture to jpg Pin
Christian Graus5-Jul-04 12:13
protectorChristian Graus5-Jul-04 12:13 
GeneralRe: screen capture to jpg Pin
Christian Graus15-Sep-04 11:43
protectorChristian Graus15-Sep-04 11:43 
GeneralEvents - How Many Pin
Grahamfff5-Jul-04 10:22
Grahamfff5-Jul-04 10:22 
GeneralRe: Events - How Many Pin
Blake Miller6-Jul-04 12:47
Blake Miller6-Jul-04 12:47 
GeneralReceiving File from Mobile phone Pin
steve chua5-Jul-04 10:14
steve chua5-Jul-04 10:14 
GeneralCustom Draw of TreeView-Control Pin
steven115-Jul-04 10:13
steven115-Jul-04 10:13 
GeneralRe: Custom Draw of TreeView-Control Pin
Roger Allen6-Jul-04 4:25
Roger Allen6-Jul-04 4:25 
GeneralRe: Custom Draw of TreeView-Control Pin
steven116-Jul-04 5:36
steven116-Jul-04 5:36 
GeneralAbout SAPI Pin
Member 12180445-Jul-04 9:36
Member 12180445-Jul-04 9:36 
GeneralAdding a toolbar button to Internet Explorer Pin
Member 12180445-Jul-04 9:24
Member 12180445-Jul-04 9:24 
GeneralCTabCtrl frame background color Pin
alma5-Jul-04 8:46
alma5-Jul-04 8:46 
Generalhelp, style convert: Dialog -&gt; MDI Pin
junhonguk5-Jul-04 6:51
junhonguk5-Jul-04 6:51 
GeneralRe: help, style convert: Dialog -&gt; MDI Pin
Jaime Stuardo5-Jul-04 7:06
Jaime Stuardo5-Jul-04 7:06 
QuestionHow to take a snapshot from a (partially o fully) hidden window Pin
Member 1338885-Jul-04 6:48
Member 1338885-Jul-04 6:48 
AnswerRe: How to take a snapshot from a (partially o fully) hidden window Pin
Ravi Bhavnani5-Jul-04 7:56
professionalRavi Bhavnani5-Jul-04 7:56 
GeneralRe: How to take a snapshot from a (partially o fully) hidden window Pin
Scozturk5-Jul-04 9:22
professionalScozturk5-Jul-04 9:22 
GeneralRe: How to take a snapshot from a (partially o fully) hidden window Pin
Jijo.Raj5-Jul-04 21:34
Jijo.Raj5-Jul-04 21:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.