关于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的解释:
sent when the size and position of a window's client area must be calculated. by processing this message, an application can control the content of the window's client area when the size or position of the window changes.
当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回调函数实现的。
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);
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.
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:
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.
通知应用程序在会话状态下的变化。
上一篇: 【模板】 线段树