Jump to content

Bring window to front when loading a file associated with a built application.


Recommended Posts

Hello:

I have written a LabVIEW application that I build and distribute to students for use in one of my classes. The application uses a custom data file and I have been successful in following suggestions in both of the following threads to be able to assocate these data files with the application so that if the user double-clicks a data file then the built application will start if necessary and will load the data file.

How to assisgn a file extension to an EXE? and

Associating my EXE with a specific file extension type

I basically used a second, small file loader applicaiton that is associated with the data files (via registry settings on Windows) that captures command line arguments and passes them to my main application. My application presently works on both Windows and Mac platforms so I used a TCP/IP based approach to pass the file path to open rather than DDE as was discussed (along with an example) in one of the threads.

With the advice found in various parts of the above threads I was successful in getting the file association to work on my applicaiton (at least in Windows so far, I'll work on the Mac side soon) with one small issue that I'd like to fix. If my appilcation is already running then when the new file to open is passed by the file loader I'd like to bring my application to the front so that the result of the request to load the new data can be seen.

This is especially a problem when the appliation has a modified data set that hasn't been saved yet. In this case I prompt the user with a dialog asking if he/she would like to save the existing data before loading the new data file that was requested via the launch attempt from the OS. If any window is above the center of the screen (such as an explorer window where the user was browing the data files) then the dialog ends up being hidden behind this window and the user has no indication that he needs to move something out of the way to get to the dialog.

I tried using the "Bring To Front" method on a VI Server application class node but it didn't do anything. Could I be using this wrong or is there a better way to have the window assocaited with a built application be brought to the top most. I'd really prefer an approach that would work on both Windows and Mac platforms as the rest of my application is platform independent.

Thanks in advance for any assistance offered.

Doug

Link to comment

In Windows, you can call the SetWindowPos function from User32.DLL:

post-1431-0-94066700-1347181321_thumb.pn

This image is from the Winutil library which you can find on NI's site, but you can also just do this yourself. You only need the window handle which is a 32 bit number.

I don't know what the equivalent code would be on the Mac, but you should be able to use a conditional disable structure to enable the relevant code based on the OS.

Link to comment

Yair:

Thanks very much for the advice on the Winutil library. I had heard of it before but never had a need to use it until now. I was able to obtain the functionality that I wanted by making my application "Topmost" and then setting it back to "Not Topmost". If I just set it at Topmost then I couldn't get any other windows to stay on top of it anymore, which I guess makes sense.

I'm still interested in knowing how to do this on a built Mac application, but honestly I have a few other problems to figure out on the Mac platform regarding associating my datafiles with the application before this will be an issue for me.

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.