How to set a C # form never be focused?

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)
 
T

Timothy

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.
 
J

JamesDastard

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top