註冊或取消註冊視窗,以接收通知以關閉其工具提示視窗。
語法
BOOL RegisterForTooltipDismissNotification(
HWND hWnd,
TOOLTIP_DISMISS_FLAGS tdFlags
);
參數
hWnd
類型: HWND
接收 WM_TOOLTIPDISMISS 訊息之視窗的句柄。
tdFlags
列舉值,指定函式註冊或取消註冊視窗。 要註冊TDF_REGISTER ; TDF_UNREGISTER 取消註冊。
傳回值
如果視窗已成功註冊或取消註冊,則為TRUE;否則為 FALSE。 (請參閱<備註>)。
備註
此函式可讓支援工具提示的應用程式和架構在系統需要關閉所有顯示工具提示時,透過 WM_TOOLTIPDISMISS 訊息註冊和取消註冊,讓工具提示更容易存取。
應用程式應該在每次顯示工具提示並隱藏工具提示以回應 WM_TOOLTIPDISMISS 訊息時註冊此通知。 當工具提示因為其他原因而隱藏時,例如滑鼠動作,應用程式應該取消註冊。
工具提示關閉的系統定義觸發程式包含單一 Ctrl 鍵向上或 Ctrl+Shift+F10。 (一組觸發程式可能會隨著時間而變更。)
函式會採用工具提示視窗的 HWND 或具有子工具提示之應用程式視窗 的 HWND 。
- 如果已註冊工具提示 HWND 本身,工具提示視窗應該會在顯示時註冊,並在收到 WM_TOOLTIPDISMISS 訊息時關閉。
- 如果應用程式 HWND 代表其工具提示註冊,應用程式視窗應該會在顯示工具提示時註冊,並在收到 WM_TOOLTIPDISMISS 訊息時關閉其所有工具提示。
工具提示或應用程式視窗預期會在每次顯示工具提示時呼叫函式來註冊。 註冊的視窗會在張貼 WM_TOOLTIPDISMISS時自動取消註冊。
當應用程式或架構預先 (關閉工具提示視窗時, TDF_UNREGISTER 旗標可用來明確取消註冊視窗,例如將游標移出「安全區域」) 。 如果應用程式或架構在窗口自動取消註冊之後,使用 TDF_UNREGISTER 呼叫RegisterForTooltipDismissNotification,則函式會傳回 FALSE。 未來註冊沒有任何影響。
傳回值
傳入函式的 HWND 必須由呼叫進程擁有;否則,函式會傳回 FALSE。
使用 TDF_REGISTER 和屬於呼叫進程的視窗呼叫時,如果視窗已成功註冊,則函式會傳回 TRUE ;如果視窗已註冊,則為 FALSE 。 視窗會以任一方式視為已註冊。
當使用 TDF_UNREGISTER 和屬於呼叫程式的視窗呼叫時,如果視窗成功取消註冊,則函式會傳回 TRUE ,如果目前尚未註冊視窗,則傳回 FALSE 。 視窗會被視為未註冊任一方式。
規格需求
| 需求 | 值 |
|---|---|
| 最低支援的用戶端 | Windows 11 組建 22621 |
| 目標平台 | Windows |
| 標頭 | winuser.h |
| 程式庫 | user32.lib |
另請參閱
範例
// WndProc: Window procedure for a window that is the parent of one or more
// tooltip windows.
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_TOOLTIPDISMISS:
// System is asking us to dismiss tooltip window due to system hotkey.
if (hwndVisibleTooltip)
{
// Hide the tooltip window. Not necessary to unregister as window is
// automatically unregistered upon notification.
ShowWindow(hwndVisibleTooltip, SW_HIDE);
hwndVisibleTooltip = nullptr;
}
break;
case WM_NOTIFY:
{
LPNMHDR toolInfo = (LPNMHDR) lParam;
switch (toolInfo->code)
{
case TTN_SHOW:
// Notification that a tooltip is about to show. Register this
// window to receive dismiss notification when the system wants
// to dismiss tooltips (such as in response to a system hotkey).
RegisterForTooltipDismissNotification(hWnd, TDF_REGISTER);
// Remember the visible tooltip window, so we know which one to
// hide when we receive WM_TOOLTIPTISMISS.
hwndVisibleTooltip = toolInfo->hwndFrom;
break;
case TTN_POP:
// Notification that a tooltip is about to hide
if (hwndVisibleTooltip)
{
// With the tooltip hiding, we will no longer need the system
// dismiss notification, so we can unregister from it.
RegisterForTooltipDismissNotification(hWnd, TDF_UNREGISTER);
hwndVisibleTooltip = nullptr;
}
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}