{ Testing the wMessages2.pp unit.
  This is a very important unit in the GAP Library.
  All texts and language dependent information should be stored
  in a  .msg  message file. In this case the  tEx026.msg  message file
  This file is then ridden with the help of the wMessages2.pp unit.

  If the file  tEx026.msg  exist in the same directory as the executable file
  i.e. the directory and name are the same as the  '.exe'  file, with
  the extension  '.msg'  then it is opened automatically.
  Short tests.
  --------------------------------------------}
program tEx026;

// To tell FreePascal that the application is a Graphical User Interface
// i.e. is running in windows, not in text mode.
{$APPTYPE GUI}

Uses
  Windows
// ,wGlobals2
// ,wUtiles0
 ,wMessages2
 ,wApplication0
 ,wWindow0
 ,wErrors0
 ,wDebug0;

type
  PMyWindow = ^TMyWindow;
  TMyWindow = object(TWindow)
  //"""""""""""""""""""""""""
  constructor Init(strWinTitlePrm:ShortString);
  procedure WMPaint;
  procedure WMButtonDown;
  function WindowProc(hWindow:HWND; wMsg:UINT; wPar:WPARAM; lPar:LPARAM):LRESULT; virtual;
  end; // TMyWindow = object(TWindow0)

// var nNotUsed : integer; // only to avoid an error message while compliling in DevPascal 1.9

constructor TMyWindow.Init(strWinTitlePrm:ShortString);
//=====================================================
begin
inherited Init(strWinTitlePrm);
end;  // TMyWindow.Init

procedure TMyWindow.WMPaint;
//==========================
Var
  rRec        : rect;
  dc          : hdc;
  ps          : paintstruct;

begin
dc:=BeginPaint(hWin, @ps);
GetClientRect(hWin, @rRec);
DrawText( dc, 'Example 026 Testing the wMessages2.pp unit.',-1,@rRec,
          DT_SINGLELINE or DT_CENTER or DT_VCENTER);
rRec.Top :=rRec.top    + 50;
DrawText( dc, 'Click with the mouse',-1,@rRec,
          DT_SINGLELINE or DT_CENTER or DT_VCENTER);
EndPaint(hWin, ps);
end;  // TMyWindow.WMPaint

procedure TMyWindow.WMButtonDown;
//===============================
var
  strS        : ShortString;
  nn          : integer;

begin
// Opens the message file, to get texts from an external text file.
// OpenMsg(gglstrMsgPathName, nErr);  Already done in  TApplication.Run

// Reads a first line of text in the .msg file.
strS:=GetMsg(1000);
DBW0(1, 'Message=' + strS);
DBW0(1, '');

strS:=GetMsg(1010);
nn:=0;
repeat
   inc(nn); // security, to not loop forever
   DBW0(1, strS);
   strS:=GetMsg(msgNext);
   until (strS = '...END') or (nn > 20);  // nn > 20 is a security

DBW0(1, '');
DBW0(1, 'Read message from the standardEn.msg file');
DBW0(1, GetMsg(2000000000));
DBW0(1, GetMsg(2100000001));  // = 'English'
DBW0(1, GetMsg(2100000002));  // = 'No'
DBW0(1, GetMsg(2100000003));  // = 'Yes'

// close the message file.
// CloseAllMsg;  Already done in  TApplication.Run
end;  // TMyWindow.WMButtonDown

function TMyWindow.WindowProc(hWindow:HWND; wMsg:UINT; wPar:WPARAM; lPar:LPARAM):LRESULT;
//=======================================================================================
// All window messages are send here.

Begin
WindowProc := 0; // Default return value when processing a message

Case wMsg Of
   WM_paint : WMPaint;
   WM_LButtonDown,
   WM_RButtonDown : WMButtonDown;

   else begin // Case wMsg Of
      // Default processing of the messages.
      WindowProc:=inherited WindowProc(hWindow, wMsg, wPar, lPar);
      end; // Case wMsg Of
   End; // Case wMsg Of

End;  // TMyWindow.WindowProc

var
  oApp        : TApplication;
  poMyMainWin : PMyWindow;

Begin // MAIN ******
// Name under which the main window is registered. Spaces are not allowed
oApp.Init('Example026');

// Creation of the main window
new(poMyMainWin, Init('tEx026. Test the wMessages2.pp unit.'));

oApp.Run;
oApp.Done;  // The main window object is disposed here.
End.

