Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


What API's do I need?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
manc
Grandmaster Cheater
Reputation: 1

Joined: 16 Jun 2006
Posts: 551

PostPosted: Mon Jul 13, 2009 7:18 pm    Post subject: What API's do I need? Reply with quote

Ok, say i wanted to make a program that has 2 hotkeys.

Numpad 8 will take a screen shot and save it to desktop.
Numpad 9 will take a screenshot and open it in paint.


Which Api's would I need and what would the basic concept be to accomplish this?

( I dont need help with setting hotkeys or making the GUI, just with the parts pertaining to the screenshots and saving to desktop)

Thanks for any help.

_________________
Back to top
View user's profile Send private message
HomerSexual
Grandmaster Cheater Supreme
Reputation: 5

Joined: 03 Feb 2007
Posts: 1657

PostPosted: Mon Jul 13, 2009 8:00 pm    Post subject: Reply with quote

in c++?

This is my code for a program that will save the pictures like (bitmap0, bitmap1, bitmap2 etc)

saving a bitmap is pretty complex so i just found some code and modified it to my needs .

Code:
//Steve aka blankrider
#include <windows.h>
#include <stdio.h>

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

static char sClassName[] = "MyClass";
static HINSTANCE zhInstance = NULL;
HWND HwndHideShow;
HFONT hf;
int i;
HBITMAP hBitmap;

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,
    int nCmdShow) {
            WNDCLASSEX WndClass;
       HWND hwnd;
       MSG Msg;


       zhInstance = hInstance;

       WndClass.cbSize        = sizeof(WNDCLASSEX);
       WndClass.style         = NULL;
       WndClass.lpfnWndProc   = WndProc;
       WndClass.cbClsExtra    = 0;
       WndClass.cbWndExtra    = 0;
       WndClass.hInstance     = zhInstance;
       WndClass.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
       WndClass.hCursor       = LoadCursor(NULL, IDC_ARROW);
       WndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW);
       WndClass.lpszMenuName  = NULL;
       WndClass.lpszClassName = sClassName;
       WndClass.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);

       if(!RegisterClassEx(&WndClass)) {
               MessageBox(0, "Error Registering Class!", "Error!", MB_ICONSTOP | MB_OK);
               return 0;
       }

       hwnd = CreateWindowEx(WS_EX_STATICEDGE, sClassName, "Printscreen", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT,

CW_USEDEFAULT,
                             500, 250, NULL, NULL, zhInstance, NULL);

       if(hwnd == NULL) {
               MessageBox(0, "Error Creating Window!", "Error!", MB_ICONSTOP | MB_OK);
               return 0;
       }
       ShowWindow(hwnd, nCmdShow);
       UpdateWindow(hwnd);





       while(GetMessage(&Msg, NULL, 0, 0)) {
               TranslateMessage(&Msg);
               DispatchMessage(&Msg);
       }

       return Msg.wParam;



}

void find(){
WIN32_FIND_DATA FindFileData;
HANDLE hFind = INVALID_HANDLE_VALUE;
i = 0;
hFind = FindFirstFile("bitmap*.bmp", &FindFileData);
   if(hFind == INVALID_HANDLE_VALUE)
     i = 0;
    else{
        i++;
    }
while(FindNextFile(hFind, &FindFileData) != 0)
   i++;
FindClose(hFind);
}

//found this somewhere and modified it somewhat, but mostly from codeproject (i think)
bool SaveBitmap(HDC hDC,HBITMAP hBitmap, char* szPath)
{
    FILE* fp = NULL;
    fp = fopen(szPath ,"wb");
    if(fp == NULL)
        return false;

    BITMAP Bm;
    BITMAPINFO BitInfo;
    ZeroMemory(&BitInfo, sizeof(BITMAPINFO));
    BitInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
    BitInfo.bmiHeader.biBitCount = 0;

    if(!GetDIBits(hDC, hBitmap, 0, 0, NULL, &BitInfo, DIB_RGB_COLORS))
        return (false);

    Bm.bmHeight = BitInfo.bmiHeader.biHeight;
    Bm.bmWidth  = BitInfo.bmiHeader.biWidth;

    BITMAPFILEHEADER    BmHdr;

    BmHdr.bfType        = 0x4d42;   // 'BM' WINDOWS_BITMAP_SIGNATURE
    BmHdr.bfSize        = (((3 * Bm.bmWidth + 3) & ~3) * Bm.bmHeight)
                          + sizeof(BITMAPFILEHEADER)
                          + sizeof(BITMAPINFOHEADER);
    BmHdr.bfReserved1    = BmHdr.bfReserved2 = 0;
    BmHdr.bfOffBits      = (DWORD) sizeof(BITMAPFILEHEADER)
                          + sizeof(BITMAPINFOHEADER);

    BitInfo.bmiHeader.biCompression = 0;
    // Writing Bitmap File Header ////
    fwrite(&BmHdr,sizeof(BITMAPFILEHEADER),1,fp);

    fwrite(&BitInfo.bmiHeader,sizeof(BITMAPINFOHEADER),1,fp);

    BYTE *pData = new BYTE[BitInfo.bmiHeader.biSizeImage + 5];
    if(!GetDIBits(hDC, hBitmap, 0, Bm.bmHeight,
                 pData, &BitInfo, DIB_RGB_COLORS))
                         return (false);
    if(pData != NULL)
        fwrite(pData,1,BitInfo.bmiHeader.biSizeImage,fp);

    fclose(fp);
    delete (pData);

    return (true);
}

void CreateBit (int xStart, int yStart, int xFinish, int yFinish, HBITMAP hBitmap)
{
    BITMAP bm;
    HDC hdcScreen, hdcCompatible;
    POINT pt;
    char buffer2[33];

       hdcScreen = CreateDC("DISPLAY", NULL, NULL, NULL);
        hdcCompatible = CreateCompatibleDC(hdcScreen);
        hBitmap = CreateCompatibleBitmap(hdcScreen,
                     GetDeviceCaps(hdcScreen, HORZRES),
                     GetDeviceCaps(hdcScreen, VERTRES));
        if (hBitmap == 0)
            MessageBox(0, "Error, hBitmap", "Error!", MB_ICONSTOP | MB_OK);

                if (!SelectObject(hdcCompatible, hBitmap))
            MessageBox(0, "Error, Select Object", "Error!", MB_ICONSTOP | MB_OK);
            GetObject (hBitmap, sizeof(BITMAP), &bm);


              if (!BitBlt(hdcCompatible,
               0,0,
               bm.bmWidth, bm.bmHeight,
               hdcScreen,
               0,0,
               SRCCOPY))
               MessageBox(0, "Error, BitBlt1", "Error!", MB_ICONSTOP | MB_OK);
               wsprintf(buffer2, "%s%i%s", "bitmap", i , ".bmp");
                if(!SaveBitmap(hdcCompatible, hBitmap, buffer2))
            MessageBox(0, "Error Creating bmp!", "Error!", MB_ICONSTOP | MB_OK);
            i++;


    DeleteDC(hdcScreen);
    DeleteDC(hdcCompatible);
    DeleteObject(hBitmap);
}


LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) {
 
        switch(Message) {
    case WM_CREATE:

        find();

        if (!RegisterHotKey(hwnd, 1, MOD_CONTROL, VK_F12))
        MessageBox(0, "Error RegisterHotkey", "Error", MB_OK);
    break;
    case WM_HOTKEY:
        if(wParam == 1)
                    CreateBit (0, 0, 500, 400, hBitmap);
        break;
    case WM_CLOSE:
        if(!UnregisterHotKey(hwnd, 1))
        MessageBox(0, "Error UnRegisterHotkey", "Error", MB_OK);
        DeleteObject(hBitmap);
        DestroyWindow(hwnd);
    break;

    case WM_DESTROY:

        PostQuitMessage(0);
    break;

    default:
        return DefWindowProc(hwnd, Message, wParam, lParam);
       }
       return 0;
}

_________________
Back to top
View user's profile Send private message
manc
Grandmaster Cheater
Reputation: 1

Joined: 16 Jun 2006
Posts: 551

PostPosted: Mon Jul 13, 2009 8:32 pm    Post subject: Reply with quote

Goddam, didn't expect it to be that difficult.

And yes, c++. Thanks for the example

_________________
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites