OpenIcon not restoring to previous size

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:

[DllImport("user32.dll")]
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.

mrnbnfAsked:
Who is Participating?
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Try using ShowWindow() with SW_RESTORE instead:
http://msdn2.microsoft.com/en-us/library/ms633548.aspx
0
 
Bob LearnedCommented:
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?  

Bob
0
 
mrnbnfAuthor Commented:
Works - Thanks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.