8000 [Bug]: can't intercept WM_CLIPBOARDUPDATE windows messages on windows · Issue #31173 · electron/electron · GitHub 8000
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
[Bug]: can't intercept WM_CLIPBOARDUPDATE windows messages on windows #31173
Open
@pushkin-

Description

@pushkin-

Preflight Checklist

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);

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0