I have a program that we use inhouse and it needs to keep the focus. I have the below code in a timer and the first time it fires it appears to switch my program back to the active application, but after that it doesnt work even though it is calling the
function. Does anyone see any problem or is there a different way I need to do this?
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; const <span style="color:Blue; int nChars = 256;
<span style="color:Blue; int handle = 0;
StringBuilder Buff = <span style="color:Blue; new StringBuilder(nChars);
handle = GetForegroundWindow();
<span style="color:Blue; if ( GetWindowText(handle, Buff, nChars) > 0 )
{
<span style="color:Blue; string WindowCaption = Buff.ToString();
<span style="color:Blue; int WindowID = handle;
<span style="color:Blue; if (WindowID!=<span style="color:Blue; this.Handle.ToInt32())
{
<span style="color:Green; // This is not the active window so lets make it active
SetActiveWindow(<span style="color:Blue; this.Handle.ToInt32());
}
}
[/code]
View the full article
function. Does anyone see any problem or is there a different way I need to do this?
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; const <span style="color:Blue; int nChars = 256;
<span style="color:Blue; int handle = 0;
StringBuilder Buff = <span style="color:Blue; new StringBuilder(nChars);
handle = GetForegroundWindow();
<span style="color:Blue; if ( GetWindowText(handle, Buff, nChars) > 0 )
{
<span style="color:Blue; string WindowCaption = Buff.ToString();
<span style="color:Blue; int WindowID = handle;
<span style="color:Blue; if (WindowID!=<span style="color:Blue; this.Handle.ToInt32())
{
<span style="color:Green; // This is not the active window so lets make it active
SetActiveWindow(<span style="color:Blue; this.Handle.ToInt32());
}
}
[/code]
View the full article