• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Functions
2<!--Kit: ArkUI-->
3<!--Subsystem: Window-->
4<!--Owner: @waterwin-->
5<!--Designer: @nyankomiya-->
6<!--Tester: @qinliwen0417-->
7<!--Adviser: @ge-yafang-->
8
9> **NOTE**
10>
11> The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version.
12
13## Modules to Import
14
15```ts
16import { window } from '@kit.ArkUI';
17```
18
19## window.createWindow<sup>9+</sup>
20
21createWindow(config: Configuration, callback: AsyncCallback&lt;Window&gt;): void
22
23Creates a child window or system window. This API uses an asynchronous callback to return the result.
24
25**Required permissions**: ohos.permission.SYSTEM_FLOAT_WINDOW (required only when the window type is **window.WindowType.TYPE_FLOAT**.)
26
27**Atomic service API**: This API can be used in atomic services since API version 12.
28
29**System capability**: SystemCapability.WindowManager.WindowManager.Core
30
31**Parameters**
32
33| Name| Type| Mandatory| Description|
34| -------- | -------------------------------------- | -- | --------------------------------- |
35| config   | [Configuration](arkts-apis-window-i.md#configuration9)       | Yes| Parameters used for creating the window.  |
36| callback | AsyncCallback&lt;[Window](arkts-apis-window-Window.md)&gt; | Yes| Callback used to return the window created.|
37
38**Error codes**
39
40For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md).
41
42| ID| Error Message|
43| ------- | -------------------------------- |
44| 201     | Permission verification failed. The application does not have the permission required to call the API. |
45| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
46| 801     | Capability not supported. createWindow can not work correctly due to limited device capabilities. |
47| 1300001 | Repeated operation. |
48| 1300002 | This window state is abnormal. |
49| 1300004 | Unauthorized operation. |
50| 1300006 | This window context is abnormal. |
51| 1300009 | The parent window is invalid. |
52
53**Example**
54
55```ts
56import { UIAbility } from '@kit.AbilityKit';
57import { window } from '@kit.ArkUI';
58import { BusinessError } from '@kit.BasicServicesKit';
59
60export default class EntryAbility extends UIAbility {
61  onWindowStageCreate(windowStage: window.WindowStage): void {
62    let windowClass: window.Window | undefined = undefined;
63    let config: window.Configuration = {
64      name: "test",
65      windowType: window.WindowType.TYPE_DIALOG,
66      ctx: this.context
67    };
68    try {
69      window.createWindow(config, (err: BusinessError, data) => {
70        const errCode: number = err.code;
71        if (errCode) {
72          console.error(`Failed to create the window. Cause code: ${err.code}, message: ${err.message}`);
73          return;
74        }
75        windowClass = data;
76        console.info('Succeeded in creating the window. Data: ' + JSON.stringify(data));
77        windowClass.resize(500, 1000);
78      });
79    } catch (exception) {
80      console.error(`Failed to create the window. Cause code: ${exception.code}, message: ${exception.message}`);
81    }
82  }
83}
84```
85
86## window.createWindow<sup>9+</sup>
87
88createWindow(config: Configuration): Promise&lt;Window&gt;
89
90Creates a child window or system window. This API uses a promise to return the result.
91
92**Required permissions**: ohos.permission.SYSTEM_FLOAT_WINDOW (required only when the window type is **window.WindowType.TYPE_FLOAT**.)
93
94**Atomic service API**: This API can be used in atomic services since API version 12.
95
96**System capability**: SystemCapability.WindowManager.WindowManager.Core
97
98**Parameters**
99
100| Name| Type| Mandatory| Description|
101| ------ | -------------------------------- | -- | ------------------ |
102| config | [Configuration](arkts-apis-window-i.md#configuration9) | Yes| Parameters used for creating the window.|
103
104**Return value**
105
106| Type| Description|
107| -------------------------------- | ------------------------------------ |
108| Promise&lt;[Window](arkts-apis-window-Window.md)&gt; | Promise used to return the window created.|
109
110**Error codes**
111
112For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md).
113
114| ID| Error Message|
115| ------- | -------------------------------- |
116| 201     | Permission verification failed. The application does not have the permission required to call the API. |
117| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
118| 801     | Capability not supported. createWindow can not work correctly due to limited device capabilities. |
119| 1300001 | Repeated operation. |
120| 1300002 | This window state is abnormal. |
121| 1300004 | Unauthorized operation. |
122| 1300006 | This window context is abnormal. |
123| 1300009 | The parent window is invalid. |
124
125**Example**
126
127```ts
128import { UIAbility } from '@kit.AbilityKit';
129import { window } from '@kit.ArkUI';
130import { BusinessError } from '@kit.BasicServicesKit';
131
132export default class EntryAbility extends UIAbility {
133  onWindowStageCreate(windowStage: window.WindowStage): void {
134    let config: window.Configuration = {
135      name: "test",
136      windowType: window.WindowType.TYPE_DIALOG,
137      ctx: this.context,
138      defaultDensityEnabled: true
139    };
140    try {
141      window.createWindow(config).then((value:window.Window) => {
142        console.info('Succeeded in creating the window. Data: ' + JSON.stringify(value));
143        value.resize(500, 1000);
144      }).catch((err:BusinessError)=> {
145        console.error(`Failed to create the window. Cause code: ${err.code}, message: ${err.message}`);
146      });
147    } catch (exception) {
148      console.error(`Failed to create the window. Cause code: ${exception.code}, message: ${exception.message}`);
149    }
150  }
151}
152```
153
154## window.findWindow<sup>9+</sup>
155
156findWindow(name: string): Window
157
158Finds a window based on the name.
159
160**System capability**: SystemCapability.WindowManager.WindowManager.Core
161
162**Atomic service API**: This API can be used in atomic services since API version 11.
163
164**Parameters**
165
166| Name| Type  | Mandatory| Description    |
167| ------ | ------ | ---- | -------- |
168| name   | string | Yes  | Window name, that is, the value of name in [Configuration](arkts-apis-window-i.md#configuration9).|
169
170**Return value**
171
172| Type| Description|
173| ----------------- | ------------------- |
174| [Window](arkts-apis-window-Window.md) | Window found.|
175
176**Error codes**
177
178For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md).
179
180| ID| Error Message|
181| ------- | -------------------------------- |
182| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
183| 1300002 | This window state is abnormal. |
184
185**Example**
186
187```ts
188let windowClass: window.Window | undefined = undefined;
189try {
190  windowClass = window.findWindow('test');
191} catch (exception) {
192  console.error(`Failed to find the Window. Cause code: ${exception.code}, message: ${exception.message}`);
193}
194```
195
196## window.getLastWindow<sup>9+</sup>
197
198getLastWindow(ctx: BaseContext, callback: AsyncCallback&lt;Window&gt;): void
199
200Obtains the topmost layer child window of the current application. This API uses an asynchronous callback to return the result.
201
202If no child window exists or the child window is not displayed by calling [showWindow()](arkts-apis-window-Window.md#showwindow9), the main window of the application is returned.
203
204**Atomic service API**: This API can be used in atomic services since API version 12.
205
206**System capability**: SystemCapability.WindowManager.WindowManager.Core
207
208**Parameters**
209
210| Name| Type| Mandatory| Description|
211| -------- | -------------------------------------- | -- | ---------------------------------------- |
212| ctx      | [BaseContext](../apis-ability-kit/js-apis-inner-application-baseContext.md) | Yes| Current application context.|
213| callback | AsyncCallback&lt;[Window](arkts-apis-window-Window.md)&gt; | Yes| Callback used to return the topmost layer window obtained.|
214
215**Error codes**
216
217For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md).
218
219| ID| Error Message|
220| ------- | -------------------------------- |
221| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
222| 1300002 | This window state is abnormal. Top window or main window is null or destroyed.  |
223| 1300006 | This window context is abnormal. |
224
225**Example**
226
227```ts
228import { UIAbility } from '@kit.AbilityKit';
229import { window } from '@kit.ArkUI';
230import { BusinessError } from '@kit.BasicServicesKit';
231
232export default class EntryAbility extends UIAbility {
233  // ...
234  onWindowStageCreate(windowStage: window.WindowStage): void {
235    console.info('onWindowStageCreate');
236    windowStage.createSubWindow('TestSubWindow').then((subWindow) => {
237      subWindow.showWindow().then(() => {
238        try {
239          window.getLastWindow(this.context, (err: BusinessError, topWindow) => {
240            const errCode: number = err.code;
241            if (errCode) {
242              console.error(`Failed to obtain the top window. Cause code: ${err.code}, message: ${err.message}`);
243              return;
244            }
245            console.info(`Succeeded in obtaining the top window. Window id: ${topWindow.getWindowProperties().id}`);
246          });
247        } catch (exception) {
248          console.error(`Failed to obtain the top window. Cause code: ${exception.code}, message: ${exception.message}`);
249        }
250      });
251    });
252  }
253  //...
254}
255```
256
257## window.getLastWindow<sup>9+</sup>
258
259getLastWindow(ctx: BaseContext): Promise&lt;Window&gt;
260
261Obtains the topmost layer child window of the current application. This API uses a promise to return the result.
262
263If no child window exists or the child window is not displayed by calling [showWindow()](arkts-apis-window-Window.md#showwindow9), the main window of the application is returned.
264
265**Atomic service API**: This API can be used in atomic services since API version 12.
266
267**System capability**: SystemCapability.WindowManager.WindowManager.Core
268
269**Parameters**
270
271| Name| Type| Mandatory| Description|
272| ------ | ----------- | ---- | ------------------------------------------------------------ |
273| ctx    | [BaseContext](../apis-ability-kit/js-apis-inner-application-baseContext.md) | Yes  | Current application context.|
274
275**Return value**
276
277| Type| Description|
278| -------------------------------- | ------------------------------------------- |
279| Promise&lt;[Window](arkts-apis-window-Window.md)&gt; | Promise used to return the topmost layer window obtained.|
280
281**Error codes**
282
283For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md).
284
285| ID| Error Message|
286| ------- | -------------------------------- |
287| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
288| 1300002 | This window state is abnormal. Top window or main window is null or destroyed.   |
289| 1300006 | This window context is abnormal. |
290
291**Example**
292
293```ts
294// EntryAbility.ets
295import { UIAbility } from '@kit.AbilityKit';
296import { window } from '@kit.ArkUI';
297import { BusinessError } from '@kit.BasicServicesKit';
298
299export default class EntryAbility extends UIAbility {
300  // ...
301  onWindowStageCreate(windowStage: window.WindowStage): void {
302    console.info('onWindowStageCreate');
303    windowStage.createSubWindow('TestSubWindow').then((subWindow) => {
304      subWindow.showWindow().then(() => {
305        try {
306          window.getLastWindow(this.context).then((topWindow) => {
307            console.info(`Succeeded in obtaining the top window. Window id: ${topWindow.getWindowProperties().id}`);
308          }).catch((err: BusinessError) => {
309            console.error(`Failed to obtain the top window. Cause code: ${err.code}, message: ${err.message}`);
310          });
311        } catch (exception) {
312          console.error(`Failed to obtain the top window. Cause code: ${exception.code}, message: ${exception.message}`);
313        }
314      });
315    });
316  }
317  //...
318}
319```
320
321## window.shiftAppWindowFocus<sup>11+</sup>
322shiftAppWindowFocus(sourceWindowId: number, targetWindowId: number): Promise&lt;void&gt;
323
324Shifts the window focus from the source window to the target window in the same application. The window focus can be shifted between the main window and a child window.
325
326Ensure that the focusable property of the target window is true (see [setWindowFocusable()](arkts-apis-window-Window.md#setwindowfocusable9)) and that [showWindow()](arkts-apis-window-Window.md#showwindow9) is successfully executed.
327
328**Atomic service API**: This API can be used in atomic services since API version 12.
329
330**System capability**: SystemCapability.Window.SessionManager
331
332**Parameters**
333
334| Name         | Type  | Mandatory | Description                   |
335| -------------- | ------ | ----- | ----------------------- |
336| sourceWindowId | number | Yes   | ID of the source window, which is having the focus.|
337| targetWindowId | number | Yes   | ID of the target window.            |
338
339**Return value**
340
341| Type               | Description                     |
342| ------------------- | ------------------------- |
343| Promise&lt;void&gt; | Promise that returns no value.|
344
345**Error codes**
346
347For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md).
348
349| ID| Error Message                                     |
350| ------- | --------------------------------------------- |
351| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
352| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
353| 1300002 | This window state is abnormal.                |
354| 1300003 | This window manager service works abnormally. |
355| 1300004 | Unauthorized operation.                       |
356
357**Example**
358
359```ts
360// EntryAbility.ets
361import { UIAbility } from '@kit.AbilityKit';
362import { window } from '@kit.ArkUI';
363import { BusinessError } from '@kit.BasicServicesKit';
364
365export default class EntryAbility extends UIAbility {
366  onWindowStageCreate(windowStage: window.WindowStage) {
367    // ...
368    console.info('onWindowStageCreate');
369    let mainWindow: window.Window | undefined = undefined;
370    let subWindow: window.Window | undefined = undefined;
371    let mainWindowId: number = -1;
372    let subWindowId: number = -1;
373
374    try {
375      // Obtain the main window and ID of the application.
376      windowStage.getMainWindow().then((data) => {
377        if (data == null) {
378          console.error('Failed to obtain the main window. Cause: The data is empty');
379          return;
380        }
381        mainWindow = data;
382        mainWindowId = mainWindow.getWindowProperties().id;
383        console.info('Succeeded in obtaining the main window');
384      }).catch((err: BusinessError) => {
385        console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
386      });
387
388      // Create or obtain a child window and its ID. In this case, the child window has focus.
389      windowStage.createSubWindow('testSubWindow').then((data) => {
390        if (data == null) {
391          console.error('Failed to obtain the sub window. Cause: The data is empty');
392          return;
393        }
394        subWindow = data;
395        subWindowId = subWindow.getWindowProperties().id;
396        subWindow.resize(500, 500);
397        subWindow.showWindow();
398
399        // Listen for the window status and ensure that the window is ready.
400        subWindow.on("windowEvent", (windowEvent) => {
401          if (windowEvent == window.WindowEventType.WINDOW_ACTIVE) {
402            // Switch the focus.
403            window.shiftAppWindowFocus(subWindowId, mainWindowId).then(() => {
404              console.info('Succeeded in shifting app window focus');
405            }).catch((err: BusinessError) => {
406              console.error(`Failed to shift app window focus. Cause code: ${err.code}, message: ${err.message}`);
407            });
408          }
409        });
410      });
411    } catch (exception) {
412      console.error(`Failed to shift app focus. Cause code: ${exception.code}, message: ${exception.message}`);
413    }
414  }
415}
416```
417
418## window.shiftAppWindowPointerEvent<sup>15+</sup>
419shiftAppWindowPointerEvent(sourceWindowId: number, targetWindowId: number): Promise&lt;void&gt;
420
421Transfers an input event from one window to another within the same application, particularly in split-window scenarios. This API uses a promise to return the result. It works only in [freeform window](../../windowmanager/window-terminology.md#freeform-window) mode and takes effect only for the main window and its child windows.
422
423The source window must be in a mouse-down state for this API to work; otherwise, the call does not take effect. After the input event is transferred, a mouse-up event is sent to the source window, and a mouse-down event is sent to the target window.
424
425**Atomic service API**: This API can be used in atomic services since API version 15.
426
427**System capability**: SystemCapability.Window.SessionManager
428
429**Device behavior differences**: This API can be properly called on 2-in-1 devices and tablets. If it is called on other device types, error code 801 is returned.
430
431**Parameters**
432
433| Name         | Type  | Mandatory | Description                   |
434| -------------- | ------ | ----- | ----------------------- |
435| sourceWindowId | number | Yes   | ID of the source window. You are advised to call [getWindowProperties()](arkts-apis-window-Window.md#getwindowproperties9) to obtain the window ID.           |
436| targetWindowId | number | Yes   | ID of the target window. You are advised to call [getWindowProperties()](arkts-apis-window-Window.md#getwindowproperties9) to obtain the window ID.            |
437
438**Return value**
439
440| Type               | Description                     |
441| ------------------- | ------------------------- |
442| Promise&lt;void&gt; | Promise that returns no value.|
443
444**Error codes**
445
446For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md).
447
448| ID| Error Message                                     |
449| ------- | --------------------------------------------- |
450| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
451| 801     | Capability not supported. Failed to call the API due to limited device capabilities. |
452| 1300002 | This window state is abnormal.                |
453| 1300003 | This window manager service works abnormally. |
454| 1300004 | Unauthorized operation.                       |
455
456**Example**
457
458```ts
459// ets/pages/Index.ets
460import { window } from '@kit.ArkUI';
461import { BusinessError } from '@kit.BasicServicesKit';
462
463@Entry
464struct Index {
465  build() {
466    Row() {
467      Column() {
468        Blank('160')
469          .color(Color.Blue)
470          .onTouch((event: TouchEvent) => {
471            if (event.type === TouchType.Down) {
472              try {
473                let sourceWindowId = 1;
474                let targetWindowId = 2;
475                let promise = window.shiftAppWindowPointerEvent(sourceWindowId, targetWindowId);
476                promise.then(() => {
477                  console.info('Succeeded in shifting app window pointer event');
478                }).catch((err: BusinessError) => {
479                  console.error(`Failed to shift app window pointer event. Cause code: ${err.code}, message: ${err.message}`);
480                });
481              } catch (exception) {
482                console.error(`Failed to shift app pointer event. Cause code: ${exception.code}, message: ${exception.message}`);
483              }
484            }
485          })
486      }.width('100%')
487    }.height('100%').width('100%')
488  }
489}
490```
491
492## window.shiftAppWindowTouchEvent<sup>20+</sup>
493shiftAppWindowTouchEvent(sourceWindowId: number, targetWindowId: number, fingerId: number): Promise&lt;void&gt;
494
495Moves touch screen input events from one window to another in scenarios where windows within the same application are being split or merged. This API uses a promise to return the result. It takes effect only for the main window and its child windows.
496
497To transfer touch screen input events, the source window must call this API within the callback of the [onTouch](arkui-ts/ts-universal-events-touch.md#ontouch) event (the event type must be **TouchType.Down**). After a successful call, the system sends a touch-up event to the source window and a touch-down event to the target window.
498
499<!--RP6-->This API can be used only on 2-in-1 devices.<!--RP6End-->
500
501**System capability**: SystemCapability.Window.SessionManager
502
503**Parameters**
504
505| Name         | Type  | Mandatory | Description                   |
506| -------------- | ------ | ----- | ----------------------- |
507| sourceWindowId | number | Yes   | ID of the source window. You are advised to call [getWindowProperties()](arkts-apis-window-Window.md#getwindowproperties9) to obtain the window ID. The value must be an integer greater than 0. If it is less than or equal to 0, error code 1300016 is returned.           |
508| targetWindowId | number | Yes   | ID of the target window. You are advised to call [getWindowProperties()](arkts-apis-window-Window.md#getwindowproperties9) to obtain the window ID. The value must be an integer greater than 0. If it is less than or equal to 0, error code 1300016 is returned.            |
509| fingerId | number | Yes   | Finger ID of the touch event. You are advised to use the [touches](arkui-ts/ts-universal-events-touch.md#touchobject) property in the [touchEvent](arkui-ts/ts-universal-events-touch.md#touchevent) event to obtain the ID. This parameter must be an integer greater than or equal to 0. If the value is less than 0, error code 1300016 is returned.            |
510
511**Return value**
512
513| Type               | Description                     |
514| ------------------- | ------------------------- |
515| Promise&lt;void&gt; | Promise that returns no value.|
516
517**Error codes**
518
519For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md).
520
521| ID| Error Message                                     |
522| ------- | --------------------------------------------- |
523| 801     | Capability not supported. Function shiftAppWindowTouchEvent can not work correctly due to limited device capabilities. |
524| 1300002 | This window state is abnormal.                |
525| 1300003 | This window manager service works abnormally. |
526| 1300004 | Unauthorized operation.                       |
527| 1300016 | Parameter error. Possible cause: 1. Invalid parameter range.|
528
529**Example**
530
531```ts
532// ets/pages/Index.ets
533import { window } from '@kit.ArkUI';
534import { BusinessError } from '@kit.BasicServicesKit';
535
536@Entry
537struct Index {
538  build() {
539    Row() {
540      Column() {
541        Blank('160')
542          .color(Color.Blue)
543          .onTouch((event: TouchEvent) => {
544            // The source window touch event type must be TouchType.Down.
545            if (event.type === TouchType.Down) {
546              try {
547                let sourceWindowId = 1;
548                let targetWindowId = 2;
549                let promise = window.shiftAppWindowTouchEvent(sourceWindowId, targetWindowId, event.touches[0].id);
550                promise.then(() => {
551                  console.info(`Succeeded in shifting app window touch event`);
552                }).catch((err: BusinessError) => {
553                  console.error(`Failed to shift app window touch event. Cause code: ${err.code}, message: ${err.message}`);
554                });
555              } catch (exception) {
556                console.error(`Failed to shift app touch event. Cause code: ${exception.code}, message: ${exception.message}`);
557              }
558            }
559          })
560      }.width('100%')
561    }.height('100%').width('100%')
562  }
563}
564```
565
566## window.getWindowsByCoordinate<sup>14+</sup>
567
568getWindowsByCoordinate(displayId: number, windowNumber?: number, x?: number, y?: number): Promise&lt;Array&lt;Window&gt;&gt;
569
570Obtains visible windows at the specified coordinates within the current application, sorted by their current layer order. The window at the topmost layer corresponds to index 0 of the array. This API uses a promise to return the result.
571
572**Atomic service API**: This API can be used in atomic services since API version 14.
573
574**System capability**: SystemCapability.Window.SessionManager
575
576**Parameters**
577
578| Name| Type  | Mandatory| Description                                                                       |
579| ------ | ---------- |----|---------------------------------------------------------------------------|
580| displayId   | number| Yes | ID of the display where the windows are located. The value must be an integer and can be obtained from [WindowProperties](arkts-apis-window-i.md#windowproperties).|
581| windowNumber    | number| No | Number of windows to obtain. The value must be an integer greater than 0. If this parameter is not set or is less than or equal to 0, all windows that meet the conditions are returned.                                 |
582| x    | number | No | X coordinate. The value must be a non-negative integer. If this parameter is not set or is less than 0, all visible windows are returned.                                        |
583| y    | number| No | Y coordinate. The value must be a non-negative integer. If this parameter is not set or is less than 0, all visible windows are returned.                                        |
584
585**Return value**
586
587| Type                            | Description                     |
588| -------------------------------- |-------------------------|
589| Promise&lt;Array&lt;[Window](arkts-apis-window-Window.md)&gt;&gt; | Promise used to return an array of window objects.|
590
591**Error codes**
592
593For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md).
594
595| ID   | Error Message|
596|----------| ------------------------------ |
597| 401      | Parameter error. Possible cause: Incorrect parameter types. |
598| 801      | Capability not supported. Failed to call the API due to limited device capabilities. |
599| 1300003 | This window manager service works abnormally. |
600
601```ts
602import { UIAbility } from '@kit.AbilityKit';
603import { window } from '@kit.ArkUI';
604import { BusinessError } from '@kit.BasicServicesKit';
605
606export default class EntryAbility extends UIAbility {
607
608  onWindowStageCreate(windowStage: window.WindowStage): void {
609    try {
610      let windowClass = windowStage.getMainWindowSync();
611      let properties = windowClass.getWindowProperties();
612      window.getWindowsByCoordinate(properties.displayId).then((data) => {
613        console.info('Succeeded in creating the subwindow. Data: ' + JSON.stringify(data));
614        for (let window of data) {
615          // do something with window
616        }
617      }).catch((err: BusinessError) => {
618        console.error(`Failed to get window from point. Cause code: ${err.code}, message: ${err.message}`);
619      });
620      window.getWindowsByCoordinate(properties.displayId, 2, 500, 500).then((data) => {
621        console.info('Succeeded in creating the subwindow. Data: ' + JSON.stringify(data));
622        for (let window of data) {
623          // do something with window
624        }
625      }).catch((err: BusinessError) => {
626        console.error(`Failed to get window from point. Cause code: ${err.code}, message: ${err.message}`);
627      });
628    } catch (exception) {
629      console.error(`Failed to get window from point. Cause code: ${exception.code}, message: ${exception.message}`);
630    }
631  }
632}
633```
634
635## window.getAllWindowLayoutInfo<sup>15+</sup>
636
637getAllWindowLayoutInfo(displayId: number): Promise&lt;Array&lt;WindowLayoutInfo&gt;&gt;
638
639Obtains 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. This API uses a promise to return the result.
640
641**Atomic service API**: This API can be used in atomic services since API version 15.
642
643**System capability**: SystemCapability.Window.SessionManager
644
645**Parameters**
646
647| Name| Type  | Mandatory| Description                                                                       |
648| ------ | ---------- |----|---------------------------------------------------------------------------|
649| displayId   | number| Yes | ID of the display where the windows are located. The value must be an integer and can be obtained from [WindowProperties](arkts-apis-window-i.md#windowproperties).|
650
651**Return value**
652
653| Type                            | Description                     |
654| -------------------------------- |-------------------------|
655| Promise&lt;Array&lt;[WindowLayoutInfo](arkts-apis-window-i.md#windowlayoutinfo15)&gt;&gt; | Promise used to return an array of window layout information objects.|
656
657**Error codes**
658
659For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md).
660
661| ID   | Error Message|
662|----------| ------------------------------ |
663| 401     | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.|
664| 801      | Capability not supported. function getAllWindowLayoutInfo can not work correctly due to limited device capabilities. |
665| 1300003 | This window manager service works abnormally. |
666
667```ts
668import { window } from '@kit.ArkUI';
669import { BusinessError } from '@kit.BasicServicesKit';
670
671try {
672  let displayId = 0;
673  let promise = window.getAllWindowLayoutInfo(displayId);
674  promise.then((data) => {
675    console.info('Succeeded in obtaining all window layout info. Data: ' + JSON.stringify(data));
676  }).catch((err: BusinessError) => {
677    console.error(`Failed to obtain all window layout info. Cause code: ${err.code}, message: ${err.message}`);
678  });
679} catch (exception) {
680  console.error(`Failed to obtain all window layout info. Cause code: ${exception.code}, message: ${exception.message}`);
681}
682```
683
684## window.getVisibleWindowInfo<sup>18+</sup>
685
686getVisibleWindowInfo(): Promise&lt;Array&lt;WindowInfo&gt;&gt;
687
688Obtains information about visible main windows on the current screen. Visible main windows are main windows that are not returned to the background. This API uses a promise to return the result.
689
690**System capability**: SystemCapability.Window.SessionManager
691
692**Required permissions**: ohos.permission.VISIBLE_WINDOW_INFO
693
694**Return value**
695
696| Type| Description|
697| ------------------- | ----------------------- |
698| Promise&lt;Array&lt;[WindowInfo](arkts-apis-window-i.md#windowinfo18)&gt;&gt; | Promise used to return the information about visible windows.|
699
700**Error codes**
701
702For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md).
703
704| ID| Error Message|
705| ------- | ------------------------------ |
706| 201     | Permission verification failed. The application does not have the permission required to call the API. |
707| 801     | Capability not supported. Function getVisibleWindowInfo can not work correctly due to limited device capabilities. |
708| 1300003 | This window manager service works abnormally. |
709
710**Example**
711
712```ts
713import { window } from '@kit.ArkUI';
714import { BusinessError } from '@kit.BasicServicesKit';
715
716try {
717  let promise = window.getVisibleWindowInfo();
718  promise.then((data) => {
719    data.forEach(windowInfo=>{
720      console.info(`left:${windowInfo.rect.left}`);
721      console.info(`top:${windowInfo.rect.top}`);
722      console.info(`width:${windowInfo.rect.width}`);
723      console.info(`height:${windowInfo.rect.height}`);
724      console.info(`windowId:${windowInfo.windowId}`);
725      console.info(`windowStatusType:${windowInfo.windowStatusType}`);
726      console.info(`abilityName:${windowInfo.abilityName}`);
727      console.info(`bundleName:${windowInfo.bundleName}`);
728      console.info(`isFocused:${windowInfo.isFocused}`);
729    })
730  }).catch((err: BusinessError) => {
731    console.error('Failed to getWindowInfo. Cause: ' + JSON.stringify(err));
732  });
733} catch (exception) {
734  console.error(`Failed to get visible window info. Cause code: ${exception.code}, message: ${exception.message}`);
735}
736```
737
738## window.getGlobalWindowMode<sup>20+</sup>
739
740getGlobalWindowMode(displayId?: number): Promise&lt;number&gt;
741
742Obtains the window mode of the window that is in the foreground lifecycle on the specified screen. This API uses a promise to return the result.
743
744**Atomic service API**: This API can be used in atomic services since API version 20.
745
746**System capability**: SystemCapability.Window.SessionManager
747
748**Parameters**
749
750| Name| Type      | Mandatory                | Description                                                                             |
751| ------ | ---------- |--------------------|------------------------------------------------------------------------------------|
752| displayId   | number| No | Optional display ID, which is used to obtain the window mode information on the corresponding screen. This parameter must be an integer greater than or equal to 0. If it is less than 0, error code 1300016 is returned. If this parameter is not passed or is set to null or undefined, all screens are queried. If the specified screen does not exist, the return value is 0. You are advised to call [getWindowProperties()](arkts-apis-window-Window.md#getwindowproperties9) to obtain the display ID of the window.                                                   |
753
754**Return value**
755
756| Type                            | Description                     |
757| -------------------------------- |-------------------------|
758| Promise&lt;number&gt; | Promise used to return the window mode. Each binary bit represents a window mode. For details about the supported window modes, see [GlobalWindowMode](arkts-apis-window-e.md#globalwindowmode20). The return value is the result of a bitwise OR operation on the corresponding window mode values. For example, if there are full-screen, floating, and PiP windows on the specified screen, the return value is `0b1\|0b100\|0b1000 = 13`.| | |
759
760**Error codes**
761
762For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md).
763
764| ID   | Error Message|
765|----------| ------------------------------ |
766| 801      | Capability not supported. function getGlobalWindowMode can not work correctly due to limited device capabilities. |
767| 1300003 | This window manager service works abnormally. |
768| 1300016 | Parameter error. Possible cause: 1. Invalid parameter range. |
769
770**Example**
771```ts
772import { window } from '@kit.ArkUI';
773import { BusinessError } from '@kit.BasicServicesKit';
774
775try {
776  let displayId = 0;
777  let promise = window.getGlobalWindowMode(displayId);
778  promise.then((data) => {
779    console.info(`Succeeded in obtaining global window mode. Data: ${data}`);
780  }).catch((err: BusinessError) => {
781    console.error(`Failed to obtain global window mode. Cause code: ${err.code}, message: ${err.message}`);
782  });
783} catch (exception) {
784  console.error(`Failed to obtain global window mode. Cause code: ${exception.code}, message: ${exception.message}`);
785}
786```
787
788## window.setStartWindowBackgroundColor<sup>20+</sup>
789
790setStartWindowBackgroundColor(moduleName: string, abilityName: string, color: ColorMetrics): Promise&lt;void&gt;
791
792Sets the background color of the splash screen of the UIAbility based on the specified module name and ability name in the same application. This API uses a promise to return the result.
793
794This API takes effect for all processes of the same application, for example, in multi-instance or clone scenarios.
795
796**Atomic service API**: This API can be used in atomic services since API version 20.
797
798**System capability**: SystemCapability.Window.SessionManager
799
800**Parameters**
801
802| Name  | Type                         | Mandatory| Description                                                    |
803| -------- | ----------------------------- | ---- | -------------------------------------------------------- |
804| moduleName     | string                        | Yes  | Module name of the UIAbility. The value is a string of 0 to 200 characters. Only the module names within the same application can be set.|
805| abilityName     | string                        | Yes  | Name of the UIAbility. The value is a string of 0 to 200 characters. Only the ability names within the same application can be set.|
806| color | [ColorMetrics](js-apis-arkui-graphics.md#colormetrics12) | Yes  | Background color of the splash screen.                      |
807
808**Return value**
809
810| Type| Description|
811| ------------------- | ------------------------ |
812| Promise&lt;void&gt; | Promise that returns no value.|
813
814**Error codes**
815
816For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Window Error Codes](errorcode-window.md).
817
818| ID| Error Message|
819| ------- | -------------------------------------------- |
820| 801     | Capability not supported.function setStartWindowBackgroundColor can not to work correctly due to limited device capabilities. |
821| 1300003 | This window manager service works abnormally. |
822| 1300016 | Parameter error. Possible cause: 1. Invalid parameter range. |
823
824**Example**
825
826```ts
827import { BusinessError } from '@kit.BasicServicesKit';
828import { ColorMetrics, window } from '@kit.ArkUI';
829
830try {
831  let promise = window.setStartWindowBackgroundColor("entry", "EntryAbility", ColorMetrics.numeric(0xff000000));
832  promise.then(() => {
833    console.log('Succeeded in setting the starting window color.');
834  }).catch((err: BusinessError) => {
835    console.error(`Failed to set the starting window color. Cause code: ${err.code}, message: ${err.message}`);
836  });
837} catch (exception) {
838  console.error(`Failed to set the starting window color. Cause code: ${exception.code}, message: ${exception.message}`);
839}
840```
841
842## window.create<sup>(deprecated)</sup>
843
844create(id: string, type: WindowType, callback: AsyncCallback&lt;Window&gt;): void
845
846Creates a child window. This API uses an asynchronous callback to return the result.
847
848> **NOTE**
849>
850> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [createWindow()](#windowcreatewindow9) instead.
851
852**Model restriction**: This API can be used only in the FA model.
853
854**System capability**: SystemCapability.WindowManager.WindowManager.Core
855
856**Parameters**
857
858| Name  | Type                                  | Mandatory| Description                                |
859| -------- | -------------------------------------- | ---- | ------------------------------------ |
860| id       | string                                 | Yes  | Window name, that is, the value of name in [Configuration](arkts-apis-window-i.md#configuration9).|
861| type     | [WindowType](arkts-apis-window-e.md#windowtype7)              | Yes  | Window type.                          |
862| callback | AsyncCallback&lt;[Window](arkts-apis-window-Window.md)&gt; | Yes  | Callback used to return the child window created.|
863
864
865**Example**
866
867```ts
868import { BusinessError } from '@kit.BasicServicesKit';
869
870let windowClass: window.Window | undefined = undefined;
871window.create('test', window.WindowType.TYPE_APP, (err: BusinessError, data) => {
872  const errCode: number = err.code;
873  if (errCode) {
874    console.error(`Failed to create the subWindow. Cause code: ${err.code}, message: ${err.message}`);
875    return;
876  }
877  windowClass = data;
878  console.info('Succeeded in creating the subWindow. Data: ' + JSON.stringify(data));
879});
880```
881
882## window.create<sup>(deprecated)</sup>
883
884create(id: string, type: WindowType): Promise&lt;Window&gt;
885
886Creates a child window. This API uses a promise to return the result.
887
888> **NOTE**
889>
890> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [createWindow()](#windowcreatewindow9-1) instead.
891
892**Model restriction**: This API can be used only in the FA model.
893
894**System capability**: SystemCapability.WindowManager.WindowManager.Core
895
896**Parameters**
897
898| Name| Type                     | Mandatory| Description      |
899| ------ | ------------------------- | ---- | ---------- |
900| id     | string                    | Yes  | Window name, that is, the value of name in [Configuration](arkts-apis-window-i.md#configuration9).  |
901| type   | [WindowType](arkts-apis-window-e.md#windowtype7) | Yes  | Window type.|
902
903**Return value**
904
905| Type                            | Description                                   |
906| -------------------------------- | --------------------------------------- |
907| Promise&lt;[Window](arkts-apis-window-Window.md)&gt; | Promise used to return the child window created.|
908
909
910**Example**
911
912```ts
913import { BusinessError } from '@kit.BasicServicesKit';
914
915let windowClass: window.Window | undefined = undefined;
916let promise = window.create('test', window.WindowType.TYPE_APP);
917promise.then((data) => {
918  windowClass = data;
919  console.info('Succeeded in creating the subWindow. Data: ' + JSON.stringify(data));
920}).catch((err: BusinessError) => {
921  console.error(`Failed to create the subWindow. Cause code: ${err.code}, message: ${err.message}`);
922});
923```
924
925## window.create<sup>(deprecated)</sup>
926
927create(ctx: BaseContext, id: string, type: WindowType, callback: AsyncCallback&lt;Window&gt;): void
928
929Creates a system window. This API uses an asynchronous callback to return the result.
930
931> **NOTE**
932>
933> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [createWindow()](#windowcreatewindow9) instead.
934
935**System capability**: SystemCapability.WindowManager.WindowManager.Core
936
937**Parameters**
938
939| Name  | Type                                                   | Mandatory| Description                                |
940| -------- | ------------------------------------------------------- | ---- | ------------------------------------ |
941| ctx      | [BaseContext](../apis-ability-kit/js-apis-inner-application-baseContext.md) | Yes  | Current application context.                |
942| id       | string                                                  | Yes  | Window name, that is, the value of name in [Configuration](arkts-apis-window-i.md#configuration9).  |
943| type     | [WindowType](arkts-apis-window-e.md#windowtype7)                              | Yes  | Window type.                          |
944| callback | AsyncCallback&lt;[Window](arkts-apis-window-Window.md)&gt;                  | Yes  | Callback used to return the child window created.|
945
946
947**Example**
948
949```ts
950import { BusinessError } from '@kit.BasicServicesKit';
951
952let windowClass: window.Window | undefined = undefined;
953window.create(globalThis.getContext(), 'test', window.WindowType.TYPE_SYSTEM_ALERT, (err: BusinessError, data) => {
954  const errCode: number = err.code;
955  if (errCode) {
956    console.error(`Failed to create the window. Cause code: ${err.code}, message: ${err.message}`);
957    return;
958  }
959  windowClass = data;
960  console.info('Succeeded in creating the window. Data: ' + JSON.stringify(data));
961  windowClass.resetSize(500, 1000);
962});
963```
964
965## window.create<sup>(deprecated)</sup>
966
967create(ctx: BaseContext, id: string, type: WindowType): Promise&lt;Window&gt;
968
969Creates a system window. This API uses a promise to return the result.
970
971> **NOTE**
972>
973> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [createWindow()](#windowcreatewindow9-1) instead.
974
975**System capability**: SystemCapability.WindowManager.WindowManager.Core
976
977**Parameters**
978
979| Name| Type                     | Mandatory| Description                                                        |
980| ------ | ------------------------- | ---- | ------------------------------------------------------------ |
981| ctx    | [BaseContext](../apis-ability-kit/js-apis-inner-application-baseContext.md) | Yes  | Current application context.|
982| id     | string                    | Yes  | Window name, that is, the value of name in [Configuration](arkts-apis-window-i.md#configuration9).|
983| type   | [WindowType](arkts-apis-window-e.md#windowtype7) | Yes  | Window type.                                                  |
984
985**Return value**
986
987| Type                            | Description                                   |
988| -------------------------------- | --------------------------------------- |
989| Promise&lt;[Window](arkts-apis-window-Window.md)&gt; | Promise used to return the child window created.|
990
991
992**Example**
993
994```ts
995import { BusinessError } from '@kit.BasicServicesKit';
996
997let windowClass: window.Window | undefined = undefined;
998let promise = window.create(globalThis.getContext(), 'test', window.WindowType.TYPE_SYSTEM_ALERT);
999promise.then((data) => {
1000  windowClass = data;
1001  console.info('Succeeded in creating the window. Data:' + JSON.stringify(data));
1002}).catch((err: BusinessError) => {
1003  console.error(`Failed to create the Window. Cause code: ${err.code}, message: ${err.message}`);
1004});
1005```
1006
1007## window.find<sup>(deprecated)</sup>
1008
1009find(id: string, callback: AsyncCallback&lt;Window&gt;): void
1010
1011Finds a window based on the ID. This API uses an asynchronous callback to return the result.
1012
1013> **NOTE**
1014>
1015> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [findWindow()](#windowfindwindow9) instead.
1016
1017**System capability**: SystemCapability.WindowManager.WindowManager.Core
1018
1019**Parameters**
1020
1021| Name  | Type                                  | Mandatory| Description                                |
1022| -------- | -------------------------------------- | ---- | ------------------------------------ |
1023| id       | string                                 | Yes  | Window name, that is, the value of name in [Configuration](arkts-apis-window-i.md#configuration9).|
1024| callback | AsyncCallback&lt;[Window](arkts-apis-window-Window.md)&gt; | Yes  | Callback used to return the window found.|
1025
1026**Example**
1027
1028```ts
1029import { BusinessError } from '@kit.BasicServicesKit';
1030
1031let windowClass: window.Window | undefined = undefined;
1032window.find('test', (err: BusinessError, data) => {
1033  const errCode: number = err.code;
1034  if (errCode) {
1035    console.error(`Failed to find the Window. Cause code: ${err.code}, message: ${err.message}`);
1036    return;
1037  }
1038  windowClass = data;
1039  console.info('Succeeded in finding the window. Data: ' + JSON.stringify(data));
1040});
1041```
1042
1043## window.find<sup>(deprecated)</sup>
1044
1045find(id: string): Promise&lt;Window&gt;
1046
1047Finds a window based on the ID. This API uses a promise to return the result.
1048
1049> **NOTE**
1050>
1051> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [findWindow()](#windowfindwindow9) instead.
1052
1053**System capability**: SystemCapability.WindowManager.WindowManager.Core
1054
1055**Parameters**
1056
1057| Name| Type  | Mandatory| Description    |
1058| ------ | ------ | ---- | -------- |
1059| id     | string | Yes  | Window name, that is, the value of name in [Configuration](arkts-apis-window-i.md#configuration9).|
1060
1061**Return value**
1062
1063| Type                            | Description                                 |
1064| -------------------------------- | ------------------------------------- |
1065| Promise&lt;[Window](arkts-apis-window-Window.md)&gt; | Promise used to return the window found.|
1066
1067**Example**
1068
1069```ts
1070import { BusinessError } from '@kit.BasicServicesKit';
1071
1072let windowClass: window.Window | undefined = undefined;
1073let promise = window.find('test');
1074promise.then((data) => {
1075  windowClass = data;
1076  console.info('Succeeded in finding the window. Data: ' + JSON.stringify(data));
1077}).catch((err: BusinessError) => {
1078  console.error(`Failed to find the Window. Cause code: ${err.code}, message: ${err.message}`);
1079});
1080```
1081
1082## window.getTopWindow<sup>(deprecated)</sup>
1083
1084getTopWindow(callback: AsyncCallback&lt;Window&gt;): void
1085
1086Obtains the top window of the current application. This API uses an asynchronous callback to return the result.
1087
1088> **NOTE**
1089>
1090> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [getLastWindow()](#windowgetlastwindow9) instead.
1091
1092**Model restriction**: This API can be used only in the FA model.
1093
1094**System capability**: SystemCapability.WindowManager.WindowManager.Core
1095
1096**Parameters**
1097
1098| Name  | Type                                  | Mandatory| Description                                        |
1099| -------- | -------------------------------------- | ---- | -------------------------------------------- |
1100| callback | AsyncCallback&lt;[Window](arkts-apis-window-Window.md)&gt; | Yes  | Callback used to return the top window obtained.|
1101
1102**Example**
1103
1104```ts
1105import { BusinessError } from '@kit.BasicServicesKit';
1106
1107let windowClass: window.Window | undefined = undefined;
1108window.getTopWindow((err: BusinessError, data) => {
1109  const errCode: number = err.code;
1110  if (errCode) {
1111    console.error(`Failed to obtain the top window. Cause code: ${err.code}, message: ${err.message}`);
1112    return;
1113  }
1114  windowClass = data;
1115  console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data));
1116});
1117```
1118
1119## window.getTopWindow<sup>(deprecated)</sup>
1120
1121getTopWindow(): Promise&lt;Window&gt;
1122
1123Obtains the top window of the current application. This API uses a promise to return the result.
1124
1125> **NOTE**
1126>
1127> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [getLastWindow()](#windowgetlastwindow9-1) instead.
1128
1129**Model restriction**: This API can be used only in the FA model.
1130
1131**System capability**: SystemCapability.WindowManager.WindowManager.Core
1132
1133**Return value**
1134
1135| Type                            | Description                                           |
1136| -------------------------------- | ----------------------------------------------- |
1137| Promise&lt;[Window](arkts-apis-window-Window.md)&gt; | Promise used to return the top window obtained.|
1138
1139**Example**
1140
1141```ts
1142import { BusinessError } from '@kit.BasicServicesKit';
1143
1144let windowClass: window.Window | undefined = undefined;
1145let promise = window.getTopWindow();
1146promise.then((data)=> {
1147    windowClass = data;
1148    console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data));
1149}).catch((err: BusinessError)=>{
1150    console.error(`Failed to obtain the top window. Cause code: ${err.code}, message: ${err.message}`);
1151});
1152```
1153
1154## window.getTopWindow<sup>(deprecated)</sup>
1155
1156getTopWindow(ctx: BaseContext, callback: AsyncCallback&lt;Window&gt;): void
1157
1158Obtains the top window of the current application. This API uses an asynchronous callback to return the result.
1159
1160> **NOTE**
1161>
1162> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getLastWindow()](#windowgetlastwindow9) instead.
1163
1164**System capability**: SystemCapability.WindowManager.WindowManager.Core
1165
1166**Parameters**
1167
1168| Name  | Type                                  | Mandatory| Description                                                        |
1169| -------- | -------------------------------------- | ---- | ------------------------------------------------------------ |
1170| ctx      | [BaseContext](../apis-ability-kit/js-apis-inner-application-baseContext.md)                            | Yes  | Current application context.|
1171| callback | AsyncCallback&lt;[Window](arkts-apis-window-Window.md)&gt; | Yes  | Callback used to return the top window obtained.                |
1172
1173**Example**
1174
1175```ts
1176// EntryAbility.ets
1177import { UIAbility } from '@kit.AbilityKit';
1178import { BusinessError } from '@kit.BasicServicesKit';
1179
1180export default class EntryAbility extends UIAbility {
1181  onWindowStageCreate(windowStage:window.WindowStage){
1182    console.info('onWindowStageCreate');
1183    let windowClass: window.Window | undefined = undefined;
1184    try {
1185      window.getTopWindow(this.context, (err: BusinessError, data) => {
1186        const errCode: number = err.code;
1187        if(errCode){
1188          console.error(`Failed to obtain the top window. Cause code: ${err.code}, message: ${err.message}`);
1189          return ;
1190        }
1191        windowClass = data;
1192        console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data));
1193      });
1194    } catch(error){
1195      console.error(`Failed to obtain the top window. Cause code: ${error.code}, message: ${error.message}`);
1196    }
1197  }
1198}
1199```
1200
1201## window.getTopWindow<sup>(deprecated)</sup>
1202
1203getTopWindow(ctx: BaseContext): Promise&lt;Window&gt;
1204
1205Obtains the top window of the current application. This API uses a promise to return the result.
1206
1207> **NOTE**
1208>
1209> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getLastWindow()](#windowgetlastwindow9-1) instead.
1210
1211**System capability**: SystemCapability.WindowManager.WindowManager.Core
1212
1213**Parameters**
1214
1215| Name| Type   | Mandatory| Description                                                        |
1216| ------ | ----------- | ---- | ------------------------------------------------------------ |
1217| ctx    | [BaseContext](../apis-ability-kit/js-apis-inner-application-baseContext.md) | Yes  | Current application context.|
1218
1219**Return value**
1220
1221| Type                            | Description                                           |
1222| -------------------------------- | ----------------------------------------------- |
1223| Promise&lt;[Window](arkts-apis-window-Window.md)&gt; | Promise used to return the top window obtained.|
1224
1225**Example**
1226
1227```ts
1228// EntryAbility.ets
1229import { UIAbility } from '@kit.AbilityKit';
1230import { BusinessError } from '@kit.BasicServicesKit';
1231
1232export default class EntryAbility extends UIAbility {
1233  onWindowStageCreate(windowStage:window.WindowStage) {
1234    console.info('onWindowStageCreate');
1235    let windowClass: window.Window | undefined = undefined;
1236    let promise = window.getTopWindow(this.context);
1237    promise.then((data) => {
1238      windowClass = data;
1239      console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data));
1240    }).catch((error: BusinessError) => {
1241      console.error(`Failed to obtain the top window. Cause code: ${error.code}, message: ${error.message}`);
1242    });
1243  }
1244}
1245```
1246