ReactOS 0.4.17-dev-1321-g5c122a9
window.c
Go to the documentation of this file.
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 */
37static 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;
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 {
91 freep(p);
92 return 1;
93 }
94
95 pos.top = _ttoi (++tmp);
96 if (!(tmp=_tcschr(tmp, _T(','))))
97 {
99 freep(p);
100 return 1;
101 }
102
103 pos.right = _ttoi(++tmp) + pos.left;
104 if (!(tmp = _tcschr(tmp, _T(','))))
105 {
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 {
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)
139
140 wp.length = sizeof(WINDOWPLACEMENT);
142
143 if (iAction & A_POS)
145
146 if (iAction & A_MIN)
147 wp.showCmd = SW_MINIMIZE;
148
149 if (iAction & A_MAX)
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 PostMessage(hWnd, WM_CLOSE, 0, 0);
159 }
160 else
161 {
162 wp.length = sizeof(WINDOWPLACEMENT);
164 }
165
166 if (p)
167 freep(p);
168
169 return 0;
170}
171
172
173
174
176{
177 HWND hwnd;
178
179 if (_tcsncmp (param, _T("/?"), 2) == 0)
180 {
182 return 0;
183 }
184
186 Sleep(0);
187 return ServiceActivate(param, hwnd);
188}
189
190
192{
193 HWND hwnd;
194 LPTSTR *arg;
195 INT argc;
196
197 if (_tcsncmp (param, _T("/?"), 2) == 0)
198 {
200 return 0;
201 }
202
203 if (!(*param))
204 return 1;
205
206 /* Split the user input into array */
207 arg = split (param, &argc, FALSE);
208 if (argc < 2)
209 {
210 if (arg != NULL)
211 freep(arg);
212 }
213 hwnd = FindWindow(NULL, arg[0]);
214 if (hwnd == NULL)
215 {
216 if (arg != NULL)
217 freep(arg);
219 return 1;
220 }
221 if (arg != NULL)
222 freep(arg);
223
224 return ServiceActivate(param, hwnd);
225}
226
227#endif /* defined(INCLUDE_CMD_WINDOW) || defined(INCLUDE_CMD_ACTIVATE) */
HWND hWnd
Definition: settings.c:17
INT CommandActivate(LPTSTR)
INT CommandWindow(LPTSTR)
VOID error_invalid_parameter_format(PCTSTR s)
VOID ConOutResPaging(BOOL StartPaging, UINT resID)
Definition: console.c:178
#define ConErrResPuts(uID)
Definition: console.h:38
#define STRING_WINDOW_HELP1
Definition: resource.h:207
#define STRING_WINDOW_ERROR
Definition: resource.h:66
#define STRING_WINDOW_HELP2
Definition: resource.h:208
static VOID freep(LPSTR *p)
Definition: cmdcons.c:98
static LPSTR * split(LPSTR s, LPINT args)
Definition: cmdcons.c:163
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
HWND WINAPI GetConsoleWindow(void)
Definition: console.c:1102
MonoAssembly int argc
Definition: metahost.c:107
GLfloat GLfloat p
Definition: glext.h:8902
GLfloat param
Definition: glext.h:5796
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define _ttoi
Definition: tchar.h:611
#define _tcsncmp
Definition: tchar.h:1428
#define _tcsnicmp
Definition: tchar.h:1431
#define _tcsicmp
Definition: tchar.h:1425
#define _tcschr
Definition: tchar.h:1406
LPSTR LPTSTR
Definition: ms-dtyp.idl:131
static char title[]
Definition: ps.c:92
#define SW_SHOWMAXIMIZED
Definition: winuser.h:784
#define WM_CLOSE
Definition: winuser.h:1649
#define FindWindow
Definition: winuser.h:5943
BOOL WINAPI GetWindowPlacement(_In_ HWND, _Inout_ WINDOWPLACEMENT *)
#define SW_MINIMIZE
Definition: winuser.h:787
#define PostMessage
Definition: winuser.h:5998
#define SW_RESTORE
Definition: winuser.h:790
#define SetWindowText
Definition: winuser.h:6023
struct _WINDOWPLACEMENT WINDOWPLACEMENT
BOOL WINAPI SetWindowPlacement(_In_ HWND hWnd, _In_ const WINDOWPLACEMENT *)
Definition: dcommon.idl:28
RECT rcNormalPosition
Definition: winuser.h:3403
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:726
int32_t INT
Definition: typedefs.h:58
#define _T(x)
Definition: vfdio.h:22
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023
void * arg
Definition: msvc.h:10