LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Make .NET called Print Dialog frontmost

In an effort to give my end user standard windows print capabilites, I am using .NET to call print dialogs (setup/preview/print).

The problem is that the dialog pops up behind my active LV windows.

This can be overcome by using the overloaded ShowDialog(owner) method.

The problem is: I can not find a way to properly obtain an owner ref to the active LV window/app so that the dialog is modal on top of LV.

Any Ideas?
0 Kudos
Message 1 of 14
(8,779 Views)
I have not tried doing this.
Try this: Write a trivial little .NET class that implements IWin32Window. Call it, say, Win32Handle.
Get the HWND of the VI's front panel by dropping a Static VI Reference to the current VI; Right-click, Create >> Property >> Front Panel Window >> OS Window, which will return the HWND as an I32. Pass that the the constructor of Win32Handle and pass that to ShowDialog(owner).
George Erwin-Grotsky
National Instruments
LabVIEW Research & Development
0 Kudos
Message 2 of 14
(8,769 Views)
.... What version of LV are you using?

I can not find "OS Window" in my list of .... wait.

You need to turn off your "super secret" stuff before posting how to do things.

In any case, I can get the HWND via the User32.dll functions, but it does not accept that, even if I typecast it to the proper type.
0 Kudos
Message 3 of 14
(8,767 Views)
Well, ahem, assuming you can find some way to get the HWND as a 32-bit integer (blush) ...
... and assuming that you have a .NET compiler and know a .NET language, build a .DLL assembly containing a little class like this (I've written it in C# here):

public class Win32Handle
: System.Windows.Forms.IWin32Window
{
private IntPtr m_hwnd;

public Win32Handle( Int32 hwnd )
{
m_hwnd = (IntPtr) hwnd;
}

public System.IntPtr Handle
{
get
{
return m_hwnd;
}
}
}

Then, wire the HWND to a constructor node for one of these jobbies and you'll have a .NET object refnum that you can wire into ShowDialog(owner). I tried it (with FontDialog) and I think it does what you need.
George Erwin-Grotsky
National Instruments
LabVIEW Research & Development
Message 4 of 14
(8,765 Views)
Lucky thing I knew what was going on, otherwise you would have a hell of a time explaining the "oversite" j/k

Back on topic, it looks like you're just doing some typecasting/wrapping. Know of any way to do this within LV.

I thought doing a typecast or a "to more specific type" function would do it, but looks like it spits out the genric 1172 error.

-Norm

~,~ The Captain was here
0 Kudos
Message 5 of 14
(8,760 Views)
I don't think there is a way to do that using LabVIEW. The HWND you get is going to look like a 32-bit integer to LabVIEW. ShowDialog() needs a reference to some class of that implements the IWin32Window interface. The only public class in the .NET framework that implements it is System.Windows.Forms.Control (and classes derived from it, of course), and no constructor is provided that takes an HWND. So there's really no amount of up- or down-casting that will help.
George Erwin-Grotsky
National Instruments
LabVIEW Research & Development
Message 6 of 14
(8,753 Views)
Write a class implementing IWin32Window
from System.Windows.Forms. This class
wraps the call to GetForegroundWindow()
from user32.dll to get a
System.Windows.Forms. IWin32Window
handle instead of a HWND.
Use this handle to set the owner attribute
of the overloaded Method ShowDialog.

using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;

public class ForegroundWindow : IWin32Window
{
    private static ForegroundWindow _window = new ForegroundWindow();
    private ForegroundWindow(){}

    public static IWin32Window Instance
    {
        get { return _window; }
    }

    [DllImport("user32.dll")]
    private static extern IntPtr GetForegroundWindow();

    IntPtr IWin32Window.Handle
    {
        get
        {
            return GetForegroundWindow();
        }
    }
}


Peter Griese
NI
Message 7 of 14
(8,485 Views)
Hello,

I have the same problem with the OpenFileDialog and SaveFileDialog.
The only thing I need is the IWin32Window.Handle for the overloaded ShowDialog(owner) method in order to set the dialog frontmost.
Unfortunately, I have insufficient experience with .NET programming and I don't know how to create that DLL (or class) described above.

Is there no chance to get the needed handle via LabView's own .NET functions?
Or could anybody please give me some advise, how to build the DLL which only returns the IWin32Window.Handle?

Any help would be appreciated!

Tom S.
0 Kudos
Message 8 of 14
(7,931 Views)
Tom,

Attached you will find an example that demonstrates this functionality.  The example first gets the Window Handle of the Front Panel window we'd like to make the parent window, and then accesses a class that can hold the window handle and implement the IWin32Window Interface. We can then use this class as the owner to the ShowDialog method, effectively making the VI Front Panel the parent of the dialog window.  For more detailed information regarding the operation of this example, look at the attached Word document.

Hope this helps!

Brian T
Applications Engineer


Message Edited by Brian_T on 01-08-2008 01:33 PM
Message 9 of 14
(7,901 Views)
Brian,

Thank you very much for your support. The  WindowWrapper.dll is exactly that what I needed! And your example project is also very helpful! Smiley Happy

But now another problem occurred with the .NET FileDialog: If I have multiple patterns as "Filter" (e.g. "All Files (*.*)|*.*|Word-Documents (*.doc)|*.doc") and then I change the file type within the OpenFileDialog (or SaveFileDialog), everything disappears in the listbox of the file dialog (all files and even the folders). Only if I click
subsequently on the open/save button the listbox is filtered properly. I tried several different settings of the properties of the .NET FileDialog but that didn't affect on the inappropriate behavior of the file filter.
What's going wrong with that filter method? Has anyone an idea?

I attached the example project with an OpenFileDialog.

Best regards
Tom S.
0 Kudos
Message 10 of 14
(7,861 Views)