nativeEvent介绍和使用

nativeEvent(const QByteArray &eventType, void *message, long *result)
{
chASSERT(message != NULL);
MSG* winMsg = static_cast<MSG *>(message);
HWND hWnd = winMsg->hwnd;
switch (winMsg->message)
}

nativeEvent获取windows的事件处理,暂时用到的几个消息:

1、WM_NCCALCSIZE message

   MicroSoft的Docs的解释:
   
  当windows程序的客户端区域的位置和大小发生变化时,会发出这个消息。
  通过这个程序,当它的位置和大小发生变化时,一个应用程序可以控制windows客户端区域。

2、WM_NCPAINT message :

The WM_NCPAINT message is sent to a window when its frame must be painted.A window receives this message through its WindowProc function.

LRESULT CALLBACK WindowProc(
  HWND hwnd, 
  UINT  uMsg, 
  WPARAM wParam, 
  LPARAM lParam     
);

当窗口的边框需求重新绘制的时候,会给窗口发送这个消息。
这个消息的发出,是系统通过调用窗口的 windowproc回调函数实现的。

  • hwnd是当前窗口的句柄。
  • uMsg是系统发过来的消息。
  • wParam是消息参数。
  • lParam是消息参数。

如果系统调用windowproc函数未处理,就直接 调用系统默认的 defWIndowproc,关于这个函数的详细解释,有个博客写的不错,推荐看下:

URL:https://www.cnblogs.com/kingln/archive/2008/09/09/1287563.html

3、WM_NCACTIVATE message:

Sent to a window when its nonclient area needs to be changed to indicate an active or inactive state.

A window receives this message through its WindowProc function.

当窗口的非客户端区域发生变化时,这个消息将被发送到窗口,来指示当前是活跃还是非活跃状态,这个消息也是通过,windowproc回调实现的。

注意:窗口激活时和反激活时会触发系统重绘非客户区以反应窗口状态更改,所以需要在将lparam 传入-1阻止系统重绘窗体边框。

解释如下:

Remarks
Processing messages related to the nonclient area of a standard window is not recommended, because the application must be able to draw all the required parts of the nonclient area for the window. If an application does process this message, it must return TRUE to direct the system to complete the change of active window. If the window is minimized when this message is received, the application should pass the message to the DefWindowProc function.

举例:

case WM_NCACTIVATE:
auto res = DefWindowProc(winMsg->hwnd, winMsg->message, winMsg->wParam, -1);

4、WM_SIZING message

Sent to a window that the user is resizing. By processing this message, an application can monitor the size and position of the drag rectangle and, if needed, change its size or position.

A window receives this message through its WindowProc function.

当用户改变了窗口的大小,发送给窗口,通过这个消息,一个应用程序可以监控它的大小和拖动矩形的位置,如果需要,修改他的大小和位置。

5、WM_NCHITTEST message

Sent to a window in order to determine what part of the window corresponds to a particular screen coordinate. This can happen, for example, when the cursor moves, when a mouse button is pressed or released, or in response to a call to a function such as WindowFromPoint. If the mouse is not captured, the message is sent to the window beneath the cursor. Otherwise, the message is sent to the window that has captured the mouse.

A window receives this message through its WindowProc function.

发送到窗口,用来确定,窗口的某一个位置面对应屏幕的某一个坐标。这个发生的时候,例如,当鼠标移动,或者当鼠标的按键点击或松开。或者是对一个函数的调用,比如window frompoint。如果鼠标没有被捕获,消息就会被发送到光标下面的窗口。否则,消息被发送到捕获鼠标的窗口。

注意:不要使用LOWORD或HIWORD宏来提取光标位置的x和y坐标,因为这些宏在具有多个监视器的系统上返回不正确的结果。有多个显示器的系统可以有负x和y坐标,

Remarks
Use the following code to obtain the horizontal and vertical position:

Copy
xPos = GET_X_LPARAM(lParam);
yPos = GET_Y_LPARAM(lParam);
As noted above, the x-coordinate is in the low-order short of the return value; the y-coordinate is in the high-order short (both represent signed values because they can take negative values on systems with multiple monitors). If the return value is assigned to a variable, you can use the MAKEPOINTS macro to obtain a POINTS structure from the return value. You can also use the GET_X_LPARAM or GET_Y_LPARAMmacro to extract the x- or y-coordinate.

[!Important]
Do not use the LOWORD or HIWORD macros to extract the x- and y- coordinates of the cursor position because these macros return incorrect results on systems with multiple monitors. Systems with multiple monitors can have negative x- and y- coordinates, and LOWORD and HIWORD treat the coordinates as unsigned quantities.

顺便说下:WindowFromPoint function

Retrieves a handle to the window that contains the specified point.

HWND WINAPI WindowFromPoint(
In POINT Point
);
这个函数,获取包含指定点的窗口的句柄。

6、WM_TIMECHANGE message

时间变化

7、WM_WTSSESSION_CHANGE message

Notifies applications of changes in session state.

通知应用程序在会话状态下的变化。

发布了85 篇原创文章 · 获赞 46 · 访问量 4万+
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 技术工厂 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览