Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 211
  • Last Modified:

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?
0
girvine1963
Asked:
girvine1963
1 Solution
 
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
 
Computer101Commented:
PAQed with points refunded (50)

Computer101
EE Admin
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now