|
Hi fellows
I'm need to capture a screen in my app, but I have no idea how I can do this or where I start. Can someone help with this saying where I can get some information about how and where to start?
Thanks a lot
Alex Cutovoi
|
|
|
|
|
Since there is no such thing as a screen in C++ I assume you mean the WindowsAPI. Are you using opengl as I see you have a question about opengl above??
John
-- modified at 12:55 Monday 10th October, 2005
|
|
|
|
|
|
John, I've read that article that you said. I don't understand almost all, it's complicated. Well, I got made this, is this correct??
At this point I'm completely lost, I don't know what is the next step. I'll try to understand.
void CapturaTela()
{
int iWidth = GetSystemMetrics(SM_CXSCREEN);
int iHeight = GetSystemMetrics(SM_CYSCREEN);
HWND screenHwnd;
HDC screenHdc;
HDC copyHdc;
HBITMAP newBitmap;
screenHwnd = GetDesktopWindow();
screenHdc = GetDC(screenhwnd);
copyHdc = CreateCompatibleDC(screenHdc);
HBITMAP bitmap = CreateCompatibleBitmap(screenHdc, iWidth, iHeight);
SelectObject(copyHdc, bitmap);
BitBlt(copyHdc, 0, 0, iWidth, iHeight, screenHdc, 0, 0, SRCCOPY);
newBitmap = bitmap;
}
|
|
|
|
|
Alex Cutovoi wrote:
newBitmap = bitmap;
This seems redundant to me.
This leaks memory ( you need to catch the HBITMAP returned by select object and put it back in, you need to delete your DC and any HBITMAP you're not going to return ), but off the top of my head, it looks pretty much right, in that it should work.
Alex Cutovoi wrote:
HWND screenHwnd;
HDC screenHdc;
HDC copyHdc;
HBITMAP newBitmap;
There is no reason to create these before the moment you assign their value, and it's bad to have variables with random values in them flying about.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Christian and John, my code now is this, it's a little big. Is this correct?
Please, I made this based on the article that you(John) said me, and I don't know if this thing is all correct. It's my first time that I do this.
Thanks for you guys
void CapturaTheScreen()
{
int iWidth = GetSystemMetrics(SM_CXSCREEN);
int iHeight = GetSystemMetrics(SM_CYSCREEN);
HWND screenHwnd;
HDC* screenHdc;
RECT theRect;
HDC copyHdc;
BYTE* desenhobits;
//HBITMAP newBitmap;
theRect.bottom = 0;
theRect.left = 0;
theRect.right = 0;
theRect.top = 0;
screenHwnd = GetDesktopWindow();
screenHdc = GetDC(screenHwnd);
copyHdc = CreateCompatibleDC(screenHdc);
HBITMAP bitmap = CreateCompatibleBitmap(screenHdc, iWidth, iHeight);
SelectObject(copyHdc, bitmap);
BitBlt(copyHdc, 0, 0, iWidth, iHeight, screenHdc, 0, 0, SRCCOPY);
BITMAPINFOHEADER infoHeader;
//Image header info
infoHeader.biSize = sizeof(BITMAPINFOHEADER);
infoHeader.biBitCount = 24;
infoHeader.biPlanes = 1;
infoHeader.biWidth = theRect.right;
infoHeader.biHeight = theRect.bottom;
infoHeader.biCompression = BI_RGB;
infoHeader.biSizeImage = ((((infoHeader.biWidth * infoHeader.biBitCount) + 31) & ~31) >> 3) * infoHeader.biHeight;
theRect = CreateDIBSection(screenHdc, (CONST BITMAPINFO*)&infoHeader, DIB_RGB_COLORS, (void**)&desenhobits, NULL, 0);
ReleaseDC(screenHdc);
//processo de gravação
FILE* fImage = fopen("img1.bmp", "wb");
if(fImage == NULL)
{
//image info
BITMAPFILEHEADER fileHeader;
int iBits= sizeof(BITMAPFILEHEADER) + infoHeader.biSize;
LONG lTamImagem = infoHeader.biSizeImage;
LONG lFileSize = lTamImagem + iBits;
fileHeader.bfOffBits = iBits;
fileHeader.bfType = 'B'+('M'<<8);
fileHeader.bfSize = lFileSize;
fileHeader.bfReserved1 = 0;
fileHeader.bfReserved2 = 0;
unsigned int iTheFileHeader = fwrite(&fileHeader, 1, sizeof(BITMAPFILEHEADER), fImage);
unsigned int iTheInfoHeader = fwrite(&infoHeader, 1, sizeof(BITMAPINFOHEADER), fImage);
unsigned int iTheImage = fwrite(desenhobits, 1, lFileSize, fImage);
}
}
-- modified at 18:10 Monday 10th October, 2005
|
|
|
|
|
I guess the question is, what does it do that you're still asking ?
Alex Cutovoi wrote:
if(fImage == NULL)
I assume this should be != ? I dunno tho, I don't use C file handling.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
|
John, my code works fine, but when I open the image with Windows Picture appears the message: "Drawing failed". I don't know why. it's strange, cause the code is right(I think);
The Image when it's saved has the size of 4kb. The BITMAPINFOHEADER's biXPelsPerMeter and biYPelsPerMeter properties I set to 0, cause when I saw the horizontal and vertical resolution values, they was absolutely crazy.
Can you help?
Thanks again
Alex Cutovoi
|
|
|
|
|
I hope someone could tell me a efficient way to find some strings in another string.Thanks!
|
|
|
|
|
You can use strstr function.
See more information in MSDN.
-- modified at 5:05 Monday 10th October, 2005
|
|
|
|
|
Are there any wanys even more efficient? Thanks!
|
|
|
|
|
Jacky Chee wrote:
Are there any wanys even more efficient?
Ask yourself this: "Does it need to be more efficient?"
If "yes", then: "Have I profiled the code so that I know this for a fact?"
If "no", then accept the offered strstr for a char* buffer (or std::string::find for a std::string object).
--
The Blog: Bits and Pieces
|
|
|
|
|
I'm new to network programming, and I would apperciate if I could get some links to tutorials/samples of UDP client/server programming in c++.
Thanks
|
|
|
|
|
i need a program, the program should take as input 2 intgers and the operation to be performed.It should then output the numbers,the operator and the result.
|
|
|
|
|
You're joking, right ? This would be what, your first homework task ? Maybe try showing up for a class or two.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I am a beginner in GDI+, and am trying to apply effects like "blur" and "sharpen" to a Bitmap object.
My program can sucessfully import the bitmap, and save it to a different format. This program compiles and runs perfectly well.
However, when I type in one of the effects classes, the program will not even compile. For example,
typing in "BlurParams myBlurParams;" to create a BlurParams object, causes the error "error C2065 'BlurParams':undeclared identifier."
I'm not sure if I need to include some other file to enable effects, but most other GDI+ stuff seems to work fine.
To make sure it wasn't just my code that was causing the problem, I copied and pasted the following code from the MSDN
------------------------------
Bitmap myBitmap(L"Picture.bmp");
UINT srcWidth = myBitmap.GetWidth();
UINT srcHeight = myBitmap.GetHeight();
BrightnessContrastParams briConParams;
briConParams.brightnessLevel = 50;
briConParams.contrastLevel = 0;
BrightnessContrast briCon;
briCon.SetParameters(&briConParams);
RECT rectOfInterest = {20, 15, 80, 50};
// Draw the original image.
graphics.DrawImage(&myBitmap, 20, 20, srcWidth, srcHeight);
// Increase the brightness in a portion of the image.
myBitmap.ApplyEffect(&briCon, &rectOfInterest);
// Draw the image again.
graphics.DrawImage(&myBitmap, 200, 20, srcWidth, srcHeight);
----------------------------
Trying to compile this, I get several errors, the first being
"error C2065: 'briConParams': undeclared identifier"
There must be some way to set up these effects. Could someone please help me? GDI+ hasn't given me troubles before now.
|
|
|
|
|
ben09090 wrote:
BlurParams
Say what ? I've never heard of this. According to MSDN :
Minimum availability GDI+ 1.1
I guess that's why I've not heard of it, and perhaps why you can't use it. Try to update your GDI+ version. Alternatively, read my image processing articles ( they are in C#, but easy to port ).
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
|
ben09090 wrote:
Is GDI+1.1 not out yet,and is that why these effects are not defined?
If you have the absolute latest SDK and it still does not work, then probably.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
As far as I can tell, GDI+ 1.1 is not out yet. Maybe Microsoft should make it more clear in the MSDN which classes do not exist yet. I wonder when it will be available?
Your image effect code is really helpful! I have looked at your code, and that should be sufficient for the project I'm working on.
Thanks for the help.
-Ben
|
|
|
|
|
I'm glad I helped. Yeah, it's not always totally clear, but I'd say a lot of the docs are for .NET 2.0, and that GDI+ 1.1 probably will come out with Vista.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I'm now trying to transplant a C++ program written in Linux to make it run in DOS, but there are quite a lot of header files that are not support in VC 6.0( I am now using it ),like<unistd.h>,<sys socket.h="">,etc.What can I do?
Thanks for help.
|
|
|
|
|
Sorry , like "sys/socket.h", "unistd.h", etc.
|
|
|
|
|
I hope by DOS you mean Windows command line, since with VC6 you can't make DOS programs.
Is there an option to install Cygwin on the machines where you want your Linux software to run?
My programming blahblahblah blog. If you ever find anything useful here, please let me know to remove it.
|
|
|
|
|