MicrosoftEdge / MicrosoftEdge/WebView2Feedback
Draggable regions doesn't work with VSTO
Nobody has claimed this yet.
- Dominant language
- PowerShell
- Stars
- 526
- Forks
- 67
- PR merge metrics
- No merged PRs in 30d
Description
Description
I am using WebView2 with WinForms to make VSTO PowerPoint Addin.
I implemented draggable regions (Issue #200),
and it works in the WinForms project,
but it doesn't work with PowerPoint.
I found SendMessage takes a long time so that users cannot drag the window.
Version
SDK: 1.0.774.44
Runtime: 89.0.774.63
Framework: WinForms
OS: Win 10 Home (1909)
Reproducing Codes
using System;
using System.Windows.Forms;
using System.IO;
using Microsoft.Web.WebView2.WinForms;
using Microsoft.Web.WebView2.Core;
using System.Runtime.InteropServices;
namespace WebViewMouseEventTest
{
public partial class ThisAddIn
{
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
new Form1().Show();
}
private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
}
private void InternalStartup()
{
this.Startup += new System.EventHandler(ThisAddIn_Startup);
this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
}
}
public class Form1 : Form
{
public const int WM_NCLBUTTONDOWN = 0xA1;
public const int HT_CAPTION = 0x2;
[DllImportAttribute("user32.dll")]
public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
[DllImportAttribute("user32.dll")]
public static extern int PostMessageA(IntPtr hWnd, int Msg, int wParam, int lParam);
[DllImportAttribute("user32.dll")]
public static extern bool ReleaseCapture();
public delegate void F();
private WebView2 webview2;
public Form1()
{
InitializeComponent();
}
private void InitializeComponent()
{
this.MouseDown += Form1_MouseDown;
webview2 = new WebView2();
Controls.Add(webview2);
webview2.Top = 50;
webview2.Width = 100;
webview2.Height = 100;
var env = CoreWebView2Environment.CreateAsync(null, Path.Combine(Path.GetTempPath(), "webview2")).Result;
webview2.EnsureCoreWebView2Async(env)
.ContinueWith((t) => this.Invoke(new F(_InitializeAsync)));
webview2.Source = new Uri(Path.GetFullPath(@"index.html"));
}
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
ReleaseCapture();
SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
}
private void _InitializeAsync()
{
this.webview2.CoreWebView2.WebMessageReceived += CoreWebView2_WebMessageReceived;
}
private void CoreWebView2_WebMessageReceived(object sender, CoreWebView2WebMessageReceivedEventArgs e)
{
ReleaseCapture();
SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
}
}
}
<!DOCTYPE html>
<html style="height: 100%; margin: 0; padding: 0;" lang="en" xmlns="http://www.w3.org/1999/xhtml">
<body style="background-color: yellow; height: 100%; margin: 0; padding: 0;">
WebView
<script>
window.addEventListener('DOMContentLoaded', () => {
console.log('DOMContentLoaded');
document.body.addEventListener('mousedown', evt => {
console.log('mousedown');
chrome.webview.postMessage('mousedown');
evt.preventDefault();
evt.stopPropagation();
});
})
</script>
</body>
</html>
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the provided WinForms reproduction, especially CoreWebView2_WebMessageReceived, which calls ReleaseCapture and SendMessage after a WebView2 message. Compare the behavior in a regular WinForms project with the reported VSTO PowerPoint add-in case. Done means identifying why the draggable region fails in that environment and establishing whether it can work reliably; the issue names no test or project file.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- html, javascript
- Domain
- desktop
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100