Open
Description
Preflight Checklist
- I have read the Contributing Guidelines for this project.
- I agree to follow the Code of Conduct that this project adheres to.
- I have searched the issue tracker for a feature request that matches the one I want to file, without success.
Electron Version
15.0.0, 11.4
What operating system are you using?
Windows
Operating System Version
Windows 10
What arch are you using?
x64
Last Known Working Electron version
No response
Expected Behavior
I expect to be able to use the hookWindowMessage
API to intercept the WM_CLIPBOARDUPDATE
Windows message.
Actual Behavior
The handler never fires.
Testcase Gist URL
https://gist.github.com/8ebf946a7f62d48d00a14ba3f45cc539
Additional Information
This might be a dupe of this, or maybe I'm misunderstanding what the hookWindowMessage
API does.
main.js:
const {app, BrowserWindow} = require('electron')
async function createWindow() {
const mainWindow = new BrowserWindow();
await mainWindow.loadFile('index.html')
mainWindow.webContents.on("did-create-window", (window, details) => {
const handle = Array.from(window.getNativeWindowHandle());
// await sending handle to .NET process to register the window with the clipboard thing as per the Remarks section in the docs below
const CLIP = 0x031D; // https://docs.microsoft.com/en-us/windows/win32/dataxchg/wm-clipboardupdate
window.hookWindowMessage(CLIP, (wp, lp) =>
{
console.log(wp);
});
});
}
app.whenReady().then(() => {
createWindow()
app.on('activate', function () {
if (BrowserWindow.getAllWindows().length === 0) createWindow()
})
})
app.on('window-all-closed', function () {
if (process.platform !== 'darwin') app.quit()
})
index.html:
<button >Open Window</button>
My .NET process which receives the window handle does:
using System.Runtime.InteropServices;
public static void RegisterWindowWithClipboard(byte[] hwndBuffer) {
if (!BitConverter.IsLittleEndian) {
Array.Reverse(hwndBuffer);
}
IntPtr winHandle;
if (hwndBuffer.Length == 4) winHandle = (IntPtr)BitConverter.ToUInt32(hwndBuffer, 0);
else winHandle = (IntPtr)BitConverter.ToUInt64(hwndBuffer, 0);
AddClipboardFormatListener(winHandle);
}
[DllImport("user32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool AddClipboardFormatListener(IntPtr hwnd);