home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / os2 / mparam / mparam.cpp
Encoding:
C/C++ Source or Header  |  1994-06-24  |  3.5 KB  |  120 lines

  1. // This file defines and tests a class definition for an MPARAM C++ class.
  2. // It works with all of the PM programs with which I have tested it.
  3.  
  4. // If you have any comments, bug fixes, etc. please write a note to the
  5. // OS2DF1 forum under section 7 (development tools) with a topic of:
  6. // "C++ Headers for PM"
  7.  
  8. // It is my hope that some improved version of this class definition and
  9. // classes for MRESULT and others will follow from this discourse.
  10.  
  11. // My name is Steve Behman [76360,3153]
  12.  
  13.  
  14.  
  15. #define INCL_PM
  16. #define INCL_WIN
  17. #include <os2.h>
  18.  
  19. //  If after trying this you want to use it then,
  20. //  in \toolkt21\cplus\os2h\PMWIN.H do the following:
  21. //  Comment out line 166 "typedef VOID *MPARAM;    /* mp    */"
  22. //  At line 167 insert the lines which follow these comments to the line
  23. //  "//***" after changing all references to "MP" in that text to "MPARAM".
  24.  
  25.  
  26. #define S2 S[0]
  27. #define S1 S[1]
  28. #define C4 C[0]
  29. #define C3 C[1]
  30. #define C2 C[2]
  31. #define C1 C[3]
  32. // These defines (above) are used in the absence of an "anonymous structure"
  33. // construct in C++ in order to give "proper" names to the accessors to MPARAM
  34. // and to "unconfuse" the byte ordering of the 80x86 processor.
  35. // I prefer the brevity -- others may prefer something with more content
  36. // like SHORT1 or CHAR3 -- Comments on this issue would be very interesting
  37. // to me.
  38.  
  39. class MP
  40.   {
  41.   public:
  42.    union
  43.      {
  44.       void * VP;
  45.       char * CP;
  46.       long * LP;
  47.       unsigned long * ULP;
  48.       unsigned long  WNDH;
  49.       short * SP;
  50.       short S[2];
  51.       char C[4];
  52.       long L;
  53.       unsigned long UL;
  54.      };
  55.    MP():VP( 0 ){}
  56.    MP( MP& mp ):VP( mp.VP ){}
  57.    MP( void * p ):VP( p ){};
  58.    MP( char a1, char a2, char a3, char a4 ):UL( a1<<24|a2<<16|a3<<8|a4){}
  59.    MP( short a1, char a3, char a4 ):UL(a1<<16|a3<<8|a4){}
  60.    MP( short a1, short a2 ):UL( a1<<16 | a2){}
  61.    MP( long ll ):L(ll){};
  62.    int operator==(long l){ return L==l;}
  63.    int operator!(){return UL ? 0 : 1;}
  64.    int operator==(MP l){ return UL==l.UL;}
  65.    operator long(){return L;}
  66.    void * operator=(MP mp){return mp.VP;}
  67.   };
  68. //***
  69.  
  70.  
  71. ULONG test( MP a );
  72.  
  73. void main()
  74.   {
  75.    MP mp;
  76.    void *v;
  77.    HWND h;
  78.    char arr[20], *ar;
  79.    MP t( 0x0102, 0x03,0x04 );
  80.    t.UL=0x01020304;
  81.    ar=( char * )t.CP;
  82.    short *sar=t.SP;
  83.    t.C1=0x11;
  84.    char g=t.C1;
  85.    h=t.WNDH;
  86.    h=t.UL;
  87.    long lll=t.UL;
  88.    mp=t;
  89.    mp=test( 0L );  // NOTE: plain "0" won't work! "0L" resolves the ambiguity!!!
  90.  
  91. // This particular thing makes me long for a language construct such that for
  92. // a function declared as:
  93. //    returntype func( param1, param2, param3 );
  94. // An invocation like:
  95. //     returntype rt=func( param1(), ,p3 );
  96. // is allowed and the omitted parameter (",,") calls the param2() constructor
  97. // if it exists and is an error otherwise.  (>: Bjarne, are you listening? :<)
  98.  
  99.    v=t.CP;
  100.   }
  101.  
  102. ULONG test( MP a )
  103.   {
  104.    return ( ULONG) a;
  105.   }
  106.  
  107. // P.S.
  108.  
  109. // If you modify \toolkt21\cplus\os2h\PMWIN.H to include the MPARAM Class
  110. // definition further modifications to the function prototypes in that file
  111. // will enhance the use of that class.
  112. //
  113. // I have changed ALL of the prototypes (except WinBroadcastMsg) which have
  114. // MPARAM arguments from:
  115. //     WinXxxxx( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2);
  116. //     to: WinXxxxx( HWND hwnd, ULONG msg, MPARAM mp1=0L, MPARAM mp2=0L);
  117. //
  118. // So that the MANY WinXxxx(...) calls for which mp2=0 or mp1=mp2=0 can be
  119. // written with the last one or two argunents omitted.
  120.