OpenIcon not restoring to previous size

Posted on 2007-07-25
Last Modified: 2013-12-17
Using C# - Visual Studio 2005

The documentation for OpenIcon says that it will restore a window to its previous size
and location. This isn't happening - it is restoring the window, but It only restores it to its previous size/location if it was not maximized. I want it to go back to however it was displayed before the user sent it to the taskbar. Is there something extra that needs to be done when calling it from C#?
The ReturnValue indicates success.

My original code:

static extern bool OpenIcon(IntPtr hwnd);
IntPtr wHandle = process.MainWindowHandle;
bool ReturnValue = OpenIcon (wHandle);
On suggestion, I modified the code to:

[DllImport("user32.dll", CharSet = CharSet.Auto)]
        [return: MarshalAs(UnmanagedType.Bool)]
private static extern bool OpenIcon(HandleRef hwnd);
HandleRef HandleReference = new HandleRef(new Object(), process.MainWindowHandle);
OpenIcon (HandleReference);

This behaves the same way, which was not that surprising to me since it doesn't appear to be a
problem with the garbage collector/object not being found.

Question by:mrnbnf
    LVL 85

    Accepted Solution

    Try using ShowWindow() with SW_RESTORE instead:
    LVL 96

    Assisted Solution

    by:Bob Learned
    From my understanding of OpenIcon, it restores a minimized window to its previous size and location, and not the window state.

    Are you working with windows outside of your application?  


    Author Comment

    Works - Thanks!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
    Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now