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. Managed C++/CLI
  4. Are there any easy methods to...

Are there any easy methods to...

Scheduled Pinned Locked Moved Managed C++/CLI
csharpquestion
14 Posts 5 Posters 37 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.
  • N Nish Nishant

    capture the screen using .NET? Nish


    Check out last week's Code Project posting stats presentation from :- http://www.busterboy.org/codeproject/ Feel free to make your comments.

    J Offline
    J Offline
    James T Johnson
    wrote on last edited by
    #2

    Not that I know of, you can use the same technique you use in GDI though. BTW, congrats on having post #100 :) James Simplicity Rules!

    N 1 Reply Last reply
    0
    • J James T Johnson

      Not that I know of, you can use the same technique you use in GDI though. BTW, congrats on having post #100 :) James Simplicity Rules!

      N Offline
      N Offline
      Nish Nishant
      wrote on last edited by
      #3

      James T. Johnson wrote: Not that I know of, you can use the same technique you use in GDI though As if I know how to do that with GDI :-) James T. Johnson wrote: BTW, congrats on having post #100 I guess no one would believe me if I said that it was entirely accidental :( Nish


      Check out last week's Code Project posting stats presentation from :- http://www.busterboy.org/codeproject/ Feel free to make your comments.

      J N 2 Replies Last reply
      0
      • N Nish Nishant

        capture the screen using .NET? Nish


        Check out last week's Code Project posting stats presentation from :- http://www.busterboy.org/codeproject/ Feel free to make your comments.

        R Offline
        R Offline
        Rama Krishna Vavilala
        wrote on last edited by
        #4

        incidentally I spend two hours today in order to find that. I also wanted to know how to set XOR mode in drawing. Unfortunately it looks like that we have to rely on P/Invoke

        N J 2 Replies Last reply
        0
        • R Rama Krishna Vavilala

          incidentally I spend two hours today in order to find that. I also wanted to know how to set XOR mode in drawing. Unfortunately it looks like that we have to rely on P/Invoke

          N Offline
          N Offline
          Nish Nishant
          wrote on last edited by
          #5

          Rama Krishna wrote: Unfortunately it looks like that we have to rely on P/Invoke No! Not P/Invoke. We can always use IJW if we are using MC++ Nish


          Check out last week's Code Project posting stats presentation from :- http://www.busterboy.org/codeproject/ Feel free to make your comments.

          1 Reply Last reply
          0
          • R Rama Krishna Vavilala

            incidentally I spend two hours today in order to find that. I also wanted to know how to set XOR mode in drawing. Unfortunately it looks like that we have to rely on P/Invoke

            J Offline
            J Offline
            James T Johnson
            wrote on last edited by
            #6

            XOR isn't supported under GDI+, from what I can infer it was because XOR was used as a hack because of speed/memory constraints and the proper way now is to ensure that what you are drawing is visible (grey's around the 128 area don't show up well at all when black is xor'd on it). James Simplicity Rules!

            1 Reply Last reply
            0
            • N Nish Nishant

              James T. Johnson wrote: Not that I know of, you can use the same technique you use in GDI though As if I know how to do that with GDI :-) James T. Johnson wrote: BTW, congrats on having post #100 I guess no one would believe me if I said that it was entirely accidental :( Nish


              Check out last week's Code Project posting stats presentation from :- http://www.busterboy.org/codeproject/ Feel free to make your comments.

              J Offline
              J Offline
              James T Johnson
              wrote on last edited by
              #7

              Nish [BusterBoy] wrote: As if I know how to do that with GDI Ask (ok imply) and ye shall receive :) Courtesy of MSDN

              // Create a normal DC and a memory DC for the entire screen. The
              // normal DC provides a "snapshot" of the screen contents. The
              // memory DC keeps a copy of this "snapshot" in the associated
              // bitmap.

              hdcScreen = CreateDC("DISPLAY", NULL, NULL, NULL);
              hdcCompatible = CreateCompatibleDC(hdcScreen);

              // Create a compatible bitmap for hdcScreen.

              hbmScreen = CreateCompatibleBitmap(hdcScreen,
              GetDeviceCaps(hdcScreen, HORZRES),
              GetDeviceCaps(hdcScreen, VERTRES));

              if (hbmScreen == 0)
              errhandler("hbmScreen", hwnd);

              // Select the bitmaps into the compatible DC.

              if (!SelectObject(hdcCompatible, hbmScreen))
              errhandler("Compatible Bitmap Selection", hwnd);

              // Hide the application window.

              ShowWindow(hwnd, SW_HIDE);

              //Copy color data for the entire display into a
              //bitmap that is selected into a compatible DC.

              if (!BitBlt(hdcCompatible,
              0,0,
              bmp.bmWidth, bmp.bmHeight,
              hdcScreen,
              0,0,
              SRCCOPY))

                  errhandler("Screen to Compat Blt Failed", hwnd); 
              

              // Redraw the application window.

              ShowWindow(hwnd, SW_SHOW);

              James Simplicity Rules! [Edit: You obviously won't need the calls to ShowWindow, you can just call Show and Hide on the form :)]

              N 1 Reply Last reply
              0
              • J James T Johnson

                Nish [BusterBoy] wrote: As if I know how to do that with GDI Ask (ok imply) and ye shall receive :) Courtesy of MSDN

                // Create a normal DC and a memory DC for the entire screen. The
                // normal DC provides a "snapshot" of the screen contents. The
                // memory DC keeps a copy of this "snapshot" in the associated
                // bitmap.

                hdcScreen = CreateDC("DISPLAY", NULL, NULL, NULL);
                hdcCompatible = CreateCompatibleDC(hdcScreen);

                // Create a compatible bitmap for hdcScreen.

                hbmScreen = CreateCompatibleBitmap(hdcScreen,
                GetDeviceCaps(hdcScreen, HORZRES),
                GetDeviceCaps(hdcScreen, VERTRES));

                if (hbmScreen == 0)
                errhandler("hbmScreen", hwnd);

                // Select the bitmaps into the compatible DC.

                if (!SelectObject(hdcCompatible, hbmScreen))
                errhandler("Compatible Bitmap Selection", hwnd);

                // Hide the application window.

                ShowWindow(hwnd, SW_HIDE);

                //Copy color data for the entire display into a
                //bitmap that is selected into a compatible DC.

                if (!BitBlt(hdcCompatible,
                0,0,
                bmp.bmWidth, bmp.bmHeight,
                hdcScreen,
                0,0,
                SRCCOPY))

                    errhandler("Screen to Compat Blt Failed", hwnd); 
                

                // Redraw the application window.

                ShowWindow(hwnd, SW_SHOW);

                James Simplicity Rules! [Edit: You obviously won't need the calls to ShowWindow, you can just call Show and Hide on the form :)]

                N Offline
                N Offline
                Nish Nishant
                wrote on last edited by
                #8

                James T. Johnson wrote: Copy color data for the entire display into a bitmap that is selected into a compatible DC. Bit confusing there. What's a bitmap object. Later I see that it is an object because you use two members, bmWidth and bmHeight. And how do I select it into a compatible DC? Nish


                Check out last week's Code Project posting stats presentation from :- http://www.busterboy.org/codeproject/ Feel free to make your comments.

                J C N 3 Replies Last reply
                0
                • N Nish Nishant

                  James T. Johnson wrote: Copy color data for the entire display into a bitmap that is selected into a compatible DC. Bit confusing there. What's a bitmap object. Later I see that it is an object because you use two members, bmWidth and bmHeight. And how do I select it into a compatible DC? Nish


                  Check out last week's Code Project posting stats presentation from :- http://www.busterboy.org/codeproject/ Feel free to make your comments.

                  J Offline
                  J Offline
                  James T Johnson
                  wrote on last edited by
                  #9

                  :-D I don't know, like i said it was just a copy/paste of code in MSDN, I suppose you could replace bmp.bmWidth with GetDeviceCaps(hdcScreen, HORZRES); and bmp.bmHeight with GetDeviceCaps(hdcScreen, VERTRES); James Simplicity Rules!

                  1 Reply Last reply
                  0
                  • N Nish Nishant

                    James T. Johnson wrote: Copy color data for the entire display into a bitmap that is selected into a compatible DC. Bit confusing there. What's a bitmap object. Later I see that it is an object because you use two members, bmWidth and bmHeight. And how do I select it into a compatible DC? Nish


                    Check out last week's Code Project posting stats presentation from :- http://www.busterboy.org/codeproject/ Feel free to make your comments.

                    C Offline
                    C Offline
                    Christian Graus
                    wrote on last edited by
                    #10

                    Are you using MFC ? If you are, it's a lot simpler than this SDK sample makes it look. Christian The tragedy of cyberspace - that so much can travel so far, and yet mean so little. And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002

                    1 Reply Last reply
                    0
                    • N Nish Nishant

                      James T. Johnson wrote: Copy color data for the entire display into a bitmap that is selected into a compatible DC. Bit confusing there. What's a bitmap object. Later I see that it is an object because you use two members, bmWidth and bmHeight. And how do I select it into a compatible DC? Nish


                      Check out last week's Code Project posting stats presentation from :- http://www.busterboy.org/codeproject/ Feel free to make your comments.

                      N Offline
                      N Offline
                      Neil Van Note
                      wrote on last edited by
                      #11

                      bmWidth, and bmHeight are the members of a BITMAP structure defined in WIN32. You can obtain this structre by calling GetObject for the WIN32 bitmap handle (HBITMAP). Regards

                      1 Reply Last reply
                      0
                      • N Nish Nishant

                        James T. Johnson wrote: Not that I know of, you can use the same technique you use in GDI though As if I know how to do that with GDI :-) James T. Johnson wrote: BTW, congrats on having post #100 I guess no one would believe me if I said that it was entirely accidental :( Nish


                        Check out last week's Code Project posting stats presentation from :- http://www.busterboy.org/codeproject/ Feel free to make your comments.

                        N Offline
                        N Offline
                        Neil Van Note
                        wrote on last edited by
                        #12

                        HDC hDC = GetDC(NULL);
                        HDC hMemDC = CreateCompatibleDC(hDC);

                        SIZE size = { GetSystemMetrics(SM\_CXSCREEN), GetSystemMetrics(SM\_CYSCREEN) };
                        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);
                        
                        	Bitmap \*pBitmap = Bitmap::FromHbitmap(hBitmap);
                        	DeleteDC(hMemDC);
                        	ReleaseDC(NULL, hDC);
                        
                        	if (pBitmap)
                        	{
                        		pBitmap->Save("./test.bmp");
                        		pBitmap->Dispose();
                        		pBitmap = 0;
                        	}
                        
                        	DeleteObject(hBitmap);
                        }
                        
                        N 1 Reply Last reply
                        0
                        • N Neil Van Note

                          HDC hDC = GetDC(NULL);
                          HDC hMemDC = CreateCompatibleDC(hDC);

                          SIZE size = { GetSystemMetrics(SM\_CXSCREEN), GetSystemMetrics(SM\_CYSCREEN) };
                          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);
                          
                          	Bitmap \*pBitmap = Bitmap::FromHbitmap(hBitmap);
                          	DeleteDC(hMemDC);
                          	ReleaseDC(NULL, hDC);
                          
                          	if (pBitmap)
                          	{
                          		pBitmap->Save("./test.bmp");
                          		pBitmap->Dispose();
                          		pBitmap = 0;
                          	}
                          
                          	DeleteObject(hBitmap);
                          }
                          
                          N Offline
                          N Offline
                          Nish Nishant
                          wrote on last edited by
                          #13

                          Thanks! Is Bitmap a non-MFC GDI class? Nish


                          The posting stats are now in PDF:- http://www.busterboy.org/codeproject/ Feel free to make your comments. Updated - May 04th, Saturday

                          N 1 Reply Last reply
                          0
                          • N Nish Nishant

                            Thanks! Is Bitmap a non-MFC GDI class? Nish


                            The posting stats are now in PDF:- http://www.busterboy.org/codeproject/ Feel free to make your comments. Updated - May 04th, Saturday

                            N Offline
                            N Offline
                            Neil Van Note
                            wrote on last edited by
                            #14

                            Bitmap is a managed class in System.Drawing...

                            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