Link to home
Start Free TrialLog in
Avatar of girvine1963
girvine1963

asked on

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?
Avatar of girvine1963
girvine1963

ASKER

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);
    }
  }
ASKER CERTIFIED SOLUTION
Avatar of Computer101
Computer101
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial