home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / MONTE.ZIP / PMTHREAD / OBJECT.C < prev    next >
Text File  |  1993-02-22  |  3KB  |  94 lines

  1. /* object.c: the object window procedure on thread 2  */
  2. // os2 includes
  3. #define INCL_DOSPROCESS
  4. #define INCL_WIN
  5. #include <os2.h>
  6. // crt includes
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <string.h>
  10. // app includes
  11. #include "def.h"
  12. #include "app.h"
  13. #include "pmassert.h"
  14.  
  15. //----------------------------------------------------------------------
  16. // thread 2 entry point: gets and dispatches object window messages
  17. // _Optlink is an IBM C Set/2 function modifier
  18. void _Optlink threadmain( void * pv  )
  19. {
  20.   BOOL       fSuccess;
  21.   HAB        hab;
  22.   HMQ        hmq;
  23.   PGLOBALS   pg;
  24.   QMSG       qmsg;
  25.  
  26.   // cast and set pointer to globals
  27.   pg = (PGLOBALS) pv;
  28.  
  29.   // thread initialization
  30.   hab = WinInitialize( 0 );
  31.   hmq = WinCreateMsgQueue( hab, 0 );
  32.  
  33.   // prevent system from posting object window a WM_QUIT
  34.   // I'll post WM_QUIT when it's time.
  35.   fSuccess = WinCancelShutdown( hmq, TRUE );
  36.   pmassert( hab, fSuccess );
  37.  
  38.   fSuccess = WinRegisterClass( hab, APP_CLASS_OBJECT,
  39.                   (PFNWP)ObjectWinProc, 0, sizeof( PGLOBALS ));
  40.   pmassert( hab, fSuccess );
  41.  
  42.   pg->hwndObject = WinCreateWindow( HWND_OBJECT, APP_CLASS_OBJECT, "",
  43.              0, 0, 0, 0, 0, HWND_OBJECT, HWND_BOTTOM, 0, (PVOID)pg, NULL );
  44.   pmassert( hab, pg->hwndObject );
  45.  
  46.   // created OK, ack client
  47.   WinPostMsg( pg->hwndClient, WM_USER_ACK, 0, 0 );
  48.  
  49.   // get/dispatch messages; user messages, for the most part
  50.   while( WinGetMsg ( hab, &qmsg, 0, 0, 0 ))
  51.   {
  52.     WinDispatchMsg ( hab, &qmsg );
  53.   }
  54.  
  55.   // tell client window to quit
  56.   WinPostMsg( pg->hwndClient, WM_QUIT, 0, 0 );
  57.  
  58.   // clean up
  59.   WinDestroyWindow( pg->hwndObject );
  60.   WinDestroyMsgQueue( hmq );
  61.   WinTerminate( hab );
  62.   return;
  63. }
  64.  
  65. // --------------------------------------------------------------------------
  66. // object window procedure; mp1 is the window to acknowledge upon completion
  67. MRESULT EXPENTRY ObjectWinProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  68. {
  69.   PGLOBALS      pg;
  70.   HWND          hwndToAck;
  71.  
  72.   // store the handle of the window to ack upon task completion;
  73.   hwndToAck = (HWND)mp1;
  74.  
  75.   switch( msg ) {
  76.   case WM_CREATE:
  77.     // for the create case, mp1 is pointer to globals;
  78.     // save it in object window words
  79.     WinSetWindowULong( hwnd, QWL_USER, (ULONG) mp1 );
  80.     return (MRESULT) 0;
  81.  
  82.   case WM_USER_SLEEP:
  83.     // sleep as though this were a time-consuming task
  84.     pg = (PGLOBALS) WinQueryWindowULong( hwnd, QWL_USER );
  85.     DosSleep( 20000 );
  86.     DosBeep( 500, 150 );
  87.     WinPostMsg( hwndToAck, WM_USER_ACK, (MPARAM) msg, 0 );
  88.     return (MRESULT) 0;
  89.   }
  90.  
  91.   // default:
  92.   return WinDefWindowProc( hwnd, msg, mp1, mp2 );
  93. }
  94.