home *** CD-ROM | disk | FTP | other *** search
/ Windows 95 v2.4 Fix / W95-v2.4fix.iso / ACADWIN / ADS / CPP / MFCADS / MFCLIST / MFCWND.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-08  |  4.5 KB  |  156 lines

  1. /* 
  2.     MFCWND.CPP -
  3.     
  4.     This file:
  5.  
  6.         Defines CWINDOW that contains a CListBox and a CStatic.
  7.  
  8.     ( C ) Copyright 1988-1994 by Autodesk, Inc.
  9.  
  10.     This program is copyrighted by Autodesk, Inc. and is  licensed
  11.     to you under the following conditions.  You may not distribute
  12.     or  publish the source code of this program in any form.   You
  13.     may  incorporate this code in object form in derivative  works
  14.     provided  such  derivative  works  are  ( i. ) are  designed and
  15.     intended  to  work  solely  with  Autodesk, Inc. products, and
  16.     ( ii. )  contain  Autodesk's  copyright  notice  "( C )  Copyright
  17.     1988-1994 by Autodesk, Inc."
  18.  
  19.     AUTODESK  PROVIDES THIS PROGRAM "AS IS" AND WITH  ALL  FAULTS.
  20.     AUTODESK  SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF  MER-
  21.     CHANTABILITY OR FITNESS FOR A PARTICULAR USE.  AUTODESK,  INC.
  22.     DOES  NOT  WARRANT THAT THE OPERATION OF THE PROGRAM  WILL  BE
  23.     UNINTERRUPTED OR ERROR FREE.
  24.  
  25. */
  26. #include "mfclist.h"
  27.  
  28. /******************************************************************************
  29. *                                                                             *
  30. *                            CWINDOW member functions                         *
  31. *                                                                             *
  32. ******************************************************************************/
  33. //-----------------------------------------------------------------------------
  34. // The window's constructor
  35. CWINDOW::CWINDOW()
  36.     CRect rect;
  37.  
  38.     Create( NULL
  39.             , "ADS MFCList Demo"
  40.             , WS_OVERLAPPEDWINDOW
  41.             , CRect( 0,0,250,100 ) ); 
  42.     
  43.     GetClientRect( &rect );
  44.     rect.bottom -= 24;
  45.     list = new CListBox();
  46.     list->Create( WS_CHILD | WS_VISIBLE|WS_BORDER 
  47.                     | WS_VSCROLL | WS_HSCROLL | LBS_NOINTEGRALHEIGHT
  48.                     | LBS_NOTIFY | LBS_EXTENDEDSEL
  49.                   , rect
  50.                   , this
  51.                   , LIST );
  52.  
  53.     GetClientRect( &rect );
  54.     rect.top = rect.bottom - 24;        
  55.     label = new CStatic();
  56.     label->Create( "xxx"
  57.                 , WS_CHILD | WS_BORDER | WS_VISIBLE
  58.                 , rect
  59.                 , this
  60.                 , LABEL );
  61.  
  62.     entity_name[ 0 ] = 0;
  63.     entity_name[ 1 ] = 0;
  64.     // Fill the list
  65.     ads_name    ename;
  66.  
  67.     if ( ads_entnext( NULL, ename ) != RTERROR )
  68.     {
  69.         do
  70.         {
  71.             struct resbuf *rb;
  72.             rb = ads_entget( ename );
  73.  
  74.             ADS_ENT_OBJ* temp_obj = MakeAdsEntity( rb );
  75.             if ( temp_obj != 0 )
  76.             {
  77.                 char s[100];
  78.                 temp_obj->GetEntityName( s, 100 );
  79.                 list->AddString( s );
  80.                 DeleteAdsEntity( temp_obj );
  81.             }
  82.             ads_relrb( rb );
  83.         }
  84.         while ( ads_entnext( ename, ename ) != RTERROR );
  85.     }
  86. }
  87.  
  88. //-----------------------------------------------------------------------------
  89. CWINDOW::~CWINDOW()
  90. {
  91.     delete list;
  92.     delete label;
  93. }
  94.  
  95. //-----------------------------------------------------------------------------
  96. // The message map
  97. BEGIN_MESSAGE_MAP( CWINDOW, CFrameWnd )
  98.     ON_WM_SIZE()
  99.     ON_LBN_SELCHANGE( LIST, HandleSelchange )
  100.     ON_LBN_DBLCLK( LIST, HandleDblclk )
  101. END_MESSAGE_MAP()
  102.  
  103. //-----------------------------------------------------------------------------
  104. // Handle resize events
  105. void CWINDOW::OnSize( UINT nFlags, int cx, int cy )
  106. {
  107.     CRect rect;
  108.     
  109.     GetClientRect( &rect );
  110.     rect.bottom -= 24;
  111.     list->MoveWindow( rect );
  112.     
  113.     GetClientRect( &rect );
  114.     rect.top = rect.bottom - 24;
  115.     label->MoveWindow( rect );        
  116. }
  117.  
  118. //-----------------------------------------------------------------------------
  119. // Handle selections
  120. void CWINDOW::HandleSelchange()
  121. {
  122.     int i, *a;
  123.     i = list->GetSelCount();
  124.     a = new int[i];
  125.     list->GetSelItems( i,a );
  126.  
  127.     char s[100];
  128.     int x;
  129.     ostrstream ostr( s,100 );
  130.     for ( x=0; x<i; x++ )
  131.     {
  132.         ostr << a[x] << " ";
  133.     }
  134.     ostr << ends;
  135.     SetDlgItemText( LABEL, s );
  136.  
  137.     delete a;
  138. }
  139.  
  140. //-----------------------------------------------------------------------------
  141. // Handle double clicked items
  142. void CWINDOW::HandleDblclk()
  143. {
  144.     int i = list->GetCurSel();
  145.  
  146.     char s[100];
  147.     list->GetText( i,s );
  148.  
  149.     SetDlgItemText( LABEL, s );
  150.     Str2AdsName( entity_name, s );
  151.  
  152.     ( DDE_GLOBAL::acad_connection )->ExcuteCommand( "GetSelectedEntity\n" );
  153. }
  154.  
  155.