home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / thread2.zip / OBJECT.C < prev    next >
Text File  |  1993-06-28  |  3KB  |  99 lines

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