Skip to content

Working with context menu #5129

Open
Open
@ajtruckle

Description

@ajtruckle

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.

Metadata

Metadata

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