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 25 INT CommandMsgbox (LPTSTR param) 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 */ 40 GetConsoleTitle(buff, ARRAYSIZE(buff)); 41 title = buff; 42 43 if (_tcsncmp (param, _T("/?"), 2) == 0) 44 { 45 ConOutResPaging(TRUE,STRING_MSGBOX_HELP); 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 { 73 uType |= MB_ICONQUESTION | MB_YESNOCANCEL; 74 param += 12; 75 } 76 else 77 { 78 #ifdef _SYNTAX_CHECK 79 error_req_param_missing (); 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 { 95 error_req_param_missing (); 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 { 123 error_req_param_missing (); 124 return 1; 125 } 126 #endif 127 128 prompt = param; 129 130 hWnd=GetConsoleWindow (); 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 */ 154