move network tools
[reactos.git] / reactos / subsys / system / cmd / msgbox.c
1 /*
2 * MSGBOX.C - msgbox internal command.
3 *
4 * clone from 4nt msgbox command
5 *
6 * 25 Aug 1999
7 * started - Paolo Pantaleo <paolopan@freemail.it>
8 *
9 * 30-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>)
10 * Remove all hardcode string to En.rc
11 */
12
13 #include <precomp.h>
14 #include "resource.h"
15
16 #ifdef INCLUDE_CMD_MSGBOX
17
18
19 #define U_TYPE_INIT 0
20
21 //undefine it to allow to omit arguments
22 //that will be replaced by default ones
23 #define _SYNTAX_CHECK
24
25
26 INT CommandMsgbox (LPTSTR cmd, LPTSTR param)
27 {
28
29 //used to parse command line
30 LPTSTR tmp;
31
32 //used to find window title (used as messagebox title)
33 //and to find window handle to pass to MessageBox
34 HWND hWnd;
35 TCHAR buff[128];
36
37 //these are MessabeBox() parameters
38 LPTSTR title, prompt = "";
39 UINT uType = U_TYPE_INIT;
40
41 /* set default title to window title */
42 GetConsoleTitle(buff, 128);
43 title = buff;
44
45 if (_tcsncmp (param, _T("/?"), 2) == 0)
46 {
47 ConOutResPaging(TRUE,STRING_MSGBOX_HELP);
48 return 0;
49 }
50
51 //yes here things are quite massed up :)
52
53 //skip spaces
54 while(_istspace(*param))
55 param++;
56
57 //search for type of messagebox (ok, okcancel, ...)
58 if (_tcsnicmp(param, _T("ok "), 3) == 0)
59 {
60 uType |= MB_ICONEXCLAMATION | MB_OK;
61 param += 3;
62 }
63 else if (_tcsnicmp(param, _T("okcancel "), 9) == 0)
64 {
65 uType |= MB_ICONQUESTION | MB_OKCANCEL;
66 param += 9;
67 }
68 else if (_tcsnicmp(param, _T("yesno "), 6) == 0)
69 {
70 uType |= MB_ICONQUESTION | MB_YESNO;
71 param += 6;
72 }
73 else if (_tcsnicmp(param, _T("yesnocancel "), 12) == 0)
74 {
75 uType |= MB_ICONQUESTION | MB_YESNOCANCEL;
76 param += 12;
77 }
78 else
79 {
80 #ifdef _SYNTAX_CHECK
81 error_req_param_missing ();
82 return 1;
83 #else
84 uType |= MB_ICONEXCLAMATION | MB_OK;
85 #endif
86 }
87
88
89 //skip spaces
90 while(_istspace(*param))
91 param++;
92
93 #ifdef _SYNTAX_CHECK
94 //if reached end of string
95 //it is an error becuase we do not yet have prompt
96 if (*param == 0)
97 {
98 error_req_param_missing ();
99 return 1;
100 }
101 #endif
102
103 //search for "title"
104 tmp = param;
105
106 if (*param == '"')
107 {
108 tmp = _tcschr(param + 1, '"');
109 if (tmp)
110 {
111 *tmp = 0;
112 title = param + 1;
113 tmp++;
114 param = tmp;
115 }
116 }
117
118 //skip spaces
119 while(_istspace(*param))
120 param++;
121
122 #ifdef _SYNTAX_CHECK
123 //get prompt
124 if (*param == 0)
125 {
126 error_req_param_missing ();
127 return 1;
128 }
129 #endif
130
131 prompt = param;
132
133 hWnd=GetConsoleWindow ();
134 // DebugPrintf("FindWindow hWnd = %d\n",hWnd);
135 // ConErrPrintf("FindWindow hWnd = %d\n",hWnd);
136
137 switch (MessageBox(hWnd, prompt, title, uType))
138 {
139 case IDYES:
140 case IDOK:
141 nErrorLevel = 10;
142 break;
143
144 case IDNO:
145 nErrorLevel = 11;
146 break;
147
148 case IDCANCEL:
149 nErrorLevel = 12;
150 break;
151 }
152
153 return 0;
154 }
155
156 #endif /* INCLUDE_CMD_MSGBOX */
157
158 /* EOF */