home *** CD-ROM | disk | FTP | other *** search
- // This file defines and tests a class definition for an MPARAM C++ class.
- // It works with all of the PM programs with which I have tested it.
-
- // If you have any comments, bug fixes, etc. please write a note to the
- // OS2DF1 forum under section 7 (development tools) with a topic of:
- // "C++ Headers for PM"
-
- // It is my hope that some improved version of this class definition and
- // classes for MRESULT and others will follow from this discourse.
-
- // My name is Steve Behman [76360,3153]
-
-
-
- #define INCL_PM
- #define INCL_WIN
- #include <os2.h>
-
- // If after trying this you want to use it then,
- // in \toolkt21\cplus\os2h\PMWIN.H do the following:
- // Comment out line 166 "typedef VOID *MPARAM; /* mp */"
- // At line 167 insert the lines which follow these comments to the line
- // "//***" after changing all references to "MP" in that text to "MPARAM".
-
-
- #define S2 S[0]
- #define S1 S[1]
- #define C4 C[0]
- #define C3 C[1]
- #define C2 C[2]
- #define C1 C[3]
- // These defines (above) are used in the absence of an "anonymous structure"
- // construct in C++ in order to give "proper" names to the accessors to MPARAM
- // and to "unconfuse" the byte ordering of the 80x86 processor.
- // I prefer the brevity -- others may prefer something with more content
- // like SHORT1 or CHAR3 -- Comments on this issue would be very interesting
- // to me.
-
- class MP
- {
- public:
- union
- {
- void * VP;
- char * CP;
- long * LP;
- unsigned long * ULP;
- unsigned long WNDH;
- short * SP;
- short S[2];
- char C[4];
- long L;
- unsigned long UL;
- };
- MP():VP( 0 ){}
- MP( MP& mp ):VP( mp.VP ){}
- MP( void * p ):VP( p ){};
- MP( char a1, char a2, char a3, char a4 ):UL( a1<<24|a2<<16|a3<<8|a4){}
- MP( short a1, char a3, char a4 ):UL(a1<<16|a3<<8|a4){}
- MP( short a1, short a2 ):UL( a1<<16 | a2){}
- MP( long ll ):L(ll){};
- int operator==(long l){ return L==l;}
- int operator!(){return UL ? 0 : 1;}
- int operator==(MP l){ return UL==l.UL;}
- operator long(){return L;}
- void * operator=(MP mp){return mp.VP;}
- };
- //***
-
-
- ULONG test( MP a );
-
- void main()
- {
- MP mp;
- void *v;
- HWND h;
- char arr[20], *ar;
- MP t( 0x0102, 0x03,0x04 );
- t.UL=0x01020304;
- ar=( char * )t.CP;
- short *sar=t.SP;
- t.C1=0x11;
- char g=t.C1;
- h=t.WNDH;
- h=t.UL;
- long lll=t.UL;
- mp=t;
- mp=test( 0L ); // NOTE: plain "0" won't work! "0L" resolves the ambiguity!!!
-
- // This particular thing makes me long for a language construct such that for
- // a function declared as:
- // returntype func( param1, param2, param3 );
- // An invocation like:
- // returntype rt=func( param1(), ,p3 );
- // is allowed and the omitted parameter (",,") calls the param2() constructor
- // if it exists and is an error otherwise. (>: Bjarne, are you listening? :<)
-
- v=t.CP;
- }
-
- ULONG test( MP a )
- {
- return ( ULONG) a;
- }
-
- // P.S.
-
- // If you modify \toolkt21\cplus\os2h\PMWIN.H to include the MPARAM Class
- // definition further modifications to the function prototypes in that file
- // will enhance the use of that class.
- //
- // I have changed ALL of the prototypes (except WinBroadcastMsg) which have
- // MPARAM arguments from:
- // WinXxxxx( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2);
- // to: WinXxxxx( HWND hwnd, ULONG msg, MPARAM mp1=0L, MPARAM mp2=0L);
- //
- // So that the MANY WinXxxx(...) calls for which mp2=0 or mp1=mp2=0 can be
- // written with the last one or two argunents omitted.
-