關於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回調函數實現的。
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:

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.

通知應用程序在會話狀態下的變化。






免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM