[SOLVED] Application Focus in Windows 7

Author: jrussell@proware.com (jruss)

I'm looking for a way to move my Uniface desktop application to the top of the Windows OS Z-Order.  Preferably without using a third party tool.   Currently using Uniface 9.6.05.

10 Comments

  1. Could you provide more details about what exactly you would like to achieve? Do you want that your Uniface application is staying on top or are you looking for a way to bring the application to the front?


    Author: diseli (daniel.iseli@uniface.com)
  2. I'm curious as well.  Sometimes when a Uniface App starts it goes behind the current window and I have to "find" it.  Sometimes it's on top but does not have focus.  9.6.05 here as well.


    Author: RobM (maciokr@natfuel.com)
  3. I'm using the timeout function to log users out after a certain amount of inactivity.  Instead of just abruptly logging the user out though, I would like to give the user a chance to say they are still working in case they have unsaved work.  If the user has my Uniface application minimized or just another application in front of it on the desktop, I would like to push my application to the front and in focus for the user to see.   Thanks in advance, Jared


    Author: jruss (jrussell@proware.com)
  4. jruss said I'm using the timeout function to log users out after a certain amount of inactivity.  Instead of just abruptly logging the user out though, I would like to give the user a chance to say they are still working in case they have unsaved work.  If the user has my Uniface application minimized or just another application in front of it on the desktop, I would like to push my application to the front and in focus for the user to see.   Thanks in advance, Jared  

    Hi Jared, Thanks for the additional info. You could use the Windows API User32 function SetWindowsPos (and call it with a C Call-Out signature) to bring the Uniface Application window to the front. I don't have a ready-made sample for this at the moment, but I'll try to plan some time next week to create one. Will keep you posted. Hope this helps. Daniel


    Author: diseli (daniel.iseli@uniface.com)
  5. Hi Jared, I did some tests and I could achieve the best results when I use the USER32 function ShowWindowAsync and SetForegroundWindow. I've created a small sample that demonstrates the two functions in "action" (see the Community Sample "Bring Uniface application window to front"). The sample includes the form BRINGTOFRONT and 2 C Call-Out signatures (YRTL and USER32). The form features the button "Start" that will generate an asynchronous message after about 30 seconds (using the UTIMER component). And when the Asynchronous Interrupt trigger of the form is fired then the following code is executed:

    newinstance "YRTL", hYrtl hWnd = hYRTL->uGetHwnd() newinstance "USER32", hUser32 hUser32->ShowWindowAsync(hWnd, SW_SHOWDEFAULT) ; constant SW_SHOWDEFAULT = 10 hUser32->ShowWindowAsync(hWnd, SW_SHOW)        ; constant SW_SHOW = 5 hUser32->SetForegroundWindow(hWnd)

    The YRTL function ugethwnd will get the window handle of the Uniface application window that will be used with ShowWindowAsync and SetForegroundWindow. Please note that I've created this sample using Uniface 9.7.03. But it should also work with any other Uniface 9.7 or 9.6 version. Hope this helps. Daniel


    Author: diseli (daniel.iseli@uniface.com)
  6. I've forgot to mention that not in all situations the Uniface application will be brought to the front. In case a menu of another application is open or the foreground window is locked then the Uniface application window will stay in the background and the icon in the Windows taskbar will flash. This is just normal Windows behavior.


    Author: diseli (daniel.iseli@uniface.com)
  7. diseli said Hi Jared, I did some tests and I could achieve the best results when I use the USER32 function ShowWindowAsync and SetForegroundWindow. I've created a small sample that demonstrates the two functions in "action" (see the Community Sample "Bring Uniface application window to front"). The sample includes the form BRINGTOFRONT and 2 C Call-Out signatures (YRTL and USER32). The form features the button "Start" that will generate an asynchronous message after about 30 seconds (using the UTIMER component). And when the Asynchronous Interrupt trigger of the form is fired then the following code is executed:
    newinstance "YRTL", hYrtl<br /> hWnd = hYRTL-&gt;uGetHwnd()<br /> newinstance "USER32", hUser32<br /> hUser32-&gt;ShowWindowAsync(hWnd, SW_SHOWDEFAULT) ; constant SW_SHOWDEFAULT = 10<br /> hUser32-&gt;ShowWindowAsync(hWnd, SW_SHOW)        ; constant SW_SHOW = 5<br /> hUser32-&gt;SetForegroundWindow(hWnd)
    The YRTL function ugethwnd will get the window handle of the Uniface application window that will be used with ShowWindowAsync and SetForegroundWindow. Please note that I've created this sample using Uniface 9.7.03. But it should also work with any other Uniface 9.7 or 9.6 version. Hope this helps. Daniel  

    Hi Daniel, This worked perfectly.  I was having a lot of trouble getting the window handle and was unaware of the ugethwnd function.   Thanks, Jared


    Author: jruss (jrussell@proware.com)
  8. jruss said Hi Daniel, This worked perfectly.  I was having a lot of trouble getting the window handle and was unaware of the ugethwnd function.   Thanks, Jared  

     Hi Jared, Thanks for your feedback. And I'm happy to hear that this is working for you. Daniel


    Author: diseli (daniel.iseli@uniface.com)
  9. Good and easy solution, only one observation: starting with a maximised window, the application reappears as non-maximised. But I think this sideeffect (of SW_SHOWDEFAULT ??) can be tolerated; I haven't found a better option under those provided by MSoft


    Author: ulrich-merkel (ulrichmerkel@web.de)
  10. The following extension may help:

        hUser32->IsIconic(n_IsIconic, hWnd);
       if (n_IsIconic)
           hUser32->ShowWindowAsync(hWnd, SW_SHOWDEFAULT); showdefault
       endif

    Author: ulrich-merkel (ulrichmerkel@web.de)