Article ID: 943453 - View products that this article applies to.
RAPID PUBLISHING ARTICLES PROVIDE INFORMATION DIRECTLY FROM WITHIN THE MICROSOFT SUPPORT ORGANIZATION. THE INFORMATION CONTAINED HEREIN IS CREATED IN RESPONSE TO EMERGING OR UNIQUE TOPICS, OR IS INTENDED SUPPLEMENT OTHER KNOWLEDGE BASE INFORMATION.
A Windows Forms application is run on a desktop with no existing windows (for example, a screen saver).
A "GDI+ Window" appears and is set as the foreground window. Keyboard input does not go to the application's window.
The Windows Forms library initializes GDI+ to do its drawing when it starts. GDI
()+ spawns a worker thread on which it creates a hidden message-only window
()"). If this "GDI+ Window" is the first window created on a desktop then the "GDI+ Window" will be set as the foreground window. Since the "GDI+ Window" is created on a separate thread, there is a race condition whether it is created first or the application's main window is created first.
Set the application's window as the foreground window after it has been created by calling the Win32 function SetForegroundWindow() and passing in the window's handle. This can be done in .NET applications though a P/Invoke call.
Applications which explicitly initialize GDI+ may be able to do so after creating their main window.
Example in C#:
public partial class Form1 : Form
static extern bool SetForegroundWindow(IntPtr hWnd);
protected override void OnLoad(EventArgs e)
MICROSOFT CORPORATION AND/OR ITS RESPECTIVE SUPPLIERS MAKE NO REPRESENTATIONS ABOUT THE SUITABILITY, RELIABILITY, OR ACCURACY OF THE INFORMATION AND RELATED GRAPHICS CONTAINED HEREIN. ALL SUCH INFORMATION AND RELATED GRAPHICS ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT AND/OR ITS RESPECTIVE SUPPLIERS HEREBY DISCLAIM ALL WARRANTIES AND CONDITIONS WITH REGARD TO THIS INFORMATION AND RELATED GRAPHICS, INCLUDING ALL IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, WORKMANLIKE EFFORT, TITLE AND NON-INFRINGEMENT. YOU SPECIFICALLY AGREE THAT IN NO EVENT SHALL MICROSOFT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY DIRECT, INDIRECT, PUNITIVE, INCIDENTAL, SPECIAL, CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF USE, DATA OR PROFITS, ARISING OUT OF OR IN ANY WAY CONNECTED WITH THE USE OF OR INABILITY TO USE THE INFORMATION AND RELATED GRAPHICS CONTAINED HEREIN, WHETHER BASED ON CONTRACT, TORT, NEGLIGENCE, STRICT LIABILITY OR OTHERWISE, EVEN IF MICROSOFT OR ANY OF ITS SUPPLIERS HAS BEEN ADVISED OF THE POSSIBILITY OF DAMAGES.
Contact us for more help
Connect with Answer Desk for expert help.