home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / sysutils / mshell / source / create.c next >
Text File  |  1993-10-16  |  4KB  |  138 lines

  1. // create.c
  2.  
  3. // called from WM_CREATE in main app's client wm_create;
  4. // allocates storage for globals and starts filling them in;
  5. // starts thread 2 for the object window to perform lengthy tasks;
  6.  
  7.  
  8.  
  9. #define INCL_DOS
  10. #define INCL_PM
  11. #include <os2.h>
  12.  
  13. // c includes
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16. #include <stddef.h>
  17. #include <string.h>
  18. #include <process.h>
  19.  
  20.  
  21. // app includes
  22. #include "def.h"
  23. #include "mshell.h"
  24. #include "pmassert.h"
  25.  
  26.  
  27.  
  28.  
  29.  
  30. // -------------------------------------------------------------------------
  31. // called from WM_CREATE in client win proc
  32.  
  33.  
  34. PGLOBALS Create( HWND hwnd )
  35. {
  36.   BOOL            bOK;
  37.   BOOL            bNeedDefaults;
  38.   HAB             hab;
  39.   PGLOBALS        pg;
  40.   int             idThread;
  41.   ULONG           rc;
  42.   ULONG           ul;
  43.  
  44.  
  45.  
  46.  
  47.   // query hab
  48.   hab = WinQueryAnchorBlock( hwnd );
  49.  
  50.  
  51.   // allocate global memory; see GLOBALS struct in MSHELL.H
  52.   pg = malloc( sizeof( GLOBALS ));
  53.   pmassert( hab, pg );
  54.   memset( pg, 0, sizeof( GLOBALS ));
  55.  
  56.   // set globals pointer into window words
  57.   bOK = WinSetWindowULong( hwnd, QWL_USER, (ULONG) pg );
  58.   pmassert( hab, bOK  );
  59.  
  60.   // store window handles etc in globals
  61.   pg->hwndClient   = hwnd;
  62.   pg->hab          = hab;
  63.   pg->hwndFrame    = WinQueryWindow( hwnd, QW_PARENT );
  64.   pmassert( hab, pg->hwndFrame );
  65.   pg->hwndTitlebar = WinWindowFromID( pg->hwndFrame, FID_TITLEBAR );
  66.   pmassert( hab, pg->hwndTitlebar );
  67.   pg->hwndMenubar  = WinWindowFromID( pg->hwndFrame, FID_MENU );
  68.   pmassert( hab, pg->hwndMenubar );
  69.  
  70.  
  71.   // set text into title bar
  72.   bOK = WinSetWindowText( pg->hwndTitlebar, CAPTION );
  73.   pmassert( hab, bOK   );
  74.  
  75.   // query size of desktop
  76.   WinQueryWindowRect( HWND_DESKTOP, &(pg->rectlDesktop) );
  77.  
  78.  
  79.  
  80.   // disable client and menubar until application completely initializes.
  81.   // these windows will reenable when object window is done with its WM_CREATE
  82.   WinSendMsg( hwnd, WM_USER_DISABLE_CLIENT, 0, 0 );
  83.  
  84.   // create a listbox, child of the client window
  85.   pg->hwndListbox = WinCreateWindow( hwnd, WC_LISTBOX, "", WS_VISIBLE , 0,0,0,0, hwnd, HWND_TOP, ID_LISTBOX, NULL, NULL );
  86.   pmassert( hab, pg->hwndListbox );
  87.  
  88.   // listbox must have focus (else doesn't work on mouseless systems)
  89.   WinSetFocus( HWND_DESKTOP, pg->hwndListbox );
  90.  
  91.   // create a modeless dialog for the spooler interface dialog
  92.   pg->hwndSpooler = (HWND) WinLoadDlg( HWND_DESKTOP, HWND_DESKTOP, (PFNWP) SpoolerDlgProc, (HMODULE)0,  IDD_SPOOLER, (PVOID) pg );
  93.   pmassert( hab, pg->hwndSpooler );
  94.  
  95.   // read the saved profile for size and position
  96.   bOK = PrfQueryProfileSize( HINI_PROFILE, INI_APP, INIKEY_PROFILE, &ul );
  97.   bNeedDefaults = FALSE;
  98.   dbprintf(( "Profile size is %d\n", ul ));
  99.  
  100.  
  101.   if( !bOK  ||  ul != sizeof( PROFILE )) {
  102.     // set up profile defaults
  103.     bNeedDefaults = TRUE;
  104.   } else {
  105.     ul = sizeof( PROFILE );
  106.     bOK = PrfQueryProfileData( HINI_PROFILE, INI_APP, INIKEY_PROFILE, (PVOID)&(pg->profile), &ul );
  107.     pmassert( hab, bOK );
  108.  
  109.     // sanity checks on profile data
  110.     bOK   = ( 0 < pg->profile.swp.x   &&   pg->profile.swp.x < pg->rectlDesktop.xRight  );
  111.     bOK  &= ( 0 < pg->profile.swp.y   &&   pg->profile.swp.y < pg->rectlDesktop.yTop    );
  112.     bOK  &= ( pg->profile.swp.x + pg->profile.swp.cx  < pg->rectlDesktop.xRight  );
  113.     bOK  &= ( pg->profile.swp.y + pg->profile.swp.cy  < pg->rectlDesktop.yTop    );
  114.     bNeedDefaults = !bOK;
  115.  
  116.     if( !bOK  ) {
  117.       dbprintf(( "sanity checks failed\n" ));
  118.     }
  119.   }
  120.  
  121.   if( bNeedDefaults ) {
  122.     dbprintf(( "Using defaults from WinQueryTaskSizePos\n" ));
  123.     rc = WinQueryTaskSizePos( pg->hab, 0, &(pg->profile.swp) );
  124.     pmassert( hab, rc == 0 );
  125.   }
  126.  
  127.  
  128.   // create the invisible object window operated by thread 2
  129.   // perform any lengthy tasks on thread 2 by posting a work msg to object window
  130.   // see WM_CREATE case in OBJECT.C which continues initialization
  131.   idThread = _beginthread( threadmain, NULL, LEN_STACK, (void*)pg );
  132.   pmassert( hab, idThread );
  133.  
  134.   // return the pointer to globals
  135.   return pg;
  136. }
  137.  
  138.