Рисование оверлеев с помощью gdiplus - PullRequest
0 голосов
/ 27 апреля 2020

Сейчас я пытаюсь нарисовать оверлеи в gdiplus, однако, когда я запускаю свою программу, она может найти наше окно, но она не будет рисовать мою линию наложения. Я что-то пропустил? Документация предполагает, что я должен быть в состоянии сделать это.

#include <windows.h>
#include <objidl.h>
#include <gdiplus.h>
#include <iostream>

using namespace Gdiplus;
#pragma comment (lib,"Gdiplus.lib")




VOID OnPaint(HDC hdc)
{
    Graphics graphics(hdc);
    Pen pen(Color(255, 0, 0, 0), 5);
    graphics.DrawLine(&pen, 0, 0, 200, 100);
}
ULONG_PTR gdiplusToken;

int main() {

    //Untitled - Notepad
    HWND hWnd = FindWindow(NULL, TEXT("*Untitled - Notepad"));
    // In top of main
    GdiplusStartupInput gdiplusStartupInput;
    GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
    if (hWnd == 0) {
        std::cout << "[-] - Unable to locate window!\n";
        return 0;
    }
    std::cout << "[+] - Located Window, starting hook.\n";
    HDC hdc = GetDC(FindWindowA(NULL, "*Untitled - Notepad"));
    PAINTSTRUCT ps;
    hdc = BeginPaint(hWnd, &ps);
    if (hdc == ERROR) {
        std::cout << "[-] - An error occured\n";
        return 0;
    }
    OnPaint(hdc);
    Sleep(3000);
    EndPaint(hWnd, &ps);
    std::cout << "Finished Drawing\n";

}

1 Ответ

0 голосов
/ 27 апреля 2020

Вы пропускаете вызов GdiplusStartup .

Кроме того, уберите вызов BeginPaint и EndPaint. Это просто сотрет окно, чтобы вы не увидели, что нарисовали.

Вот что работает:

#include <windows.h>
#include <objidl.h>
#include <gdiplus.h>
#include <iostream>

using namespace Gdiplus;
#pragma comment (lib,"Gdiplus.lib")
VOID OnPaint(HDC hdc)
{
    Graphics graphics(hdc);
    Pen pen(Color(255, 0, 0, 0), 5);
    graphics.DrawLine(&pen, 0, 0, 200, 100);
}

int main() {


    // GDI+ startup incantation
    GdiplusStartupInput gdiplusStartupInput;
    ULONG_PTR gdiplusToken;
    GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);

    //Untitled - Notepad
    HWND hWnd = FindWindow(NULL, TEXT("Untitled - Notepad"));
    if (hWnd == 0) {
        std::cout << "[-] - Unable to locate window!\n";
        return 0;
    }
    std::cout << "[+] - Located Window, starting hook.\n";
    HDC hdc;
    hdc = GetDC(hWnd);
    std::cout << hdc;
    OnPaint(hdc);
    std::cout << "Finished Drawing\n";

}

Доказательство:

enter image description here

...