sam,
I don't think this is possible. Back in the time of win16 applications there
was a "system modal" style dialogs. They was meant to be used exactly for
this. However this style was deprecated for Win32 because such application
may cause the whole system to lock up. Actually Windows tries to make sure
that any application can be deactivated so the control cannot be taken over.
Speaking of .NET there is no even managed solution for activating an
application. If one wants to do that one needs to resort to using PInvoke
and calling Win32 API methods.
I played little bit with this and the following is the code I get not too
bad results with. To play with this code create new empty winforms project,
set the TopMost property of the form to *true*, copy and paste this code
into the form's class, add a timer (timer1) and hook its Tick event to the
timer1_Tick method. You shold add *using* clause for
System.Runtime.InteropServices namespace.
private const int WM_ACTIVATEAPP = 0x001C;
[DllImportAttribute( "User32.dll" )]
private static extern int SetForegroundWindow( IntPtr hWnd );
protected override void WndProc(ref Message m)
{
base.WndProc (ref m);
if(m.Msg == WM_ACTIVATEAPP && ((int)m.WParam) == 0)
{
this.timer1.Interval = 1;
this.timer1.Start();
}
}
private void timer1_Tick(object sender, System.EventArgs e)
{
this.timer1.Enabled = false;
SetForegroundWindow(this.Handle);
}
Using timer may look wierd, but my tests show that we need to give windows
some time after sending WM_ACTIVATEAPP to set up all the active/inactive
window stuff otherwise the result is not as good.
Again keep in mind that this is not the best solution possible. I believe
better results can be achieved installing WH_CBT hook. The problem is that
global CBT hook cannot be written in managed code, therefore the hook needs
to be written in native code and compiled in native DLL then the hook can
control activating and deactivating windows.
BTW why don't you create a full screen application that covers the whole
desktop. This way at least you can make activating via mouse clicks
inconvenient.
--
Stoitcho Goutsev (100) [C# MVP].
"sam" <s@s.com> wrote in message
news:e4****************@TK2MSFTNGP15.phx.gbl...
Yes, window that can never be hidden and lose focus. In another words i
want
focus on my window form1 for all times even if mouse clicks on other
windows, focus should be on the window form1.
I hope it will be clear to u
cheers,
Sam
"vooose" <no****@microsoft.com> schreef in bericht
news:O4**************@TK2MSFTNGP12.phx.gbl... What do you mean by "constant focus"? Is that a window that can never be
hidden? (ie shows on top of other windows regardless)
--
Wal
http://www.vooose.com
*** Sent via Developersdex http://www.developersdex.com ***