{"id":13829,"date":"2024-03-15T07:58:56","date_gmt":"2024-03-15T07:58:56","guid":{"rendered":"https:\/\/www.silicloud.com\/blog\/detailed-explanation-of-the-setwindowpos-function-in-c-c\/"},"modified":"2025-08-06T00:03:24","modified_gmt":"2025-08-06T00:03:24","slug":"detailed-explanation-of-the-setwindowpos-function-in-c-c","status":"publish","type":"post","link":"https:\/\/www.silicloud.com\/blog\/detailed-explanation-of-the-setwindowpos-function-in-c-c\/","title":{"rendered":"SetWindowPos C++: Window Position API Guide"},"content":{"rendered":"<p>The SetWindowPos function is a function in the Windows API that is used to set the position and size of a window.<\/p>\n<p>Function prototype:<\/p>\n<pre class=\"post-pre\"><code>BOOL SetWindowPos(\r\n  HWND hWnd,      \/\/ \u7a97\u53e3\u53e5\u67c4\r\n  HWND hWndInsertAfter,  \/\/ \u7a97\u53e3\u7684\u76f8\u5bf9\u4f4d\u7f6e\r\n  int X,          \/\/ \u7a97\u53e3\u7684\u5de6\u4e0a\u89d2x\u5750\u6807\r\n  int Y,          \/\/ \u7a97\u53e3\u7684\u5de6\u4e0a\u89d2y\u5750\u6807\r\n  int cx,         \/\/ \u7a97\u53e3\u7684\u5bbd\u5ea6\r\n  int cy,         \/\/ \u7a97\u53e3\u7684\u9ad8\u5ea6\r\n  UINT uFlags     \/\/ \u63a7\u5236\u7a97\u53e3\u5927\u5c0f\u548c\u4f4d\u7f6e\u7684\u6807\u5fd7\r\n);\r\n<\/code><\/pre>\n<p>Explanation of parameters:<\/p>\n<ol>\n<li>hWnd: Handle of the window to set the position and size.<\/li>\n<li>hWndInsertAfter: Specifies the handle of the window relative to which the window&#8217;s position is to be set, which can be special handles such as HWND_TOPMOST, HWND_NOTOPMOST, HWND_TOP, or HWND_BOTTOM.<\/li>\n<li>The coordinates of the top-left corner of window X relative to its parent window or screen.<\/li>\n<li>cx and cy: width and height of the window.<\/li>\n<li>uFlags: flags that control the window size and position, which can be a combination of flags like SWP_NOSIZE, SWP_NOMOVE, SWP_NOZORDER, SWP_FRAMECHANGED, and so on.<\/li>\n<\/ol>\n<p>The return value of the function:<\/p>\n<ol>\n<li>Return a non-zero value if the function call is successful; return zero if the function call fails.<\/li>\n<\/ol>\n<p>The SetWindowPos function can be used to achieve the following tasks:<\/p>\n<ol>\n<li>Adjust the position and size of the window, allowing you to move it to a specific location.<\/li>\n<li>Adjusting the size of the window can change both the width and height of the window.<\/li>\n<li>Arrange the window hierarchy to place windows either above or below other windows.<\/li>\n<li>Changing the z-axis order of the windows can make them display at the front or back.<\/li>\n<li>Refreshing the appearance of the window allows you to redraw the window&#8217;s frame.<\/li>\n<\/ol>\n<p>In conclusion, the SetWindowPos function is very useful for controlling the position and size of a window by setting parameters. It is commonly used in C\/C++ programming to change the window&#8217;s position and size, as well as adjust its layering.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The SetWindowPos function is a function in the Windows API that is used to set the position and size of a window. Function prototype: BOOL SetWindowPos( HWND hWnd, \/\/ \u7a97\u53e3\u53e5\u67c4 HWND hWndInsertAfter, \/\/ \u7a97\u53e3\u7684\u76f8\u5bf9\u4f4d\u7f6e int X, \/\/ \u7a97\u53e3\u7684\u5de6\u4e0a\u89d2x\u5750\u6807 int Y, \/\/ \u7a97\u53e3\u7684\u5de6\u4e0a\u89d2y\u5750\u6807 int cx, \/\/ \u7a97\u53e3\u7684\u5bbd\u5ea6 int cy, \/\/ \u7a97\u53e3\u7684\u9ad8\u5ea6 UINT uFlags \/\/ \u63a7\u5236\u7a97\u53e3\u5927\u5c0f\u548c\u4f4d\u7f6e\u7684\u6807\u5fd7 ); [&hellip;]<\/p>\n","protected":false},"author":6,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_import_markdown_pro_load_document_selector":0,"_import_markdown_pro_submit_text_textarea":"","footnotes":""},"categories":[1],"tags":[274,18579,18581,18580,7040],"class_list":["post-13829","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-c","tag-setwindowpos","tag-win32-programming","tag-window-position","tag-windows-api"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v21.5 (Yoast SEO v21.5) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>SetWindowPos C++: Window Position API Guide - Blog - Silicon Cloud<\/title>\n<meta name=\"description\" content=\"Master SetWindowPos in Windows API: Control window position, size &amp; Z-order with detailed parameters &amp; C++ examples.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.silicloud.com\/blog\/detailed-explanation-of-the-setwindowpos-function-in-c-c\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"SetWindowPos C++: Window Position API Guide\" \/>\n<meta property=\"og:description\" content=\"Master SetWindowPos in Windows API: Control window position, size &amp; Z-order with detailed parameters &amp; C++ examples.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.silicloud.com\/blog\/detailed-explanation-of-the-setwindowpos-function-in-c-c\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog - Silicon Cloud\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/SiliCloudGlobal\/\" \/>\n<meta property=\"article:published_time\" content=\"2024-03-15T07:58:56+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-08-06T00:03:24+00:00\" \/>\n<meta name=\"author\" content=\"Benjamin Taylor\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@SiliCloudGlobal\" \/>\n<meta name=\"twitter:site\" content=\"@SiliCloudGlobal\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Benjamin Taylor\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/detailed-explanation-of-the-setwindowpos-function-in-c-c\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/detailed-explanation-of-the-setwindowpos-function-in-c-c\/\"},\"author\":{\"name\":\"Benjamin Taylor\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/ac801fe9549a25960ce48aa2e0a691c9\"},\"headline\":\"SetWindowPos C++: Window Position API Guide\",\"datePublished\":\"2024-03-15T07:58:56+00:00\",\"dateModified\":\"2025-08-06T00:03:24+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/detailed-explanation-of-the-setwindowpos-function-in-c-c\/\"},\"wordCount\":283,\"publisher\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/#organization\"},\"keywords\":[\"c#\",\"SetWindowPos\",\"Win32 Programming\",\"Window Position\",\"Windows API\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/detailed-explanation-of-the-setwindowpos-function-in-c-c\/\",\"url\":\"https:\/\/www.silicloud.com\/blog\/detailed-explanation-of-the-setwindowpos-function-in-c-c\/\",\"name\":\"SetWindowPos C++: Window Position API Guide - Blog - Silicon Cloud\",\"isPartOf\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/#website\"},\"datePublished\":\"2024-03-15T07:58:56+00:00\",\"dateModified\":\"2025-08-06T00:03:24+00:00\",\"description\":\"Master SetWindowPos in Windows API: Control window position, size & Z-order with detailed parameters & C++ examples.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/detailed-explanation-of-the-setwindowpos-function-in-c-c\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.silicloud.com\/blog\/detailed-explanation-of-the-setwindowpos-function-in-c-c\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/detailed-explanation-of-the-setwindowpos-function-in-c-c\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.silicloud.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"SetWindowPos C++: Window Position API Guide\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#website\",\"url\":\"https:\/\/www.silicloud.com\/blog\/\",\"name\":\"Silicon Cloud Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/#organization\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#organization\",\"name\":\"Silicon Cloud Blog\",\"url\":\"https:\/\/www.silicloud.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.silicloud.com\/blog\/wp-content\/uploads\/2023\/11\/EN-SILICON-Full.png\",\"contentUrl\":\"https:\/\/www.silicloud.com\/blog\/wp-content\/uploads\/2023\/11\/EN-SILICON-Full.png\",\"width\":1024,\"height\":1024,\"caption\":\"Silicon Cloud Blog\"},\"image\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/SiliCloudGlobal\/\",\"https:\/\/twitter.com\/SiliCloudGlobal\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/ac801fe9549a25960ce48aa2e0a691c9\",\"name\":\"Benjamin Taylor\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/ec2e3d3e2d525fd148047c4520ae7c1cdccd1f4b48a1a488422b31f04f345c14?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/ec2e3d3e2d525fd148047c4520ae7c1cdccd1f4b48a1a488422b31f04f345c14?s=96&d=mm&r=g\",\"caption\":\"Benjamin Taylor\"},\"url\":\"https:\/\/www.silicloud.com\/blog\/author\/benjamintaylor\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"SetWindowPos C++: Window Position API Guide - Blog - Silicon Cloud","description":"Master SetWindowPos in Windows API: Control window position, size & Z-order with detailed parameters & C++ examples.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.silicloud.com\/blog\/detailed-explanation-of-the-setwindowpos-function-in-c-c\/","og_locale":"en_US","og_type":"article","og_title":"SetWindowPos C++: Window Position API Guide","og_description":"Master SetWindowPos in Windows API: Control window position, size & Z-order with detailed parameters & C++ examples.","og_url":"https:\/\/www.silicloud.com\/blog\/detailed-explanation-of-the-setwindowpos-function-in-c-c\/","og_site_name":"Blog - Silicon Cloud","article_publisher":"https:\/\/www.facebook.com\/SiliCloudGlobal\/","article_published_time":"2024-03-15T07:58:56+00:00","article_modified_time":"2025-08-06T00:03:24+00:00","author":"Benjamin Taylor","twitter_card":"summary_large_image","twitter_creator":"@SiliCloudGlobal","twitter_site":"@SiliCloudGlobal","twitter_misc":{"Written by":"Benjamin Taylor","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.silicloud.com\/blog\/detailed-explanation-of-the-setwindowpos-function-in-c-c\/#article","isPartOf":{"@id":"https:\/\/www.silicloud.com\/blog\/detailed-explanation-of-the-setwindowpos-function-in-c-c\/"},"author":{"name":"Benjamin Taylor","@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/ac801fe9549a25960ce48aa2e0a691c9"},"headline":"SetWindowPos C++: Window Position API Guide","datePublished":"2024-03-15T07:58:56+00:00","dateModified":"2025-08-06T00:03:24+00:00","mainEntityOfPage":{"@id":"https:\/\/www.silicloud.com\/blog\/detailed-explanation-of-the-setwindowpos-function-in-c-c\/"},"wordCount":283,"publisher":{"@id":"https:\/\/www.silicloud.com\/blog\/#organization"},"keywords":["c#","SetWindowPos","Win32 Programming","Window Position","Windows API"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.silicloud.com\/blog\/detailed-explanation-of-the-setwindowpos-function-in-c-c\/","url":"https:\/\/www.silicloud.com\/blog\/detailed-explanation-of-the-setwindowpos-function-in-c-c\/","name":"SetWindowPos C++: Window Position API Guide - Blog - Silicon Cloud","isPartOf":{"@id":"https:\/\/www.silicloud.com\/blog\/#website"},"datePublished":"2024-03-15T07:58:56+00:00","dateModified":"2025-08-06T00:03:24+00:00","description":"Master SetWindowPos in Windows API: Control window position, size & Z-order with detailed parameters & C++ examples.","breadcrumb":{"@id":"https:\/\/www.silicloud.com\/blog\/detailed-explanation-of-the-setwindowpos-function-in-c-c\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.silicloud.com\/blog\/detailed-explanation-of-the-setwindowpos-function-in-c-c\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.silicloud.com\/blog\/detailed-explanation-of-the-setwindowpos-function-in-c-c\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.silicloud.com\/blog\/"},{"@type":"ListItem","position":2,"name":"SetWindowPos C++: Window Position API Guide"}]},{"@type":"WebSite","@id":"https:\/\/www.silicloud.com\/blog\/#website","url":"https:\/\/www.silicloud.com\/blog\/","name":"Silicon Cloud Blog","description":"","publisher":{"@id":"https:\/\/www.silicloud.com\/blog\/#organization"},"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.silicloud.com\/blog\/#organization","name":"Silicon Cloud Blog","url":"https:\/\/www.silicloud.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.silicloud.com\/blog\/wp-content\/uploads\/2023\/11\/EN-SILICON-Full.png","contentUrl":"https:\/\/www.silicloud.com\/blog\/wp-content\/uploads\/2023\/11\/EN-SILICON-Full.png","width":1024,"height":1024,"caption":"Silicon Cloud Blog"},"image":{"@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/SiliCloudGlobal\/","https:\/\/twitter.com\/SiliCloudGlobal"]},{"@type":"Person","@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/ac801fe9549a25960ce48aa2e0a691c9","name":"Benjamin Taylor","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/ec2e3d3e2d525fd148047c4520ae7c1cdccd1f4b48a1a488422b31f04f345c14?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/ec2e3d3e2d525fd148047c4520ae7c1cdccd1f4b48a1a488422b31f04f345c14?s=96&d=mm&r=g","caption":"Benjamin Taylor"},"url":"https:\/\/www.silicloud.com\/blog\/author\/benjamintaylor\/"}]}},"_links":{"self":[{"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/posts\/13829","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/comments?post=13829"}],"version-history":[{"count":2,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/posts\/13829\/revisions"}],"predecessor-version":[{"id":157838,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/posts\/13829\/revisions\/157838"}],"wp:attachment":[{"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/media?parent=13829"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/categories?post=13829"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/tags?post=13829"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}