Is there a way to make the resulting rectangle from the FillRect() function stay on the screen? I am calling this function but it only remains up on the screen for a fraction of a second before disappearing. The only way to keep it on the screen is to run this in a while (true) loop which seems very inefficient.
void DrawRect(int x, int y, int w, int h, HBRUSH brushColor)
{
RECT rect = { x, y, x w, y h };
FillRect(HDC_Desktop, &rect, brushColor);
}
I have to ask what makes the resulting box from this function disappear? I notice it still sometimes flashes even when ran inside a while (true) loop. Does it disappear when your monitor refreshes or is disappearing not inherent to this function? My goal is to make a rectangle that stays on the screen for a set amount of time. Whether that be me setting a time period for it to last or having to manually delete it but either way running a while (true) loop to continuously print a rectangle to my screen is terribly inefficient.
CodePudding user response:
You should not paint directly on the screen DC! This has not worked properly since Vista (DWM) and even before that it was not a great thing to do.
You should create a window with the WS_POPUP
style and draw there when you get the WM_PAINT
message (don't forget to call BeginPaint
/EndPaint
)...