home *** CD-ROM | disk | FTP | other *** search
/ Prima Shareware 3 / DuCom_Prima-Shareware-3_cd1.bin / PROGRAMO / C / FLUTE / SAMP_ACT.CPP / SAMP_VW.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1995-04-07  |  4.7 KB  |  179 lines

  1. // samp_vw.cpp : implementation of the CSamp_actView class
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "samp_act.h"
  6.  
  7. #include "samp_doc.h"
  8. #include "samp_vw.h"
  9.  
  10. // WINDACTS - include the windacts.h file
  11. extern "C" {        
  12.     #include    "windacts.h"
  13. };
  14.  
  15.  
  16. // WINDACTS - declare space for our static class variables
  17. UINT    CSamp_actView::m_Acts[2];
  18.  
  19. #ifdef _DEBUG
  20. #undef THIS_FILE
  21. static char BASED_CODE THIS_FILE[] = __FILE__;
  22. #endif
  23.  
  24. // switch off warning of cast from HGLOBAL to LRESULT which is intended
  25. #pragma    warning(disable:4769)
  26.  
  27. /////////////////////////////////////////////////////////////////////////////
  28. // CSamp_actView
  29.  
  30. IMPLEMENT_DYNCREATE(CSamp_actView, CView)
  31.  
  32. BEGIN_MESSAGE_MAP(CSamp_actView, CView)
  33.     //{{AFX_MSG_MAP(CSamp_actView)
  34.     ON_WM_CREATE()
  35.     //}}AFX_MSG_MAP
  36.     // WINDACTS: HERE WE ADD MESSAGE MAPS FOR OUR WINDOW ACTS AND ACTLIST
  37.     ON_REGISTERED_MESSAGE(CSamp_actView::m_Acts[0], OnSetValues)
  38.     ON_REGISTERED_MESSAGE(CSamp_actView::m_Acts[1], OnGetValues)
  39.     ON_REGISTERED_MESSAGE(uActListMsg, OnActList)
  40. END_MESSAGE_MAP()
  41.  
  42. /////////////////////////////////////////////////////////////////////////////
  43. // CSamp_actView construction/destruction
  44.  
  45. CSamp_actView::CSamp_actView()
  46. {
  47.     m_lValue1= 1000;
  48.     m_sValue2 = "Present String";
  49. }
  50.  
  51. CSamp_actView::~CSamp_actView()
  52. {
  53. }
  54.  
  55. /////////////////////////////////////////////////////////////////////////////
  56. // CSamp_actView drawing
  57.  
  58. void CSamp_actView::OnDraw(CDC* pDC)
  59. {
  60.     CSamp_actDoc* pDoc = GetDocument();
  61.     ASSERT_VALID(pDoc);
  62.  
  63.     // we are displaying the values
  64.     {
  65.         CString    sres;
  66.         RECT    cr;
  67.         
  68.         GetClientRect(&cr);
  69.         wsprintf(sres.GetBufferSetLength(128),"%ld\r\n",m_lValue1);
  70.         sres.ReleaseBuffer();
  71.         
  72.         sres += m_sValue2;
  73.         
  74.         pDC->DrawText(sres,sres.GetLength(),&cr,DT_LEFT|DT_NOPREFIX|DT_EXPANDTABS|DT_TOP);
  75.     }
  76. }
  77.  
  78. /////////////////////////////////////////////////////////////////////////////
  79. // CSamp_actView diagnostics
  80.  
  81. #ifdef _DEBUG
  82. void CSamp_actView::AssertValid() const
  83. {
  84.     CView::AssertValid();
  85. }
  86.  
  87. void CSamp_actView::Dump(CDumpContext& dc) const
  88. {
  89.     CView::Dump(dc);
  90. }
  91.  
  92. CSamp_actDoc* CSamp_actView::GetDocument() // non-debug version is inline
  93. {
  94.     ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CSamp_actDoc)));
  95.     return (CSamp_actDoc*)m_pDocument;
  96. }
  97. #endif //_DEBUG
  98.  
  99. /////////////////////////////////////////////////////////////////////////////
  100. // CSamp_actView message handlers
  101.  
  102. int CSamp_actView::OnCreate(LPCREATESTRUCT lpCreateStruct)
  103. {
  104.     if (CView::OnCreate(lpCreateStruct) == -1)
  105.         return -1;
  106.     
  107.     // WINDACTS - register the acts supported by this window when it is first created
  108.     // see the resources for IDS_ACTSTRING1 etc.
  109.     RegisterActList(AfxGetInstanceHandle(), IDS_ACTSTRING1,m_Acts);
  110.     // Set the FluteName for this window
  111.     SetWindowFluteName(m_hWnd, "My_Sample_Window");
  112.     return 0;
  113. }
  114.  
  115. ////////////////////////////////////////////////////////////////////////////
  116. // Window Acts message handlers
  117. // WINDACTS
  118. // Set values into this window class (a Window Act)
  119. LRESULT CSamp_actView::OnSetValues(WPARAM wParam, LPARAM lParam)
  120. {
  121.     DataObj    *pob;
  122.     BOOL    b1,b2;
  123.     long    lval;
  124.     CString    sval;
  125.  
  126.     if (!wParam) return 0;        // there is a problem
  127.     
  128.     pob = DataGlobalLock((HGLOBAL)wParam);
  129.     if (pob->tint.vtype!=ARRAYTYPE || pob->tarray.elements!=2) {
  130.         // we haven't been given the correct parameters - report an error
  131.         GlobalUnlock((HGLOBAL)wParam);
  132.         return (LRESULT)GeneralError(AfxGetInstanceHandle(),IDS_PARAMETERERROR);
  133.     };
  134.     
  135.     pob = PtrContent(pob);
  136.     lval = GetALong(pob,&b1);
  137.     pob = NextDataObj(pob);
  138.     GetAString(pob, &b2, sval.GetBufferSetLength(256),256);
  139.     sval.ReleaseBuffer();
  140.     GlobalUnlock((HGLOBAL)wParam);
  141.     
  142.     // if the extraction of data failed, then report an error
  143.     if (!b1 || !b2)
  144.         return (LRESULT)GeneralError(AfxGetInstanceHandle(),IDS_PARAMETERERROR);
  145.     
  146.     // set the values and update the window
  147.     m_lValue1 = lval;
  148.     m_sValue2 = sval;
  149.     Invalidate();
  150.     
  151.     return NULL;
  152. }
  153.  
  154. // Window ACT to support getting the values set in our window class
  155. LRESULT CSamp_actView::OnGetValues(WPARAM wParam, LPARAM lParam)
  156. {
  157.     return (LRESULT)MakeArray2(MakeInt(m_lValue1), MakeString(m_sValue2) );
  158. }
  159.  
  160.  
  161. // process the actlist message, if wParam is zero then return a list
  162. // of supported window acts, otherwise provide help on the given
  163. // act (in wParam)
  164. LRESULT CSamp_actView::OnActList(WPARAM wParam, LPARAM)
  165. {
  166.     CString    sres;
  167.  
  168.     // if not wParam then return a list of Acts
  169.     if (!wParam) return (LRESULT)ProduceActList(AfxGetInstanceHandle(), IDS_ACTSTRING1);
  170.     
  171.     // else provide help - find the act name
  172.     FindActName(AfxGetInstanceHandle(), (UINT)wParam, IDS_ACTSTRING1, sres.GetBufferSetLength(128), 128);
  173.     sres.ReleaseBuffer();
  174.     
  175.     ::WinHelp(m_hWnd,"SampAct.hlp",HELP_PARTIALKEY, (DWORD)(LPCSTR)sres);
  176.     return NULL;
  177. }
  178.  
  179.