C++ .NET form save

Hi,
Does anyone know a quick way to capture and save a C++ .NET application's forms to disk in a graphics file?
girvine1963Asked:
Who is Participating?
 
Computer101Commented:
PAQed with points refunded (50)

Computer101
EE Admin
0
 
girvine1963Author Commented:
OK, found a solution of sorts. It is below if anyone's interested. Would still like to hear if anyone else has a better solution though.

  public: void saveIssuerForm(void)
  {
    PictureBox *pbox = new PictureBox();
    pbox->Location=Point(5,45);
    pbox->Size=Drawing::Size(800,600);
    pbox->BorderStyle = BorderStyle::Fixed3D;
    pbox->SizeMode = PictureBoxSizeMode::StretchImage;
    this->Refresh();

    HDC hDC;
    HWND hWnd=(HWND)this->Handle.ToInt32(); //Get HWND of form
    hDC = GetWindowDC(hWnd); //Now get it's DC handle
    HDC hMemDC = CreateCompatibleDC(hDC);
    RECT r;
    GetWindowRect((HWND)this->Handle.ToInt32(),&r);
    SIZE size;
    size.cx = r.right-r.left;
    size.cy = r.bottom-r.top;
    HBITMAP hBitmap = CreateCompatibleBitmap(hDC, size.cx, size.cy);
    if (hBitmap)
    {
      HBITMAP hOld = (HBITMAP) SelectObject(hMemDC, hBitmap);
      BitBlt(hMemDC, 0, 0, size.cx, size.cy, hDC, 0, 0, SRCCOPY);
      SelectObject(hMemDC, hOld);
      DeleteDC(hMemDC);
      ReleaseDC(NULL, hDC);
      pbox->Image = Image::FromHbitmap(hBitmap);
      pbox->Image->Save("C:\\Z.Jpg",
                        Drawing::Imaging::ImageFormat::Jpeg);        
      DeleteObject(hBitmap);
    }
  }
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.