Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Download Visual Studio Add-In

IsIconic (user32)
 
.
Summary

C# Signature:

[DllImport("user32.dll")]
static extern bool IsIconic(IntPtr hWnd);

VB Signature:

  Private Declare Auto Function IsIconic Lib "user32.dll" (ByVal hwnd As IntPtr) As Boolean

User-Defined Types:

None.

Notes:

The hWnd parameter can be obtained by the Handle property of a Form, or by

MainWindowHandle on a Process.

Tips & Tricks:

Please add some!

Sample Code:

      // Want only one instance of an application?

      [DllImport("User32.Dll")]
      private static extern bool SetForegroundWindow(IntPtr hWnd);
      [DllImport("User32.Dll")]
      private static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);
      [DllImport("User32.Dll")]
      private static extern bool IsIconic(IntPtr hWnd);


      private const int SW_RESTORE = 9;

      /// <summary>
      /// Main entry point for the application.
      /// </summary>
      [STAThread]
      static int
      Main
    (
      string[] arguments
    )
    {
      // Check for running instance

      Process thisProcess = Process.GetCurrentProcess();
      Process[] processes = Process.GetProcessesByName(thisProcess.ProcessName);

      if (processes.Length > 1)
        {
          // One is us (which will end); the other we activate

          int index = 0;
          if (processes[index].Id == thisProcess.Id)
        index = 1;

          IntPtr hWnd = processes[index].MainWindowHandle;

          if (IsIconic(hWnd))
        ShowWindowAsync(hWnd, SW_RESTORE);

          SetForegroundWindow(hWnd);

          // Exit
          return 0;
        }


       // Normal startup code continues here...

     }

Alternative Managed API:

Do you know one? Please contribute it!

Documentation
IsIconic on MSDN

Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

 
Access PInvoke.net directly from VS:
Terms of Use
Find References
Show Printable Version
Revisions