NTK and The NTK Project
are properties of Jn Dechereux
Home | Documentation | FAQ.

Vanilla 1.1.8 is a product of Lussumo. More Information: Documentation, Community Support.

Welcome Guest!
Want to take part in these discussions? If you have an account, sign in now.
If you don't have an account, apply for one now.
    •  
      CommentAuthorccarrignon
    • CommentTimeSep 11th 2020 edited
     

    Hi there
    In my new project I need to programatically take a picture of the machine desktop at regular intervals - but have no idea how to do this. So, just wondering if a function capable to take a screenshot and save it to disk already exists in NTK? -or- If someone has already developed such kind of code and would like to share it? Any help would be appreciated.
    TIA
    -Chris


    •  
      CommentAuthorAbbougaga
    • CommentTime5 days ago edited
     
    Hi Chris,
    You should give a try to your ..\Contribs\snapshot\ directory. Just a basic contrib I submited to the community a few years ago. Also, have a closest look to the GrabFullScreen() function in Snapshot.prg - imo all you need is there, and many more. :smile:

    Cheers,
    Ab.

    Just an excerpt:
    FUNCTION GrabFullScreen(hWndP)
    Local hDcScr, hdcMem, hBmpWin
    Local aScrRect := ARRAY(4)
    Local cBmpFileDest := "Image_"+DTOS(Date())+"_"+nToc(Second())+".bmp"
    
    CLEAR TYPEAHEAD
    
    
    NTK_HideWindow(hWndP, .T.)   // temporally hide NTK-Snapshot window
    
    
    // Now, we take a snapshot of the full screen...
    
    hDcScr := NTK_GetDC( NULL )   // Get a DC on the fullscreen
    
    // Retreive the fullscreen resolution
    aScrRect[ RECT_Left   ] := 0
    aScrRect[ RECT_Top    ] := 0
    aScrRect[ RECT_Right  ] := NTK_GetSystemMetrics( SM_CXSCREEN )
    aScrRect[ RECT_Bottom ] := NTK_GetSystemMetrics( SM_CYSCREEN )
    
    hDcMem  := NTK_CreateCompatibleDC( hDcScr )
    
    hBmpWin := NTK_CreateCompatibleBitmap( hDcScr,;
                                           aScrRect[ RECT_Right  ] - aScrRect[ RECT_Left ],;
                                           aScrRect[ RECT_Bottom ] - aScrRect[ RECT_Top  ] )
    
    NTK_SelectObject( hdcMem, hBmpWin )
    
    NTK_BitBlt( hDcMem, 0, 0, aScrRect[RECT_Right] - aScrRect[RECT_Left], aScrRect[RECT_Bottom] - aScrRect[RECT_Top],;
                hDcScr, 0, 0,;
                SRCCOPY )
    
    NTK_DeleteDC( hdcMem )
    NTK_ReleaseDC( hDcScr, NULL )
    
    
    NTK_HideWindow(hWndP, .F.)    // Call back the NTK-Snapshot window
    
    
    IF NTK_SaveBmp( nil, hBmpWin, cBmpFileDest )
       lRet := .T.
       Alert( "FULL-SCREEN:"+CR+;
              "Picture successfully taken and saved under:"+CR+cBmpFileDest )
    ELSE
       lRet := .F.
        Alert( "FULL-SCREEN:"+CR+;
               "Cannot save "+CR+cBmpFileDest )
    ENDIF
    
    NTK_DeleteObject(hBmpWin)
    
    RETURN( lRet )
    
    •  
      CommentAuthorccarrignon
    • CommentTime4 days ago edited
     

    Hi Ab
    It was there since years and I did not see it! :shamed:
    Many thanks - this is exactly what I was looking for.
    -Chris