ReactOS  0.4.14-dev-845-g8381e29
msgbox.c
Go to the documentation of this file.
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 hardcoded strings in En.rc
11  */
12 
13 #include "precomp.h"
14 
15 #ifdef INCLUDE_CMD_MSGBOX
16 
17 
18 #define U_TYPE_INIT 0
19 
20 //undefine it to allow to omit arguments
21 //that will be replaced by default ones
22 #define _SYNTAX_CHECK
23 
24 
26 {
27  //used to parse command line
28  LPTSTR tmp;
29 
30  //used to find window title (used as messagebox title)
31  //and to find window handle to pass to MessageBox
32  HWND hWnd;
33  TCHAR buff[128];
34 
35  //these are MessageBox() parameters
36  LPTSTR title, prompt = "";
37  UINT uType = U_TYPE_INIT;
38 
39  /* set default title to window title */
41  title = buff;
42 
43  if (_tcsncmp (param, _T("/?"), 2) == 0)
44  {
46  return 0;
47  }
48 
49  //yes here things are quite massed up :)
50 
51  //skip spaces
52  while(_istspace(*param))
53  param++;
54 
55  //search for type of messagebox (ok, okcancel, ...)
56  if (_tcsnicmp(param, _T("ok "), 3) == 0)
57  {
58  uType |= MB_ICONEXCLAMATION | MB_OK;
59  param += 3;
60  }
61  else if (_tcsnicmp(param, _T("okcancel "), 9) == 0)
62  {
63  uType |= MB_ICONQUESTION | MB_OKCANCEL;
64  param += 9;
65  }
66  else if (_tcsnicmp(param, _T("yesno "), 6) == 0)
67  {
68  uType |= MB_ICONQUESTION | MB_YESNO;
69  param += 6;
70  }
71  else if (_tcsnicmp(param, _T("yesnocancel "), 12) == 0)
72  {
74  param += 12;
75  }
76  else
77  {
78 #ifdef _SYNTAX_CHECK
80  return 1;
81 #else
82  uType |= MB_ICONEXCLAMATION | MB_OK;
83 #endif
84  }
85 
86  //skip spaces
87  while(_istspace(*param))
88  param++;
89 
90 #ifdef _SYNTAX_CHECK
91  //if reached end of string
92  //it is an error becuase we do not yet have prompt
93  if (*param == 0)
94  {
96  return 1;
97  }
98 #endif
99 
100  //search for "title"
101  tmp = param;
102 
103  if (*param == '"')
104  {
105  tmp = _tcschr(param + 1, '"');
106  if (tmp)
107  {
108  *tmp = 0;
109  title = param + 1;
110  tmp++;
111  param = tmp;
112  }
113  }
114 
115  //skip spaces
116  while(_istspace(*param))
117  param++;
118 
119 #ifdef _SYNTAX_CHECK
120  //get prompt
121  if (*param == 0)
122  {
124  return 1;
125  }
126 #endif
127 
128  prompt = param;
129 
131 
132  switch (MessageBox(hWnd, prompt, title, uType))
133  {
134  case IDYES:
135  case IDOK:
136  nErrorLevel = 10;
137  break;
138 
139  case IDNO:
140  nErrorLevel = 11;
141  break;
142 
143  case IDCANCEL:
144  nErrorLevel = 12;
145  break;
146  }
147 
148  return 0;
149 }
150 
151 #endif /* INCLUDE_CMD_MSGBOX */
152 
153 /* EOF */
INT nErrorLevel
Definition: cmd.c:157
#define TRUE
Definition: types.h:120
#define IDOK
Definition: winuser.h:824
#define IDYES
Definition: winuser.h:829
HWND hWnd
Definition: settings.c:17
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
VOID ConOutResPaging(BOOL StartPaging, UINT resID)
Definition: console.c:182
int32_t INT
Definition: typedefs.h:56
INT CommandMsgbox(LPTSTR)
CHAR * LPTSTR
Definition: xmlstorage.h:192
#define MB_ICONEXCLAMATION
Definition: winuser.h:779
#define MB_YESNO
Definition: winuser.h:811
#define _tcsnicmp
Definition: xmlstorage.h:207
VOID error_req_param_missing(VOID)
Definition: error.c:108
#define MB_ICONQUESTION
Definition: winuser.h:783
#define MB_YESNOCANCEL
Definition: winuser.h:812
#define GetConsoleTitle
Definition: wincon.h:763
#define MB_OKCANCEL
Definition: winuser.h:798
_TCHAR * _tcschr(const _TCHAR *s, _XINT c)
Definition: tcschr.h:4
char TCHAR
Definition: xmlstorage.h:189
#define _T(x)
Definition: vfdio.h:22
GLfloat param
Definition: glext.h:5796
#define MessageBox
Definition: winuser.h:5797
unsigned int UINT
Definition: ndis.h:50
#define MB_OK
Definition: winuser.h:784
#define STRING_MSGBOX_HELP
Definition: resource.h:149
#define _istspace
Definition: tchar.h:1504
#define IDNO
Definition: winuser.h:830
#define IDCANCEL
Definition: winuser.h:825
static char title[]
Definition: ps.c:92
static unsigned char buff[32768]
Definition: fatten.c:17
int _tcsncmp(const _TCHAR *s1, const _TCHAR *s2, size_t n)
Definition: tcsncmp.h:9
HWND WINAPI DECLSPEC_HOTPATCH GetConsoleWindow(VOID)
Definition: console.c:2730