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

  1. /***************************************************************/
  2. /* Filename: cppctl.cpp                                        */
  3. /*                                                             */
  4. /* Purpose: Main source file for C++ control test app. Contains*/
  5. /*          definition of MainFrame class.                     */
  6. /*                                                             */
  7. /* Program name: cppctl.exe     Title: C++ PM Control Test App */
  8. /* OS/2 Developer Magazine, Issue: Sept. '94, page             */
  9. /* Article title: Writing OS/2 PM Controls in C++              */
  10. /* Authors: Eric Snell and Lori Ruffing                        */
  11. /*                                                             */
  12. /* Description: This example shows how to implement an OS/2 PM */
  13. /*              control window in C++.                         */
  14. /*                                                             */
  15. /* Program Requirements: This example requires the IBM C Set++ */
  16. /*                       compiler and libraries.               */
  17. /***************************************************************/
  18.  
  19. extern "C"
  20.    {
  21.    #define INCL_WINWINDOWMGR
  22.    #define INCL_WINFRAMEMGR
  23.    #define INCL_WINPOINTERS
  24.    #define INCL_DOSPROCESS
  25.    #include "os2.h"
  26.    }
  27.  
  28. #include "cppctl.hpp"
  29.  
  30. #ifndef _IAPP_
  31.    #include <iapp.hpp>
  32. #endif
  33.  
  34. int main(int argc, char *argv[])
  35.    {
  36.    MainFrame mainFrame;
  37.  
  38.    IApplication::current().run();
  39.  
  40.    return 0;
  41.    }
  42.  
  43. //----------------------------------------------------------------------------
  44. // Method: MainFrame::MainFrame
  45. //
  46. // Description: Construct our frame window, hard coding window IDs.
  47. //----------------------------------------------------------------------------
  48. MainFrame::MainFrame()
  49.    : IFrameWindow(100),
  50.      clientWin(101, this, this)
  51.    {
  52.    // clientWin's ID will be changed to FID_CLIENT when
  53.    // it is set as the client
  54.    setClient(&clientWin);
  55.  
  56.    // Attach the mouse move handler so we will be notified of the
  57.    // controlPointer messages.
  58.    IMouseMoveHandler::handleEventsFor(this);
  59.  
  60.    // Attach the NewControl handler so we will be notified of the
  61.    // button1Click and button2Click messages.
  62.    NewControlHandler::handleEventsFor(this);
  63.  
  64.    setFocus();
  65.    show();
  66.    }
  67.  
  68. //----------------------------------------------------------------------------
  69. // Method: MainFrame::~MainFrame
  70. //
  71. // Description: Destructor for our frame window.
  72. //----------------------------------------------------------------------------
  73. MainFrame::~MainFrame()
  74.    {
  75.    }
  76.  
  77. //----------------------------------------------------------------------------
  78. // Method: MainFrame::controlPointer
  79. //
  80. // Description: 'controlPointer' is called in response to a
  81. //              WM_CONTROLPOINTER message/event, 'evt', being sent
  82. //              from a control.
  83. //----------------------------------------------------------------------------
  84. Boolean MainFrame::controlPointer(IControlPointerEvent &evt)
  85.    {
  86.    Boolean rc = false;
  87.  
  88.    // See if the pointer is over the client window and if so, change the
  89.    // pointer to an I-beam. Return true to say we handled the event.
  90.    if (FID_CLIENT == evt.pointerOverId())
  91.       {
  92.       evt.setNewPointer(WinQuerySysPointer(desktopWindow()->handle(),
  93.                                            SPTR_TEXT,
  94.                                            FALSE));
  95.       rc = true;
  96.       }
  97.  
  98.    return rc;
  99.    }
  100.  
  101. //----------------------------------------------------------------------------
  102. // Method: MainFrame::button1Click
  103. //
  104. // Description: 'button1Click' is called in response to a NewControl
  105. //              sending a button1 click event, 'evt'.
  106. //----------------------------------------------------------------------------
  107. Boolean MainFrame::button1Click(NewControlEvent& evt)
  108.    {
  109.    evt;
  110.  
  111.    //Just beep to recognize the message.
  112.    DosBeep(1000, 500);
  113.  
  114.    return true;
  115.    }
  116.  
  117. //----------------------------------------------------------------------------
  118. // Method: MainFrame::button2Click
  119. //
  120. // Description: 'button2Click' is called in response to a NewControl
  121. //              sending a button2 click event, 'evt'.
  122. //----------------------------------------------------------------------------
  123. Boolean MainFrame::button2Click(NewControlEvent& evt)
  124.    {
  125.    evt;
  126.  
  127.    //Just beep to recognize the message.
  128.    DosBeep(500, 500);
  129.  
  130.    return true;
  131.    }
  132.  
  133.  
  134.  
  135.