1999-10-03 22:16:14 +00:00
|
|
|
/* $Id: window.c,v 1.3 1999/10/03 22:16:14 ekohl Exp $
|
1999-09-24 22:03:11 +00:00
|
|
|
*
|
1999-10-03 22:16:14 +00:00
|
|
|
* WINDOW.C - activate & window internal commands.
|
1999-09-24 22:03:11 +00:00
|
|
|
*
|
1999-10-03 22:16:14 +00:00
|
|
|
* clone from 4nt activate command
|
1999-09-24 22:03:11 +00:00
|
|
|
*
|
1999-10-03 22:16:14 +00:00
|
|
|
* 10 Sep 1999 (Paolo Pantaleo)
|
|
|
|
* started (window command in WINDOW.c)
|
1999-09-24 22:03:11 +00:00
|
|
|
*
|
1999-10-03 22:16:14 +00:00
|
|
|
* 29 Sep 1999 (Paolo Pantaleo)
|
|
|
|
* activate and window in a single file using mainly the same code
|
|
|
|
* (nice size optimization :)
|
1999-09-24 22:03:11 +00:00
|
|
|
*/
|
|
|
|
|
1999-09-27 22:15:44 +00:00
|
|
|
|
1999-09-24 22:03:11 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
1999-10-03 22:16:14 +00:00
|
|
|
#if ( defined(INCLUDE_CMD_WINDOW) || defined(INCLUDE_CMD_ACTIVATE) )
|
1999-09-24 22:03:11 +00:00
|
|
|
|
|
|
|
#include "cmd.h"
|
|
|
|
#include <windows.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <tchar.h>
|
|
|
|
|
|
|
|
|
|
|
|
#define A_MIN 0x01
|
|
|
|
#define A_MAX 0x02
|
|
|
|
#define A_RESTORE 0x04
|
|
|
|
#define A_POS 0x08
|
|
|
|
#define A_SIZE 0x10
|
1999-10-03 22:16:14 +00:00
|
|
|
#define A_CLOSE 0x20
|
1999-09-24 22:03:11 +00:00
|
|
|
|
|
|
|
|
1999-10-03 22:16:14 +00:00
|
|
|
/*service funciton to perform actions on windows
|
|
|
|
|
|
|
|
param is a string to parse for options/actions
|
|
|
|
hWnd is the handle of window on wich perform actions
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
static
|
|
|
|
INT ServiceActivate (LPTSTR param, HWND hWnd)
|
1999-09-24 22:03:11 +00:00
|
|
|
{
|
1999-10-03 22:16:14 +00:00
|
|
|
LPTSTR *p=0,p_tmp;
|
|
|
|
INT argc=0,i;
|
1999-09-24 22:03:11 +00:00
|
|
|
INT iAction=0;
|
|
|
|
LPTSTR title=0;
|
|
|
|
WINDOWPLACEMENT wp;
|
|
|
|
RECT pos;
|
|
|
|
LPTSTR tmp;
|
|
|
|
|
|
|
|
|
1999-10-03 22:16:14 +00:00
|
|
|
if(*param)
|
|
|
|
p=split(param,&argc);
|
|
|
|
|
1999-09-24 22:03:11 +00:00
|
|
|
|
1999-09-27 22:15:44 +00:00
|
|
|
for(i = 0; i < argc; i++)
|
1999-09-24 22:03:11 +00:00
|
|
|
{
|
1999-09-27 22:15:44 +00:00
|
|
|
p_tmp=p[i];
|
|
|
|
if (*p_tmp == _T('/'))
|
|
|
|
p_tmp++;
|
|
|
|
|
|
|
|
if (_tcsicmp(p_tmp,_T("min"))==0)
|
1999-09-24 22:03:11 +00:00
|
|
|
{
|
1999-09-27 22:15:44 +00:00
|
|
|
iAction |= A_MIN;
|
1999-09-24 22:03:11 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
1999-09-27 22:15:44 +00:00
|
|
|
if (_tcsicmp(p_tmp,_T("max"))==0)
|
1999-09-24 22:03:11 +00:00
|
|
|
{
|
1999-09-27 22:15:44 +00:00
|
|
|
iAction |= A_MAX;
|
1999-09-24 22:03:11 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
1999-09-27 22:15:44 +00:00
|
|
|
if (_tcsicmp(p_tmp,_T("restore"))==0)
|
1999-09-24 22:03:11 +00:00
|
|
|
{
|
1999-09-27 22:15:44 +00:00
|
|
|
iAction |= A_RESTORE;
|
1999-09-24 22:03:11 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
1999-10-03 22:16:14 +00:00
|
|
|
if (_tcsicmp(p_tmp,_T("close"))==0)
|
|
|
|
{
|
|
|
|
iAction |= A_CLOSE;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
1999-09-27 22:15:44 +00:00
|
|
|
if (_tcsnicmp(p_tmp,_T("pos"),3)==0)
|
1999-09-24 22:03:11 +00:00
|
|
|
{
|
1999-09-27 22:15:44 +00:00
|
|
|
iAction |= A_POS;
|
|
|
|
tmp = p_tmp+3;
|
1999-09-24 22:03:11 +00:00
|
|
|
if (*tmp == _T('='))
|
|
|
|
tmp++;
|
|
|
|
|
1999-09-27 22:15:44 +00:00
|
|
|
pos.left= _ttoi(tmp);
|
1999-09-24 22:03:11 +00:00
|
|
|
if(!(tmp=_tcschr(tmp,_T(','))))
|
|
|
|
{
|
|
|
|
error_invalid_parameter_format(p[i]);
|
|
|
|
freep(p);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
1999-09-27 22:15:44 +00:00
|
|
|
pos.top = _ttoi (++tmp);
|
1999-09-24 22:03:11 +00:00
|
|
|
if(!(tmp=_tcschr(tmp,_T(','))))
|
|
|
|
{
|
|
|
|
error_invalid_parameter_format(p[i]);
|
|
|
|
freep(p);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
1999-09-27 22:15:44 +00:00
|
|
|
pos.right = _ttoi(++tmp)+pos.left;
|
1999-09-24 22:03:11 +00:00
|
|
|
if(!(tmp=_tcschr(tmp,_T(','))))
|
|
|
|
{
|
|
|
|
error_invalid_parameter_format(p[i]);
|
|
|
|
freep(p);
|
|
|
|
return 1;
|
|
|
|
}
|
1999-09-27 22:15:44 +00:00
|
|
|
pos.bottom = _ttoi(++tmp) + pos.top;
|
1999-09-24 22:03:11 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
1999-09-27 22:15:44 +00:00
|
|
|
if (_tcsnicmp(p_tmp,_T("size"),4)==0)
|
1999-09-24 22:03:11 +00:00
|
|
|
{
|
|
|
|
iAction |=A_SIZE;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
1999-10-03 22:16:14 +00:00
|
|
|
/*none of them=window title*/
|
1999-09-24 22:03:11 +00:00
|
|
|
if (title)
|
|
|
|
{
|
|
|
|
error_invalid_parameter_format(p[i]);
|
|
|
|
freep(p);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
1999-09-27 22:15:44 +00:00
|
|
|
if (p_tmp[0] == _T('"'))
|
1999-09-24 22:03:11 +00:00
|
|
|
{
|
1999-09-27 22:15:44 +00:00
|
|
|
title = (p_tmp+1);
|
|
|
|
*_tcschr(p_tmp+1,_T('"'))=0;
|
1999-09-24 22:03:11 +00:00
|
|
|
continue;
|
|
|
|
}
|
1999-09-27 22:15:44 +00:00
|
|
|
title = p_tmp;
|
1999-09-24 22:03:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(title)
|
1999-10-03 22:16:14 +00:00
|
|
|
SetWindowText(hWnd,title);
|
1999-09-24 22:03:11 +00:00
|
|
|
|
|
|
|
wp.length=sizeof(WINDOWPLACEMENT);
|
|
|
|
GetWindowPlacement(hWnd,&wp);
|
|
|
|
|
1999-10-03 22:16:14 +00:00
|
|
|
if(iAction & A_POS)
|
|
|
|
wp.rcNormalPosition = pos;
|
1999-09-24 22:03:11 +00:00
|
|
|
|
|
|
|
if(iAction & A_MIN)
|
|
|
|
wp.showCmd=SW_MINIMIZE;
|
|
|
|
|
|
|
|
if(iAction & A_MAX)
|
|
|
|
wp.showCmd=SW_SHOWMAXIMIZED;
|
|
|
|
|
1999-10-03 22:16:14 +00:00
|
|
|
/*if no actions are specified default is SW_RESTORE*/
|
|
|
|
if( (iAction & A_RESTORE) || (!iAction) )
|
1999-09-24 22:03:11 +00:00
|
|
|
wp.showCmd=SW_RESTORE;
|
|
|
|
|
1999-10-03 22:16:14 +00:00
|
|
|
if(iAction & A_CLOSE)
|
|
|
|
ConErrPrintf(_T("!!!FIXME: CLOSE Not implemented!!!\n"));
|
|
|
|
|
1999-09-24 22:03:11 +00:00
|
|
|
wp.length=sizeof(WINDOWPLACEMENT);
|
|
|
|
SetWindowPlacement(hWnd,&wp);
|
|
|
|
|
1999-10-03 22:16:14 +00:00
|
|
|
if(p)
|
|
|
|
freep(p);
|
|
|
|
|
1999-09-24 22:03:11 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1999-10-03 22:16:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
INT CommandWindow (LPTSTR cmd, LPTSTR param)
|
|
|
|
{
|
|
|
|
HWND h;
|
|
|
|
|
|
|
|
if (_tcsncmp (param, _T("/?"), 2) == 0)
|
|
|
|
{
|
|
|
|
ConOutPuts(_T("change console window aspect\n"
|
|
|
|
"\n"
|
|
|
|
"WINDOW [/POS[=]left,top,width,heigth]\n"
|
|
|
|
" [MIN|MAX|RESTORE] [\"title\"]\n"
|
|
|
|
"\n"
|
|
|
|
"/POS specify window placement and dimensions\n"
|
|
|
|
"MIN minimize the window\n"
|
|
|
|
"MAX maximize the window\n"
|
|
|
|
"RESTORE restore the window"));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
h = GetConsoleWindow();
|
|
|
|
Sleep(0);
|
|
|
|
return ServiceActivate(param,h);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
INT CommandActivate (LPTSTR cmd, LPTSTR param)
|
|
|
|
{
|
|
|
|
LPTSTR str;
|
|
|
|
HWND h;
|
|
|
|
|
|
|
|
if (_tcsncmp (param, _T("/?"), 2) == 0)
|
|
|
|
{
|
|
|
|
ConOutPuts(_T("change console window aspect\n"
|
|
|
|
"\n"
|
|
|
|
"ACTIAVTE \"window\" [/POS[=]left,top,width,heigth]\n"
|
|
|
|
" [MIN|MAX|RESTORE] [\"title\"]\n"
|
|
|
|
"\n"
|
|
|
|
"window tile of window on wich perform actions\n"
|
|
|
|
"/POS specify window placement and dimensions\n"
|
|
|
|
"MIN minimize the window\n"
|
|
|
|
"MAX maximize the window\n"
|
|
|
|
"RESTORE restore the window\n"
|
|
|
|
"title new title"));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!(*param))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
str=_tcschr(param,_T(' '));
|
|
|
|
|
|
|
|
if (str)
|
|
|
|
{
|
|
|
|
*str=_T('\0');
|
|
|
|
str++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
str = "";
|
|
|
|
|
|
|
|
h=FindWindow(NULL, param);
|
|
|
|
if (!h)
|
|
|
|
{
|
|
|
|
ConErrPuts("window not found");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ServiceActivate(str,h);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* ( defined(INCLUDE_CMD_WINDOW) || defined(INCLUDE_CMD_ACTIVATE) ) */
|