Click to See Complete Forum and Search --> : BitBlt problem


dumbquestion
October 6th, 2004, 10:06 PM
Hi there. I've tried looking around previous posts on BitBlt's, but was unable to figure out the error in my code. I'm trying to save an entire form's graphics to a .jpg file using BitBlt. I have a menuItem_Click that calls the code below to open a file and then save the form to .jpg format.

private: System::Void menuItem8_Click(System::Object * sender, System::EventArgs * e)
{
if (saveFileDialog1->ShowDialog() == DialogResult::OK)
{
System::IO::StreamWriter * sw = new System::IO::StreamWriter(saveFileDialog1->FileName);
Graphics *g1 = CreateGraphics();
Image *MyImage = new Bitmap(this->ClientRectangle.Width,this->ClientRectangle.Height,g1);
Graphics *g2 = Graphics::FromImage(MyImage);
IntPtr dc1 = g1->GetHdc();
IntPtr dc2 = g2->GetHdc();
BitBlt(dc2,0,0,this->ClientRectangle.Width,this->ClientRectangle.Height,dc1,0,0,SRCCOPY);
g1->ReleaseHdc(dc1);
g2->ReleaseHdc(dc2);
MyImage->Save(saveFileDialog1->FileName,Imaging::ImageFormat::get_Jpeg());
}
}

When I attempt to compile, I get the following errors:

'SRCCOPY' : undeclared identifier
'BitBlt' : redefinition; previous definition was a 'formerly unknown identifier'

When I double-click on the second error message, the "WinGDI.h" file is opened and the error points to a line containing:

WINGDIAPI BOOL WINAPI BitBlt( IN HDC, IN int, IN int, IN int, IN int, IN HDC, IN int, IN int, IN DWORD);

I'm a bit lost here. I've tried playing around with DllImport methods, but the examples I saw were for C#, not C++ .NET.

Am I missing something here? Any suggestions? Thanks a lot!

Herryzz
March 4th, 2005, 04:01 AM
Have you solved the question?
I meet the same condition!!!

dumbquestion
March 8th, 2005, 10:59 AM
Well, I got something that works, and I have to say all documentation I saw on DllImports for Windows Forms applications with Visual C++ .NET was not very helpful to me. Of course there were plenty of C# forms examples. :)

In my example, I am trying to capture a form by pressing a button on it. I've attached a paraphrasing of my .h file below. Basically you need the DllImport line for the BitBlt command at the top. A lot of the lines at the top are auto-generated by VC++ .NET 2003 when you create a new class. The button1 and saveFileDialog1 handlers were auto-generated when I added a button and a saveFileDialog to the form view. I modified the code inside the button handler from code I saw on a C# example when I searched the web. (The guy's name was Mike Gold, I think. You could search him and BitBlt and probably get the link.)

Anyways, hope this helps. The images I get from this method have not very high resolution. I have not yet figured out how to modify the ImageFormat descriptor to increase the .jpg resolution. I posted on the Graphics forum on here asking for help with this actually.

Good luck. Let me know if you have any problems.