Search code examples
luaiup

Identifying active iup dialog


I'm writing a lua program that needs to call an external popup (let's call it Poppy) provided as an external library/API by another active programme (environment is Windows).

Poppy has a bad habit; when invoked, it pops up, does its work and then vanishes -- leaving the current Lua dialog hidden behind Poppy's parent program.

After calling Poppy, dlg.BRINGFRONT="YES" will bring the iup dialog dlg to the front.

Is there a technique to identify what dlg should be -- i.e. what was the topmost iup dialog before the external API was invoked?

I've read the iup documentation and can't see a way to do this. However, as I need to call Poppy in a large number of instances, I'd like to simplify the process of bringing the current dialog to the front.

I'm invoking Poppy thus:

local res = Poppy('INDI')
dlg.BRINGFRONT="YES"
return res

Solution

  • I've succeeded in doing this using the Winapi library and the following code:

    winapi = require ("winapi")
    currentwin = winapi.get_foreground_window()
    --invoke Poppy here and wait for control to return
    currentwin:set_foreground()