Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Working with context menu #5129

Open
ajtruckle opened this issue Feb 27, 2025 · 0 comments
Open

Working with context menu #5129

ajtruckle opened this issue Feb 27, 2025 · 0 comments

Comments

@ajtruckle
Copy link

I am confused.

Take this handler snippet:

// ===============================================================
// Refresh AJT 23.2.0 JIRA MSA 210
if (!m_itemRefresh || bFullInit)
{
	m_itemRefresh.reset();
	wil::com_ptr<IStream> iconStream;
	CHECK_FAILURE(SHCreateStreamOnFileEx(
		theApp.GetCommonAppDataFolder() + L"WebView2\\refresh" + strIconSuffix, STGM_READ, FILE_ATTRIBUTE_NORMAL, FALSE,
		nullptr, &iconStream));

	CString strMenuText;
	strMenuText.LoadString(IDS_STR_MENU_REFRESH);
	CHECK_FAILURE(webviewEnvironment->CreateContextMenuItem(
		strMenuText, iconStream.get(),
		COREWEBVIEW2_CONTEXT_MENU_ITEM_KIND_COMMAND, &m_itemRefresh));

	CHECK_FAILURE(m_itemRefresh->add_CustomItemSelected(
		Callback<ICoreWebView2CustomItemSelectedEventHandler>(
			[appWindow = this, target](ICoreWebView2ContextMenuItem* sender, IUnknown* args)
			{
				appWindow->GetParentWindow()->SendMessage(WM_COMMAND, ID_VIEW_REFRESH, NULL);

				return S_OK;
			})
		.Get(), nullptr));
}
CHECK_FAILURE(items->InsertValueAtIndex(0, m_itemRefresh.get()));
// ===============================================================

Now, if my context is:

CDialog > WebView2 > Right-click > Refresh

Works. GetParentWindow() is the pointer to CDialog.

Now, if my context is:

CDialog > TabCtrl > WebView2 Child Container > WebView2 > Right-click > Refresh

It doesn't work. I realised this was because GetParentWindow() is going to be WebView2 Child Container. So I tried two things:

1/ GetParentWindow()->GetParent()>GetParent()->PostMessage ...
The main dialog code is intercepted. But the moment the AfxMessageBox call happens in main dialog the app appears to freeze. I can see no popup. The app feels it is running this but I can't respond to the popup message box.

2/ When my WV2 is created, and before setting up the handlers, I pass it my WebView2 Child Container pointer. Then in the event handler it uses that pointer. Then, in WebView2 Child container I catch that, and post (or send) up the chain to CDialog. The result is the same, the moment a AfxMessageBox is encounter, app is freezing.

I have spent all afternoon and evening trying to get around this. The basic scenario is fine.

My latter scenario is a dialog, which has a TabCtrl, which has 3 tabs, each with a WebView2 Child Container, housing a WebView2.

I appreciate help. Thanks.

Win32.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant