| 3166 | |
| 3167 | |
| 3168 | ResultType Line::WinSet(char *aAttrib, char *aValue, char *aTitle, char *aText |
| 3169 | , char *aExcludeTitle, char *aExcludeText) |
| 3170 | { |
| 3171 | WinSetAttributes attrib = ConvertWinSetAttribute(aAttrib); |
| 3172 | if (attrib == WINSET_INVALID) |
| 3173 | return LineError(ERR_WINSET, FAIL, aAttrib); |
| 3174 | |
| 3175 | // Set default ErrorLevel for any commands that change ErrorLevel. |
| 3176 | // The default should be ERRORLEVEL_ERROR so that that value will be returned |
| 3177 | // by default when the target window doesn't exist: |
| 3178 | if (attrib == WINSET_STYLE || attrib == WINSET_EXSTYLE || attrib == WINSET_REGION) |
| 3179 | g_ErrorLevel->Assign(ERRORLEVEL_ERROR); |
| 3180 | |
| 3181 | // Since this is a macro, avoid repeating it for every case of the switch(): |
| 3182 | HWND target_window = DetermineTargetWindow(aTitle, aText, aExcludeTitle, aExcludeText); |
| 3183 | if (!target_window) |
| 3184 | return OK; // Let ErrorLevel (for commands that set it above) tell the story. |
| 3185 | |
| 3186 | int value; |
| 3187 | DWORD exstyle; |
| 3188 | |
| 3189 | switch (attrib) |
| 3190 | { |
| 3191 | case WINSET_ALWAYSONTOP: |
| 3192 | { |
| 3193 | if ( !(exstyle = GetWindowLong(target_window, GWL_EXSTYLE)) ) |
| 3194 | return OK; |
| 3195 | HWND topmost_or_not; |
| 3196 | switch(ConvertOnOffToggle(aValue)) |
| 3197 | { |
| 3198 | case TOGGLED_ON: topmost_or_not = HWND_TOPMOST; break; |
| 3199 | case TOGGLED_OFF: topmost_or_not = HWND_NOTOPMOST; break; |
| 3200 | case NEUTRAL: // parameter was blank, so it defaults to TOGGLE. |
| 3201 | case TOGGLE: topmost_or_not = (exstyle & WS_EX_TOPMOST) ? HWND_NOTOPMOST : HWND_TOPMOST; break; |
| 3202 | default: return OK; |
| 3203 | } |
| 3204 | // SetWindowLong() didn't seem to work, at least not on some windows. But this does. |
| 3205 | // As of v1.0.25.14, SWP_NOACTIVATE is also specified, though its absence does not actually |
| 3206 | // seem to activate the window, at least on XP (perhaps due to anti-focus-stealing measure |
| 3207 | // in Win98/2000 and beyond). Or perhaps its something to do with the presence of |
| 3208 | // topmost_or_not (HWND_TOPMOST/HWND_NOTOPMOST), which might always avoid activating the |
| 3209 | // window. |
| 3210 | SetWindowPos(target_window, topmost_or_not, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE); |
| 3211 | break; |
| 3212 | } |
| 3213 | |
| 3214 | // Note that WINSET_TOP is not offered as an option since testing reveals it has no effect on |
| 3215 | // top level (parent) windows, perhaps due to the anti focus-stealing measures in the OS. |
| 3216 | case WINSET_BOTTOM: |
| 3217 | // Note: SWP_NOACTIVATE must be specified otherwise the target window often/always fails to go |
| 3218 | // to the bottom: |
| 3219 | SetWindowPos(target_window, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE); |
| 3220 | break; |
| 3221 | |
| 3222 | case WINSET_TRANSPARENT: |
| 3223 | case WINSET_TRANSCOLOR: |
| 3224 | { |
| 3225 | // IMPORTANT (when considering future enhancements to these commands): Unlike |
nothing calls this directly
no test coverage detected