#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2014
    Posts
    7
    Rep Power
    0

    Angry Screen Shots in C.


    I'm creating a keylogger with screen shots on mouse clicks.
    I've completed most of its part but i'm now stuck on how to take screen shots with a mouse click.
    Please do tell me if there is specific library to perform this task or if there is any other way.

    I'm using "Dev C" for coding. :chomp:
  2. #2
  3. Lord of the Dance
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2003
    Posts
    3,733
    Rep Power
    1959
    Codeproject has a project with Various methods for capturing the screen
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2014
    Posts
    7
    Rep Power
    0
    Originally Posted by Gleedaniel13
    Yes, I agree that a lot of codeproject are there. You can use them though.
    Bro as i have already mentioned that i'm usin 'dev c'
    and it does not supports "stdafx.h".
    where do i get this library?
  6. #4
  7. Lord of the Dance
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2003
    Posts
    3,733
    Rep Power
    1959
    You can not change the program to another one? for example MS Visual Studio Express?
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    187
    Rep Power
    83
    Originally Posted by incredibleX
    Bro as i have already mentioned that i'm usin 'dev c'
    and it does not supports "stdafx.h".
    where do i get this library?
    Bro, You really don't "get" the library for stdafx.h. This header file is a precompiled header file. It's a file that is generated by MS Visual Studio. The purpose of this file is to substantially reduce the compilation time of your project. In very small projects, the inclusion of stdafx.h is a moot issue.

    Although I'm not familiar with DEV-C, I believe this compiler also has the same feature in order to reduce compile time.

    It appears that the GDI option from the previous post would be the easiest approach. So, I would recommend that you copy and paste the minimally required GDI code to flesh out your screen capture function to a new source file. Do NOT include the stdafx.h file in your new source file and continue from that point.
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2014
    Posts
    7
    Rep Power
    0
    Code:
    #include <Windows.h>
    #include <iostream>
    
    void CaptureScreen()
    {
        int nScreenWidth = GetSystemMetrics(SM_CXSCREEN);
        int nScreenHeight = GetSystemMetrics(SM_CYSCREEN);
        HWND hDesktopWnd = GetDesktopWindow();
        HDC hDesktopDC = GetDC(hDesktopWnd);
        HDC hCaptureDC = CreateCompatibleDC(hDesktopDC);
        HBITMAP hCaptureBitmap =CreateCompatibleBitmap(hDesktopDC,nScreenWidth, nScreenHeight);
        SelectObject(hCaptureDC,hCaptureBitmap); 
        BitBlt(hCaptureDC,0,0,nScreenWidth,nScreenHeight, hDesktopDC,0,0,SRCCOPY|CAPTUREBLT); 
        SaveCapturedBitmap(hCaptureBitmap); //Place holder - Put your code
                                    //here to save the captured image to disk
        ReleaseDC(hDesktopWnd,hDesktopDC);
        DeleteDC(hCaptureDC);
        DeleteObject(hCaptureBitmap);
    }
    
    int main(){
    CaptureScreen();
    	return 0;
    }
    What is the problem with this code?/
    Its not working as required.
  12. #7
  13. Lord of the Dance
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2003
    Posts
    3,733
    Rep Power
    1959
    You have to be more specific than "its not working".

    Looks like you didn't read the comment in the code.
    It tells you that you have to implement the function SaveCapturedBitmap yourself.

    What happens if you comment out that call?
  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2014
    Posts
    7
    Rep Power
    0
    Originally Posted by MrFujin
    You have to be more specific than "its not working".

    Looks like you didn't read the comment in the code.
    It tells you that you have to implement the function SaveCapturedBitmap yourself.

    What happens if you comment out that call?
    Now it only gives this error:
    " 19 C:\Users\Delluser\Usefull\screen shot code 4.cpp `CAPTUREBLT' undeclared (first use this function) "
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    187
    Rep Power
    83
    Originally Posted by incredibleX
    Now it only gives this error:
    " 19 C:\Users\Delluser\Usefull\screen shot code 4.cpp `CAPTUREBLT' undeclared (first use this function) "
    Try adding the following to your code....

    Code:
    #ifndef CAPTUREBLT
    #define CAPTUREBLT (DWORD)0x40000000 /* Include layered windows */
    #endif
  18. #10
  19. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2014
    Posts
    7
    Rep Power
    0
    Code:
    #include <Windows.h>
    #include <wingdi.h>
    #include <conio.h>
    #include <iostream>
    #include <stdio.h>
    #include <string.h>
    #include <malloc.h>
    #include <stdlib.h>
    #include <math.h>
    #ifndef CAPTUREBLT
    #define CAPTUREBLT (DWORD)0x40000000 /* Include layered windows */
    #endif
    #include <assert.h>
    
    void CaptureScreen()
    {
        int nScreenWidth = GetSystemMetrics(SM_CXSCREEN);
        int nScreenHeight = GetSystemMetrics(SM_CYSCREEN);
        HWND hDesktopWnd = GetDesktopWindow();
        HDC hDesktopDC = GetDC(hDesktopWnd);
        HDC hCaptureDC = CreateCompatibleDC(hDesktopDC);
        HBITMAP hCaptureBitmap =CreateCompatibleBitmap(hDesktopDC,nScreenWidth, nScreenHeight);
        SelectObject(hCaptureDC,hCaptureBitmap); 
        BitBlt(hCaptureDC,0,0,nScreenWidth,nScreenHeight, hDesktopDC,0,0,SRCCOPY|CAPTUREBLT); 
        //SaveCapturedBitmap(hCaptureBitmap); //Place holder - Put your code
                                    //here to save the captured image to disk
        ReleaseDC(hDesktopWnd,hDesktopDC);
        DeleteDC(hCaptureDC);
        DeleteObject(hCaptureBitmap);
    }
    
    int main(){
    CaptureScreen();
    	getch();
    	return 0;
    }
    Now this is the final code.
    It is giving the following error's now:

    [Linker error] undefined reference to `CreateCompatibleDC@4'
    [Linker error] undefined reference to CreateCompatibleBitmap@12'
    [Linker error] undefined reference to `SelectObject@8'
    [Linker error] undefined reference to `BitBlt@36'
    [Linker error] undefined reference to `DeleteObject@4'
    [Linker error] undefined reference to `DeleteDC@4'
    ld returned 1 exit status
  20. #11
  21. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    187
    Rep Power
    83
    Try linking your code with GDI32.LIB

IMN logo majestic logo threadwatch logo seochat tools logo