SetWindowPos function (winuser.h)
Changes the size, position, and Z order of a child, pop-up, or top-level window. These windows are ordered according to their appearance on the screen. The topmost window receives the highest rank and is the first window in the Z order.
Syntax
Parameters
A handle to the window.
A handle to the window to precede the positioned window in the Z order. This parameter must be a window handle or one of the following values.
Value | Meaning |
---|---|
HWND_BOTTOM (HWND)1 | Places the window at the bottom of the Z order. If the hWnd parameter identifies a topmost window, the window loses its topmost status and is placed at the bottom of all other windows. |
HWND_NOTOPMOST (HWND)-2 | Places the window above all non-topmost windows (that is, behind all topmost windows). This flag has no effect if the window is already a non-topmost window. |
HWND_TOP (HWND)0 | Places the window at the top of the Z order. |
HWND_TOPMOST (HWND)-1 | Places the window above all non-topmost windows. The window maintains its topmost position even when it is deactivated. |
В
For more information about how this parameter is used, see the following Remarks section.
The new position of the left side of the window, in client coordinates.
The new position of the top of the window, in client coordinates.
The new width of the window, in pixels.
The new height of the window, in pixels.
The window sizing and positioning flags. This parameter can be a combination of the following values.
Value | Meaning |
---|---|
SWP_ASYNCWINDOWPOS 0x4000 | If the calling thread and the thread that owns the window are attached to different input queues, the system posts the request to the thread that owns the window. This prevents the calling thread from blocking its execution while other threads process the request. |
SWP_DEFERERASE 0x2000 | Prevents generation of the WM_SYNCPAINT message. |
SWP_DRAWFRAME 0x0020 | Draws a frame (defined in the window’s class description) around the window. |
SWP_FRAMECHANGED 0x0020 | Applies new frame styles set using the SetWindowLong function. Sends a WM_NCCALCSIZE message to the window, even if the window’s size is not being changed. If this flag is not specified, WM_NCCALCSIZE is sent only when the window’s size is being changed. |
SWP_HIDEWINDOW 0x0080 | Hides the window. |
SWP_NOACTIVATE 0x0010 | Does not activate the window. If this flag is not set, the window is activated and moved to the top of either the topmost or non-topmost group (depending on the setting of the hWndInsertAfter parameter). |
SWP_NOCOPYBITS 0x0100 | Discards the entire contents of the client area. If this flag is not specified, the valid contents of the client area are saved and copied back into the client area after the window is sized or repositioned. |
SWP_NOMOVE 0x0002 | Retains the current position (ignores X and Y parameters). |
SWP_NOOWNERZORDER 0x0200 | Does not change the owner window’s position in the Z order. |
SWP_NOREDRAW 0x0008 | Does not redraw changes. If this flag is set, no repainting of any kind occurs. This applies to the client area, the nonclient area (including the title bar and scroll bars), and any part of the parent window uncovered as a result of the window being moved. When this flag is set, the application must explicitly invalidate or redraw any parts of the window and parent window that need redrawing. |
SWP_NOREPOSITION 0x0200 | Same as the SWP_NOOWNERZORDER flag. |
SWP_NOSENDCHANGING 0x0400 | Prevents the window from receiving the WM_WINDOWPOSCHANGING message. |
SWP_NOSIZE 0x0001 | Retains the current size (ignores the cx and cy parameters). |
SWP_NOZORDER 0x0004 | Retains the current Z order (ignores the hWndInsertAfter parameter). |
SWP_SHOWWINDOW 0x0040 | Displays the window. |
Return value
If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error information, call GetLastError.
Remarks
As part of the Vista re-architecture, all services were moved off the interactive desktop into Session 0. hwnd and window manager operations are only effective inside a session and cross-session attempts to manipulate the hwnd will fail. For more information, see The Windows Vista Developer Story: Application Compatibility Cookbook.
If you have changed certain window data using SetWindowLong, you must call SetWindowPos for the changes to take effect. Use the following combination for uFlags: SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED .
A window can be made a topmost window either by setting the hWndInsertAfter parameter to HWND_TOPMOST and ensuring that the SWP_NOZORDER flag is not set, or by setting a window’s position in the Z order so that it is above any existing topmost windows. When a non-topmost window is made topmost, its owned windows are also made topmost. Its owners, however, are not changed.
If neither the SWP_NOACTIVATE nor SWP_NOZORDER flag is specified (that is, when the application requests that a window be simultaneously activated and its position in the Z order changed), the value specified in hWndInsertAfter is used only in the following circumstances.
- Neither the HWND_TOPMOST nor HWND_NOTOPMOST flag is specified in hWndInsertAfter.
- The window identified by hWnd is not the active window.
An application cannot activate an inactive window without also bringing it to the top of the Z order. Applications can change an activated window’s position in the Z order without restrictions, or it can activate a window and then move it to the top of the topmost or non-topmost windows.
If a topmost window is repositioned to the bottom (HWND_BOTTOM) of the Z order or after any non-topmost window, it is no longer topmost. When a topmost window is made non-topmost, its owners and its owned windows are also made non-topmost windows.
A non-topmost window can own a topmost window, but the reverse cannot occur. Any window (for example, a dialog box) owned by a topmost window is itself made a topmost window, to ensure that all owned windows stay above their owner.
If an application is not in the foreground, and should be in the foreground, it must call the SetForegroundWindow function.
To use SetWindowPos to bring a window to the top, the process that owns the window must have SetForegroundWindow permission.
Windows 10 activity history and your privacy
Activity history helps keep track of the things you do on your device, such as the apps and services you use, the files you open, and the websites you browse. Your activity history is stored locally on your device, and if you’ve signed in to your device with a Microsoft account and given your permission, Windows sends your activity history to Microsoft. Microsoft uses the activity history data to provide you with personalized experiences (such as ordering your activities based on duration of use) and relevant suggestions (such as anticipating what your needs might be based on your activity history).
The following Windows 10 features use your activity history. Be sure to refer back to this page following future releases and updates to Windows to learn what additional services and features use your activity history:
Timeline. See a timeline of activities and be able to resume those activities from your device. For example, let’s say that you were editing a Word document on your device, but you were unable to finish before you had to leave the office for the day. If you selected the Store my activity history on this device check box on the Activity history settings page, you would see that Word activity in your timeline the following day, and for the next several days, and from there, you could resume working on it. If you selected the Send my activity history to Microsoft check box and you were unable to finish before you had to leave the office for the day, not only would you see that Word activity in your timeline for up to 30 days, but you could also resume working on it later from another device.
Cortana. When collecting activity history only on your device, Cortana lets you pick up where you left off on that device. If you choose to send your activities to the cloud, you can pick up where you left off with activities you started on other devices. Cortana will notify you about those activities so you can resume them quickly on your device, and with sync turned on, across your other devices. Note that for the cross-device “Pick up where you left off” experience to work you need to have the Browsing history permission turned On in Cortana. To do this, open Cortana’s home from the search box on the taskbar, and then select Settings > Cortana > Permissions > Manage the information Cortana can access from this device > Browsing history.
Microsoft Edge. When you use Microsoft Edge, your browsing history will be included in your activity history. Activity history will not be saved when browsing with InPrivate tabs or windows.
If you’ve signed in to your device with a Microsoft account and enabled the setting to send Microsoft your activity history, Microsoft uses your activity history data to enable cross-device experiences. So even when you switch devices, you will be able to see notifications about your activities and resume them. For example, your activity history can also be sent to Microsoft when using another Windows 10 device or certain Microsoft apps on an iOS or Android device. You can continue activities that you started from those other devices on your Windows device. Initially, this will be limited to Microsoft Edge mobile, but will soon include Office mobile apps like Word, Excel, and PowerPoint.
Microsoft will also use your activity history to improve Microsoft products and services when the setting for sending your activity history to Microsoft is enabled. We do this by applying machine-learning techniques to better understand how customers in general use our products and services. We also diagnose where customers encounter errors and then help fix them.
Regarding multiple accounts: Activity history is collected and stored locally for each local account, personal Microsoft account (MSA), or work or school account (AAD) that you have associated with your device in Settings > Accounts > Email & accounts. When you choose to send your activity history to Microsoft, activities from the primary account on that device are sent to Microsoft. If you have more than one device, and you have multiple accounts on one or more of those devices, you can see activity history from your second device’s primary account on the first device (as a secondary account). You can also see these accounts under Settings > Privacy > Activity history, where you can filter out activities from specific accounts from showing in your timeline. Hiding an account does not delete the data on the device, nor in the cloud. See the following section for more details on managing your data.
To learn more about how Microsoft products and services use this data to personalize experiences while respecting your privacy, see the Privacy Statement.
Manage activity history settings
On your device
To stop saving activity history locally on your device, select Start , then select Settings > Privacy > Activity history. On this page, clear the Store my activity history on this device check box.
Open Activity history settings
If you turn this setting off, you won’t be able to use any of the on-device features that rely on activity history, such as your timeline or Cortana’s “Pick up where you left off” feature. You will still be able to see your browsing history in Microsoft Edge.
In previous versions of Windows, this setting was called Let Windows collect my activities from this PC.
To stop sending your activity history to Microsoft, select Start , then select Settings > Privacy > Activity history. On this page, clear the Send my activity history to Microsoft check box.
If you turn this setting off, you won’t be able to use a full 30 days in your timeline or get cross-device activity experiences.
In previous versions of Windows, this setting was called Let Windows sync my activities from this PC to the cloud.
Windows has additional privacy settings that control whether app activity and browsing history data is sent to Microsoft, such as the Diagnostic data setting.
If you have a personal Microsoft account (MSA), you can manage the activity history data that is associated with your Microsoft account in the cloud by selecting Manage my Microsoft account activity data. Once you’ve signed in to the privacy dashboard, select the Activity history tab, and then select the data you want to manage.
If you have a work or school account, you can clear and delete both the activity history stored on your device and sent to the Microsoft cloud. Select Start , then select Settings > Privacy > Activity history. Under Clear activity history, select Clear.
If you have multiple accounts, and your work or school account (AAD) is the primary account on the device, then clearing your activity history will delete any of your work and/or school (AAD) activity history that is synced to the cloud. To manage your personal Microsoft account (MSA) activity history data in the cloud, select Manage my Microsoft account activity data. If you have multiple accounts (MSA/AAD) but your personal account (MSA) is your primary account on the device, and you want to delete your AAD activities, go to your other device where your work/school (AAD) account is primary, and then clear your activity history on that device.
In your timeline, you can clear individual activities, or all activities from an individual day. To do so, right-click an activity and select the option you prefer.
On your mobile device (iOS and Android)
Some apps like Microsoft Edge mobile (iOS and Android) will let you turn off browser history sharing. For other apps like Microsoft Office, you can sign out of the app from which you no longer want to send activity history to Microsoft. You can manage activity history data that is stored in the cloud for your Microsoft account by selecting Manage my Microsoft account activity data.