Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Save Screenshot

Save Screenshot

Scheduled Pinned Locked Moved C / C++ / MFC
c++helpquestion
15 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    CDRAIN
    wrote on last edited by
    #1

    Hi, I'm developing a Visual C++ App. I need to save my app's screenshot and save it as an image (to analize it in future). Can somebody help me to do this on a Button's click event? Thanks a lot

    D N H 3 Replies Last reply
    0
    • C CDRAIN

      Hi, I'm developing a Visual C++ App. I need to save my app's screenshot and save it as an image (to analize it in future). Can somebody help me to do this on a Button's click event? Thanks a lot

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      CDRAIN wrote:

      I need to save my app's screenshot...

      To where?


      "A good athlete is the result of a good and worthy opponent." - David Crow

      "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

      1 Reply Last reply
      0
      • C CDRAIN

        Hi, I'm developing a Visual C++ App. I need to save my app's screenshot and save it as an image (to analize it in future). Can somebody help me to do this on a Button's click event? Thanks a lot

        N Offline
        N Offline
        Naveen
        wrote on last edited by
        #3

        You can save your app's screen as a bmp file. there are many samples in code project desribing this. Have a search. How ever i will explain the steps. Get the device context of your window. Create a memory dc and a bitmap. bitblt the content of the screen to the memory dc now get the pixel data and other informarion from this bimap object and write to a file.

        nave [OpenedFileFinder]

        1 Reply Last reply
        0
        • C CDRAIN

          Hi, I'm developing a Visual C++ App. I need to save my app's screenshot and save it as an image (to analize it in future). Can somebody help me to do this on a Button's click event? Thanks a lot

          H Offline
          H Offline
          Hamid Taebi
          wrote on last edited by
          #4

          Do you have any handle of this screenshot (hbitmap)?


          WhiteSky


          C 1 Reply Last reply
          0
          • H Hamid Taebi

            Do you have any handle of this screenshot (hbitmap)?


            WhiteSky


            C Offline
            C Offline
            CDRAIN
            wrote on last edited by
            #5

            I need to save the screenshot in a file .bmp or jpg (better) and the post it via email. I don't have implement nothing code yet, have you sample code? How I've just said I need to post it in email message (compiled with the TO: address), is there an API function (like the HTML "mailto:mymail@my.com" or some simple command) to open the user's email App with this message ready to me sent? Thanks. -- modified at 6:53 Friday 15th June, 2007

            H 1 Reply Last reply
            0
            • C CDRAIN

              I need to save the screenshot in a file .bmp or jpg (better) and the post it via email. I don't have implement nothing code yet, have you sample code? How I've just said I need to post it in email message (compiled with the TO: address), is there an API function (like the HTML "mailto:mymail@my.com" or some simple command) to open the user's email App with this message ready to me sent? Thanks. -- modified at 6:53 Friday 15th June, 2007

              H Offline
              H Offline
              Hamid Taebi
              wrote on last edited by
              #6

              Yeah I had and I think its easy for you,you can send a message with attachment for send message with attachment you can use of IMAPI(I think you can find an example on the codeproject. for make a file simplest code is like this (but you didnt tell me do you have a handle (hbitmap) or no)

              CImage m_Image;
              m_Image.Attach(hbitmap);
              m_Image.Save(filename,file type but if you dont set this parameter I think it makes a bitmap);
              //but you can save your file with png,jpg,...
              m_Image.Detach();

              this code is simplest code that you can make your file. Does this information helpful and does your problem solve or no.


              WhiteSky


              C 1 Reply Last reply
              0
              • H Hamid Taebi

                Yeah I had and I think its easy for you,you can send a message with attachment for send message with attachment you can use of IMAPI(I think you can find an example on the codeproject. for make a file simplest code is like this (but you didnt tell me do you have a handle (hbitmap) or no)

                CImage m_Image;
                m_Image.Attach(hbitmap);
                m_Image.Save(filename,file type but if you dont set this parameter I think it makes a bitmap);
                //but you can save your file with png,jpg,...
                m_Image.Detach();

                this code is simplest code that you can make your file. Does this information helpful and does your problem solve or no.


                WhiteSky


                C Offline
                C Offline
                CDRAIN
                wrote on last edited by
                #7

                I don't have hbitmap I need to capture the screen, and than save the image with the code you post (thanks for this). - I need to know how to capture the screen bitmap? - Can you easilly post me code or an example of the IMAPI's use (or when I can I'll search an examle).. Thaks of all.

                H 2 Replies Last reply
                0
                • C CDRAIN

                  I don't have hbitmap I need to capture the screen, and than save the image with the code you post (thanks for this). - I need to know how to capture the screen bitmap? - Can you easilly post me code or an example of the IMAPI's use (or when I can I'll search an examle).. Thaks of all.

                  H Offline
                  H Offline
                  Hamid Taebi
                  wrote on last edited by
                  #8

                  You must wait till I find my code and then send for you.:)


                  WhiteSky


                  1 Reply Last reply
                  0
                  • C CDRAIN

                    I don't have hbitmap I need to capture the screen, and than save the image with the code you post (thanks for this). - I need to know how to capture the screen bitmap? - Can you easilly post me code or an example of the IMAPI's use (or when I can I'll search an examle).. Thaks of all.

                    H Offline
                    H Offline
                    Hamid Taebi
                    wrote on last edited by
                    #9

                    HDC m_hdcMem,hdc;
                    HBITMAP m_Bitmap,m_OldBitmap,hMainBmp ;
                    //one intersting for you if you want to use of other resulition
                    you can simply change 800x600(640x480/1024x768,...)
                    int x=800;
                    int y=600;

                    //use of GetDC()->m_hDC and see result.
                    //hdc=GetDC()->m_hDC;
                    hdc=GetDesktopWindow()->GetDC()->m_hDC;

                    m_hdcMem= CreateCompatibleDC(hdc);

                    //one interesting for you if you want to use of other
                    m_Bitmap = CreateCompatibleBitmap(hdc,x,y);
                    m_OldBitmap=(HBITMAP) SelectObject(m_hdcMem, m_Bitmap);

                    BitBlt(m_hdcMem, 0,0,x,y, hdc,0,0,SRCCOPY);
                    hMainBmp =(HBITMAP) SelectObject(m_hdcMem, m_OldBitmap);
                    ///////////Now you have a hbitmap of screen hMainBmp/////

                    CImage m_Image;
                    m_Image.Attach(hMainBmp);
                    m_Image.Save("c:\\test.bmp");//use of jpg instead bmp but if you can zip your file its good.
                    m_Image.Detach();
                    DeleteDC(m_hdcMem);
                    DeleteObject(hMainBmp );
                    DeleteObject(m_OldBitmap);

                    for second part I could'nt find my program but I found a good article for you Another simple MAPI class[^]


                    WhiteSky


                    C 1 Reply Last reply
                    0
                    • H Hamid Taebi

                      HDC m_hdcMem,hdc;
                      HBITMAP m_Bitmap,m_OldBitmap,hMainBmp ;
                      //one intersting for you if you want to use of other resulition
                      you can simply change 800x600(640x480/1024x768,...)
                      int x=800;
                      int y=600;

                      //use of GetDC()->m_hDC and see result.
                      //hdc=GetDC()->m_hDC;
                      hdc=GetDesktopWindow()->GetDC()->m_hDC;

                      m_hdcMem= CreateCompatibleDC(hdc);

                      //one interesting for you if you want to use of other
                      m_Bitmap = CreateCompatibleBitmap(hdc,x,y);
                      m_OldBitmap=(HBITMAP) SelectObject(m_hdcMem, m_Bitmap);

                      BitBlt(m_hdcMem, 0,0,x,y, hdc,0,0,SRCCOPY);
                      hMainBmp =(HBITMAP) SelectObject(m_hdcMem, m_OldBitmap);
                      ///////////Now you have a hbitmap of screen hMainBmp/////

                      CImage m_Image;
                      m_Image.Attach(hMainBmp);
                      m_Image.Save("c:\\test.bmp");//use of jpg instead bmp but if you can zip your file its good.
                      m_Image.Detach();
                      DeleteDC(m_hdcMem);
                      DeleteObject(hMainBmp );
                      DeleteObject(m_OldBitmap);

                      for second part I could'nt find my program but I found a good article for you Another simple MAPI class[^]


                      WhiteSky


                      C Offline
                      C Offline
                      CDRAIN
                      wrote on last edited by
                      #10

                      Thanks al lot for the help, now I'm able to save and send screenshot vie email. With the sample you send me I'm able to send email directly in "background", but how can I obtain an editable and pre-compiled mail on my email's Manager (Outlook Express) so that I can add text or modify something before send it? Thanks.

                      H 1 Reply Last reply
                      0
                      • C CDRAIN

                        Thanks al lot for the help, now I'm able to save and send screenshot vie email. With the sample you send me I'm able to send email directly in "background", but how can I obtain an editable and pre-compiled mail on my email's Manager (Outlook Express) so that I can add text or modify something before send it? Thanks.

                        H Offline
                        H Offline
                        Hamid Taebi
                        wrote on last edited by
                        #11

                        I think you can find exmaples about outlook express but I'm not sure I saw on the Codeproject or other sites(I saw many years ago) on that article user able to fill fields on the outlook,but why you dont use of your program I dont know aout your program is that a project or homework but for example you can insert two options to your program on the first option user use of a file that this file made previous with program,on other choise you show a dialog to user and he can selects detaily for send (To,Bc,BCC,attachment) and for detaily of image(size of image(100x100,...),type of image(bmp,...) and advanced option on the BitBlt(0(or insert different x),0(or insert different y),x,y,..).


                        WhiteSky


                        C 1 Reply Last reply
                        0
                        • H Hamid Taebi

                          I think you can find exmaples about outlook express but I'm not sure I saw on the Codeproject or other sites(I saw many years ago) on that article user able to fill fields on the outlook,but why you dont use of your program I dont know aout your program is that a project or homework but for example you can insert two options to your program on the first option user use of a file that this file made previous with program,on other choise you show a dialog to user and he can selects detaily for send (To,Bc,BCC,attachment) and for detaily of image(size of image(100x100,...),type of image(bmp,...) and advanced option on the BitBlt(0(or insert different x),0(or insert different y),x,y,..).


                          WhiteSky


                          C Offline
                          C Offline
                          CDRAIN
                          wrote on last edited by
                          #12

                          My programm is a project, an "analisy and reporter project", and I want to fit it with the MS Office's standards, so I must have a preview of the mail to send with the document attached (or empty if so). However I accept your suggest and I can try to perform this (initially) but then I like to obtain what I search. Thanks a lot for Help, it's very usefull. Bye

                          H 1 Reply Last reply
                          0
                          • C CDRAIN

                            My programm is a project, an "analisy and reporter project", and I want to fit it with the MS Office's standards, so I must have a preview of the mail to send with the document attached (or empty if so). However I accept your suggest and I can try to perform this (initially) but then I like to obtain what I search. Thanks a lot for Help, it's very usefull. Bye

                            H Offline
                            H Offline
                            Hamid Taebi
                            wrote on last edited by
                            #13

                            Some time ago I saw a question on this forum bout preview of print well it seems to you do you wan to make your print preview or use of a activex (I personal dont want to tell you use of activex I like that you make your class and use of it its better for preview an article is on the www.codresource.net (Im not sure spell of this address is correct or no) except this site on the codeproject you can see a lot of articles that they show steps for write preview).Your answer doesnt have an answer "MS Office's standards" I think you want to write a package that conform with office well I think you are lucky I think if you search on the codeproject you can find your answer and more thing that I like to tell you always check variables and return value and generaly all things for example you get a screenshot but hbitmap is null so if you pass this variable to CImage you will get an exception or other example you run your program of CD so you cant save your file on the CD. I hope this informations helpful for you.


                            WhiteSky


                            C 1 Reply Last reply
                            0
                            • H Hamid Taebi

                              Some time ago I saw a question on this forum bout preview of print well it seems to you do you wan to make your print preview or use of a activex (I personal dont want to tell you use of activex I like that you make your class and use of it its better for preview an article is on the www.codresource.net (Im not sure spell of this address is correct or no) except this site on the codeproject you can see a lot of articles that they show steps for write preview).Your answer doesnt have an answer "MS Office's standards" I think you want to write a package that conform with office well I think you are lucky I think if you search on the codeproject you can find your answer and more thing that I like to tell you always check variables and return value and generaly all things for example you get a screenshot but hbitmap is null so if you pass this variable to CImage you will get an exception or other example you run your program of CD so you cant save your file on the CD. I hope this informations helpful for you.


                              WhiteSky


                              C Offline
                              C Offline
                              CDRAIN
                              wrote on last edited by
                              #14

                              Hi, I solve my problem with your help.:-D Thanks a lot. Bye

                              H 1 Reply Last reply
                              0
                              • C CDRAIN

                                Hi, I solve my problem with your help.:-D Thanks a lot. Bye

                                H Offline
                                H Offline
                                Hamid Taebi
                                wrote on last edited by
                                #15

                                I tried to told a good answer to you but maybe I was lucky that I saw your question!;)


                                WhiteSky


                                1 Reply Last reply
                                0
                                Reply
                                • Reply as topic
                                Log in to reply
                                • Oldest to Newest
                                • Newest to Oldest
                                • Most Votes


                                • Login

                                • Don't have an account? Register

                                • Login or register to search.
                                • First post
                                  Last post
                                0
                                • Categories
                                • Recent
                                • Tags
                                • Popular
                                • World
                                • Users
                                • Groups