is it possible to minimize iX or alt-tab?

Discussion of application development using iX Developer, including but not limited to getting started, using the functions tab, properties, objects and installation.
Post Reply
mmarchese
Posts: 13
Joined: Mon Mar 11, 2013 11:00 am

is it possible to minimize iX or alt-tab?

Post by mmarchese »

I have a T10A HMI running iX. On the same machine, I have a Cognex vision system. I was able to install Cognex's VisionView software on the T10A HMI, and launch it from my iX interface. Once it's running, I can minimize it or put it behind iX, but once I do that, I can't get it back in front.

I need to be able to minimize iX or do an alt-tab type of action to switch which window is on top. Anyone know if such a thing is possible?

mmarchese
Posts: 13
Joined: Mon Mar 11, 2013 11:00 am

Re: is it possible to minimize iX or alt-tab?

Post by mmarchese »

After posting, I searched more and found this thread, which is exactly what I need (Edmund's post at the bottom).

http://ixtalk.beijerelectronics.us/view ... ocus#p2726

But I have a panel rather than a PC, so that code doesn't work for me. I also don't know what the name of the process is, but I'll see if I can figure it out.

User avatar
Edmund
Posts: 92
Joined: Thu Nov 29, 2012 2:27 pm

Re: is it possible to minimize iX or alt-tab?

Post by Edmund »

Well here is a example for Windows CE.

It starts Wordpad (builtin in the panel), or if it´s running it will put it to foreground.

Try to replace it with the Cognex software.

Code: Select all

namespace Neo.ApplicationFramework.Generated
{
    using System.Windows.Forms;
    using System;
    using System.Drawing;
    using Neo.ApplicationFramework.Tools;
    using Neo.ApplicationFramework.Common.Graphics.Logic;
    using Neo.ApplicationFramework.Controls;
    using Neo.ApplicationFramework.Interfaces;
	using System.Diagnostics;
	using System.Runtime.InteropServices;
    using System.Reflection;
    using System.Collections;
    using System.Windows;

    public partial class Screen1
    {
		
		[DllImport("coredll.dll", EntryPoint="SetForegroundWindow")]
		private static extern int SetForegroundWindow(IntPtr hWnd);
		
		[DllImport("coredll.dll")]
		private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
		
		[DllImport("coredll.dll",CallingConvention = CallingConvention.Winapi,CharSet = CharSet.Auto)]
			static extern bool CreateProcess(
			string lpApplicationName,
			string lpCommandLine,
			IntPtr lpProcessAttributes,
			IntPtr lpThreadAttributes,
			bool bInheritHandles,
			uint dwCreationFlags,
			IntPtr lpEnvironment,
			string lpCurrentDirectory,
			IntPtr lpStartupInfo,
			out ProcessInfo lpProcessInformation
		);
		
		[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
		public struct ProcessInfo
		{
			public IntPtr hProcess;
			public IntPtr hThread;
			public Int32 ProcessId;
			public Int32 ThreadId;
		}

		[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
		public struct SecurityAttributes
		{
			public int length;
			public IntPtr lpSecurityDescriptor;
			public bool bInheritHandle;
		}

		[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
		public struct StartupInfo
		{
			public uint cb;
			public string lpReserved;
			public string lpDesktop;
			public string lpTitle;
			public uint dwX;
			public uint dwY;
			public uint dwXSize;
			public uint dwYSize;
			public uint dwXCountChars;
			public uint dwYCountChars;
			public uint dwFillAttribute;
			public uint dwFlags;
			public short wShowWindow;
			public short cbReserved2;
			public IntPtr lpReserved2;
			public IntPtr hStdInput;
			public IntPtr hStdOutput;
			public IntPtr hStdError;
		}

		
		
		void Button1_Click(System.Object sender, System.EventArgs e)
		{			
			IntPtr windowHandle = FindWindow("Wordpad", null);
			if(windowHandle.ToInt32() > 0)
				SetForegroundWindow(windowHandle);
			else
			{
				ProcessInfo pi;
				
				CreateProcess(
					"pword.exe",
					null,
					IntPtr.Zero,
					IntPtr.Zero,
					false,
					0,
					IntPtr.Zero,
					null,
					IntPtr.Zero, 
					out pi
					);	
			}
		}
    }
}

Best Regards
Edmund Andersson

AITECH AB

Part of Beijer Integrator Group

mmarchese
Posts: 13
Joined: Mon Mar 11, 2013 11:00 am

Re: is it possible to minimize iX or alt-tab?

Post by mmarchese »

Edmund, you are a force to be reckoned with. Thanks so much for all that code!

After some trial and error, the window-switching part of the code is working great:

Code: Select all

IntPtr windowHandle = FindWindow(null, "VisionView");
         if(windowHandle.ToInt32() > 0)
            SetForegroundWindow(windowHandle);
The program-launching part of the code is where I am still struggling a bit. I don't know how change what you wrote to launch my process, but maybe we can do it a different way. Right now, I have a separate button that launches the program with a click action like this:

Action: Run
Executable: \FlashDrive\VisionView\VisionView.exe
Arguments: -bounds:0,0,640,430 -nottopmost -nominimize

What would be the equivalent script code?

User avatar
Edmund
Posts: 92
Joined: Thu Nov 29, 2012 2:27 pm

Re: is it possible to minimize iX or alt-tab?

Post by Edmund »

mmarchese wrote:Edmund, you are a force to be reckoned with. Thanks so much for all that code!
Thank you mmarchese ;)

Hmm let´s see if we can figure this out together...

The function CreateProcess in coredll.dll has alot of arguments passed to it.

The first argument is the application to start (*.exe) so in your case it would be

"\\FlashDrive\\VisionView\\VisionView.exe", sience it been installed it could work just by calling "VisionView.exe"...

The second parameter is the argument being send to the application at startup (Main Args), in the previus example we didn´t pass anyting on (then wordpad starts with a new document).

So try add "-bounds:0,0,640,430 -nottopmost -nominimize" there....

So now we got the following

Code: Select all

	ProcessInfo pi;
				
	CreateProcess(
		"\\FlashDrive\\VisionView\\VisionView.exe",
		"-bounds:0,0,640,430 -nottopmost -nominimize",
		IntPtr.Zero,
		IntPtr.Zero,
		false,
		0,
		IntPtr.Zero,
		null,
		IntPtr.Zero, 
		out pi
	);	

Try it and see what happends...

Best Regards
Edmund Andersson

AITECH AB

Part of Beijer Integrator Group

mmarchese
Posts: 13
Joined: Mon Mar 11, 2013 11:00 am

Re: is it possible to minimize iX or alt-tab?

Post by mmarchese »

Success! Thanks again, Edmund!

Here is some more information for future readers of this topic who want to know why you would do this in the first place:

It is possible to open VisionView (or whatever program you are using) from iX with a button (as described in my earlier post) and then just close that program when you want to go back to your regular iX interface. The problem with that method is that it can take a long time to open the program (30 seconds in this case), whereas leaving it running and just bringing it to the front only takes a 1-2 seconds.

To switch back from your secondary program to iX, you can launch the secondary program at something smaller than full-screen size so that you can touch the part of your iX interface that is still showing to bring it to the front. I'm sure there are other ways, but that's what I'm doing.

Post Reply