home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / wclass.zip / CPPAPP.CPP < prev    next >
Text File  |  1994-04-25  |  4KB  |  130 lines

  1. /*----------------------------------------------------------------------------*/
  2. /* (c) 1993, 1994 Larry Morley / Enlightened Computer Solutions               */
  3. /*----------------------------------------------------------------------------*/
  4. /*   module: cppapp.cpp                created_on: 5 May 1993   by: LJM       */
  5. /*   desc  : Application sample using framework library 'classlib.cpp'        */
  6. /*   complr: icc /Fi /Fd /c /Ss /Sp1 /Gm+ /G4 /Kb+ [/Ti+ intrnl, /Ti- rel]    */
  7. /*   lnkr  : link386 /a:4 [/deb intrnl,rel=<none> /base:65536 /noe            */
  8. /*           rc $*.res                                                        */
  9. /*   etc   : rc -r $*.rc                                                      */
  10. /*   mkfile: makefile                                                         */
  11. /*   depend: (see makefile)                                                   */
  12. /*   mhist :                                                                  */
  13. /*----------------------------------------------------------------------------*/
  14.  
  15. #define INCL_WIN
  16. #define INCL_DOS
  17. #define INCL_GPI
  18. #include <os2.h>
  19.  
  20. #include "cppapp.hpp"
  21. #include "classlib.hpp"
  22.  
  23. #include <stdio.h>
  24.  
  25. /*----------------------------------------------------------------------------*/
  26. // Get access to the status / message / whatever line's text
  27. extern char szStatLineText[];
  28.  
  29. /*----------------------------------------------------------------------------*/
  30. // Declare a window class
  31. class MyWindow : public Window
  32. {
  33.    public:
  34.       MRESULT PaintEventHandler(HWND,ULONG,MPARAM,MPARAM);
  35.       MRESULT CommandEventHandler(HWND,ULONG,MPARAM,MPARAM);
  36.       MRESULT MenuSelectEventHandler(HWND,ULONG,MPARAM,MPARAM);
  37. };
  38.  
  39. /*----------------------------------------------------------------------------*/
  40. // Set up event handlers for all events I chose above
  41. MRESULT MyWindow ::
  42.    PaintEventHandler(HWND hwnd,ULONG msg,MPARAM mp1,MPARAM mp2)
  43. {
  44.    HPS    hPS;
  45.    RECTL  rcl;
  46.    POINTL ptl;
  47.    int i;
  48.    int j;
  49.  
  50.    hPS = WinBeginPaint(hwnd,(HPS)0,&rcl);
  51.    GpiErase(hPS);
  52.  
  53.    for (i=0,j=640;i<640;i+=5,j-=5)
  54.    {
  55.       ptl.x = i;
  56.       ptl.y = 0;
  57.       GpiMove(hPS,&ptl);
  58.       ptl.x = j;
  59.       ptl.y = 480;
  60.       GpiLine(hPS,&ptl);
  61.    }
  62.  
  63.    WinEndPaint(hPS);
  64.    return (MRESULT)0;
  65.  
  66. }
  67.  
  68. /*----------------------------------------------------------------------------*/
  69.  
  70. MRESULT MyWindow ::
  71.    CommandEventHandler(HWND hwnd,ULONG msg,MPARAM mp1,MPARAM mp2)
  72. {
  73.    switch ((int)mp1)
  74.    {
  75.       case IDM_FILE_ABOUT:
  76.          WinMessageBox(
  77.             HWND_DESKTOP,
  78.             HWND_DESKTOP,
  79.             "C++ Application",
  80.             "About",
  81.             999,
  82.             MB_OK);
  83.          break;
  84.    }
  85.    return (MRESULT)0;
  86. }
  87.  
  88. /*----------------------------------------------------------------------------*/
  89.  
  90. MRESULT MyWindow::
  91.    MenuSelectEventHandler(HWND hwnd,ULONG msg,MPARAM mp1,MPARAM mp2)
  92. {
  93.    char *p;
  94.  
  95.    p = new char [80];
  96.  
  97.    if (p)
  98.    {
  99.       sprintf(
  100.          szStatLineText,
  101.          "*** Menu Option %5u selected ***",
  102.          SHORT1FROMMP(mp1));
  103.       delete[] p;
  104.       WinInvalidateRect(hwndStatus,(PRECTL)0,TRUE);
  105.    }
  106.  
  107.    return WinDefWindowProc(hwnd,msg,mp1,mp2);
  108.  
  109. }
  110.  
  111. /*----------------------------------------------------------------------------*/
  112. // Create a new App, a Window, then run the App.
  113.  
  114. int main()
  115. {
  116.    App *p;
  117.    MyWindow *w;
  118.    p = new App;
  119.    w = new MyWindow;
  120.  
  121.    if (w->Create())
  122.       p->Run();
  123.  
  124.    delete w;
  125.    delete p;
  126.    return 0;
  127. }
  128.  
  129. /*----------------------------------------------------------------------------*/
  130.