|
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]
|
|
|
|
|
Sorry, how did you expect this code to save a jpg ?
The best and easiest way is to use GDI+.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
In answer to your email, my articles on GDI+ are not the only ones here that will show you have to save a jpg with GDI+.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
I am planning to use Named Events to provide a scripting interface to my application.
The scripting DLL would fire these Events, say Check box 1 checked etc.
My question is how many Named Events can an application deal with without any problems.
i.e. 1 ~10; 10 ~100; 100 ~ 500 etc.
I thought that Events would provide a nice clean interface; rather than using memory mapped files/mutux protected etc.
Any comments?
grahamfff
|
|
|
|
|
You can make hundreds, but you have to ask yourself, would you want to?
You can only wait on, I think, 32 at a time with WaitForMultipleObjects, so having so many events might not be a good solution to your design problem.
It might be better to have a few in several classes, like 'data ready' and 'abort' and a few others. Then find some scheme to generate a queue that you can put command or data items into to be read by your 'processor' when a particular event is set.
If you want to proivde a scripting interface to your application, can't you just embed visual basic for applications, make an OLE Automation Interface, or implement local RPC calls for example?
|
|
|
|
|
How to develop a program to receive file from mobile phone to pocket pc 2003?
|
|
|
|
|
Hi,
I want to have multiline items in my CTreeCtrl. Therefore I use Custom Draw and the drawing works perfect!
but I have 2 issues:
First I have to know how I can draw the ExpandBox (the box with + and -) left of the Treeitems. Is there any API-function or do I have to create an icon and draw it by myself?
The next issue is related to the position of the rootlines. How can I get the coordinates of the rootlines?
Has somebody of you done this yet? Or do you know some good links?
|
|
|
|
|
I did something similiar to what you need in this article which handles the printing of a tree control. It shouldn't be too hard to modify it to do what you need. I handled the special +/- | icons by using GDI to draw them (not too good but ok for printer). I have been thinking of changing these to icons in an image list and handling the drawing of them the same way as the item icons.
Anyway, here is the link Tree control print[^]
If you vote me down, my score will only get lower
|
|
|
|
|
thank you! i use an imagelist now
|
|
|
|
|
I went through the example code for text to speech conversion. I actually need to pass the text to that program by selectin text from Internet Explorer and then passing it to the VC++ application by some custom built button or right click option.
I'll be greatful if anyone helps me out.
|
|
|
|
|
Hello
I want to know how to add a toolbar button to Internet explorer just like we have the "Stop", "Refresh" and other buttons added.
Secondly i want to run a VC++ program when I click on that button. How to do this?
|
|
|
|
|
Hello!
I need to change the background of a tab control. I can change the background of the tab windows, but I don't know how to change the background of the surrounding frame, keeping the lines that give the frame-like look.
Does anyone know how to do that?
Thanks in advance.
-Alma-
|
|
|
|
|
I'm new C++ learner.
Now I have to convert DIALOG style of the source code into MDI.
Could any expert tell me how to do?
thanks a lot.
|
|
|
|
|
It's a very long task.... what I would do is to use AppWizard to create the MDI application skeleton. Then copy the relevant code from the dialog based application to the new generated one.
Jaime
|
|
|
|
|
Help !!!
Any idea?
|
|
|
|
|
If by "snapshot" you mean capture its bitmap to the clipboard, you might want to try this:/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
Here is a win32 code:
<br />
int Screenshot(HDC hdc, char *pszflname)<br />
{<br />
HDC memdc;<br />
HANDLE hfl;<br />
DWORD dwBytes, dwWidth, dwHeight, dwNumColors, dwBPP, ColorSize;<br />
void *pBits;<br />
HBITMAP hbmp;<br />
BITMAPFILEHEADER fileheader;<br />
BITMAPINFOHEADER infoheader;<br />
RGBQUAD colors[256];<br />
BITMAPINFO bmpinfo;<br />
HGDIOBJ hret;<br />
<br />
dwWidth = GetDeviceCaps(hdc, HORZRES);<br />
dwHeight = GetDeviceCaps(hdc, VERTRES);<br />
dwBPP = GetDeviceCaps(hdc, BITSPIXEL);<br />
if (dwBPP <= 8)<br />
dwNumColors = 256;<br />
else<br />
dwNumColors = 0;<br />
if (!(memdc = CreateCompatibleDC(hdc)))<br />
return (0);<br />
bmpinfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);<br />
bmpinfo.bmiHeader.biWidth = dwWidth;<br />
bmpinfo.bmiHeader.biHeight = dwHeight;<br />
bmpinfo.bmiHeader.biPlanes = 1;<br />
bmpinfo.bmiHeader.biBitCount = (WORD)dwBPP;<br />
bmpinfo.bmiHeader.biCompression = BI_RGB;<br />
bmpinfo.bmiHeader.biSizeImage = 0;<br />
bmpinfo.bmiHeader.biXPelsPerMeter = 0;<br />
bmpinfo.bmiHeader.biYPelsPerMeter = 0;<br />
bmpinfo.bmiHeader.biClrUsed = dwNumColors;<br />
bmpinfo.bmiHeader.biClrImportant = dwNumColors;<br />
hbmp = CreateDIBSection(hdc, &bmpinfo, DIB_PAL_COLORS, &pBits, NULL, 0);<br />
if (!hbmp)<br />
{<br />
DeleteDC(memdc);<br />
return (0);<br />
}<br />
hret = SelectObject(memdc, hbmp);<br />
if (!hret || (hret == HGDI_ERROR))<br />
{<br />
DeleteDC(memdc);<br />
return (0);<br />
}<br />
if (!BitBlt(memdc, 0, 0, dwWidth, dwHeight, hdc, 0, 0, SRCCOPY))<br />
{<br />
DeleteDC(memdc);<br />
return (0);<br />
}<br />
if (dwNumColors)<br />
dwNumColors = GetDIBColorTable(memdc, 0, dwNumColors, colors);<br />
fileheader.bfType = 0x4D42;<br />
ColorSize = dwNumColors * sizeof(RGBQUAD);<br />
fileheader.bfSize = ((dwWidth*dwHeight*dwBPP) >> 3) + ColorSize + sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);<br />
fileheader.bfReserved1 = fileheader.bfReserved2 = 0;<br />
fileheader.bfOffBits = ColorSize + sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);<br />
infoheader.biSize = sizeof(BITMAPINFOHEADER);<br />
infoheader.biWidth = dwWidth;<br />
infoheader.biHeight = dwHeight;<br />
infoheader.biPlanes = 1;<br />
infoheader.biBitCount = (WORD)dwBPP;<br />
infoheader.biCompression = BI_RGB;<br />
infoheader.biSizeImage = infoheader.biClrImportant = 0;<br />
infoheader.biXPelsPerMeter = infoheader.biYPelsPerMeter = 0;<br />
infoheader.biClrUsed = dwNumColors;<br />
hfl = CreateFile(pszflname, GENERIC_WRITE, 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);<br />
if (hfl == INVALID_HANDLE_VALUE)<br />
{<br />
DeleteObject(hbmp);<br />
{<br />
DeleteDC(memdc);<br />
return (0);<br />
}<br />
}<br />
WriteFile(hfl, &fileheader, sizeof(BITMAPFILEHEADER), &dwBytes, 0);<br />
WriteFile(hfl, &infoheader, sizeof(BITMAPINFOHEADER), &dwBytes, 0);<br />
if (!dwNumColors)<br />
WriteFile(hfl, colors, ColorSize, &dwBytes, 0);<br />
ColorSize = (dwWidth * dwHeight * dwBPP) >> 3;<br />
WriteFile(hfl, pBits, ColorSize, &dwBytes, 0);<br />
CloseHandle(hfl);<br />
DeleteObject(hbmp);<br />
DeleteDC(memdc);<br />
return (1);<br />
}<br />
and you can use it like this
<br />
Screenshot(GetDC(GetDesktopWindow()), "myscreenshot.bmp");<br />
I hope this helps....
Well... I am a beginner ...
|
|
|
|
|
Simply Great!!!
A very useful code snippet.
Thanks a lot...
Regards,
Jijo.
________________________________
Yesterday is history,
Tomorrow is a mystery,
But today is a present.
|
|
|
|
|
Hi,
I have a C++ DLL ( not MFC )which has a static method
say
class Test
{
static GetData();
Static GetParams();
bool TestDatat();
};
I am exporting this class and using in another DLL.
I built Test.dll,Test.lib.
Now i included in another DLL(say Samp.DLL):
Test.dll,Test.lib abd Test.h
in Samp.h file i inclued "Test.h" and linkedTest.lib and Placed Test.dll in Release/Debug folder.
I am calling Test::GetData() in Samp.DLL.
But after compiling Samp.DLL giving error like:
"error LNK 2001: unresolved external symbol. _declspec(dllimport) public:static bool _stdcall Test::GetDatta(char const *,bool)(_imp_?GetData@Test@SG_NPBD_N@Z)".
while building if i change project setttings "_cdecl*" in calling conventions, DLL is building fine,but failing to call a value from Samp.DLL by passing value to Test.DLL.
If i what to build my Samp.DLL by "_stdcall" convention how can i build this ?
Any help on this..
Thank you.
|
|
|
|
|
Have you exported using _declspec(dllexport) and imported using _declspec(dllimport)?
Can you show how you are importing and exporting?
Jaime
|
|
|
|
|
[edit] Regular DLLs don't You shouldn't [/edit] expose objects in a regular DLL (only ActiveX or MFC Extension DLLs) if you want the calling code to be something besides C++. You'll need to export a regular C-style function that serves as a wrapper to the method/property you are trying to invoke.
Jeremy Falcon
|
|
|
|
|
He's exporting a regular C++ class. Nothing magical about that, and is certainly possible with DLLs.
--
Ich bin Joachim von Hassel, und ich bin Pilot der Bundeswehr.
Welle: Erdball - F104-G Starfighter
|
|
|
|
|
Possible, but not practical and in poor practice IMO. Because, if you do that, then your calling language has to be C++.
Jeremy Falcon
|
|
|
|
|
Hello,
I have a hevey problem your you out there,
I need to right a app that handle the "%1" %*
when a app start.
When a app start my app should start and then i want
to check what app thats realy starded how do i do that?
|
|
|
|
|
Please rephrase your question because I really don't understand what you are asking !!!
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|