Question

I am attempting to paint over an existing window. Ultimately I would like to draw a border around the window. But for now I am simply attempting to paint over a window. This is what I am doing

static PAINTSTRUCT ps;
static HDC hDC;

RECT rect;
rect.left = 0; 
rect.right = 100; 
rect.top = 0; 
rect.bottom = 100;

HBRUSH hBrush = CreateSolidBrush(RGB(50,100,255));
HWND hWnd = FindWindow("Notepad++", 0);
hDC = BeginPaint(hWnd, &ps);

    FillRect(hDC, &rect, hBrush);

EndPaint(hWnd, &ps);

Unfortunately this does nothing to the notepad window. Am i missing something here ? Any suggestions ?

Was it helpful?

Solution

BeginPaint and EndPaint are only appropriate when handling the WM_PAINT message. They give you an HDC that is clipped to the invalid area.

If you are painting outside of that use GetDC() to get an HDC to use.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top