254b699be0eb887d0f6a0cf29ba35cf424ec089c
[reactos.git] / rosapps / cmd / window.c
1 /*
2 * WINDOW.C - activate internal command.
3 *
4 * clone from 4nt window command
5 *
6 * 10 Sep 1999
7 * started - Paolo Pantaleo <dfaustus@freemail.it>
8 *
9 *
10 */
11
12
13 #include "config.h"
14
15 #ifdef INCLUDE_CMD_WINDOW
16
17 #include "cmd.h"
18 #include <windows.h>
19 #include <stdlib.h>
20 #include <string.h>
21 #include <tchar.h>
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
30
31 INT CommandWindow (LPTSTR cmd, LPTSTR param)
32 {
33 LPTSTR *p,p_tmp;
34 INT argc,i;
35 INT iAction=0;
36 LPTSTR title=0;
37 HWND hWnd;
38 WINDOWPLACEMENT wp;
39 RECT pos;
40 LPTSTR tmp;
41
42 if (_tcsncmp (param, _T("/?"), 2) == 0)
43 {
44 ConOutPuts(_T("change console window aspect\n"
45 "\n"
46 "WINDOW [/POS[=]left,top,width,heigth]\n"
47 " [MIN|MAX|RESTORE]\n"
48 "\n"
49 "/POS specify window placement and dimensions\n"
50 "MIN minimize the window\n"
51 "MAX maximize the window\n"
52 "RESTORE restore the window"));
53 return 0;
54 }
55
56 p=split(param,&argc);
57
58 for(i = 0; i < argc; i++)
59 {
60 p_tmp=p[i];
61 if (*p_tmp == _T('/'))
62 p_tmp++;
63
64 if (_tcsicmp(p_tmp,_T("min"))==0)
65 {
66 iAction |= A_MIN;
67 continue;
68 }
69
70 if (_tcsicmp(p_tmp,_T("max"))==0)
71 {
72 iAction |= A_MAX;
73 continue;
74 }
75
76 if (_tcsicmp(p_tmp,_T("restore"))==0)
77 {
78 iAction |= A_RESTORE;
79 continue;
80 }
81
82 if (_tcsnicmp(p_tmp,_T("pos"),3)==0)
83 {
84 iAction |= A_POS;
85 tmp = p_tmp+3;
86 if (*tmp == _T('='))
87 tmp++;
88
89 pos.left= _ttoi(tmp);
90 if(!(tmp=_tcschr(tmp,_T(','))))
91 {
92 error_invalid_parameter_format(p[i]);
93 freep(p);
94 return 1;
95 }
96
97 pos.top = _ttoi (++tmp);
98 if(!(tmp=_tcschr(tmp,_T(','))))
99 {
100 error_invalid_parameter_format(p[i]);
101 freep(p);
102 return 1;
103 }
104
105 pos.right = _ttoi(++tmp)+pos.left;
106 if(!(tmp=_tcschr(tmp,_T(','))))
107 {
108 error_invalid_parameter_format(p[i]);
109 freep(p);
110 return 1;
111 }
112 pos.bottom = _ttoi(++tmp) + pos.top;
113 continue;
114 }
115
116 if (_tcsnicmp(p_tmp,_T("size"),4)==0)
117 {
118 iAction |=A_SIZE;
119 continue;
120 }
121
122 #if 0
123 if(*p_tmp != '"')
124 {
125 error_invalid_parameter_format(p[i]);
126
127 freep(p);
128 return 1;
129 }
130 #endif
131
132 //none of them=window title
133 if (title)
134 {
135 error_invalid_parameter_format(p[i]);
136 freep(p);
137 return 1;
138 }
139
140 if (p_tmp[0] == _T('"'))
141 {
142 title = (p_tmp+1);
143 *_tcschr(p_tmp+1,_T('"'))=0;
144 continue;
145 }
146 title = p_tmp;
147 }
148
149 if(title)
150 SetConsoleTitle(title);
151
152 hWnd=GetConsoleWindow();
153
154 wp.length=sizeof(WINDOWPLACEMENT);
155 GetWindowPlacement(hWnd,&wp);
156
157 if(iAction & A_POS)
158 {
159 wp.rcNormalPosition = pos;
160 }
161
162 if(iAction & A_MIN)
163 wp.showCmd=SW_MINIMIZE;
164
165 if(iAction & A_MAX)
166 wp.showCmd=SW_SHOWMAXIMIZED;
167
168 if(iAction & A_RESTORE)
169 wp.showCmd=SW_RESTORE;
170
171 wp.length=sizeof(WINDOWPLACEMENT);
172 SetWindowPlacement(hWnd,&wp);
173
174 freep(p);
175 return 0;
176 }
177
178 #endif /* INCLUDE_CMD_WINDOW */