Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #include <iostream>
- #include <Windows.h>
- #include <windef.h>
- #include <fstream>
- #include <time.h>
- #include <ole2.h>
- #include <olectl.h>
- using namespace std;
- void CreateTextFile(char Text[])
- {
- char myPath[_MAX_PATH + 1];
- GetModuleFileName(NULL, myPath, _MAX_PATH);
- char filename[] = "EXIT_FAILURE.txt";
- ofstream myfile;
- myfile.open("EXIT_FAILURE.txt", ofstream::out | ofstream::app);
- time_t now = time(0);
- tm* localtm = localtime(&now);
- myfile << "-" << asctime(localtm) << Text;
- myfile.close();
- myfile.clear();
- cout << "Creato file di debug all'indirizzo dell'exe...\n" << myPath << endl;
- return;
- }
- HWND FindLolClient(CONST LPCSTR handlename, CONST LPCSTR childname, HWND &RCLIENT)
- {
- HWND Leaguehwnd, Clienthwnd;
- int MessageBox_Value;
- CHAR TargetNameClass[50];
- do
- {
- Leaguehwnd = FindWindow(handlename, NULL);
- Clienthwnd = FindWindowEx(Leaguehwnd, NULL, childname, NULL);
- if (!Clienthwnd)
- {
- cout << "Finestra non trovata...\n";
- MessageBox_Value = MessageBox(NULL, "Impossibile trovare l'handle di League Of Legends...", "Errore", MB_RETRYCANCEL);
- if (MessageBox_Value == IDCANCEL)
- {
- cout << "EXIT_FAILURE\n";
- CreateTextFile("Impossibile trovare la finestra, errore funzione: FindLolClient...");
- return NULL;
- }
- }
- else
- {
- Clienthwnd = GetWindow(Clienthwnd, GW_CHILD);
- Clienthwnd = GetWindow(Clienthwnd, GW_CHILD);
- GetClassNameA(Clienthwnd, TargetNameClass, 49);
- cout << "Nome della classe trovata: " << TargetNameClass << endl;
- RCLIENT = Leaguehwnd;
- return Clienthwnd;
- }
- } while (true);
- }
- //BOOL CenterWindow(HWND hwnd, int &xPos, int &yPos, int &width, int &height, RECT &rc)
- //{
- // GetWindowRect(hwnd, &rc);
- //
- // width = GetSystemMetrics(SM_CXSCREEN);
- // height = GetSystemMetrics(SM_CYSCREEN);
- //
- // xPos = (width / 2) - ((rc.right-rc.left) / 2);
- // yPos = (height / 2) - ((rc.bottom - rc.top) / 2);
- //
- // SetWindowPos(hwnd, 0, xPos, yPos, 0, 0, SWP_NOZORDER | SWP_NOSIZE);
- //
- // cout <<"Finestra spostata alle coordinate:\nx = " << xPos << "\ny = " << yPos << endl;
- //
- // return TRUE;
- //
- //}
- //
- //BOOL IsWindowCentred(HWND hwnd, int x, int y, int width, int height, RECT rc)
- //{
- //
- // int xPos = (width / 2) - ((rc.right - rc.left) / 2);
- // int yPos = (height / 2) - ((rc.bottom - rc.top) / 2);
- //
- // if (xPos == x && yPos == y) return TRUE;
- // else
- // {
- // cout << "\nEXIT_FAILURE\n";
- // CreateTextFile("E' stato impossibile riposizionare la finestra di League Of Legends...");
- // return FALSE;
- // }
- //
- //}
- BOOL saveBitmap(LPCSTR filename, HBITMAP bmp, HPALETTE pal)
- {
- bool result = FALSE;
- PICTDESC pd;
- pd.cbSizeofstruct = sizeof(PICTDESC);
- pd.picType = PICTYPE_BITMAP;
- pd.bmp.hbitmap = bmp;
- pd.bmp.hpal = pal;
- LPPICTURE picture;
- HRESULT res = OleCreatePictureIndirect(&pd, IID_IPicture, false,
- reinterpret_cast<void**>(&picture));
- if (!SUCCEEDED(res))
- return FALSE;
- LPSTREAM stream;
- res = CreateStreamOnHGlobal(0, true, &stream);
- if (!SUCCEEDED(res))
- {
- picture->Release();
- return FALSE;
- }
- LONG bytes_streamed;
- res = picture->SaveAsFile(stream, true, &bytes_streamed);
- HANDLE file = CreateFile(filename, GENERIC_WRITE, FILE_SHARE_READ, 0,
- CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
- if (!SUCCEEDED(res) || !file)
- {
- stream->Release();
- picture->Release();
- return FALSE;
- }
- HGLOBAL mem = 0;
- GetHGlobalFromStream(stream, &mem);
- LPVOID data = GlobalLock(mem);
- DWORD bytes_written;
- result = !!WriteFile(file, data, bytes_streamed, &bytes_written, 0);
- result &= (bytes_written == static_cast<DWORD>(bytes_streamed));
- GlobalUnlock(mem);
- CloseHandle(file);
- stream->Release();
- picture->Release();
- return result;
- }
- BOOL ScreenShot(HWND hwnd,LPCSTR fname)
- {
- RECT rc;
- GetClientRect(hwnd, &rc);
- HDC hdcScreen = GetDC(NULL);
- HDC hdc = CreateCompatibleDC(hdcScreen);
- HBITMAP hbmp = CreateCompatibleBitmap(hdcScreen,
- rc.right - rc.left, rc.bottom - rc.top);
- SelectObject(hdc, hbmp);
- PrintWindow(hwnd, hdc, PW_CLIENTONLY);
- HPALETTE hpal = NULL;
- saveBitmap(fname, hbmp, hpal);
- if (saveBitmap(fname, hbmp, hpal)) return TRUE;
- else
- {
- cout << "EXIT_FAILURE\n";
- CreateTextFile("Impossibile eseguilo lo ScreenShot del client, errore funzione ScreenShot/SaveBitmap...");
- return FALSE;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement