I'm working on a project where I want to be able to click on a form but not have the form keep focus. Although not what I'm working on at the moment but the Windows On Screen Keyboard is a good example. The OSK when clicked on doesn't take focus, but keeps the focus on the control that had the focus before. It does this but still is able to proccess an onclick event and send the keystroke over to the control that has focus.
I'm needing to do something similar. I've tried overriding the onActivate method but it seems by then the form has already taken focus.
Any help is appreciated.

How to prevent a form from being activated/gaining focus.
PauloPina
-I create a form and call show() from the form I don't want to be activated.
-There are other Windows that have the TopMost property set to true.
I'm mainly concerned with the first one. I have another form that I'm creating from the main form that has some buttons on it. I want this to never loose focus from clicking on the main form.
I'm getting really close, I can feel it. Can anyone shed some light on this last problem
Thanks everyone for the help thus far.
Bryan Chriscoli
[DllImport("user32.dll")]
static extern IntPtr SetActiveWindow(IntPtr hWnd);
protected override void WndProc(ref System.Windows.Forms.Message m)
{
if (m.Msg == 0x001C && m.WParam.ToInt32() == 1)
{
SetActiveWindow(m.LParam);
}
else
{
base.WndProc(ref m);
}
}
But the window isn't being reactivated. I've stepped through the code and it is getting to the SetActiveWindow call but the other form is never reactivated. Any ideas as to what I might be doing wrong
I'm not at all familiar with subclassing using Windows hooks any additional info would be great.
Is there some way to override the mouse down event
Hydra20010
You might be able to do something like this by overridding the WndProc method in the Form.
The message you care about is WM_ACTIVATEAPP (0x001C) The WParam property in the Message is either 0 or 1 indicating deactivation or activation respectively. The LParam property contains the IntPtr identifier for the thread of the window being deactivated.
The problem is that I think this occurs at activation and you cannot stop it from activating. However, you can use the value from LParam to reactivate the original window. I'm not exactly sure how to do that, but the SetActiveWindow API comes to mind.
Subclassing using Windows hooks also comes to mind as a possibility. I hope this gives you enough information at least to find the answer you want.
Jeff Windsor
That only helps if you are displaying the window, that doesn't prevent the form from being activated when you click on it.
Robert Darwin
http://www.dotnet247.com/247reference/msgs/29/147917.aspx
Anyone familiar with what he is talking about
mrgilbe1
Oh sorry, i guess i missed the part mention that you don't want to get it activated when you click on it..
jefftardif
Also, PJ. van de Sande, could you please explain how this line works:
if(((int)m.WParam & 0xFFFF) != WA_INACTIVE)
I'd like to know how that works.
Thanks
smitten94
BP01-SQL Admin
Hello,
Maybe this article can help you:
Use .NET Forms as Popup Windows
http://www.vbaccelerator.com/home/NET/Code/Controls/Popup_Windows/Popup_Windows/article.asp
John.
JonathanCox
[DllImport("user32.dll")][DllImport("user32.dll")]
private extern static IntPtr SetActiveWindow(IntPtr handle);
private const int WM_ACTIVATE = 6;
private const int WA_INACTIVE = 0;
protected override void WndProc(ref Message m)
{
if(m.Msg == WM_ACTIVATE)
{
if(((int)m.WParam & 0xFFFF) != WA_INACTIVE)
{
if(m.LParam != IntPtr.Zero)
{
SetActiveWindow(m.LParam);
}
else
{
// Could not find sender, just in-activate it.
SetActiveWindow( IntPtr.Zero );
}
}
}
base.WndProc(ref m);
}