harmony 鸿蒙oh_window.h
oh_window.h
Overview
The oh_window.h file declares the window management APIs. You can use the APIs to set and obtain the properties of a window, and set its status bar style and navigation bar style.
File to include:
Library: libnative_window_manager.so
System capability: SystemCapability.Window.SessionManager
Since: 15
Related module: WindowManager
Summary
Functions
|Name|Description| |–|–| |int32_t OH_WindowManager_SetWindowStatusBarEnabled(int32_t windowId, bool enabled, bool enableAnimation)|Sets whether to display the status bar in a window.| |int32_t OH_WindowManager_SetWindowStatusBarColor(int32_t windowId, int32_t color)|Sets the color of the status bar in a window.| |int32_t OH_WindowManager_SetWindowNavigationBarEnabled(int32_t windowId, bool enabled, bool enableAnimation)|Sets whether to display the navigation bar in a window.| |int32_t OH_WindowManager_GetWindowAvoidArea(int32_t windowId, WindowManager_AvoidAreaType type, WindowManager_AvoidArea* avoidArea)|Obtains the avoid area of a window.| |WindowManager_ErrorCode OH_WindowManager_IsWindowShown(int32_t windowId, bool* isShow)|Checks whether a window is displayed.| |WindowManager_ErrorCode OH_WindowManager_ShowWindow(int32_t windowId)|Shows a window.| |int32_t OH_WindowManager_SetWindowTouchable(int32_t windowId, bool isTouchable)|Sets whether a window is touchable.| |int32_t OH_WindowManager_SetWindowFocusable(int32_t windowId, bool isFocusable)|Sets whether a window is focusable.| |int32_t OH_WindowManager_SetWindowBackgroundColor(int32_t windowId, const char* color)|Sets the background color of a window.| |int32_t OH_WindowManager_SetWindowBrightness(int32_t windowId, float brightness)|Sets the screen brightness of a window.| |int32_t OH_WindowManager_SetWindowKeepScreenOn(int32_t windowId, bool isKeepScreenOn)|Sets whether to always keep the screen on for a window.| |int32_t OH_WindowManager_SetWindowPrivacyMode(int32_t windowId, bool isPrivacy)|Sets whether to enable privacy mode for a window.| |int32_t OH_WindowManager_GetWindowProperties(int32_t windowId, WindowManager_WindowProperties* windowProperties)|Obtains the properties of a window.| |int32_t OH_WindowManager_Snapshot(int32_t windowId, OH_PixelmapNative* pixelMap)|Obtains the snapshot of a window.| |int32_t OH_WindowManager_GetAllWindowLayoutInfoList(int64_t displayId,WindowManager_Rect** windowLayoutInfoList, size_t* windowLayoutInfoSize)|Obtains the layout information array of all windows visible on a display. The layout information is arranged based on the current window stacking order, and the topmost window in the hierarchy is at index 0 of the array.| |void OH_WindowManager_ReleaseAllWindowLayoutInfoList(WindowManager_Rect* windowLayoutInfoList)|Releases the memory occupied by a window layout information array.| |int32_t OH_WindowManager_InjectTouchEvent(int32_t windowId, Input_TouchEvent* touchEvent)|Injects multimodal touch events to a window. The injection does not trigger window focus or layer changes and is directly sent to ArkUI.|
Function Description
OH_WindowManager_SetWindowStatusBarEnabled()
int32_t OH_WindowManager_SetWindowStatusBarEnabled(int32_t windowId, bool enabled, bool enableAnimation)
Description
Sets whether to display the status bar in a window.
Since: 15
Parameters
|Parameter|Description| |–|–| |int32_t windowId|Window ID. The default value is 0. The value is an integer.| |bool enabled|Whether to display the status bar. The value true means to display the status bar, and false means the opposite.| |bool enableAnimation|Whether to enable the show/hide animation of the status bar. The value true means to enable the show/hide animation of the status bar, and false means the opposite.|
Return value
|Type|Description|
|–|–|
|int32_t|One of the following result codes:
OK: The function is successfully called.
WINDOW_MANAGER_ERRORCODE_INVALID_PARAM: A parameter is incorrect.
WINDOW_MANAGER_ERRORCODE_DEVICE_NOT_SUPPORTED: The feature is not supported by the device.
WINDOW_MANAGER_ERRORCODE_STATE_ABNORMAL: The window status is abnormal.
WINDOW_MANAGER_ERRORCODE_SYSTEM_ABNORMAL: The window manager service is abnormal.|
OH_WindowManager_SetWindowStatusBarColor()
int32_t OH_WindowManager_SetWindowStatusBarColor(int32_t windowId, int32_t color)
Description
Sets the color of the status bar in a window.
Since: 15
Parameters
|Parameter|Description| |–|–| |int32_t windowId|Window ID. The default value is 0. The value is an integer.| |int32_t color|Color to set, in ARGB format.|
Return value
|Type|Description|
|–|–|
|int32_t|One of the following result codes:
OK: The function is successfully called.
WINDOW_MANAGER_ERRORCODE_INVALID_PARAM: A parameter is incorrect.
WINDOW_MANAGER_ERRORCODE_DEVICE_NOT_SUPPORTED: The feature is not supported by the device.
WINDOW_MANAGER_ERRORCODE_STATE_ABNORMAL: The window status is abnormal.
WINDOW_MANAGER_ERRORCODE_SYSTEM_ABNORMAL: The window manager service is abnormal.|
OH_WindowManager_SetWindowNavigationBarEnabled()
int32_t OH_WindowManager_SetWindowNavigationBarEnabled(int32_t windowId, bool enabled, bool enableAnimation)
Description
Sets whether to display the navigation bar in a window.
Since: 15
Parameters
|Parameter|Description| |–|–| |int32_t windowId|Window ID. The default value is 0. The value is an integer.| |bool enabled|Whether to display the navigation bar. The value true means to display the navigation bar, and false means the opposite.| |bool enableAnimation|Whether to enable the show/hide animation of the navigation bar. The value true means to enable the show/hide animation of the navigation bar, and false means the opposite.|
Return value
|Type|Description|
|–|–|
|int32_t|One of the following result codes:
OK: The function is successfully called.
WINDOW_MANAGER_ERRORCODE_INVALID_PARAM: A parameter is incorrect.
WINDOW_MANAGER_ERRORCODE_DEVICE_NOT_SUPPORTED: The feature is not supported by the device.
WINDOW_MANAGER_ERRORCODE_STATE_ABNORMAL: The window status is abnormal.
WINDOW_MANAGER_ERRORCODE_SYSTEM_ABNORMAL: The window manager service is abnormal.|
OH_WindowManager_GetWindowAvoidArea()
int32_t OH_WindowManager_GetWindowAvoidArea(int32_t windowId, WindowManager_AvoidAreaType type, WindowManager_AvoidArea* avoidArea)
Description
Obtains the avoid area of a window.
Since: 15
Parameters
|Parameter|Description| |–|–| |int32_t windowId|Window ID. The default value is 0. The value is an integer.| |WindowManager_AvoidAreaType type|Type of the avoid area.| |WindowManager_AvoidArea* avoidArea|Pointer to the avoid area.|
Return value
|Type|Description|
|–|–|
|int32_t|One of the following result codes:
OK: The function is successfully called, and the pointer to the avoid area is returned.
WINDOW_MANAGER_ERRORCODE_INVALID_PARAM: A parameter is incorrect.
WINDOW_MANAGER_ERRORCODE_STATE_ABNORMAL: The window status is abnormal.
WINDOW_MANAGER_ERRORCODE_SYSTEM_ABNORMAL: The window manager service is abnormal.|
OH_WindowManager_IsWindowShown()
WindowManager_ErrorCode OH_WindowManager_IsWindowShown(int32_t windowId, bool* isShow)
Description
Checks whether a window is displayed.
Since: 15
Parameters
|Parameter|Description| |–|–| |int32_t windowId|Window ID. The default value is 0. The value is an integer.| |bool* isShow|Pointer to the check result. The value true means that the window is displayed, and false means the opposite.|
Return value
|Type|Description|
|–|–|
|WindowManager_ErrorCode|One of the following result codes:
OK: The function is successfully called.
WINDOW_MANAGER_ERRORCODE_INVALID_PARAM: A parameter is incorrect.
WINDOW_MANAGER_ERRORCODE_STATE_ABNORMAL: The window status is abnormal.|
OH_WindowManager_ShowWindow()
WindowManager_ErrorCode OH_WindowManager_ShowWindow(int32_t windowId)
Description
Shows a window.
Since: 15
Parameters
|Parameter|Description| |–|–| |int32_t windowId|Window ID. The default value is 0. The value is an integer.|
Return value
|Type|Description|
|–|–|
|WindowManager_ErrorCode|One of the following result codes:
OK: The function is successfully called.
WINDOW_MANAGER_ERRORCODE_INVALID_PARAM: A parameter is incorrect.
WINDOW_MANAGER_ERRORCODE_STATE_ABNORMAL: The window status is abnormal.
WINDOW_MANAGER_ERRORCODE_SYSTEM_ABNORMAL: The window manager service is abnormal.|
OH_WindowManager_SetWindowTouchable()
int32_t OH_WindowManager_SetWindowTouchable(int32_t windowId, bool isTouchable)
Description
Sets whether a window is touchable.
Since: 15
Parameters
|Parameter|Description| |–|–| |int32_t windowId|Window ID. The default value is 0. The value is an integer.| |bool isTouchable|Whether the window is touchable. The value true means that the window is touchable, and false means the opposite.|
Return value
|Type|Description|
|–|–|
|int32_t|One of the following result codes:
OK: The function is successfully called.
WINDOW_MANAGER_ERRORCODE_INVALID_PARAM: A parameter is incorrect.
WINDOW_MANAGER_ERRORCODE_STATE_ABNORMAL: The window status is abnormal.
WINDOW_MANAGER_ERRORCODE_SYSTEM_ABNORMAL: The window manager service is abnormal.|
OH_WindowManager_SetWindowFocusable()
int32_t OH_WindowManager_SetWindowFocusable(int32_t windowId, bool isFocusable)
Description
Sets whether a window is focusable.
Since: 15
Parameters
|Parameter|Description| |–|–| |int32_t windowId|Window ID. The default value is 0. The value is an integer.| |bool isFocusable|Whether the window is focusable. The value true means that the window is focusable, and false means the opposite.|
Return value
|Type|Description|
|–|–|
|int32_t|One of the following result codes:
OK: The function is successfully called.
WINDOW_MANAGER_ERRORCODE_INVALID_PARAM: A parameter is incorrect.
WINDOW_MANAGER_ERRORCODE_STATE_ABNORMAL: The window status is abnormal.
WINDOW_MANAGER_ERRORCODE_SYSTEM_ABNORMAL: The window manager service is abnormal.|
OH_WindowManager_SetWindowBackgroundColor()
int32_t OH_WindowManager_SetWindowBackgroundColor(int32_t windowId, const char* color)
Description
Sets the background color of a window.
Since: 15
Parameters
|Parameter|Description| |–|–| |int32_t windowId|Window ID. The default value is 0. The value is an integer.| |const char* color|Pointer to the background color. The value is a string in hexadecimal RGB or ARGB color format.|
Return value
|Type|Description|
|–|–|
|int32_t|One of the following result codes:
OK: The function is successfully called.
WINDOW_MANAGER_ERRORCODE_INVALID_PARAM: A parameter is incorrect.
WINDOW_MANAGER_ERRORCODE_STATE_ABNORMAL: The window status is abnormal.|
OH_WindowManager_SetWindowBrightness()
int32_t OH_WindowManager_SetWindowBrightness(int32_t windowId, float brightness)
Description
Sets the screen brightness of a window.
Since: 15
Parameters
|Parameter|Description| |–|–| |int32_t windowId|Window ID. The default value is 0. The value is an integer.| |float brightness|Screen brightness. The value is a floating point number in the range [0.0, 1.0] or is set to -1.0, where 1.0 indicates the brightest, and -1.0 is the default brightness.|
Return value
|Type|Description|
|–|–|
|int32_t|One of the following result codes:
OK: The function is successfully called.
WINDOW_MANAGER_ERRORCODE_INVALID_PARAM: A parameter is incorrect.
WINDOW_MANAGER_ERRORCODE_STATE_ABNORMAL: The window status is abnormal.
WINDOW_MANAGER_ERRORCODE_SYSTEM_ABNORMAL: The window manager service is abnormal.|
OH_WindowManager_SetWindowKeepScreenOn()
int32_t OH_WindowManager_SetWindowKeepScreenOn(int32_t windowId, bool isKeepScreenOn)
Description
Sets whether to always keep the screen on for a window.
Since: 15
Parameters
|Parameter|Description| |–|–| |int32_t windowId|Window ID. The default value is 0. The value is an integer.| |bool isKeepScreenOn|Whether to always keep the screen on. The value true means to always keep the screen on, and the value false indicates the opposite.|
Return value
|Type|Description|
|–|–|
|int32_t|One of the following result codes:
OK: The function is successfully called.
WINDOW_MANAGER_ERRORCODE_INVALID_PARAM: A parameter is incorrect.
WINDOW_MANAGER_ERRORCODE_STATE_ABNORMAL: The window status is abnormal.
WINDOW_MANAGER_ERRORCODE_SYSTEM_ABNORMAL: The window manager service is abnormal.|
OH_WindowManager_SetWindowPrivacyMode()
int32_t OH_WindowManager_SetWindowPrivacyMode(int32_t windowId, bool isPrivacy)
Description
Sets whether to enable privacy mode for a window.
Required permissions: ohos.permission.PRIVACY_WINDOW
Since: 15
Parameters
|Parameter|Description| |–|–| |int32_t windowId|Window ID. The default value is 0. The value is an integer.| |bool isPrivacy|Whether to enable privacy mode. The value true means to enable privacy mode, and false means the opposite.|
Return value
|Type|Description|
|–|–|
|int32_t|One of the following result codes:
OK: The function is successfully called.
WINDOW_MANAGER_ERRORCODE_INVALID_PARAM: A parameter is incorrect.
WINDOW_MANAGER_ERRORCODE_INVALID_PERMISSION: A parameter is incorrect.
WINDOW_MANAGER_ERRORCODE_STATE_ABNORMAL: The window status is abnormal.
WINDOW_MANAGER_ERRORCODE_SYSTEM_ABNORMAL: The window manager service is abnormal.
WINDOW_MANAGER_ERRORCODE_NO_PERMISSION: The permission verification fails.|
OH_WindowManager_GetWindowProperties()
int32_t OH_WindowManager_GetWindowProperties(int32_t windowId, WindowManager_WindowProperties* windowProperties)
Description
Obtains the properties of a window.
Since: 15
Parameters
|Parameter|Description| |–|–| |int32_t windowId|Window ID. The default value is 0. The value is an integer.| |WindowManager_WindowProperties* windowProperties|Pointer to the properties.|
Return value
|Type|Description|
|–|–|
|int32_t|One of the following result codes:
OK: The function is successfully called, and the pointer to the window properties is returned.
WINDOW_MANAGER_ERRORCODE_INVALID_PARAM: A parameter is incorrect.
WINDOW_MANAGER_ERRORCODE_STATE_ABNORMAL: The window status is abnormal.
WINDOW_MANAGER_ERRORCODE_SYSTEM_ABNORMAL: The window manager service is abnormal.|
OH_WindowManager_Snapshot()
int32_t OH_WindowManager_Snapshot(int32_t windowId, OH_PixelmapNative* pixelMap)
Description
Obtains the snapshot of a window.
Since: 15
Parameters
|Parameter|Description|
|–|–|
|int32_t windowId|Window ID. The default value is 0. The value is an integer.
If the window ID is invalid or the window has been destroyed, you cannot obtain the window snapshot. To successfully obtain a snapshot, a valid window ID is required.
You can obtain a valid window ID by calling the ArkTS API getWindowProperties on the window object.|
|OH_PixelmapNative* pixelMap|Pointer to the snapshot.|
Return value
|Type|Description|
|–|–|
|int32_t|One of the following result codes:
OK: The function is successfully called, and the pointer to the pixelMap is returned.
WINDOW_MANAGER_ERRORCODE_INVALID_PARAM: A parameter is incorrect.
WINDOW_MANAGER_ERRORCODE_STATE_ABNORMAL: The window status is abnormal.|
OH_WindowManager_GetAllWindowLayoutInfoList()
int32_t OH_WindowManager_GetAllWindowLayoutInfoList(int64_t displayId,WindowManager_Rect** windowLayoutInfoList, size_t* windowLayoutInfoSize)
Description
Obtains the layout information array of all windows visible on a display. The layout information is arranged based on the current window stacking order, and the topmost window in the hierarchy is at index 0 of the array.
Since: 17
Parameters
|Parameter|Description| |–|–| |int64_t displayId|ID of the display. You can obtain a valid display ID by calling the ArkTS API getWindowProperties on the window object.| |WindowManager_Rect** windowLayoutInfoList|Double pointer to the layout information array of all windows visible.| |size_t* windowLayoutInfoSize|Pointer to the length of the layout information array.|
Return value
|Type|Description|
|–|–|
|int32_t|One of the following result codes:
OK: The function is successfully called, and the double pointer to the array and the pointer to the array length are returned.
WINDOW_MANAGER_ERRORCODE_INVALID_PARAM: A parameter is incorrect.
WINDOW_MANAGER_ERRORCODE_DEVICE_NOT_SUPPORTED: The feature is not supported by the device.
WINDOW_MANAGER_ERRORCODE_SYSTEM_ABNORMAL: The window manager service is abnormal.|
OH_WindowManager_ReleaseAllWindowLayoutInfoList()
void OH_WindowManager_ReleaseAllWindowLayoutInfoList(WindowManager_Rect* windowLayoutInfoList)
Description
Releases the memory occupied by a window layout information array.
Since: 17
Parameters
|Parameter|Description| |–|–| |WindowManager_Rect* windowLayoutInfoList|Pointer to the layout information array of all windows visible on the display. You can obtain the array pointer by calling OH_WindowManager_GetAllWindowLayoutInfoList.|
OH_WindowManager_InjectTouchEvent()
int32_t OH_WindowManager_InjectTouchEvent(int32_t windowId, Input_TouchEvent* touchEvent)
Description
Injects multimodal touch events to a window. The injection does not trigger window focus or layer changes and is directly sent to ArkUI.
Since: 20
Parameters
|Parameter|Description| |–|–| |int32_t windowId|Window ID. The default value is 0. The value is an integer.| |Input_TouchEvent* touchEvent|Pointer to the multimodal touch event. For details, see Input_TouchEvent. The event is defined in oh_input_manager.h.|
Return value
|Type|Description|
|–|–|
|int32_t|One of the following result codes:
OK: The function is successfully called.
WINDOW_MANAGER_ERRORCODE_INVALID_PARAM: A parameter is incorrect.
WINDOW_MANAGER_ERRORCODE_STATE_ABNORMAL: The window status is abnormal.
WINDOW_MANAGER_ERRORCODE_SYSTEM_ABNORMAL: The window manager service is abnormal.|
你可能感兴趣的鸿蒙文章
harmony 鸿蒙ARKUI_TextPickerCascadeRangeContent
harmony 鸿蒙ARKUI_TextPickerRangeContent
harmony 鸿蒙ArkUI_AnimateCompleteCallback
harmony 鸿蒙ArkUI_ContextCallback
- 所属分类: 后端技术
- 本文标签:
热门推荐
-
2、 - 优质文章
-
3、 gate.io
-
8、 golang
-
9、 openharmony
-
10、 Vue中input框自动聚焦