home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ctlcpp.zip / MCTLEVT.CPP < prev    next >
C/C++ Source or Header  |  1994-06-06  |  3KB  |  94 lines

  1. /***************************************************************/
  2. /* Filename: mctlevt.cpp                                       */
  3. /*                                                             */
  4. /* Purpose: Definition of the MControlEvent class.             */
  5. /*                                                             */
  6. /* Program name: cppctl.exe     Title: C++ PM Control Test App */
  7. /* OS/2 Developer Magazine, Issue: Sept. '94, page             */
  8. /* Article title: Writing OS/2 PM Controls in C++              */
  9. /* Authors: Eric Snell and Lori Ruffing                        */
  10. /*                                                             */
  11. /* Description: This example shows how to implement an OS/2 PM */
  12. /*              control window in C++.                         */
  13. /*                                                             */
  14. /* Program Requirements: This example requires the IBM C Set++ */
  15. /*                       compiler and libraries.               */
  16. /***************************************************************/
  17. extern "C"
  18.    {
  19.    #define INCL_WINWINDOWMGR
  20.    #include <os2.h>
  21.    }
  22.  
  23. #ifndef _IWINDOW_
  24.    #include <iwindow.hpp>
  25. #endif
  26.  
  27. #include "mctlevt.hpp"
  28.  
  29. MControlEvent::MControlEvent(IEvent& evt)
  30.    : IControlEvent(evt)
  31.    {
  32.    }
  33.  
  34. MControlEvent::~MControlEvent()
  35.    {
  36.    }
  37.  
  38. //----------------------------------------------------------------------------
  39. // Method: MControlEvent::controlHandle
  40. //
  41. // Description: 'controlHandle' returns the window handle of the control
  42. //----------------------------------------------------------------------------
  43. IWindowHandle MControlEvent::controlHandle() const
  44.    {
  45.    IWindow* pwndControl = controlWindow();
  46.  
  47.    // The handler is either attached to the control generating
  48.    // the WM_CONTROL message or to its owner.  If
  49.    // IControlEvent::controlWindow returns 0, this must mean we
  50.    // have a non-wrappered control with a wrappered owner
  51.    // window and that the handler is attached to the owner
  52.    // window.  This case is supported only if the owner of the
  53.    // control is also the control's parent (this is in order
  54.    // for handleWithId to work).
  55.  
  56.    if (pwndControl)
  57.       {                           // in IWindowInfo list
  58.       return pwndControl->handle();
  59.       }
  60.    else
  61.       {
  62.       return IWindow::handleWithId(controlId(), handle());
  63.       }
  64.    }
  65.  
  66. //----------------------------------------------------------------------------
  67. // Method: MControlEvent::controlClassName
  68. //
  69. // Description: 'controlClassName' returns the class name of the control
  70. //              based on the handle.
  71. //----------------------------------------------------------------------------
  72. IString MControlEvent::controlClassName() const
  73.    {
  74.    IWindowHandle hwnd(controlHandle());
  75.    IString rc;
  76.  
  77.    if (hwnd.isValid())
  78.       {
  79.       // a little ugly magic stolen from ICLUI
  80.       IString temp;
  81.       unsigned len = 0;
  82.       do
  83.          {
  84.          temp = IString( 0, len + 16 );
  85.          len = WinQueryClassName(hwnd, temp.length()+1, temp);
  86.          }
  87.       while (len == temp.length());
  88.       rc = temp;
  89.       }
  90.  
  91.    return rc;
  92.    }
  93.  
  94.