Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / November 2006

Tip: Looking for answers? Try searching our database.

How to set a C # form never be focused?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
James - 17 Oct 2006 08:54 GMT
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
shihyi@iis.sinica.edu.tw
Timothy - 20 Oct 2006 08:36 GMT
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.

> Hello all,
>
[quoted text clipped - 19 lines]
> James S. Jan
> shihyi@iis.sinica.edu.tw
JamesDastard@gmail.com - 15 Nov 2006 07:41 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.