Link to home
Start Free TrialLog in
Avatar of mrnbnf
mrnbnf

asked on

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.

ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mrnbnf
mrnbnf

ASKER

Works - Thanks!