1. 程式人生 > >OnSetCursor由訊息 WM_SETCURSOR 觸發 The WM_SETCURSOR message is sent to a window if the mouse causes th

OnSetCursor由訊息 WM_SETCURSOR 觸發 The WM_SETCURSOR message is sent to a window if the mouse causes th

The WM_SETCURSOR message is sent to a window if the mouse causes the cursor to move within a window and mouse input is not captured.

看清楚了,只要滑鼠移動OnMouseMOve就會自動傳送 WM_SETCURSOR從而觸發OnSetCursor,因此在設計改變滑鼠指標的程式時,一般不要在OnMouseMOve事件中呼叫SetCursor,容易引起指標閃爍。設定滑鼠指標形狀合理的方法是:
在OnMouseMove中使用一個變數記住各矩形crect中的滑鼠形狀,然後在OnSetCursor呼叫SetCursor設定滑鼠

m_hCursor = LoadCursor(NULL,IDC_IBEAM);
SetCursor(m_hCursor);

………………

BOOL COpenGL_testView::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message) 
{
SetCursor(m_hCursor); 
return TRUE;
}

OK!問題解決。