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 ?

有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top