Metropoli BBS
VIEWER: contain4.pas MODE: TEXT (CP437)
{█▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀█}
{█                                                       █}
{█      Virtual Pascal Examples. Version 1.10            █}
{█        Container Example #4                           █}
{█        The Art Of OS/2, Chapter 23, p440-454          █}
{█      ─────────────────────────────────────────────────█}
{█      Copyright (c) 1992-1996 by Larry Salomon         █}
{█      VP/2 Version Copyright (C) 1996 fPrint UK Ltd    █}
{█                                                       █}
{▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀}

Program Contain4;

{$PMTYPE PM}
{$R *.RES}
{$D First container example - Copyright 1992 by Larry Salomon}

Uses
  Use32, Os2Def, Os2PmApi, Strings, VPUtils;

{$IFDEF VPDEMO}
  {&Dynamic VP11Demo.Lib}
{$ENDIF}

Const
  RES_CLIENT           = 256;
  WND_CONTAINER        = 257;
  ICO_ITEM             = 258;
  M_VIEWS              = 320;
  MI_ICON              = 321;
  MI_DETAIL            = 322;
  MI_TREE              = 323;
  MI_NAMEFLOWED        = 324;
  MI_TEXTFLOWED        = 325;
  M_EXIT               = 336;
  M_SORT               = 336;
  MI_SORTBYUNITS       = 337;
  MI_SORTBYYEAR        = 338;
  M_FILTER             = 352;
  MI_FILTER300DOLLARS  = 353;
  MI_FILTER400DOLLARS  = 354;
  MI_FILTER500DOLLARS  = 355;
  MI_FILTERNONE        = 356;
  MI_EXIT              = 368;
  MI_RESUME            = 338;
  CLS_CLIENT           = 'SampleClass';
  MAX_YEARS            = 10;
  MAX_MONTHS           = 12;
  MAX_COLUMNS          = 4;
  CX_SPLITBAR          = 120;

Type
  ptClientData = ^tClientData;
  tClientData = Record
    hwndCnr      : HWnd;
    hptrIcon     : HPointer;
    hwndMenu     : HWnd;
    bCnrSelected : Bool;
  end;
  ptSalesInfo = ^tSalesInfo;
  tSalesInfo = Record
    mrcStd       : MINIRECORDCORE;
    bEmphasized  : Bool;
    ulNumUnits   : ULONG;
    fSales       : Extended;
    pchSales     : PCHAR;
  end;

Procedure InitSalesInfo( pcdData  : ptClientData;
                         psiParent : ptSalesInfo;
                         psiSales : ptSalesInfo;
                         usIndex  : SmallInt);
Var
  pchPos : PChar;
  TempS  : String;

begin
   psiSales^.mrcStd.cb := sizeof(MINIRECORDCORE);

   GetMem( psiSales^.mrcStd.pszIcon, 256 );
   if psiSales^.mrcStd.pszIcon <> Nil then
     If psiParent <> nil then
       begin
         TempS := 'Month '+Int2Str(usIndex+1);
         strpCopy( psiSales^.mrcStd.pszIcon, TempS );
       end
     else
       begin
         TempS := 'Year 19'+Int2Str(usIndex+84);
         strpCopy( psiSales^.mrcStd.pszIcon, TempS );
       end;

   psiSales^.mrcStd.hptrIcon := pcdData^.hptrIcon;
   psiSales^.bEmphasized := FALSE;
   If psiParent <> nil then
     psiSales^.ulNumUnits := psiParent^.ulNumUnits div 12
   else
     psiSales^.ulNumUnits := Random( 100 );
   psiSales^.fSales := psiSales^.ulNumUnits * 9.95;

   GetMem( psiSales^.pchSales, 16 );
   if psiSales^.pchSales <> Nil then
     begin
       Str( psiSales^.fSales:10:2, TempS );
       StrPCopy( psiSales^.pchSales, TempS );
     end;
end;

Function SortRecords( psiFirst     : ptSalesInfo;
                      psiSecond    : ptSalesInfo;
                      pusSortBy    : pSmallInt ) : SmallInt; cdecl;
begin
  Case pusSortBy^ of
    MI_SORTBYUNITS :
      if psiFirst^.ulNumUnits < psiSecond^.ulNumUnits then
        SortRecords := -1
      else
        if psiFirst^.ulNumUnits = psiSecond^.ulNumUnits then
          SortRecords := 0
        else
          SortRecords := 1;
    MI_SORTBYYEAR :
      SortRecords := StrComp( psiFirst^.mrcStd.pszIcon,
                              psiSecond^.mrcStd.pszIcon );
    else
      SortRecords := 0;
  end;
end; { SortRecords }

Function FilterRecords( psiInfo: ptSalesInfo;
                        pusFilterBy: pSmallInt) : Bool; cdecl;
begin
  Case pusFilterBy^ of
    MI_FILTER300DOLLARS :
      FilterRecords := (psiInfo^.fSales > 300.0);
    MI_FILTER400DOLLARS :
      FilterRecords := (psiInfo^.fSales > 400.0);
    MI_FILTER500DOLLARS :
      FilterRecords := (psiInfo^.fSales > 500.0);
    MI_FILTERNONE :
      FilterRecords := True;
    else
      FilterRecords := True;
  end;
end;

procedure EmphasizeRecs( hwndCnr: HWnd; bEmphasize: Bool );
Var
  sFlag   : SmallInt;
  psiYear : ptSalesInfo;
begin
  If bEmphasize then
    sFlag := CRA_Selected
  else
    sFlag := CRA_Source;

  psiYear := ptSalesInfo(
               pVoidFromMR(
                 WinSendMsg( hwndCnr,
                             CM_QUERYRECORDEMPHASIS,
                             MPFROMShort( CMA_FIRST ),
                             MPFROMSHORT( sFlag ))));

  while psiYear <> nil do
    begin
      if bEmphasize then
        begin
          WinSendMsg( hwndCnr,
                      CM_SETRECORDEMPHASIS,
                      MPFROMP(psiYear),
                      MPFROM2SHORT(ord(TRUE), CRA_SOURCE));

          psiYear^.bEmphasized := TRUE;
        end
      else
        begin
          WinSendMsg( hwndCnr,
                      CM_SETRECORDEMPHASIS,
                      MPFROMP(psiYear),
                      MPFROM2SHORT(ord(FALSE), CRA_SOURCE));

          psiYear^.bEmphasized := FALSE;
        end;
      psiYear := ptSalesInfo(
                   pVoidFromMR(
                     WinSendMsg( hwndCnr,
                                 CM_QUERYRECORDEMPHASIS,
                                 MPFROMP(psiYear),
                                 MPFROMSHORT(sFlag) )) );
   end; { While }
end; { EmphasizeRecs }

Procedure freeCnrInfo( hwndCnr: HWnd );
Var
  psiYear  : ptSALESINFO;
  psiMonth : ptSALESINFO;

begin
   psiYear := ptSALESINFO(
                PVOIDFROMMR(
                  WinSendMsg( hwndCnr,
                              CM_QUERYRECORD,
                              0,
                              MPFROM2SHORT(CMA_FIRST, CMA_ITEMORDER))));

   while psiYear <> Nil do
     begin
       psiMonth := ptSALESINFO(
                     PVOIDFROMMR(
                       WinSendMsg( hwndCnr,
                                   CM_QUERYRECORD,
                                   MPFromP( psiYear ),
                                   MPFROM2SHORT(CMA_FIRSTCHILD, CMA_ITEMORDER))));
       While psiMonth <> nil do
         begin
           if psiYear^.mrcStd.pszIcon <> Nil then
             freeMem(psiMonth^.mrcStd.pszIcon, 256 );

           if psiMonth^.pchSales <> Nil then
             freeMem(psiMonth^.pchSales, 16);

           psiMonth:= ptSALESINFO(
                        PVOIDFROMMR(
                          WinSendMsg( hwndCnr,
                                      CM_QUERYRECORD,
                                      MPFROMP(psiMonth),
                                      MPFROM2SHORT(CMA_NEXT,CMA_ITEMORDER))));
         end;

       if psiYear^.mrcStd.pszIcon <> Nil then
         freeMem(psiYear^.mrcStd.pszIcon, 256 );

       if psiYear^.pchSales <> Nil then
         freeMem(psiYear^.pchSales, 16);

       psiYear := ptSALESINFO(
                    PVOIDFROMMR(
                      WinSendMsg( hwndCnr,
                                  CM_QUERYRECORD,
                                  MPFROMP(psiYear),
                                  MPFROM2SHORT(CMA_NEXT,CMA_ITEMORDER))));
     end;
end;

procedure InitColumns( pcdData : ptClientData );
Var
  ciInfo       : CNRINFO;
  pfiCurrent   : PFIELDINFO;
  pfiInfo      : PFIELDINFO;
  pfiLefty     : PFIELDINFO;
  fiiInfo      : FIELDINFOINSERT;

begin
   pfiInfo := pFieldInfo(
                PVoidFromMr(
                  WinSendMsg( pcdData^.hwndCnr,
                              CM_ALLOCDETAILFIELDINFO,
                              MPFROMLONG(MAX_COLUMNS), 0)));

   pfiCurrent := pfiInfo;

   pfiCurrent^.flData := CFA_BITMAPORICON OR CFA_HORZSEPARATOR OR CFA_CENTER
       OR CFA_SEPARATOR;

   pfiCurrent^.flTitle := CFA_STRING OR CFA_CENTER;
   pfiCurrent^.pTitleData := StrNew( 'Icon' );
   pfiCurrent^.offStruct := ofs( ptSALESINFO(nil)^.mrcStd.hptrIcon );

   pfiCurrent := pfiCurrent^.pNextFieldInfo;
   pfiCurrent^.flData := CFA_STRING OR CFA_CENTER OR CFA_HORZSEPARATOR;

   pfiCurrent^.flTitle := CFA_STRING OR CFA_CENTER;
   pfiCurrent^.pTitleData := StrNew( 'Year' );
   pfiCurrent^.offStruct := ofs( ptSALESINFO(nil)^.mrcStd.pszIcon );

   pfiLefty := pfiCurrent;

   pfiCurrent := pfiCurrent^.pNextFieldInfo;
   pfiCurrent^.flData := CFA_ULONG OR CFA_CENTER OR CFA_HORZSEPARATOR OR
      CFA_SEPARATOR;

   pfiCurrent^.flTitle := CFA_STRING OR CFA_CENTER;
   pfiCurrent^.pTitleData := strnew('Units Sold');
   pfiCurrent^.offStruct := ofs( ptSALESINFO(nil)^.ulNumUnits );

   pfiCurrent := pfiCurrent^.pNextFieldInfo;
   pfiCurrent^.flData := CFA_STRING OR CFA_RIGHT OR CFA_HORZSEPARATOR;

   pfiCurrent^.flTitle := CFA_STRING OR CFA_CENTER;
   pfiCurrent^.pTitleData := StrNew('Sales');
   pfiCurrent^.offStruct := ofs( ptSALESINFO(nil)^.pchSales );

   fiiInfo.cb := sizeof(fiiInfo);
   fiiInfo.pFieldInfoOrder := pFIELDINFO(CMA_FIRST);
   fiiInfo.cFieldInfoInsert := MAX_COLUMNS;
   fiiInfo.fInvalidateFieldInfo := ord(TRUE);

   WinSendMsg(pcdData^.hwndCnr,
              CM_INSERTDETAILFIELDINFO,
              MPFROMP(pfiInfo),
              MPFROMP(@fiiInfo));

   ciInfo.cb := sizeof(CNRINFO);
   ciInfo.pFieldInfoLast := pfiLefty;
   ciInfo.xVertSplitbar := CX_SPLITBAR;

   WinSendMsg(pcdData^.hwndCnr,
              CM_SETCNRINFO,
              MPFROMP(@ciInfo),
              MPFROMLONG(CMA_PFIELDINFOLAST OR CMA_XVERTSPLITBAR));

end;

Function ClientWndProc ( hwndClient : HWND ;
                         ulMsg      : ULONG;
                         mpParm1    : MPARAM;
                         mpParm2    : MPARAM ) : mResult; cdecl;
Var
  hpsPaint  : HPS;
  rclPaint  : RECTL;
  pcdData   : ptCLIENTDATA;
  ulExtra   : ULONG;
  riRecord  : RECORDINSERT;
  psiYears  : PtSALESINFO;
  psiCYear  : PtSALESINFO;
  psiMonths : PtSALESINFO;
  psiCMonth : PtSALESINFO;
  usIndex1  : USHORT;
  usIndex2  : USHORT;
  ciInfo    : CNRINFO;
  miItem    : MenuItem;
  ulStyle   : ULong;
  psiSales  : ptSalesInfo;
  ptlMouse  : PointL;
  usId      : SmallInt;

begin
  ClientWndProc := ord(False);

  pcdData := ptClientData( WinQueryWindowPtr(hwndClient, 0) );

  Case ulMsg of
    WM_CREATE :
      begin
        New( pcdData );

        if pcdData = Nil then
          begin
            WinAlarm(HWND_DESKTOP,
                     WA_ERROR);
            WinMessageBox(HWND_DESKTOP,
                          HWND_DESKTOP,
                          'No memory is available',
                          'Error',
                          0,
                          MB_ICONEXCLAMATION OR MB_OK);
            ClientWndProc := ord(True);
         end;

        WinSetWindowPtr(hwndClient,
                        0,
                        pcdData);

        pcdData^.hwndCnr := NULLHANDLE;
        pcdData^.hptrIcon := NULLHANDLE;
        pcdData^.hwndMenu := NULLHANDLE;
        pcdData^.bCnrSelected := FALSE;

        pcdData^.hwndCnr := WinCreateWindow(hwndClient,
                                           WC_CONTAINER,
                                           '',
                                           CCS_MINIRECORDCORE OR
                                              CCS_EXTENDSEL OR
                                              WS_VISIBLE,
                                           0,
                                           0,
                                           0,
                                           0,
                                           hwndClient,
                                           HWND_TOP,
                                           WND_CONTAINER,
                                           Nil,
                                           Nil);

        if pcdData^.hwndCnr = NULLHANDLE then
          begin
            Dispose(pcdData);
            WinAlarm(HWND_DESKTOP,
                     WA_ERROR);
            WinMessageBox(HWND_DESKTOP,
                          HWND_DESKTOP,
                          'Cannot create container',
                          'Error',
                          0,
                          MB_ICONEXCLAMATION OR MB_OK);
            ClientWndProc := ord(True);
          end;

        pcdData^.hptrIcon := WinLoadPointer(HWND_DESKTOP,
                                            NULLHANDLE,
                                            ICO_ITEM);

        pcdData^.hwndMenu := WinLoadMenu(hwndClient,
                                         NULLHANDLE,
                                         RES_CLIENT);
 { -------------------------------------------------------------- }
 {  'Gotcha' note:  you cannot specify the MS_CONDITIONALCASCADE  }
 {  style in the .RC file.  You *must* do it this way.  Also,     }
 {  you must pad the pull-right text with spaces to account for   }
 {  the button that will be placed there.                         }
 { -------------------------------------------------------------- }
        WinSendMsg( pcdData^.hwndMenu,
                    MM_QUERYITEM,
                    MPFROM2SHORT(M_VIEWS, ord(TRUE)),
                    MPFROMP(@miItem) );

        ulStyle := WinQueryWindowULong(miItem.hwndSubMenu,
                                       QWL_STYLE);

        ulStyle := ulStyle OR ms_ConditionalCascade;
        WinSetWindowULong( miItem.hwndSubMenu,
                           QWL_STYLE,
                           ulStyle );

        WinSendMsg( miItem.hwndSubMenu,
                    MM_SETDEFAULTITEMID,
                    MPFROMSHORT(MI_ICON),
                    0 );

        ulExtra := sizeof(tSALESINFO)-sizeof(MINIRECORDCORE);

        riRecord.cb := sizeof(RECORDINSERT);
        riRecord.pRecordOrder := PRECORDCORE(CMA_END);
        riRecord.fInvalidateRecord := ord(FALSE);
        riRecord.zOrder := CMA_TOP;

        psiYears :=
          ptSALESINFO(
            PVOIDFROMMR(
              WinSendMsg(pcdData^.hwndCnr,
                         CM_ALLOCRECORD,
                         MPFROMLONG(ulExtra),
                         MPFROMSHORT(MAX_YEARS) )));

        psiCYear := psiYears;

        for usIndex1 := 0 to MAX_YEARS-1 do
          begin
            initSalesInfo( pcdData,
                           nil,
                           psiCYear,
                           usIndex1 );

            riRecord.pRecordParent := Nil;
            riRecord.cRecordsInsert := 1;

            WinSendMsg(pcdData^.hwndCnr,
                       CM_INSERTRECORD,
                       MPFROMP(psiCYear),
                       MPFROMP(@riRecord));

            psiMonths :=
              ptSalesInfo(
                pVoidFromMR(
                  WinSendMsg( pcdData^.hwndCnr,
                              CM_ALLOCRECORD,
                              MPFROMLONG(ulExtra),
                              MPFROMSHORT(MAX_MONTHS) ) ) );

            psiCMonth := psiMonths;

            for usIndex2 := 0 to MAX_MONTHS-1 do
              begin
                initSalesInfo(pcdData,
                              psiCYear,
                              psiCMonth,
                              usIndex2);

                psiCMonth := ptSalesInfo( psiCMonth^.mrcStd.preccNextRecord );
              end;
            riRecord.pRecordParent := pRecordCore( psiCYear );
            riRecord.cRecordsInsert := MAX_MONTHS;

            WinSendMsg(pcdData^.hwndCnr,
                       CM_INSERTRECORD,
                       MPFROMP(psiMonths),
                       MPFROMP(@riRecord));

            psiCYear := ptSALESINFO( psiCYear^.mrcStd.preccNextRecord );
          end;

        InitColumns( pcdData );

        WinSendMsg(hwndClient,
                   WM_COMMAND,
                   MPFROMSHORT(MI_ICON),
                   0);
      end; { WM_CREATE }

    WM_DESTROY :
      begin
        freeCnrInfo( pcdData^.hwndCnr );

        if pcdData^.hwndCnr <> NULLHANDLE then
          WinDestroyWindow(pcdData^.hwndCnr);

        if pcdData^.hptrIcon <> NULLHANDLE then
          WinDestroyPointer(pcdData^.hptrIcon);

        Dispose( pcdData );
      end; { WM_DESTROY }

    WM_SIZE :
      If pcdData^.hwndCnr <> NULLHANDLE then
        WinSetWindowPos( pcdData^.hwndCnr,
                         NULLHANDLE,
                         0,
                         0,
                         SHORT1FROMMP(mpParm2),
                         SHORT2FROMMP(mpParm2),
                         SWP_MOVE OR SWP_SIZE);


    WM_MENUEND :
      Case Short1FromMP( mpParm1 ) of
        FID_MENU :
          if pcdData^.bCnrSelected then
            begin
              WinSendMsg( pcdData^.hwndCnr,
                          CM_SETRECORDEMPHASIS,
                          0,
                          MPFROM2SHORT(ord(FALSE), CRA_SOURCE));
              pcdData^.bCnrSelected := FALSE;
            end
          else
            emphasizeRecs( pcdData^.hwndCnr, FALSE );

        else
          ClientWndProc := WinDefWindowProc( hwndClient,
                                             ulMsg,
                                             mpParm1,
                                             mpParm2);
        end; { Case Short1(mp1) }
      { End WM_MENUEND }

    WM_CONTROL :
      Case Short1FromMP( mpParm1 ) of
        WND_CONTAINER :
          Case Short2FromMP( mpParm1 ) of
            CN_CONTEXTMENU :
              begin
                psiSales := ptSalesInfo( pVoidFromMP( mpParm2 ));
                if psiSales <> nil then
                  begin
                    if psiSales^.mrcStd.flRecordAttr AND CRA_SELECTED = 0 then
                      begin
                        WinSendMsg( pcdData^.hwndCnr,
                                    CM_SETRECORDEMPHASIS,
                                    MPFROMP(psiSales),
                                    MPFROM2SHORT(ord(TRUE), CRA_SOURCE));
                        psiSales^.bEmphasized := TRUE;
                      end
                    else
                      emphasizeRecs(pcdData^.hwndCnr, TRUE);
                  end
                else
                  begin
                    WinSendMsg( pcdData^.hwndCnr,
                                CM_SETRECORDEMPHASIS,
                                0,
                                MPFROM2SHORT(ord(TRUE), CRA_SOURCE));
                    pcdData^.bCnrSelected := TRUE;
                  end;

                WinQueryPointerPos( HWND_DESKTOP, ptlMouse);
                WinMapWindowPoints( HWND_DESKTOP,
                                    hwndClient,
                                    ptlMouse,
                                    1);
                WinPopupMenu( hwndClient,
                              hwndClient,
                              pcdData^.hwndMenu,
                              ptlMouse.x,
                              ptlMouse.y,
                              M_VIEWS,
                              PU_HCONSTRAIN OR PU_VCONSTRAIN OR
                              PU_KEYBOARD OR PU_MOUSEBUTTON1 OR
                              PU_MOUSEBUTTON2 OR PU_NONE);
              end; { CN_CONTEXTMENU }
            else
              ClientWndProc := WinDefWindowProc( hwndClient,
                                                 ulMsg,
                                                 mpParm1,
                                                 mpParm2);
            end; { Case Short2(mp1) }
      else
        ClientWndProc := WinDefWindowProc( hwndClient,
                                           ulMsg,
                                           mpParm1,
                                           mpParm2);
      end; { Case Short1( mp1 ) }
      { End WM_CONTROL }

    WM_COMMAND :
      Case SHORT1FROMMP(mpParm1) of
        MI_ICON :
          begin
            ciInfo.cb := sizeof(CNRINFO);
            ciInfo.flWindowAttr := CV_ICON;

            WinSendMsg( pcdData^.hwndCnr,
                        CM_SETCNRINFO,
                        MPFROMP(@ciInfo),
                        MPFROMLONG(CMA_FLWINDOWATTR) );

            WinSendMsg( pcdData^.hwndCnr,
                        CM_ARRANGE,
                        0,
                        0);
          end;

        MI_DETAIL :
          begin
            ciInfo.cb := sizeof(CNRINFO);
            ciInfo.flWindowAttr := CV_DETAIL OR CA_DETAILSVIEWTITLES;

            WinSendMsg( pcdData^.hwndCnr,
                        CM_SETCNRINFO,
                        MPFROMP(@ciInfo),
                        MPFROMLONG(CMA_FLWINDOWATTR));
          end;

        MI_TREE :
          begin
            ciInfo.cb := sizeof(CNRINFO);
            ciInfo.flWindowAttr := CV_TREE OR CV_ICON OR CA_TREELINE;
            ciInfo.cxTreeIndent := -1;
            ciInfo.cxTreeLine := -1;

            WinSendMsg( pcdData^.hwndCnr,
                        CM_SETCNRINFO,
                        MPFROMP(@ciInfo),
                        MPFROMLONG(CMA_FLWINDOWATTR) );
          end;

        MI_NAMEFLOWED :
          begin
            ciInfo.cb := sizeof(CNRINFO);
            ciInfo.flWindowAttr := CV_NAME OR CV_FLOW;

            WinSendMsg(pcdData^.hwndCnr,
                       CM_SETCNRINFO,
                       MPFROMP(@ciInfo),
                       MPFROMLONG(CMA_FLWINDOWATTR));

            WinSendMsg(pcdData^.hwndCnr,
                       CM_ARRANGE,
                       0,
                       0);

         end;

       MI_TEXTFLOWED :
         begin

           ciInfo.cb := sizeof(CNRINFO);
           ciInfo.flWindowAttr := CV_TEXT OR CV_FLOW;

           WinSendMsg(pcdData^.hwndCnr,
                      CM_SETCNRINFO,
                      MPFROMP(@ciInfo),
                      MPFROMLONG(CMA_FLWINDOWATTR));

           WinSendMsg(pcdData^.hwndCnr,
                      CM_ARRANGE,
                      0,
                      0);
         end;

       MI_SORTBYUNITS :
         begin
           usId := MI_SORTBYUNITS;

           WinSendMsg( pcdData^.hwndCnr,
                       CM_SORTRECORD,
                       MPFROMP(@sortRecords),
                       MPFROMP(@usId) );
         end;

       MI_SORTBYYEAR :
         begin
           usId := MI_SORTBYYEAR;

           WinSendMsg( pcdData^.hwndCnr,
                       CM_SORTRECORD,
                       MPFROMP(@sortRecords),
                       MPFROMP(@usId) );
         end;

       MI_FILTER300DOLLARS :
         begin
           usId := MI_FILTER300DOLLARS;

           WinSendMsg( pcdData^.hwndCnr,
                       CM_FILTER,
                       MPFROMP(@filterRecords),
                       MPFROMP(@usId) );
         end;

       MI_FILTER400DOLLARS :
         begin
           usId := MI_FILTER400DOLLARS;

           WinSendMsg( pcdData^.hwndCnr,
                       CM_FILTER,
                       MPFROMP(@filterRecords),
                       MPFROMP(@usId) );
         end;

       MI_FILTER500DOLLARS :
         begin
           usId := MI_FILTER500DOLLARS;

           WinSendMsg( pcdData^.hwndCnr,
                       CM_FILTER,
                       MPFROMP(@filterRecords),
                       MPFROMP(@usId) );
         end;

       MI_FILTERNONE :
         begin
           usId := MI_FILTERNONE;

           WinSendMsg( pcdData^.hwndCnr,
                       CM_FILTER,
                       MPFROMP(@filterRecords),
                       MPFROMP(@usId) );
          end;

       MI_EXIT :
         WinPostMsg(hwndClient, WM_CLOSE, 0, 0);

     else
       ClientWndProc := WinDefWindowProc( hwndClient,
                                          ulMsg,
                                          mpParm1,
                                          mpParm2);
     end; { WM_COMMAND }

   WM_PAINT :
     begin
        hpsPaint := WinBeginPaint( hwndClient,
                                   NULLHANDLE,
                                   @rclPaint);
        WinFillRect( hpsPaint,
                     rclPaint,
                     SYSCLR_WINDOW );
        WinEndPaint(hpsPaint);
     end;

   else
     ClientWndProc := WinDefWindowProc( hwndClient,
                                        ulMsg,
                                        mpParm1,
                                        mpParm2);
   end; { Case ulMsg }
end;

Var
  habAnchor   : HAB;
  hmqQueue    : HMQ;
  ulFlags     : ULONG;
  hwndFrame   : HWND;
  qmMsg       : QMSG;
  bLoop       : BOOL;

begin
  Randomize;
  habAnchor := WinInitialize(0);
  hmqQueue := WinCreateMsgQueue(habAnchor,
                               0);

  WinRegisterClass(habAnchor,
                   CLS_CLIENT,
                   clientWndProc,
                   0,
                   sizeof(Pointer));

  ulFlags := FCF_SIZEBORDER OR FCF_TITLEBAR OR FCF_TASKLIST OR
     FCF_SHELLPOSITION OR FCF_SYSMENU;

  hwndFrame := WinCreateStdWindow(HWND_DESKTOP,
                                  WS_VISIBLE,
                                  ulFlags,
                                  CLS_CLIENT,
                                  'Container Sample',
                                  0,
                                  NULLHANDLE,
                                  RES_CLIENT,
                                  Nil);

  if hwndFrame <> NULLHANDLE then
  begin
     bLoop := WinGetMsg(habAnchor,
                        qmMsg,
                        NULLHANDLE,
                        0,
                        0);
     while bLoop do
     begin
        WinDispatchMsg(habAnchor,
                       qmMsg);
        bLoop := WinGetMsg(habAnchor,
                           qmMsg,
                           NULLHANDLE,
                           0,
                           0);
     end;
     WinDestroyWindow(hwndFrame);
  end;

  WinDestroyMsgQueue(hmqQueue);
  WinTerminate(habAnchor);
end.


[ RETURN TO DIRECTORY ]