4

I am trying to allow the user to move/resize a CEF borderless window (created with the WS_POPUP flag).

The mouse position is caught in the CEF browser (using Javascript) and a C++ callback is called. Then, I send a message from the C++ callback to the CEF browser process via IPC (the message can contain HTRIGHT for example). The last step is moving or resizing the browser. I would like to generate WM_NCHITTEST messages in order to allow window moving/resizing.

I tried to do it that way:

PostMessage(getBrowserHwnd(), WM_NCHITTEST, 0, MAKELPARAM(cursorPos.x, cursorPos.y));

But of course, it does not work.

So my question is: Is there a way to generate WM_NCHITTEST messages? CEF does not let me access the client area of my window, therefore my window procedure doesn't receive any mouse events.

Any help would be greatly appreciated.

winapiwrapper

winapiwrapper
  • 125
  • 1
  • 12

1 Answers1

2

You are generating a WM_NCHITTEST but a hit-test does not start any actions because hit-testing can happen for reasons other than the mouse being over your window.

I believe the documented way to start a move/size operation is to use WM_SYSCOMMAND but I'm guessing this is not what you are after because this is the same as the action from the system menu where you have to choose the side before moving/sizing.

If you can handle messages then you can return HTCLIENT in response to WM_NCHITTEST or as a hack you can do this:

PostMessage(getBrowserHwnd(), WM_NCLBUTTONDOWN, HTCAPTION, MAKELPARAM(cursorPos.x, cursorPos.y)); // cursorPos should be screen coordinates
Anders
  • 97,548
  • 12
  • 110
  • 164
  • Thank you for the quick reply! Unfortunately, that doesn't work. The CEF renderer process creates its own child window and overlaps the client area of my window. Do you know if there's a way to access another window's procedure? Maybe using a hook? – winapiwrapper Feb 28 '18 at 00:35
  • 1
    The WM_NCLBUTTONDOWN hack should work as long as it is posted to the correct top-level window. I don't know anything about CEF so I can't really help you there. – Anders Feb 28 '18 at 00:49
  • Thank you anyway! This hack will certainly be useful for other purposes, I will remember it. – winapiwrapper Feb 28 '18 at 00:57