Skip to content

Why do I still get a flash? #5388

@ajtruckle

Description

@ajtruckle

Please wait a few seconds as i start my app. Then you will see the flash:

20251006-1128-13.2176151.mp4

The app is running in dark mode and the browser is set as such:

m_pWebBrowser->SetPreferredColorScheme(IsUsingDarkMode()
	? COREWEBVIEW2_PREFERRED_COLOR_SCHEME_DARK
	: COREWEBVIEW2_PREFERRED_COLOR_SCHEME_LIGHT
);

Delving into my CWebBrowser wrapper I have:

BOOL CWebBrowser::CreateHostWindow(
	LPCTSTR lpszClassName,
	LPCTSTR lpszWindowName,
	DWORD dwStyle,
	const RECT& rect,
	CWnd* pParentWnd,
	UINT nID)
{
	if (lpszClassName == nullptr)
		lpszClassName = GetWindowClass();

	if (!CWnd::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID))
		return FALSE;

	::SetWindowLongPtr(m_hWnd, GWLP_USERDATA, (LONG_PTR)this);

	m_pParentWnd = pParentWnd;

	return TRUE;
}

That function calls GetWindowClass, which is defied like this:

PCTSTR CWebBrowser::GetWindowClass()
{
	static PCTSTR windowClass = []
	{
		static TCHAR const* className = L"EdgeBrowserHost";

		WNDCLASSEX wcex;
		wcex.cbSize = sizeof(WNDCLASSEX);

		wcex.style = CS_HREDRAW | CS_VREDRAW;
		wcex.lpfnWndProc = WndProcStatic;
		wcex.cbClsExtra = 0;
		wcex.cbWndExtra = 0;
		wcex.hInstance = AfxGetInstanceHandle();
		wcex.hIcon = nullptr;
		wcex.hCursor = LoadCursor(nullptr, IDC_ARROW);

		if (DarkModeTools::InvokeUseDarkModeFunction())
		{
			static auto hbr = CreateSolidBrush(DarkModeTools::kDarkBackgroundColor);
			wcex.hbrBackground = hbr;
		}
		else
			wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);

		wcex.lpszMenuName = nullptr;
		wcex.lpszClassName = className;
		wcex.hIconSm = nullptr;

		ATOM result = RegisterClassEx(&wcex);
		if (result == 0)
		{
			[[maybe_unused]] DWORD lastError = ::GetLastError();
		}

		return className;
	}();

	return windowClass;
}

As you can see, I take steps to set the ``hbrBackground` correctly.

But I still get that initial flash when app starts.

Using latest stable WebnView2 and Windows 11, Win32:

Runtime: 140.0.3485.94
SDK: 3485.44
OS Build: 10.0.26100 (24H2)

I should point out that I am displaying a XML file, which is transformed using a XSLT1 script.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions