| 7074 | |
| 7075 | |
| 7076 | ResultType GuiType::Show(LPTSTR aOptions) |
| 7077 | { |
| 7078 | if (!mHwnd) |
| 7079 | return FAIL; // Shouldn't be possible. |
| 7080 | |
| 7081 | // In the future, it seems best to rely on mShowIsInProgress to prevent the Window Proc from ever |
| 7082 | // doing a MsgSleep() to launch a script subroutine. This is because if anything we do in this |
| 7083 | // function results in a launch of the Window Proc (such as MoveWindow and ShowWindow), our |
| 7084 | // activity here might be interrupted in a destructive way. For example, if a script subroutine |
| 7085 | // is launched while we're in the middle of something here, our activity is suspended until |
| 7086 | // the subroutine completes and the call stack collapses back to here. But if that subroutine |
| 7087 | // recursively calls us while the prior call is still in progress, the mShowIsInProgress would |
| 7088 | // be set to false when that layer completes, leaving it false when it really should be true |
| 7089 | // because our layer isn't done yet. |
| 7090 | mShowIsInProgress = true; // Signal WM_SIZE to queue the GuiSize launch. We'll unqueue via MsgSleep() when we're done. |
| 7091 | |
| 7092 | // Set defaults, to be overridden by the presence of zero or more options: |
| 7093 | int x = COORD_UNSPECIFIED; |
| 7094 | int y = COORD_UNSPECIFIED; |
| 7095 | int width = COORD_UNSPECIFIED; |
| 7096 | int height = COORD_UNSPECIFIED; |
| 7097 | bool auto_size = false; |
| 7098 | |
| 7099 | BOOL is_maximized = IsZoomed(mHwnd); // Safer to assume it's possible for both to be true simultaneously in |
| 7100 | BOOL is_minimized = IsIconic(mHwnd); // future/past OSes. |
| 7101 | int show_mode; |
| 7102 | // There is evidence that SW_SHOWNORMAL might be better than SW_SHOW for the first showing because |
| 7103 | // someone reported that a window appears centered on the screen for its first showing even if some |
| 7104 | // other position was specified. In addition, MSDN says (without explanation): "An application should |
| 7105 | // specify [SW_SHOWNORMAL] when displaying the window for the first time." However, SW_SHOWNORMAL is |
| 7106 | // avoided after the first showing of the window because that would probably also do a "restore" on the |
| 7107 | // window if it was maximized previously. Note that the description of SW_SHOWNORMAL is virtually the |
| 7108 | // same as that of SW_RESTORE in MSDN. UPDATE: mGuiShowHasNeverBeenDone is used here instead of mFirstActivation |
| 7109 | // because it seems more flexible to have "Gui Show" behave consistently (SW_SHOW) every time after |
| 7110 | // the first use of "Gui Show". UPDATE: Since SW_SHOW seems to have no effect on minimized windows, |
| 7111 | // at least on XP, and since such a minimized window will be restored by action of SetForegroundWindowEx(), |
| 7112 | // it seems best to unconditionally use SW_SHOWNORMAL, rather than "mGuiShowHasNeverBeenDone ? SW_SHOWNORMAL : SW_SHOW". |
| 7113 | // This is done so that the window will be restored and thus have a better chance of being successfully |
| 7114 | // activated (and thus not requiring the call to SetForegroundWindowEx()). |
| 7115 | // v1.0.44.08: Fixed to default to SW_SHOW for currently-maximized windows so that they don't get unmaximized |
| 7116 | // by "Gui Show" (unless other options require it). Also, it's been observed that SW_SHOWNORMAL differs from |
| 7117 | // SW_RESTORE in at least one way: When the target is a minimized window, SW_SHOWNORMAL will both restore it |
| 7118 | // and unmaximize it. But SW_RESTORE unminimizes the window in a way that retains its maximized state (if |
| 7119 | // it was previously maximized). Therefore, SW_RESTORE is now the default if the window is currently minimized. |
| 7120 | if (is_minimized) |
| 7121 | show_mode = SW_RESTORE; // See above comments. For backward compatibility, window is unminimized even if it was previously hidden (rather than simply showing its taskbar button and keeping it minimized). |
| 7122 | else if (is_maximized) |
| 7123 | show_mode = SW_SHOW; // See above. |
| 7124 | else |
| 7125 | show_mode = SW_SHOWNORMAL; |
| 7126 | |
| 7127 | for (LPTSTR cp_end = aOptions, cp = aOptions; *cp; cp = cp_end) |
| 7128 | { |
| 7129 | switch(ctoupper(*cp)) |
| 7130 | { |
| 7131 | // For options such as W, H, X and Y: Use _ttoi() vs. ATOI() to avoid interpreting something like 0x01B |
| 7132 | // as hex when in fact the B was meant to be an option letter. |
| 7133 | case ' ': |
no test coverage detected