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