By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,567 Members | 1,609 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,567 IT Pros & Developers. It's quick & easy.

Calling ALT-TAB

P: n/a
I have an application that runs full screen on a system and I would like to
be able to (at times) switch another program using an ALT-TAB like
interface. However the system only has a touchscreen display so doing this
from a keyboard is not an option. Is there any way I can instantiate the
built in ALT-TAB window or is there any way I can generate the ALT-TAB
event/message progammatically.

Thanks for any help.
Chris
Nov 16 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Interesting. I vaguely remember doing something similar in VB6 so I
could use SendKeys to populate fields in another application.
Unfortunately, that was quite some time ago, and in the wrong
language, but at least it is possible to do a similar thing.

IIRC, I had to check the title parameter of the currently running
windows, decide which to switch to, and then run the switch.

I know it's not a lot of use to you, but at least now you know it can
be done.

On Thu, 3 Mar 2005 08:27:51 -0500, "Chris Mason" <te******@gmail.com>
wrote:
I have an application that runs full screen on a system and I would like to
be able to (at times) switch another program using an ALT-TAB like
interface. However the system only has a touchscreen display so doing this
from a keyboard is not an option. Is there any way I can instantiate the
built in ALT-TAB window or is there any way I can generate the ALT-TAB
event/message progammatically.

Thanks for any help.
Chris


Nov 16 '05 #2

P: n/a
Hi,

You will have to PInvoke, first you need to get the handle of the target
window, then you need to give it focus.

Here is some code:

[DllImport("coredll",EntryPoint="FindWindow")]
public static extern IntPtr FindWindow(string lpClassName,string
lpWindowName);

[DllImport("coredll",EntryPoint="SetForegroundWindo w")]
public static extern bool SetForegroundWindow(IntPtr hWnd);
//this is how you use it

IntPtr mainwin = FindWindow(null, "Product Details");

if(! mainwin.Equals(new System.IntPtr(0)))
{
//Ask for login/Password
SetForegroundWindow(mainwin);
}
cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Chris Mason" <te******@gmail.com> wrote in message
news:u2**************@tk2msftngp13.phx.gbl...
I have an application that runs full screen on a system and I would like to
be able to (at times) switch another program using an ALT-TAB like
interface. However the system only has a touchscreen display so doing
this
from a keyboard is not an option. Is there any way I can instantiate the
built in ALT-TAB window or is there any way I can generate the ALT-TAB
event/message progammatically.

Thanks for any help.
Chris

Nov 16 '05 #3

P: n/a
hi,

sorry, I took the declarations from the pocketpc app, the correct dll to
import is user32.dll no coredll.dl

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> wrote
in message news:e8****************@TK2MSFTNGP15.phx.gbl...
Hi,

You will have to PInvoke, first you need to get the handle of the target
window, then you need to give it focus.

Here is some code:

[DllImport("coredll",EntryPoint="FindWindow")]
public static extern IntPtr FindWindow(string lpClassName,string
lpWindowName);

[DllImport("coredll",EntryPoint="SetForegroundWindo w")]
public static extern bool SetForegroundWindow(IntPtr hWnd);
//this is how you use it

IntPtr mainwin = FindWindow(null, "Product Details");

if(! mainwin.Equals(new System.IntPtr(0)))
{
//Ask for login/Password
SetForegroundWindow(mainwin);
}
cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Chris Mason" <te******@gmail.com> wrote in message
news:u2**************@tk2msftngp13.phx.gbl...
I have an application that runs full screen on a system and I would like
to
be able to (at times) switch another program using an ALT-TAB like
interface. However the system only has a touchscreen display so doing
this
from a keyboard is not an option. Is there any way I can instantiate the
built in ALT-TAB window or is there any way I can generate the ALT-TAB
event/message progammatically.

Thanks for any help.
Chris


Nov 16 '05 #4

P: n/a
Well the SendKeys method looks like it has some hope. A couple of small
issues though. The first is that when the alt-tab window comes up, it just
goes right away. It does not stay for any length of period. Do you know if
there is a way to send the key and have it stay until the user selects a
program from the list. SendKeys.SendWait() did not seem to help either.

The second problem was that the alt-tab window would only come up if I had
another window such as a messagebox come up after it. Otherwise nothing
would have happened. Any idea what may be causing that?

Thanks again

"Marc Jennings" <Ma**********@community.nospam> wrote in message
news:7l********************************@4ax.com...
Interesting. I vaguely remember doing something similar in VB6 so I
could use SendKeys to populate fields in another application.
Unfortunately, that was quite some time ago, and in the wrong
language, but at least it is possible to do a similar thing.

IIRC, I had to check the title parameter of the currently running
windows, decide which to switch to, and then run the switch.

I know it's not a lot of use to you, but at least now you know it can
be done.

On Thu, 3 Mar 2005 08:27:51 -0500, "Chris Mason" <te******@gmail.com>
wrote:
I have an application that runs full screen on a system and I would like tobe able to (at times) switch another program using an ALT-TAB like
interface. However the system only has a touchscreen display so doing thisfrom a keyboard is not an option. Is there any way I can instantiate the
built in ALT-TAB window or is there any way I can generate the ALT-TAB
event/message progammatically.

Thanks for any help.
Chris

Nov 16 '05 #5

P: n/a
Thanks for the suggestions, but it is not quite what I need. The problem is
that I do not know what the other program that I am going to be changing
focus is. It could be any application. And I was trying to avoid having to
go through and enumerate all the windows that are open, put them in a box
for the user to choose from, and then make the switch... especially when
windows does all that for me when I figure out how to tap into that :)

Chris

"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> wrote
in message news:ue**************@TK2MSFTNGP15.phx.gbl...
hi,

sorry, I took the declarations from the pocketpc app, the correct dll to
import is user32.dll no coredll.dl

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> wrote in message news:e8****************@TK2MSFTNGP15.phx.gbl...
Hi,

You will have to PInvoke, first you need to get the handle of the target
window, then you need to give it focus.

Here is some code:

[DllImport("coredll",EntryPoint="FindWindow")]
public static extern IntPtr FindWindow(string lpClassName,string
lpWindowName);

[DllImport("coredll",EntryPoint="SetForegroundWindo w")]
public static extern bool SetForegroundWindow(IntPtr hWnd);
//this is how you use it

IntPtr mainwin = FindWindow(null, "Product Details");

if(! mainwin.Equals(new System.IntPtr(0)))
{
//Ask for login/Password
SetForegroundWindow(mainwin);
}
cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Chris Mason" <te******@gmail.com> wrote in message
news:u2**************@tk2msftngp13.phx.gbl...
I have an application that runs full screen on a system and I would like
to
be able to (at times) switch another program using an ALT-TAB like
interface. However the system only has a touchscreen display so doing
this
from a keyboard is not an option. Is there any way I can instantiate the built in ALT-TAB window or is there any way I can generate the ALT-TAB
event/message progammatically.

Thanks for any help.
Chris



Nov 16 '05 #6

P: n/a
If you want to emulate the behaviour of ALT+TAB key combination just like if
you're pressing and holding the keys, you can use PInvoke calling the
keybd_event() API, instead of using the SendKeys class. The API provides
more possibilities to send keystrokes and emulate keystroke behaviour.

Here is an example for your situation:

[DllImport("user32")]
public static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int
dwExtraInfo);
private const byte VK_MENU = 0x12;
private const byte VK_TAB = 0x09;
private const int KEYEVENTF_EXTENDEDKEY = 0x01;
private const int KEYEVENTF_KEYUP = 0x02;

private void button1_Click(object sender, System.EventArgs e)
{
keybd_event(VK_MENU,0,0,0);
keybd_event(VK_TAB,0,0,0);
System.Threading.Thread.Sleep(1000);
keybd_event(VK_TAB,0,0,0);
System.Threading.Thread.Sleep(1000);
keybd_event(VK_MENU,0,KEYEVENTF_KEYUP,0);
keybd_event(VK_MENU,0,KEYEVENTF_KEYUP,0);
}

Hope it helps.

-- Ricky Lee
==================================================
^o^ "When all doors are closed, God will open a Windows" ^o^
==================================================
"Chris Mason" <te******@gmail.com> wrote in message
news:u2**************@tk2msftngp13.phx.gbl...
I have an application that runs full screen on a system and I would like to be able to (at times) switch another program using an ALT-TAB like
interface. However the system only has a touchscreen display so doing this from a keyboard is not an option. Is there any way I can instantiate the
built in ALT-TAB window or is there any way I can generate the ALT-TAB
event/message progammatically.

Thanks for any help.
Chris

Nov 16 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.