How to avert screen flicker and flash when drawing a rect

As the title described, I’m confused about drawing a rect efficiently with winapi or other way , it seems to not fit to imgui,is there any native code of dear-imgui could replace the following code:

        HDC hdc = GetDC(hwnd);
		HPEN hpen=CreatePen(PS_SOLID, 3, 0x222222);
		SelectObject(hdc, hpen);
		Rectangle(hdc, 0, 0, 100, 100);
		ReleaseDC(hwnd, hdc);