Way to retain focus of transparent form application.
-
In C#, if I make a transparent windows form using transparency key colored "control", then on clicking anywhere on screen(while application is in focus), transfers focus of the app to the one behind it, which is normal behaviour. If I want the application to retain the focus, is it possible to do anyhow ?
-
In C#, if I make a transparent windows form using transparency key colored "control", then on clicking anywhere on screen(while application is in focus), transfers focus of the app to the one behind it, which is normal behaviour. If I want the application to retain the focus, is it possible to do anyhow ?
Use a timer to set focus? Maybe P/Invoke to SetWindowFocus?
Check out the CodeProject forum Guidelines[^] The original soapbox 1.0 is back![^]
-
Use a timer to set focus? Maybe P/Invoke to SetWindowFocus?
Check out the CodeProject forum Guidelines[^] The original soapbox 1.0 is back![^]
I do not want the window to loose focus at all, because user will be drawing on this transparent window. Isn't there a straightforward way to do it, than to hack/tweak things?
-
I do not want the window to loose focus at all, because user will be drawing on this transparent window. Isn't there a straightforward way to do it, than to hack/tweak things?
Did you try setting the topmost property to true?
Check out the CodeProject forum Guidelines[^] The original soapbox 1.0 is back![^]
-
In C#, if I make a transparent windows form using transparency key colored "control", then on clicking anywhere on screen(while application is in focus), transfers focus of the app to the one behind it, which is normal behaviour. If I want the application to retain the focus, is it possible to do anyhow ?
I got this from MSDN before
\[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 { SetActiveWindow(IntPtr.Zero); } } } base.WndProc(ref m); }
I cant find the link for it though so I just found it in my own code found the link[^] :-D
modified on Friday, June 19, 2009 3:39 PM
-
I do not want the window to loose focus at all, because user will be drawing on this transparent window. Isn't there a straightforward way to do it, than to hack/tweak things?
How about skipping all this garbage and taking a screen shot and drawing on that instead. No need to worry about transparency and mouse clicks going to the wrong form at all.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008 -
I got this from MSDN before
\[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 { SetActiveWindow(IntPtr.Zero); } } } base.WndProc(ref m); }
I cant find the link for it though so I just found it in my own code found the link[^] :-D
modified on Friday, June 19, 2009 3:39 PM
This does not work. I tried this one as well as the
[DllImport("user32", CharSet = CharSet.Auto)] private extern static int SendMessage( IntPtr handle, int msg, int wParam, IntPtr lParam); [DllImport("user32", CharSet = CharSet.Auto)] private extern static int PostMessage( IntPtr handle, int msg, int wParam, IntPtr lParam); private const int WM_ACTIVATE = 0x006; private const int WM_ACTIVATEAPP = 0x01C; private const int WM_NCACTIVATE = 0x086; /// <summary> /// Subclasses the owning form's existing Window Procedure to enables the /// title bar to remain active when a popup is show, and to detect if /// the user clicks onto another application whilst the popup is visible. /// </summary> /// <param name="m">Window Procedure Message</param> protected override void WndProc(ref Message m) { // check for WM_ACTIVATEAPP and WM_NCACTIVATE if (m.Msg == WM_NCACTIVATE) { // Check if the title bar will made inactive: if (((int)m.WParam) == 0) { xyz += m.Msg + " "; // If so reactivate it. SendMessage(this.Handle, WM_NCACTIVATE, 1, IntPtr.Zero); // Note it's no good to try and consume this message; // if you try to do that you'll end up with windows // that don't respond. } } else if (m.Msg == WM_ACTIVATEAPP) { // Check if the application is being deactivated. if ((int)m.WParam == 0) { xyz += m.Msg + " "; // And put the title bar into the inactive state: PostMessage(this.Handle, WM_NCACTIVATE, 0, IntPtr.Zero); } } base.WndProc(ref m); }
code. Later code actually does the reverse of what I want, but still it does not work. Neither works. -
How about skipping all this garbage and taking a screen shot and drawing on that instead. No need to worry about transparency and mouse clicks going to the wrong form at all.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008Yes, that's an option I am considering right now. But if I could make it draw directly on screen it would have been much more better. Thanks, Parth
-
Did you try setting the topmost property to true?
Check out the CodeProject forum Guidelines[^] The original soapbox 1.0 is back![^]
Yes, I tried that. It is not effective.
-
Yes, I tried that. It is not effective.
Why doesn't that work?
Regards Senthil [MVP - Visual C#] _____________________________ My Home Page |My Blog | My Articles | My Flickr | WinMacro