Win32API SetWindowPos Example

Leave a comment

We will continue on from a previous post to show how to use SetWindowPos.

In our app, we are embedding a console app into WPF. However, we are not setting the window position, so it defaults to where the window is:


To set the position, use SetWindowPos. We will set the coordinates to 0, 0 and use Win32API.SWP_NOSIZE to ensure the window isn’t resized:

Win32API.SetWindowPos(cmdProcess.MainWindowHandle, Win32API.HWND_TOP, 0, 0, -1, -1, Win32API.SWP_NOSIZE);

Running this, we can see the window has been positioned correctly:



Carl de Souza is a developer and architect focusing on Microsoft Dynamics 365, Power BI, Azure, and AI.

carldesouza.comLinkedIn Twitter | YouTube


Leave a Reply

Your email address will not be published. Required fields are marked *