home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ocl150a.zip / OCL / Samples / Listbox / Source / Listbox.cpp next >
C/C++ Source or Header  |  1996-08-12  |  2KB  |  139 lines

  1. // OCL Sample
  2. // Listbox.cpp
  3.  
  4. #ifdef __BCPLUSPLUS__
  5.   #define __MSC
  6. #endif
  7.  
  8. #define __OCL_RESOLVE_TEMPLATES__
  9. #include "..\Source\Listbox.hpp"
  10.  
  11.  
  12. void main(void)
  13. {
  14.  BoxSample sample;
  15.  
  16.  try
  17.   {
  18.    sample.init(); 
  19.   }
  20.  
  21.  catch(OPMException err)
  22.   {
  23.    err.viewError();
  24.    _exit(1);
  25.   }
  26.  
  27.  OApp::current().run();
  28. }
  29.  
  30.  
  31. BoxSample::BoxSample()
  32.  : OFrame(BOX_MAIN) 
  33.  {}
  34.  
  35. BoxSample::~BoxSample()
  36. {
  37.  if (box) delete box;
  38. }
  39.  
  40.  
  41. void BoxSample::run()
  42. {
  43.  BOOL continuable = TRUE;
  44.  
  45.  while(continuable)
  46.   {
  47.    continuable = FALSE;
  48.  
  49.    try
  50.     {
  51.      OApp::run(); 
  52.     }
  53.  
  54.    catch(LBException *except)
  55.     {
  56.      OString str("Exception of type \"");
  57.    
  58.      str + except->isOfType();
  59.      str + "\" caught and handled.";       
  60.      DosBeep(100, 100);
  61.      box->insertItem(str);
  62.      delete except;
  63.      continuable = TRUE;
  64.     }
  65.  
  66.    catch(OPMException except)
  67.     {
  68.      except.viewError();
  69.     }
  70.   }
  71. }
  72.  
  73.  
  74. void BoxSample::init()
  75. {
  76.  winText << "ListBox Sample";
  77.  createFrame(winText);
  78.  
  79.  box = new OListBox(ID_LISTBOX, this, LS_NOADJUSTPOS | LS_HORZSCROLL);
  80.  box->createListBox(0, 0, 0, 0).setFont("10.Helv").setForeColor(RGB_BLUE);
  81.  
  82.  sizepos.cx = 400;
  83.  sizepos.cy = 300;
  84.  setSizePosFrame(HWND_TOP, sizepos, SWP_SIZE | SWP_SHOW | SWP_ACTIVATE);
  85. }
  86.  
  87.  
  88.  
  89. BOOL BoxSample::OCommand(ULONG msg, MPARAM mp1, MPARAM mp2)
  90. {
  91.  switch(msg)
  92.   {
  93.    case WM_SIZE:
  94.      if (box)
  95.        WinSetWindowPos(box->hwnd, 0, 0, 0, SHORT1FROMMP(mp2), SHORT2FROMMP(mp2), SWP_SIZE | SWP_SHOW );
  96.      break;
  97.  
  98.    case WM_COMMAND:
  99.      switch(SHORT1FROMMP(mp1))
  100.       {
  101.        case BOX_QUIT:
  102.         WinSendMsg(hwnd, WM_CLOSE, NULL, NULL);
  103.         break;
  104.  
  105.        case BOX_EXCEPTION:
  106.         throw new LBException;
  107.       }
  108.      break;
  109.  
  110.    case WM_CLOSE:
  111.      forceQuit();
  112.      break;
  113.  
  114.    default:
  115.      return(FALSE);
  116.   }
  117.  return(TRUE);
  118. #ifdef __BCPLUSPLUS__
  119.   #pragma warn -par
  120. #endif
  121. }
  122. #ifdef __BCPLUSPLUS__
  123.   #pragma warn .par
  124. #endif
  125.  
  126.  
  127. LBException::LBException()
  128.   : OException(NULL, 0, OException::unrecoverable) 
  129.   {}
  130.  
  131. LBException::~LBException() 
  132.   {}
  133.  
  134. void LBException::viewError() 
  135.   {}
  136.  
  137.  
  138. // end of source
  139.