Getting a referenvce to a form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

C# is new to me and I don't know how to get a reference to a Form when all I
have is a handle to a Window.

i.e.

hwnd = GetWindow(hwnd, GW_HWNDNEXT);
Form f = ???????????(hwnd);

thanks for any help.
 
Well, just that's not so easy. You are running in a second application and
you want to get a reference to form (assuming that this window is in a
managed forms-based application)? You should not be able to do that.

Tell us *what* you want to do, not *how* you're trying to do it...

Paul T.
 
I'm not trying to tell anyone how to do anything, I'm just trying to
communicate what I want to accomplish in a way that programmers will easily
understand. I guess not so successfully, sorry for the confusion.
I try to be as succinct as I can be because in the past if an answer leads
to a further clarifying question the thread (in my experience anyway) is
ignored.

In any case thanks for you interest to date and any subsequent help.

I want to run in Kiosk mode and for my main form this is working well,
thanks to the sample from Sergey.

What I want to do is run mstse40.exe (Terminal Services Client) and stay in
Kiosk mode for a seamless passover from my app to the terminal services app.
i.e. so that the user simply clicks a single button and waits for the app
running on ts to present itself.

I'm running the following from my main Kiosk form:

private void startMStsc()
{

ProcessStartInfo startInfo;
bool processSwitch;
ProcessEntry[] pe;

lblStatus.Visible = true;
txtStatus.Visible = true;

//--------------------------------------------------
// Kill off Terminal Server Client if it is running
//--------------------------------------------------
pe = ProcessEntry.GetProcesses();

foreach (ProcessEntry x in pe)
{

if (x.ExeFile == "mstsc40.exe")
{
x.Kill();
}

}

processSwitch = true;
startInfo = new ProcessStartInfo();

startInfo.UseShellExecute = processSwitch;
startInfo.FileName = "\\windows\\mstsc40.exe";
startInfo.Arguments = "";

setRadioOn();

// wait for connection
txtStatus.Text = "Waiting for Network";
//+++++++++++++++++++++++++++++++++++++
// connection code goes here
//+++++++++++++++++++++++++++++++++++++
txtStatus.Text = "Connected";

Process.Start(startInfo);
Thread.Sleep(5000); // give tsc some time to load

f = getForm("Terminal Services Client");

//+++++++++++++++++++++++++++++++++++++
// put term service form into kiosk mode
// Note: will have to do this for the ts connection form
// and the ts connected form
//+++++++++++++++++++++++++++++++++++++
}

Again thanks for any help.
 
OK, so, if I understand correctly, you want to hand-off from a full-screen
kiosk application to another application as a result of a UI event in the
kiosk application. I'm not clear on why you want a reference to a form
corresponding to a window in another application, though. You're trying to
get the top-level window for MSTSC and do something to it (what)? If so,
you can certainly get the window handle, but, since MSTSC is not a
Form-based application, you can't somehow wrap a form around it and do
something to it in any sensible way. Use native code calls to operate on
the window, instead. What are you trying to do to it, exactly?

Unlike MFC, where CWnd is really just a thin wrapper around a window handle
and everyone is running in the same run-time environment, that's not the
case so much in managed code. It's conceivable that you might be able to
somehow get your handle stuffed into a Form instance, but I see no benefit
to that which would justify this type of digging into the internals of the
CF.

Paul T.

B. Ron F. said:
I'm not trying to tell anyone how to do anything, I'm just trying to
communicate what I want to accomplish in a way that programmers will
easily
understand. I guess not so successfully, sorry for the confusion.
I try to be as succinct as I can be because in the past if an answer leads
to a further clarifying question the thread (in my experience anyway) is
ignored.

In any case thanks for you interest to date and any subsequent help.

I want to run in Kiosk mode and for my main form this is working well,
thanks to the sample from Sergey.

What I want to do is run mstse40.exe (Terminal Services Client) and stay
in
Kiosk mode for a seamless passover from my app to the terminal services
app.
i.e. so that the user simply clicks a single button and waits for the app
running on ts to present itself.

I'm running the following from my main Kiosk form:

private void startMStsc()
{

ProcessStartInfo startInfo;
bool processSwitch;
ProcessEntry[] pe;

lblStatus.Visible = true;
txtStatus.Visible = true;

//--------------------------------------------------
// Kill off Terminal Server Client if it is running
//--------------------------------------------------
pe = ProcessEntry.GetProcesses();

foreach (ProcessEntry x in pe)
{

if (x.ExeFile == "mstsc40.exe")
{
x.Kill();
}

}

processSwitch = true;
startInfo = new ProcessStartInfo();

startInfo.UseShellExecute = processSwitch;
startInfo.FileName = "\\windows\\mstsc40.exe";
startInfo.Arguments = "";

setRadioOn();

// wait for connection
txtStatus.Text = "Waiting for Network";
//+++++++++++++++++++++++++++++++++++++
// connection code goes here
//+++++++++++++++++++++++++++++++++++++
txtStatus.Text = "Connected";

Process.Start(startInfo);
Thread.Sleep(5000); // give tsc some time to load

f = getForm("Terminal Services Client");

//+++++++++++++++++++++++++++++++++++++
// put term service form into kiosk mode
// Note: will have to do this for the ts connection form
// and the ts connected form
//+++++++++++++++++++++++++++++++++++++
}

Again thanks for any help.



Paul G. Tobey said:
Well, just that's not so easy. You are running in a second application
and
you want to get a reference to form (assuming that this window is in a
managed forms-based application)? You should not be able to do that.

Tell us *what* you want to do, not *how* you're trying to do it...

Paul T.
 
Thanks for your interest Paul.
OK, so, if I understand correctly, you want to hand-off from a full-screen
kiosk application to another application as a result of a UI event in the
kiosk application

---------------------------------------------------------
Maybe a form reference is not what I want.
---------------------------------------------------------
You're trying to
get the top-level window for MSTSC and do something to it (what)?

------------------------------------------------------------------
I want to:

1. keep users from having access to the toolbar.
2. keep users from having access to the menubar.
(by menubar I mean the strip accross the bottom of the screen)
3. let the application that runs on the terminal server use the entire iPaq
screen.
------------------------------------------------------------------
If so, you can certainly get the window handle

------------------------------------
Yes I've been able to do that.
------------------------------------
Use native code calls to operate on the window, instead.

I've been trying that see below:

Process.Start(startInfo); // start the ts process
Thread.Sleep(3000); // give ts some time to load

IntPtr hndNewProc = FindWindow(null, "Terminal Services Client");

IntPtr tb = FindWindow("HHTaskBar", null);
IntPtr i = ShowWindow(tb, SW_HIDE);
bool b = EnableWindow(tb, enabled);

SHFullScreen(hndNewProc, SHFS_HIDESIPBUTTON);
SHFullScreen(hndNewProc, SHFS_HIDESTARTICON);


SetWindowPos(hndNewProc, 0, 0, 0, 240, 340, SWP_SHOWWINDOW);

In debug mode if I stop right after the last line the ts window is exactly
the way I want it with the exception of a blue (windows default color)
menubar accros the bottom of the screen. The menubar displays no controls.
However when I allow the code to run without stopping the ts window very
briefly displays the way I want and then displays a bar above and below the
screen area.
The bar above (in the toolbar area) displays the top of the main kiosk
screen and below is still the blue bar.
When I connect to the terminal server the app does not have access to the
toolbar/menubar areas.

Thanks for any help.




Paul G. Tobey said:
OK, so, if I understand correctly, you want to hand-off from a full-screen
kiosk application to another application as a result of a UI event in the
kiosk application. I'm not clear on why you want a reference to a form
corresponding to a window in another application, though. You're trying to
get the top-level window for MSTSC and do something to it (what)? If so,
you can certainly get the window handle, but, since MSTSC is not a
Form-based application, you can't somehow wrap a form around it and do
something to it in any sensible way. Use native code calls to operate on
the window, instead. What are you trying to do to it, exactly?

Unlike MFC, where CWnd is really just a thin wrapper around a window handle
and everyone is running in the same run-time environment, that's not the
case so much in managed code. It's conceivable that you might be able to
somehow get your handle stuffed into a Form instance, but I see no benefit
to that which would justify this type of digging into the internals of the
CF.

Paul T.

B. Ron F. said:
I'm not trying to tell anyone how to do anything, I'm just trying to
communicate what I want to accomplish in a way that programmers will
easily
understand. I guess not so successfully, sorry for the confusion.
I try to be as succinct as I can be because in the past if an answer leads
to a further clarifying question the thread (in my experience anyway) is
ignored.

In any case thanks for you interest to date and any subsequent help.

I want to run in Kiosk mode and for my main form this is working well,
thanks to the sample from Sergey.

What I want to do is run mstse40.exe (Terminal Services Client) and stay
in
Kiosk mode for a seamless passover from my app to the terminal services
app.
i.e. so that the user simply clicks a single button and waits for the app
running on ts to present itself.

I'm running the following from my main Kiosk form:

private void startMStsc()
{

ProcessStartInfo startInfo;
bool processSwitch;
ProcessEntry[] pe;

lblStatus.Visible = true;
txtStatus.Visible = true;

//--------------------------------------------------
// Kill off Terminal Server Client if it is running
//--------------------------------------------------
pe = ProcessEntry.GetProcesses();

foreach (ProcessEntry x in pe)
{

if (x.ExeFile == "mstsc40.exe")
{
x.Kill();
}

}

processSwitch = true;
startInfo = new ProcessStartInfo();

startInfo.UseShellExecute = processSwitch;
startInfo.FileName = "\\windows\\mstsc40.exe";
startInfo.Arguments = "";

setRadioOn();

// wait for connection
txtStatus.Text = "Waiting for Network";
//+++++++++++++++++++++++++++++++++++++
// connection code goes here
//+++++++++++++++++++++++++++++++++++++
txtStatus.Text = "Connected";

Process.Start(startInfo);
Thread.Sleep(5000); // give tsc some time to load

f = getForm("Terminal Services Client");

//+++++++++++++++++++++++++++++++++++++
// put term service form into kiosk mode
// Note: will have to do this for the ts connection form
// and the ts connected form
//+++++++++++++++++++++++++++++++++++++
}

Again thanks for any help.



Paul G. Tobey said:
Well, just that's not so easy. You are running in a second application
and
you want to get a reference to form (assuming that this window is in a
managed forms-based application)? You should not be able to do that.

Tell us *what* you want to do, not *how* you're trying to do it...

Paul T.

C# is new to me and I don't know how to get a reference to a Form when
all
I
have is a handle to a Window.

i.e.

hwnd = GetWindow(hwnd, GW_HWNDNEXT);
Form f = ???????????(hwnd);

thanks for any help.
 
OK, what it *sounds* like to me is the TSC seeing a size change of its main
window and making sure that it's the size it wants to be, which, it appears,
is not the full-size that you've tried to set it to be. I don't have a
device in my office right now with TSC on it. Does it have an option to run
full-screen? If so, you might set that option, which I'm sure would be
stored in the registry, before launching the TSC. You might also try doing
the changes to the task bar, etc. *before* launching TSC, if you haven't
done that already.

I think you can safely forget all about trying to build a Form instance to
wrap the window handle of the TSC.

Paul T.

B. Ron F. said:
Thanks for your interest Paul.
OK, so, if I understand correctly, you want to hand-off from a
full-screen
kiosk application to another application as a result of a UI event in the
kiosk application

---------------------------------------------------------
Maybe a form reference is not what I want.
---------------------------------------------------------
You're trying to
get the top-level window for MSTSC and do something to it (what)?

------------------------------------------------------------------
I want to:

1. keep users from having access to the toolbar.
2. keep users from having access to the menubar.
(by menubar I mean the strip accross the bottom of the screen)
3. let the application that runs on the terminal server use the entire
iPaq
screen.
------------------------------------------------------------------
If so, you can certainly get the window handle

------------------------------------
Yes I've been able to do that.
------------------------------------
Use native code calls to operate on the window, instead.

I've been trying that see below:

Process.Start(startInfo); // start the ts process
Thread.Sleep(3000); // give ts some time to load

IntPtr hndNewProc = FindWindow(null, "Terminal Services
Client");

IntPtr tb = FindWindow("HHTaskBar", null);
IntPtr i = ShowWindow(tb, SW_HIDE);
bool b = EnableWindow(tb, enabled);

SHFullScreen(hndNewProc, SHFS_HIDESIPBUTTON);
SHFullScreen(hndNewProc, SHFS_HIDESTARTICON);


SetWindowPos(hndNewProc, 0, 0, 0, 240, 340, SWP_SHOWWINDOW);

In debug mode if I stop right after the last line the ts window is exactly
the way I want it with the exception of a blue (windows default color)
menubar accros the bottom of the screen. The menubar displays no controls.
However when I allow the code to run without stopping the ts window very
briefly displays the way I want and then displays a bar above and below
the
screen area.
The bar above (in the toolbar area) displays the top of the main kiosk
screen and below is still the blue bar.
When I connect to the terminal server the app does not have access to the
toolbar/menubar areas.

Thanks for any help.




Paul G. Tobey said:
OK, so, if I understand correctly, you want to hand-off from a
full-screen
kiosk application to another application as a result of a UI event in the
kiosk application. I'm not clear on why you want a reference to a form
corresponding to a window in another application, though. You're trying
to
get the top-level window for MSTSC and do something to it (what)? If so,
you can certainly get the window handle, but, since MSTSC is not a
Form-based application, you can't somehow wrap a form around it and do
something to it in any sensible way. Use native code calls to operate on
the window, instead. What are you trying to do to it, exactly?

Unlike MFC, where CWnd is really just a thin wrapper around a window
handle
and everyone is running in the same run-time environment, that's not the
case so much in managed code. It's conceivable that you might be able to
somehow get your handle stuffed into a Form instance, but I see no
benefit
to that which would justify this type of digging into the internals of
the
CF.

Paul T.

B. Ron F. said:
I'm not trying to tell anyone how to do anything, I'm just trying to
communicate what I want to accomplish in a way that programmers will
easily
understand. I guess not so successfully, sorry for the confusion.
I try to be as succinct as I can be because in the past if an answer
leads
to a further clarifying question the thread (in my experience anyway)
is
ignored.

In any case thanks for you interest to date and any subsequent help.

I want to run in Kiosk mode and for my main form this is working well,
thanks to the sample from Sergey.

What I want to do is run mstse40.exe (Terminal Services Client) and
stay
in
Kiosk mode for a seamless passover from my app to the terminal services
app.
i.e. so that the user simply clicks a single button and waits for the
app
running on ts to present itself.

I'm running the following from my main Kiosk form:

private void startMStsc()
{

ProcessStartInfo startInfo;
bool processSwitch;
ProcessEntry[] pe;

lblStatus.Visible = true;
txtStatus.Visible = true;

//--------------------------------------------------
// Kill off Terminal Server Client if it is running
//--------------------------------------------------
pe = ProcessEntry.GetProcesses();

foreach (ProcessEntry x in pe)
{

if (x.ExeFile == "mstsc40.exe")
{
x.Kill();
}

}

processSwitch = true;
startInfo = new ProcessStartInfo();

startInfo.UseShellExecute = processSwitch;
startInfo.FileName = "\\windows\\mstsc40.exe";
startInfo.Arguments = "";

setRadioOn();

// wait for connection
txtStatus.Text = "Waiting for Network";
//+++++++++++++++++++++++++++++++++++++
// connection code goes here
//+++++++++++++++++++++++++++++++++++++
txtStatus.Text = "Connected";

Process.Start(startInfo);
Thread.Sleep(5000); // give tsc some time to load

f = getForm("Terminal Services Client");

//+++++++++++++++++++++++++++++++++++++
// put term service form into kiosk mode
// Note: will have to do this for the ts connection form
// and the ts connected form
//+++++++++++++++++++++++++++++++++++++
}

Again thanks for any help.



:

Well, just that's not so easy. You are running in a second
application
and
you want to get a reference to form (assuming that this window is in a
managed forms-based application)? You should not be able to do that.

Tell us *what* you want to do, not *how* you're trying to do it...

Paul T.

C# is new to me and I don't know how to get a reference to a Form
when
all
I
have is a handle to a Window.

i.e.

hwnd = GetWindow(hwnd, GW_HWNDNEXT);
Form f = ???????????(hwnd);

thanks for any help.
 
Back
Top