Docs / C++ Projects/External Overlay

External Overlay

C++ ProjectsC++GDI+On-Screen Drawing

Overview

An overlay creator which allows users to draw different shapes as needed onto the overlay screen.

Key Systems & Features

  • Easy to use drawing calls
  • Simple top-most overlay, which don't get in the way of mouse clicks or function calls

Code Examples

Below are some code snippets from this project.

Overlay creator
CPP
void Overlay::CreateOverlay(int nCmdShow) {
    WNDCLASSW wc = { 0 };
    wc.lpfnWndProc = WndProc;
    wc.hInstance = GetModuleHandle(NULL);
    wc.hbrBackground = (HBRUSH)(COLOR_BACKGROUND);
    wc.lpszClassName = L"OverlayClass";
    
    RegisterClassW(&wc);

    hwnd = CreateWindowEx(
        WS_EX_COMPOSITED | WS_EX_LAYERED | WS_EX_TOPMOST | WS_EX_TRANSPARENT, //WS_EX_NOACTIVATE = not in taskbar
        L"OverlayClass",
        L"Overlay Window",
        WS_POPUP, //for no program border
        0, 0, screenWidth, screenHeight,
        NULL,  
        NULL,
        wc.hInstance,
        NULL
    );

    HRGN GGG = CreateRectRgn(0, 0, screenWidth, screenHeight);
    InvertRgn(GetDC(hwnd), GGG);
    SetWindowRgn(hwnd, GGG, false);

    COLORREF RRR = RGB(0, 0, 0);
    SetLayeredWindowAttributes(hwnd, RRR, (BYTE)0, LWA_COLORKEY);

    Gdiplus::GdiplusStartupInput gdiplusStartupInput;
    Gdiplus::GdiplusStartup(&gdiToken, &gdiplusStartupInput, NULL);


    ShowWindow(hwnd, nCmdShow);
    UpdateWindow(hwnd);


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

}
Draw Line
CPP
void Drawing::DrawLine(HDC hdc, int x1, int y1, int x2, int y2, Gdiplus::Color color, int lineSize)
{
	Gdiplus::Graphics graphics(hdc);
	Gdiplus::Pen pen(color, lineSize);

	Gdiplus::Point p1(x1, y1);
	Gdiplus::Point p2(x2, y2);

	graphics.DrawLine(&pen, p1, p2);

	graphics.~Graphics();
}

Links