winapiwrapper
winapiwrapper

Reputation: 145

Generate a WM_NCHITTEST message

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

Upvotes: 4

Views: 3057

Answers (1)

Anders
Anders

Reputation: 101746

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

Upvotes: 2

Related Questions