長時間執行操作,顯示等待表徵圖.
如果程式中,需要進行長時間等待操作,可以顯示等待表徵圖,這樣可以給人更好的體驗.
在WIN32中,主要有SetCursor()函數來設定顯示的表徵圖.
在MSDN中對該函數的說明為:
HCURSOR SetCursor(
HCURSOR hCursor
);
hCursor
[in] Handle to the cursor. The cursor must have been created by the CreateCursor or loaded by the LoadCursor or LoadImage function. If this parameter is NULL, the cursor is removed from the screen.
The width and height of the cursor must be the values returned by the GetSystemMetrics function for SM_CXCURSOR and SM_CYCURSOR.
而裡面需要用到LoadCursor()函數,
HCURSOR LoadCursor(
HINSTANCE hInstance,
LPCTSTR lpCursorName
);
To use one of the Microsoft Win32 predefined cursors, the application must set the hInstance parameter to NULL and the lpCursorName parameter to a specific value. The following table shows the possible values. This parameter must be set to one of these values.
Value Description
IDC_APPSTARTING
Standard arrow and small hourglass.
IDC_ARROW
Standard arrow.
IDC_CROSS
Crosshair.
IDC_HAND
Hand.
IDC_HELP
Arrow and question mark.
IDC_ICON
Obsolete.
IDC_NO
Slashed circle.
IDC_SIZE
Obsolete; use IDC_SIZEALL.
IDC_SIZEALL
Four-pointed arrow pointing north, south, east, and west.
IDC_SIZENESW
Double-pointed arrow pointing northeast and southwest.
IDC_SIZENS
Double-pointed arrow pointing north and south.
IDC_SIZENWSE
Double-pointed arrow pointing northwest and southeast.
IDC_SIZEWE
Double-pointed arrow pointing west and east.
IDC_UPARROW
Vertical arrow.
IDC_WAIT
Hourglass.
因此要用顯示系統的等待表徵圖,可以為
SetCursor(LoadCursor(NULL, IDC_WAIT));
然後在結束的時候再把預設表徵圖切換回來.
SetCursor(LoadCursor(NULL, IDC_ARROW));