How to set a C # form never be focused?

  • Thread starter Thread starter James
  • Start date Start date
J

James

Hello all,

Here comes a C# Form focus controlling question.

I write a C# program that only contains a form and will attach to a
general process when I execute it, (e.g.: Notepad.exe) Now, the C# form
can display successfully without stealing the focus from the Notepad
process, i.e. show-no-activate, by using [DllImport( "user32.dll" ) ]
and call the SetWindowPos as follows:

{{{
SetWindowPos( handle, (IntPtr) HWND_TOPMOST, 0, 0, 0, 0,
SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE | SWP_SHOWWINDOW );
form.Visible = true;
}}}

My planned next step is to prevent the C# form from getting the focus
when I click on it. That is, it is hoped that the focus should be
always on the attached application such as Notepad. Does anyone know
how to do that?



James S. Jan
(e-mail address removed)
 
If I read correctly, you want to have a form that cannot be clicked on. I
wanted to do the same thing! Good for you I found out :)

SetWindowLong(form.Handle, GWL_EXSTYLE, WS_EX_TRANSPARENT |
GetWindowLongPtr(form.Handle, GWL_EXSTYLE).ToInt32() |
WS_EX_LAYERED);

I hope that it still works and its the answer to your question :P Keep in
mind tho, it won't work with Windows Vista.
 
Dear Timothy,

Thanks for the help. It works!!

Now I have a further work, that is to allow a form with a button still
be clickable,
but this form will be never focused. In other words, the form just as
the same as a
general form but only has little difference which is the form can't be
focused.

Is there any method allow me to do this?


James Jan
 
Back
Top