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#
  4. Multi Desktop app, Need to take Screen short of a given desktop using handle.

Multi Desktop app, Need to take Screen short of a given desktop using handle.

Scheduled Pinned Locked Moved C#
graphicstoolshelptutorial
5 Posts 3 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.
  • P Offline
    P Offline
    ptr_Electron
    wrote on last edited by
    #1

    I was been working on multiple desktop app. and would like to Screen shot of a desktop using the handle of the specific desktop.. I was using the blow code, but this always makes the the screenshort of current desktop.. as the Handle of "MyNewDesktop" was not supplyed. could you please tell me how to make use of hdesk to capture the screen short of the "MyNewDesktop". The below code is of utility app which captures desk top

    hwinsta = OpenWindowStation("WinSta0", false, WINDOWS_STATION_ACCESS_MASK.WINSTA_ALL_ACCESS);
    hwinsta2 = SetProcessWindowStation(hwinsta);
    hdesk = OpenDesktop("MyNewDesktop", 0, false, DESKTOP_ACCESS_MASK.GENERIC_ALL);//0x0001L | SetThreadDesktop);
    bool thset = SetThreadDesktop(hdesk);

            EnumDelegate delEnumfunc = new EnumDelegate(EnumWindowsProc);
            IntPtr DesktopWindow = GetDesktopWindow();
            bool bSuccessful = EnumDesktopWindows(hdesk, delEnumfunc, DesktopWindow);
            if (bSuccessful) // this was sucessfull control enters this block
            {
                string filename = string.Format("ScreenCap-{0:yyyy-MM-dd\_hh-mm-ss-tt}", DateTime.Now);
                var bounds = Screen.GetBounds(Point.Empty);
                using (Bitmap bitmap = new Bitmap(bounds.Width, bounds.Height))
                {
                    using (Graphics g = Graphics.FromImage(bitmap))
                    {
                        g.CopyFromScreen(Point.Empty, Point.Empty, bounds.Size);
                    }
                    bitmap.Save(@"C:\\" + filename + ".jpg", ImageFormat.Jpeg);
                }
             }
             else
             {
             // Get the last Win32 error code
                 int nErrorCode = Marshal.GetLastWin32Error();
                 string strErrMsg = String.Format("EnumDesktopWindows failed with code {0}.", nErrorCode);
                 throw new Exception(strErrMsg);
            }
    

    thanks

    M B 2 Replies Last reply
    0
    • P ptr_Electron

      I was been working on multiple desktop app. and would like to Screen shot of a desktop using the handle of the specific desktop.. I was using the blow code, but this always makes the the screenshort of current desktop.. as the Handle of "MyNewDesktop" was not supplyed. could you please tell me how to make use of hdesk to capture the screen short of the "MyNewDesktop". The below code is of utility app which captures desk top

      hwinsta = OpenWindowStation("WinSta0", false, WINDOWS_STATION_ACCESS_MASK.WINSTA_ALL_ACCESS);
      hwinsta2 = SetProcessWindowStation(hwinsta);
      hdesk = OpenDesktop("MyNewDesktop", 0, false, DESKTOP_ACCESS_MASK.GENERIC_ALL);//0x0001L | SetThreadDesktop);
      bool thset = SetThreadDesktop(hdesk);

              EnumDelegate delEnumfunc = new EnumDelegate(EnumWindowsProc);
              IntPtr DesktopWindow = GetDesktopWindow();
              bool bSuccessful = EnumDesktopWindows(hdesk, delEnumfunc, DesktopWindow);
              if (bSuccessful) // this was sucessfull control enters this block
              {
                  string filename = string.Format("ScreenCap-{0:yyyy-MM-dd\_hh-mm-ss-tt}", DateTime.Now);
                  var bounds = Screen.GetBounds(Point.Empty);
                  using (Bitmap bitmap = new Bitmap(bounds.Width, bounds.Height))
                  {
                      using (Graphics g = Graphics.FromImage(bitmap))
                      {
                          g.CopyFromScreen(Point.Empty, Point.Empty, bounds.Size);
                      }
                      bitmap.Save(@"C:\\" + filename + ".jpg", ImageFormat.Jpeg);
                  }
               }
               else
               {
               // Get the last Win32 error code
                   int nErrorCode = Marshal.GetLastWin32Error();
                   string strErrMsg = String.Format("EnumDesktopWindows failed with code {0}.", nErrorCode);
                   throw new Exception(strErrMsg);
              }
      

      thanks

      M Offline
      M Offline
      Mycroft Holmes
      wrote on last edited by
      #2

      Just to clarify, you are expecting to run a utility on YOUR machine and capture the image of someone else desktop? I would think you would need to deploy your utility on the target desktop, have it take the screenshot and send it to your app.

      Never underestimate the power of human stupidity RAH

      P 1 Reply Last reply
      0
      • M Mycroft Holmes

        Just to clarify, you are expecting to run a utility on YOUR machine and capture the image of someone else desktop? I would think you would need to deploy your utility on the target desktop, have it take the screenshot and send it to your app.

        Never underestimate the power of human stupidity RAH

        P Offline
        P Offline
        ptr_Electron
        wrote on last edited by
        #3

        No, it is windowsstation.. on the same PC you will have different desktop ie.. you can created and access

        1 Reply Last reply
        0
        • P ptr_Electron

          I was been working on multiple desktop app. and would like to Screen shot of a desktop using the handle of the specific desktop.. I was using the blow code, but this always makes the the screenshort of current desktop.. as the Handle of "MyNewDesktop" was not supplyed. could you please tell me how to make use of hdesk to capture the screen short of the "MyNewDesktop". The below code is of utility app which captures desk top

          hwinsta = OpenWindowStation("WinSta0", false, WINDOWS_STATION_ACCESS_MASK.WINSTA_ALL_ACCESS);
          hwinsta2 = SetProcessWindowStation(hwinsta);
          hdesk = OpenDesktop("MyNewDesktop", 0, false, DESKTOP_ACCESS_MASK.GENERIC_ALL);//0x0001L | SetThreadDesktop);
          bool thset = SetThreadDesktop(hdesk);

                  EnumDelegate delEnumfunc = new EnumDelegate(EnumWindowsProc);
                  IntPtr DesktopWindow = GetDesktopWindow();
                  bool bSuccessful = EnumDesktopWindows(hdesk, delEnumfunc, DesktopWindow);
                  if (bSuccessful) // this was sucessfull control enters this block
                  {
                      string filename = string.Format("ScreenCap-{0:yyyy-MM-dd\_hh-mm-ss-tt}", DateTime.Now);
                      var bounds = Screen.GetBounds(Point.Empty);
                      using (Bitmap bitmap = new Bitmap(bounds.Width, bounds.Height))
                      {
                          using (Graphics g = Graphics.FromImage(bitmap))
                          {
                              g.CopyFromScreen(Point.Empty, Point.Empty, bounds.Size);
                          }
                          bitmap.Save(@"C:\\" + filename + ".jpg", ImageFormat.Jpeg);
                      }
                   }
                   else
                   {
                   // Get the last Win32 error code
                       int nErrorCode = Marshal.GetLastWin32Error();
                       string strErrMsg = String.Format("EnumDesktopWindows failed with code {0}.", nErrorCode);
                       throw new Exception(strErrMsg);
                  }
          

          thanks

          B Offline
          B Offline
          Bernhard Hiller
          wrote on last edited by
          #4
                  EnumDelegate delEnumfunc = new EnumDelegate(EnumWindowsProc);
                  IntPtr DesktopWindow = GetDesktopWindow();
                  bool bSuccessful = EnumDesktopWindows(hdesk, delEnumfunc, DesktopWindow);
          

          And? What does the delegate do?

          var bounds = Screen.GetBounds(Point.Empty);

          Well, that Screen is the main screen, isn't it?

          P 1 Reply Last reply
          0
          • B Bernhard Hiller
                    EnumDelegate delEnumfunc = new EnumDelegate(EnumWindowsProc);
                    IntPtr DesktopWindow = GetDesktopWindow();
                    bool bSuccessful = EnumDesktopWindows(hdesk, delEnumfunc, DesktopWindow);
            

            And? What does the delegate do?

            var bounds = Screen.GetBounds(Point.Empty);

            Well, that Screen is the main screen, isn't it?

            P Offline
            P Offline
            ptr_Electron
            wrote on last edited by
            #5

            Thanks for response, Yes screen is the main screen, But how to capture the Screenshort of it... pls suggest

            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