home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ocl150a.zip / OCL / Samples / ValueSet / Source / Value.cpp < prev    next >
C/C++ Source or Header  |  1996-10-21  |  3KB  |  133 lines

  1. // OCL Sample OValueSet
  2. // Value.cpp
  3.  
  4. #ifdef __BCPLUSPLUS__
  5.   #define __MSC
  6. #endif
  7.  
  8.  
  9. #define __OCL_RESOLVE_TEMPLATES__
  10. #include "..\Source\Value.hpp"
  11.  
  12. #include <..\Source\OString.cpp>
  13.  
  14. void main(void)
  15. {
  16.  ValueSample sample;
  17.  
  18.  try
  19.   {
  20.    sample.init(); 
  21.    OApp::current().run();
  22.   }
  23.  
  24.  catch(OPMException &err)
  25.   {
  26.    err.viewError();
  27.   }
  28. }
  29.  
  30.  
  31. ValueSample::ValueSample()
  32.   : ODialog(VALUE_DLG),
  33.     logo("..\\..\\LOGO.BMP", VALUE_MAIN, 80, 80),
  34.     VSet(VALUE_SET, NULLHANDLE, 3, 4)
  35.   {}
  36.  
  37. ValueSample::~ValueSample() 
  38.   {}
  39.  
  40. PSZ ValueSample::isOfType() const
  41.  return("ValueSample"); 
  42. }
  43.  
  44.  
  45. void ValueSample::init()
  46. {
  47.  COLOR color[] = { CLR_RED, CLR_GREEN, CLR_BLUE, CLR_YELLOW };
  48.  
  49.  logo.showLogo(1500);
  50.  
  51.  createDlg();
  52.  if (!hwnd)
  53.    OThrowPM("Dialog creation failed.", 0, OException::unrecoverable);
  54.  
  55.  VSet.inherit(hwnd);
  56.  VSet.setItemAttr(1, 0, VIA_ICON);
  57.  VSet.setItemAttr(2, 0, VIA_BITMAP);
  58.  VSet.setItemAttr(3, 0, VIA_COLORINDEX);
  59.  
  60.  if ((VSet.selected.icon = WinLoadPointer(HWND_DESKTOP, NULLHANDLE, VALUE_ICON)) == NULLHANDLE)
  61.    OThrowPM("Loading icon failed.", 0, OException::unrecoverable);
  62.  
  63.  if (!VSet.setItem(1, 0, (ULONG)VSet.selected.icon))
  64.    OThrowPM("Could not set icons.", 0, OException::unrecoverable);
  65.  
  66.  if ((VSet.selected.bitmap = GpiLoadBitmap(WinGetPS(hwnd), NULLHANDLE, VALUE_BMP, 0, 0)) == NULLHANDLE)
  67.    OThrowPM("Loading bitmap failed.", 0, OException::unrecoverable);
  68.  
  69.  if (!VSet.setItem(2, 0, (ULONG)VSet.selected.bitmap))
  70.    OThrowPM("Could not set bitmaps.", 0, OException::unrecoverable);
  71.  
  72.  for (ULONG count = 1; count <= 4; count++)
  73.    if (!VSet.setItem(3, count, color[count-1]))
  74.      OThrowPM("Could not set color.", 0, OException::unrecoverable);
  75.  
  76.  centerDlg();
  77.  showDlg();
  78. }
  79.  
  80.  
  81.  
  82. BOOL ValueSample::OCommand(ULONG msg, MPARAM mp1, MPARAM mp2)
  83. {
  84.  switch(msg)
  85.   {
  86.    case WM_CONTROL:
  87.     switch(SHORT2FROMMP(mp1)) {
  88.      case VN_SELECT:
  89.      case VN_ENTER: {
  90.        OString Notification;
  91.        CHAR    pszTmp[5];
  92.  
  93.        VSet.querySelected();
  94.        if ((SHORT2FROMMP(mp1)) == VN_SELECT)
  95.          Notification << OString(STR_VN_SELECT, NULLHANDLE);
  96.        else
  97.          Notification << OString(STR_VN_ENTER, NULLHANDLE);
  98.        _itoa(VSet.selected.row, pszTmp, 10);
  99.        Notification + pszTmp;
  100.        Notification + " Column ";
  101.        _itoa(VSet.selected.col, pszTmp, 10);
  102.        Notification + pszTmp;
  103.        WinSetDlgItemText(hwnd, VALUE_STATUS, Notification);
  104.        break; }}
  105.      break;
  106.  
  107.    case WM_COMMAND:
  108.      WinSendMsg(hwnd, WM_CLOSE, NULL, NULL);
  109.      break;
  110.  
  111.    case WM_CLOSE:
  112.      hideDlg();
  113.      forceQuit();
  114.      break;
  115.  
  116.    default:
  117.      return(FALSE);
  118.   }
  119.  return(TRUE);
  120. #ifdef __BCPLUSPLUS__
  121.   #pragma warn -par
  122. #endif
  123. }
  124. #ifdef __BCPLUSPLUS__
  125.   #pragma warn .par
  126. #endif
  127.  
  128.  
  129.  
  130.  
  131. // end of source
  132.