1 /* 2 * WINDOW.C - activate & window internal commands. 3 * 4 * clone from 4nt activate command 5 * 6 * 10 Sep 1999 (Paolo Pantaleo) 7 * started (window command in WINDOW.c) 8 * 9 * 29 Sep 1999 (Paolo Pantaleo) 10 * activate and window in a single file using mainly the same code 11 * (nice size optimization :) 12 * 13 * 30-Apr-2005 (Magnus Olsen <magnus@greatlord.com>) 14 * Remove all hardcoded strings in En.rc 15 */ 16 17 18 #include "precomp.h" 19 20 #if defined(INCLUDE_CMD_WINDOW) || defined(INCLUDE_CMD_ACTIVATE) 21 22 23 #define A_MIN 0x01 24 #define A_MAX 0x02 25 #define A_RESTORE 0x04 26 #define A_POS 0x08 27 #define A_SIZE 0x10 28 #define A_CLOSE 0x20 29 30 31 /* 32 * service function to perform actions on windows 33 * 34 * param is a string to parse for options/actions 35 * hWnd is the handle of window on which to perform actions 36 */ 37 static INT ServiceActivate (LPTSTR param, HWND hWnd) 38 { 39 LPTSTR *p = 0, p_tmp; 40 INT argc = 0, i; 41 INT iAction = 0; 42 LPTSTR title = 0; 43 WINDOWPLACEMENT wp; 44 RECT pos; 45 LPTSTR tmp; 46 47 if (*param) 48 p = split(param, &argc, FALSE); 49 50 for (i = 0; i < argc; i++) 51 { 52 p_tmp = p[i]; 53 if (*p_tmp == _T('/')) 54 p_tmp++; 55 56 if (_tcsicmp(p_tmp, _T("min")) == 0) 57 { 58 iAction |= A_MIN; 59 continue; 60 } 61 62 if (_tcsicmp(p_tmp, _T("max")) == 0) 63 { 64 iAction |= A_MAX; 65 continue; 66 } 67 68 if (_tcsicmp(p_tmp, _T("restore")) == 0) 69 { 70 iAction |= A_RESTORE; 71 continue; 72 } 73 74 if (_tcsicmp(p_tmp, _T("close")) == 0) 75 { 76 iAction |= A_CLOSE; 77 continue; 78 } 79 80 if (_tcsnicmp(p_tmp, _T("pos"), 3) == 0) 81 { 82 iAction |= A_POS; 83 tmp = p_tmp+3; 84 if (*tmp == _T('=')) 85 tmp++; 86 87 pos.left= _ttoi(tmp); 88 if (!(tmp=_tcschr(tmp, _T(',')))) 89 { 90 error_invalid_parameter_format(p[i]); 91 freep(p); 92 return 1; 93 } 94 95 pos.top = _ttoi (++tmp); 96 if (!(tmp=_tcschr(tmp, _T(',')))) 97 { 98 error_invalid_parameter_format(p[i]); 99 freep(p); 100 return 1; 101 } 102 103 pos.right = _ttoi(++tmp) + pos.left; 104 if (!(tmp = _tcschr(tmp, _T(',')))) 105 { 106 error_invalid_parameter_format(p[i]); 107 freep(p); 108 return 1; 109 } 110 pos.bottom = _ttoi(++tmp) + pos.top; 111 continue; 112 } 113 114 if (_tcsnicmp(p_tmp, _T("size"), 4)==0) 115 { 116 iAction |=A_SIZE; 117 continue; 118 } 119 120 /* none of them=window title */ 121 if (title) 122 { 123 error_invalid_parameter_format(p[i]); 124 freep(p); 125 return 1; 126 } 127 128 if (p_tmp[0] == _T('"')) 129 { 130 title = (p_tmp + 1); 131 *_tcschr(p_tmp + 1, _T('"')) = 0; 132 continue; 133 } 134 title = p_tmp; 135 } 136 137 if (title) 138 SetWindowText(hWnd, title); 139 140 wp.length = sizeof(WINDOWPLACEMENT); 141 GetWindowPlacement(hWnd, &wp); 142 143 if (iAction & A_POS) 144 wp.rcNormalPosition = pos; 145 146 if (iAction & A_MIN) 147 wp.showCmd = SW_MINIMIZE; 148 149 if (iAction & A_MAX) 150 wp.showCmd = SW_SHOWMAXIMIZED; 151 152 /* if no actions are specified default is SW_RESTORE */ 153 if ((iAction & A_RESTORE) || (!iAction)) 154 wp.showCmd = SW_RESTORE; 155 156 if (iAction & A_CLOSE) 157 { 158 FIXME("!!!FIXME: CLOSE Not implemented!!!\n"); 159 } 160 161 wp.length = sizeof(WINDOWPLACEMENT); 162 SetWindowPlacement(hWnd, &wp); 163 164 if (p) 165 freep(p); 166 167 return 0; 168 } 169 170 171 172 173 INT CommandWindow (LPTSTR param) 174 { 175 HWND hwnd; 176 177 if (_tcsncmp (param, _T("/?"), 2) == 0) 178 { 179 ConOutResPaging(TRUE,STRING_WINDOW_HELP1); 180 return 0; 181 } 182 183 hwnd = GetConsoleWindow(); 184 Sleep(0); 185 return ServiceActivate(param, hwnd); 186 } 187 188 189 INT CommandActivate (LPTSTR param) 190 { 191 HWND hwnd; 192 LPTSTR *arg; 193 INT argc; 194 195 if (_tcsncmp (param, _T("/?"), 2) == 0) 196 { 197 ConOutResPaging(TRUE,STRING_WINDOW_HELP2); 198 return 0; 199 } 200 201 if (!(*param)) 202 return 1; 203 204 /* Split the user input into array */ 205 arg = split (param, &argc, FALSE); 206 if (argc < 2) 207 { 208 if (arg != NULL) 209 freep(arg); 210 } 211 hwnd = FindWindow(NULL, arg[0]); 212 if (hwnd == NULL) 213 { 214 if (arg != NULL) 215 freep(arg); 216 ConErrResPuts(STRING_WINDOW_ERROR); 217 return 1; 218 } 219 if (arg != NULL) 220 freep(arg); 221 222 return ServiceActivate(param, hwnd); 223 } 224 225 #endif /* defined(INCLUDE_CMD_WINDOW) || defined(INCLUDE_CMD_ACTIVATE) */ 226