CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Hybrid View

  1. #1
    Join Date
    Nov 2007
    Posts
    93

    Get a *.bmp file of a window´s view

    I need to obtain a *.bmp file from a window ´s view in order to insert in a document.
    Now i obtain this in a *.wmf file. But if I have a lot of wmf files and insert them in a document, the word file lats a lot of time when i open it.

    My options are obtain the wmf file and convert it in a bmp file, or obtain the image directly in bmp file.
    I´m working in Visual C++.
    Is there a good way of do this?.

    Thank you!

    PERE

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Get a *.bmp file of a window´s view

    What do you mean by "a *.bmp file from a window ´s view"?
    Is it a screenshot? Or what?
    Also how do you "obtain this in a *.wmf file"?
    Victor Nijegorodov

  3. #3
    Join Date
    Nov 2007
    Posts
    93

    Re: Get a *.bmp file of a window´s view

    "obtain this in a *.wmf file" :

    I take a compatible CDC of my wimdow an associate this yto the window. I draw the content and save in a CMetafile object.

    With this i can save in a .wmf file

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Get a *.bmp file of a window´s view

    What about using the CImage class?
    Victor Nijegorodov

  5. #5
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,234

    Re: Get a *.bmp file of a window´s view

    As Victor already suggested, an easy way to save a bitmap in a file is by using CImage MFC/ATL-shared class.
    Here is a simplified example which saves the client area of a window (view).
    Code:
    void CChildView::OnFileSave()
    {
        // get client rectangle and DC
        CRect rc;
        GetClientRect(rc);
        CClientDC dc(this);
    
        // create CImage object containing a 32 BPP bitmap
        CImage img;
        img.Create(rc.Width(), rc.Height(), 32);
    
        // copy bitmap from client DC to image DC
        ::BitBlt(img.GetDC(), 0, 0, rc.Width(), rc.Height(), dc.m_hDC, 0, 0, SRCCOPY);
        
        // save bitmap in a file
        img.Save(_T("c:\\work\\test.bmp"), Gdiplus::ImageFormatBMP);
    
        // release image DC 
        img.ReleaseDC();
    }
    Of course, you can modify it to get rid of hard-coded stuff, to handle errors, to let user to choose output folder, file name and format, which can be also JPEG, GIF or PNG. So far, forget that "CMetafile".
    Last edited by ovidiucucu; January 21st, 2023 at 06:46 AM.
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  6. #6
    Join Date
    Nov 2007
    Posts
    93

    Re: Get a *.bmp file of a window´s view

    Thank you!!!
    I´ll try.
    It´s great

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured