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. Desktop screen shot function failed in RDP

Desktop screen shot function failed in RDP

Scheduled Pinned Locked Moved C / C++ / MFC
helpgraphicsperformancequestion
4 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.
  • O Offline
    O Offline
    onlyjaypatel
    wrote on last edited by
    #1

    Hi All, I have one program thats taking the screen shot of desktop and save in a file.But this program is running on remote machine.I connect this machine with RDP.Problem is When i connected to machine program is working fine and taking screen shots ,but when i disconnected from RDP or minimized it it failed. I found that, The Bitblt function of the following sample code is falied with Error 6.Otherwise its working fine when i m connected to it. Error 6 means Invalid handle. Can anybody tell why its failed of any other method of taking screen shot of desktop.? Thanx in advance.. ////////////////////////////////////////// BOOL CBitmapFile::SaveDesktopAsFile(LPTSTR szFile, int nFileType) { CString strFileName, strError = ""; CWnd* pWnd = CWnd::GetDesktopWindow(); CBitmap bitmap; CWindowDC dc(pWnd); CDC memDC; CRect rect; strFileName = (CString)szFile; memDC.CreateCompatibleDC(&dc); pWnd->GetWindowRect(rect); bitmap.CreateCompatibleBitmap(&dc, rect.Width(),rect.Height() ); CBitmap* pOldBitmap = memDC.SelectObject(&bitmap); memDC.BitBlt(0, 0, rect.Width(),rect.Height(), &dc, 0, 0, SRCCOPY); // Create logical palette if device support a palette CPalette pal; if( dc.GetDeviceCaps(RASTERCAPS) & RC_PALETTE ) { UINT nSize = sizeof(LOGPALETTE) + (sizeof(PALETTEENTRY) * 256); LOGPALETTE *pLP = (LOGPALETTE *) new BYTE[nSize]; pLP->palVersion = 0x300; pLP->palNumEntries = GetSystemPaletteEntries( dc, 0, 255, pLP->palPalEntry ); // Create the palette pal.CreatePalette( pLP ); delete[] pLP; } // Convert the bitmap to a DIB HANDLE hDIB = DDBToDIB( bitmap, BI_RGB, &pal ); if( hDIB == NULL ) return FALSE; // DrawGreyScale( &memDC, hDIB ); memDC.SelectObject(pOldBitmap); // Write it to file // Write it to file if(nFileType == BMP_FILE) WriteDIB( szFile, hDIB ); else JpegFromDib(hDIB, 100, strFileName, &strError); // Free the memory allocated by DDBToDIB for the DIB GlobalFree( hDIB ); return TRUE; } //////////////////////////////////////////

    C 1 Reply Last reply
    0
    • O onlyjaypatel

      Hi All, I have one program thats taking the screen shot of desktop and save in a file.But this program is running on remote machine.I connect this machine with RDP.Problem is When i connected to machine program is working fine and taking screen shots ,but when i disconnected from RDP or minimized it it failed. I found that, The Bitblt function of the following sample code is falied with Error 6.Otherwise its working fine when i m connected to it. Error 6 means Invalid handle. Can anybody tell why its failed of any other method of taking screen shot of desktop.? Thanx in advance.. ////////////////////////////////////////// BOOL CBitmapFile::SaveDesktopAsFile(LPTSTR szFile, int nFileType) { CString strFileName, strError = ""; CWnd* pWnd = CWnd::GetDesktopWindow(); CBitmap bitmap; CWindowDC dc(pWnd); CDC memDC; CRect rect; strFileName = (CString)szFile; memDC.CreateCompatibleDC(&dc); pWnd->GetWindowRect(rect); bitmap.CreateCompatibleBitmap(&dc, rect.Width(),rect.Height() ); CBitmap* pOldBitmap = memDC.SelectObject(&bitmap); memDC.BitBlt(0, 0, rect.Width(),rect.Height(), &dc, 0, 0, SRCCOPY); // Create logical palette if device support a palette CPalette pal; if( dc.GetDeviceCaps(RASTERCAPS) & RC_PALETTE ) { UINT nSize = sizeof(LOGPALETTE) + (sizeof(PALETTEENTRY) * 256); LOGPALETTE *pLP = (LOGPALETTE *) new BYTE[nSize]; pLP->palVersion = 0x300; pLP->palNumEntries = GetSystemPaletteEntries( dc, 0, 255, pLP->palPalEntry ); // Create the palette pal.CreatePalette( pLP ); delete[] pLP; } // Convert the bitmap to a DIB HANDLE hDIB = DDBToDIB( bitmap, BI_RGB, &pal ); if( hDIB == NULL ) return FALSE; // DrawGreyScale( &memDC, hDIB ); memDC.SelectObject(pOldBitmap); // Write it to file // Write it to file if(nFileType == BMP_FILE) WriteDIB( szFile, hDIB ); else JpegFromDib(hDIB, 100, strFileName, &strError); // Free the memory allocated by DDBToDIB for the DIB GlobalFree( hDIB ); return TRUE; } //////////////////////////////////////////

      C Offline
      C Offline
      Code o mat
      wrote on last edited by
      #2

      Well, my guess would be that the desktop you are making screen shots of simply doesn't exist when there's noone looking at it, understand that as in, no remote desktop connection is made. I think when you connect to the RDP server it will create something like a virtual desktop for you and will close and destroy it once you are done using RDP and log out. So my guess is that you get NULL when you call GetDesktopWindow or maybe you get 0 for its width and height, or you just don't get a DC for it. Does this make any sense?

      > The problem with computers is that they do what you tell them to do and not what you want them to do. <

      D O 2 Replies Last reply
      0
      • C Code o mat

        Well, my guess would be that the desktop you are making screen shots of simply doesn't exist when there's noone looking at it, understand that as in, no remote desktop connection is made. I think when you connect to the RDP server it will create something like a virtual desktop for you and will close and destroy it once you are done using RDP and log out. So my guess is that you get NULL when you call GetDesktopWindow or maybe you get 0 for its width and height, or you just don't get a DC for it. Does this make any sense?

        > The problem with computers is that they do what you tell them to do and not what you want them to do. <

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

        Code-o-mat wrote:

        So my guess is that you get NULL when you call GetDesktopWindow...

        So then wouldn't the subsequent call to GetWindowRect() fail?

        "Love people and use things, not love things and use people." - Unknown

        "The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch

        1 Reply Last reply
        0
        • C Code o mat

          Well, my guess would be that the desktop you are making screen shots of simply doesn't exist when there's noone looking at it, understand that as in, no remote desktop connection is made. I think when you connect to the RDP server it will create something like a virtual desktop for you and will close and destroy it once you are done using RDP and log out. So my guess is that you get NULL when you call GetDesktopWindow or maybe you get 0 for its width and height, or you just don't get a DC for it. Does this make any sense?

          > The problem with computers is that they do what you tell them to do and not what you want them to do. <

          O Offline
          O Offline
          onlyjaypatel
          wrote on last edited by
          #4

          I have checked it with writing a log file. All pointers and rect are looking normal. But the function bitblt is failed. Why i dont know and the GetlastError gives Error 6. which is invalid handle. Is there any api to check HDC or CDC object is valid or not. bcoz it looks normal handle and pointer. Anyway thanx for reply.

          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