{"id":629,"date":"2010-12-16T20:20:57","date_gmt":"2010-12-17T01:20:57","guid":{"rendered":"http:\/\/anvil-of-time.com\/wordpress\/?p=629"},"modified":"2021-03-10T18:37:57","modified_gmt":"2021-03-10T23:37:57","slug":"powerbuilder-have-window-stay-on-top","status":"publish","type":"post","link":"https:\/\/anvil-of-time.com\/powerbuilder\/powerbuilder-have-window-stay-on-top\/","title":{"rendered":"PowerBuilder &#8211; Have Window Stay on Top"},"content":{"rendered":"<p>One common application technique is to have any notification windows stay on top of all others, even if subsequent windows are opened on top of them (and the notification window loses focus). This can easily be achieved via an external API call: SetWindowPos. From the MSDN: <em>&#8220;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.&#8221;<\/em><\/p>\n<pre name=\"code\" class=\"VB\">FUNCTION boolean SetWindowPos(ulong hWnd, int hwinpos, int x, int y, int cx, int cy, int swp) LIBRARY &quot;user32.dll&quot;<\/pre>\n<p>The values of hwinpos can be:<br \/>\n<strong>HWND_BOTTOM<br \/>\n(HWND)1<\/strong><br \/>\nPlaces 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.<\/p>\n<p><strong>HWND_NOTOPMOST<br \/>\n(HWND)-2<\/strong><br \/>\nPlaces 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.<\/p>\n<p><strong>HWND_TOP<br \/>\n(HWND)0<\/strong><br \/>\nPlaces the window at the top of the Z order.<\/p>\n<p><strong>HWND_TOPMOST<br \/>\n(HWND)-1<\/strong><br \/>\nPlaces the window above all non-topmost windows. The window maintains its topmost position even when it is deactivated.<\/p>\n<p>The next two parameters are the left and top position of the window.<\/p>\n<p>The next two parameters are the width and height in pixels of the window.<\/p>\n<p>The last parameter is a combination of 1 + 2<br \/>\n1 &#8211; retain current size<br \/>\n2 &#8211; retain current position<\/p>\n<p>Using my system tray popup window as an example, I added the API definition as a local external function, put a checkbox at the bottom of the window (with checked=true), and placed the following in the open event:<\/p>\n<pre name=\"code\" class=\"VB\">ulong ul_handle\nul_handle = handle(THIS)\nIF cbx_1.checked THEN\n\tSetWindowPos(ul_handle,-1,0,0,0,0,3)\/\/ -1 puts this at top of all others always, 3 says ignore position and size\nELSE\n\tSetWindowPos(ul_handle,1,0,0,0,0,3)\/\/ 1 put at bottom of z order\n\tbringtotop = TRUE\nEND IF<\/pre>\n<p>And the following in the clicked event of the checkbox control<\/p>\n<pre name=\"code\" class=\"VB\">ulong ul_handle\nul_handle = handle(Parent)\nIF cbx_1.checked THEN\n\tSetWindowPos(ul_handle,-1,0,0,0,0,3)\/\/ -1 puts this at top of all others always, 3 says ignore position and size\nELSE\n\tSetWindowPos(ul_handle,1,0,0,0,0,3)\/\/ 1 put at bottom of z order\n\tbringtotop = TRUE\nEND IF<\/pre>\n<p><a href=\"http:\/\/anvil-of-time.com\/wordpress\/wp-content\/uploads\/2010\/12\/ontopchecked.png\"><img loading=\"lazy\" class=\"aligncenter wp-image-632 size-full\" title=\"ontopchecked\" src=\"https:\/\/anvil-of-time.com\/wp-content\/uploads\/2010\/12\/ontopchecked.png\" alt=\"\" width=\"150\" height=\"157\" srcset=\"https:\/\/anvil-of-time.com\/wp-content\/uploads\/2010\/12\/ontopchecked.png 150w, https:\/\/anvil-of-time.com\/wp-content\/uploads\/2010\/12\/ontopchecked-143x150.png 143w\" sizes=\"(max-width: 150px) 100vw, 150px\" \/><\/a><\/p>\n<p>Now when unchecked:<br \/>\n<a href=\"http:\/\/anvil-of-time.com\/wordpress\/wp-content\/uploads\/2010\/12\/ontopunchecked.png\"><img loading=\"lazy\" class=\"aligncenter wp-image-633 size-full\" title=\"ontopunchecked\" src=\"https:\/\/anvil-of-time.com\/wp-content\/uploads\/2010\/12\/ontopunchecked.png\" alt=\"\" width=\"164\" height=\"148\" srcset=\"https:\/\/anvil-of-time.com\/wp-content\/uploads\/2010\/12\/ontopunchecked.png 164w, https:\/\/anvil-of-time.com\/wp-content\/uploads\/2010\/12\/ontopunchecked-150x135.png 150w\" sizes=\"(max-width: 164px) 100vw, 164px\" \/><\/a><\/p>\n<p>You may wish to provide another way to bring the window back to the top so the users don&#8217;t have to move or close things.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>One common application technique is to have any notification windows stay on top of all others, even if subsequent windows are opened on top of them (and the notification window loses focus). This can easily be achieved via an external API call: SetWindowPos. From the MSDN: &#8220;Changes the size, position, and Z order of a&hellip;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3,10],"tags":[12,16,42],"_links":{"self":[{"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/posts\/629"}],"collection":[{"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/comments?post=629"}],"version-history":[{"count":6,"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/posts\/629\/revisions"}],"predecessor-version":[{"id":1900,"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/posts\/629\/revisions\/1900"}],"wp:attachment":[{"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/media?parent=629"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/categories?post=629"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/tags?post=629"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}