/2014/03/19/Win32-API--Set-window-to-foreground/
{"item":{"status":"visible","url":"\/2014\/03\/19\/Win32-API--Set-window-to-foreground\/","trash":"","name":"Win32-API--Set-window-to-foreground","parent":"","title":"Win32 API: Set window to foreground","date":"2014-03-19 07:38:39","filepath":"posts\/20140319_Win32-API--Set-window-to-foreground.xml.json","type":"post","content":"<p><img style=\"margin-left: 10px; margin-right: 10px; float: left;\" src=\"http:\/\/www.8bitrobot.com\/media\/uploads\/2012\/01\/gear.png\" alt=\"\" width=\"60\" height=\"64\" \/>It can be tricky setting your window as the top z-order window. It's not just a simple call to SetForegroundWindow.<\/p>\n<div style=\"clear: both;\"> <\/div>\n<p>Here's how to do it:<\/p>\n<pre style=\"padding-left: 30px;\">AttachThreadInput(GetWindowThreadProcessId(::GetForegroundWindow(), NULL),\n GetCurrentThreadId(), TRUE);\n\nBringWindowToTop(hwnd);\nSetForegroundWindow(hwnd);\nSetFocus(hwnd);\n\nAttachThreadInput(GetWindowThreadProcessId(::GetForegroundWindow(),NULL),\n GetCurrentThreadId(),FALSE);<\/pre>\n<p>This solution is from Nish Sivakumar's <a href=\"http:\/\/www.codeproject.com\/Articles\/1724\/Some-handy-dialog-box-tricks-tips-and-workarounds\">code project article<\/a> and KevinSW's <a href=\"http:\/\/www.codeproject.com\/Articles\/1724\/Some-handy-dialog-box-tricks-tips-and-workarounds?msg=2737186#xx2737186xx\">comment<\/a>.<\/p>"}}