Commandline MessageBox tool

This tool allows you to display a message box from a batch file or schedule tasks

To see how to use it just open the file up with no parameters and it will explain it.

program msgbox;
{$APPTYPE CONSOLE}
{ MessageBox tool for batch files}
{$RESOURCE MSGBOXAPP.RES}
uses
  SysUtils,
  windows,
  Classes;
function GetConsoleWindow:hwnd;stdcall;external 'kernel32.dll';
var params,iconcsv:tstringlist;
i,ret,mode,typ:integer;
msgparamset:msgboxparams;
osver:tosversioninfo;
contitle,text:array[0..1024]of char;
begin
typ:=0;
params:=tstringlist.Create;
zeromemory(@msgparamset,sizeof(msgboxparams));
msgparamset.cbSize:=sizeof(msgparamset);
for i:=1to paramcount do begin
 params.Add(Paramstr(i));
 if StrScan(Pchar(paramstr(i)),'=')=nil then begin
 writeln('Bad parameter option or unquoted text:',paramstr(i));
 exitprocess(9);
 end;
 end;
mode:= strtointdef(params.values['mode'],0);
 if(paramcount=0)or(params.Values['text']='') then begin
writeln('Usage: ',extractfilename(paramstr(0)),
' text=  [icon=] [button=] [mode=]');
writeln('text=          The message to show in the messagebox');
writeln('caption=       MessageBox window title');
writeln('icon=          Specifies the icon to use:');
writeln('               0=No icon(default)');
writeln('               ',mb_iconinformation,'=Information icon');
writeln('               ',mb_iconwarning,'=Warning icon');
writeln('               ',mb_iconerror,'=Error icon');
writeln('               ',mb_iconquestion,'=Question Mark');
writeln('button=        Button type number');
writeln('               0=ok(default)');
writeln('               ',mb_yesno,'=Yes/no');
writeln('               ',mb_yesnocancel,'=Yes/no/cancel');
writeln('               ',mb_okcancel,'=Ok/cancel');
writeln('               ',MB_ABORTRETRYIGNORE,'=abort/retry/ignore');
writeln('               ',MB_RETRYCANCEL,'=Retry/cancel');
writeln('mode=          Set optional modes, can be a combination of the following numbers:');
writeln('               1=Hide console window until finished');
writeln('               2=Don'#39't set console window as parent of the messagebox');
writeln('               4=Show message box to the current active desktop, even when no one is logged in.');
writeln('               8=the icon= specifies an icon filename and resource name seperated by a comma');
writeln('               16=the icon resource is an integer resource, only used with mode 8');
writeln;
writeln('ErrorLevel codes:');
writeln(IDABORT,'	Abort button was selected.');
writeln(IDCANCEL,'	Cancel button was selected.');
writeln(IDIGNORE,'	Ignore button was selected.');
writeln(IDNO,'	No button was selected.');
writeln(IDOK,'	OK button was selected.');
writeln(IDRETRY,'	Retry button was selected.');
writeln(IDYES,'	Yes button was selected.');
writeln(0,'     Out of memory error');
writeln(8,'     text= wasn'#39't provided error');
writeln(9,'     Parameter syntax error');
if paramcount=0then begin writeln('Press enter to return...');readln;end;
exitprocess(8);
end;
if mode and 8=8then begin
iconcsv:=tstringlist.Create;
iconcsv.CommaText:=params.Values['icon'];
typ:=typ or MB_USERICON;
msgparamset.hInstance:=loadlibrary(pchar(iconcsv[0]));
if mode and 16=0then msgparamset.lpszIcon :=pchar(iconcsv[1]) else
msgparamset.lpszIcon:=makeintresource(strtointdef(iconcsv[1],1));
iconcsv.Free;
end;
if mode and 4=4then
begin
zeromemory(@osver,sizeof(osver));
osver.dwOSVersionInfoSize:=sizeof(osver);
getversionex(osver);
if osver.dwMajorVersion>3 then typ:=typ or MB_SERVICE_NOTIFICATION else
typ:=typ or MB_SERVICE_NOTIFICATION_NT3X;//not sure if this tool is compatible with nt3.5
                                   //but just include it just incase.
end;
getconsoletitle(contitle,1025);
if params.Values['caption']=''then params.Values['caption']:=strpas(contitle);
if mode and 6=0 then msgparamset.hwndOwner:=getconsolewindow;
if mode and 1=1then showwindow(getconsolewindow,sw_hide);
msgparamset.lpszText:=strpcopy(text,params.values['text']);
msgparamset.lpszCaption:=strpcopy(contitle,params.values['caption']);
msgparamset.dwStyle:=msgparamset.dwStyle or typ or strtointdef(
params.values['icon'],0)or strtointdef(params.values['button'],0);
ret:=integer(messageboxindirect(msgparamset));
if mode and 1=1then showwindow(getconsolewindow,sw_show);
if ret=0 then writeln('MessageBox Failed');
exitprocess(ret);
end.

Published by Justin Roeder

I am an electronics engineer and computer programmer that has autism. I learned by myself

Leave a comment

Your email address will not be published. Required fields are marked *