home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / WINPROPM.ZIP / EXAMINIT.C < prev    next >
Text File  |  1989-06-19  |  7KB  |  207 lines

  1. /* file : Examinit.c
  2.  
  3.  
  4.         Created: 21:55:45 Mon Jun 19 1989
  5.  
  6.         Description:  Initialization routines for ExamplPM
  7.                       These routines are in a separate segment and may be
  8.                       discarded after the applicatione is initialized.
  9.  
  10.         Skeleton by:  WINPRO/PM, a product from Louis J. Cutrona, Jr.
  11.                       Skeleton.pm (Revision 2.5)  
  12. */
  13.  
  14.  
  15. /* Activate standard window management definitions and typedefs */
  16. #define  INCL_WIN       1
  17.  
  18. #include <os2.h>
  19.  
  20. #include "Examrc.h"
  21. #include "Examgbl.h"
  22.  
  23.  
  24. /* I N I T  S T R I N G S */  /* Get all text strings from the resource file */
  25. BOOL InitStrings( hAB )
  26. HAB  hAB;
  27. {
  28.    NPCH    npchMem;
  29.    NPSZ    npsz;
  30.    SHORT   cchRemaining;
  31.    USHORT  i;
  32.    SHORT   cch;
  33.  
  34.    npchMem = WinAllocMem(
  35.       gbl_hheap,
  36.       (USHORT) (cchRemaining = CCHSTRINGS)
  37.       );
  38.    if( ! npchMem )
  39.       return( FALSE );
  40.  
  41.    npsz = npchMem ;
  42.    for( i = IDS_FIRSTSTRING; i < IDS_FIRSTSTRING + CSTRINGS; i++ )
  43.    {
  44.         cch = 1 + WinLoadString( hAB, (HMODULE) 0,
  45.             i, cchRemaining, (PSZ) npsz );
  46.         gbl_pszStrings[ i - IDS_FIRSTSTRING ] = npsz;
  47.         npsz += cch;
  48.         cchRemaining -= cch;
  49.    }
  50.    WinReallocMem( gbl_hheap, npchMem,
  51.       CCHSTRINGS, (USHORT) (CCHSTRINGS - cchRemaining) );
  52.    return( TRUE );
  53. }
  54.  
  55. /* Structure to be used when adding "About..." to system menu */
  56. static MENUITEM menuitem[ 2 ] =
  57. {
  58.    MIT_END, MIS_SEPARATOR, 0, 0,     (ULONG) 0, (ULONG) 0,
  59.    MIT_END, MIS_TEXT,      0, ABOUT, (ULONG) 0, (ULONG) 0
  60. } ;
  61.  
  62. /*   E X A M P L  P  M   I N I T */  /* Procedure called when the application is loaded */
  63. BOOL    ExamplPMInit()
  64. {
  65.    /* Variables needed for adding "About..." to the system menu */
  66.    HWND     hSysMenu;
  67.    SHORT    i;
  68.    SHORT    idSysMenu;
  69.    MENUITEM miSysMenu;
  70.    ULONG    CtlData;
  71.  
  72.    /* Create the local heap */
  73.    /* Initial size will be HEAPSIZE from .DEF file */
  74.    /* Default size of increments if more space is needed is 512 bytes */
  75.    if( ! ( gbl_hheap = WinCreateHeap( 0, 0, 0, 0, 0, HM_MOVEABLE ) ) )
  76.       return FALSE ;
  77.  
  78.    /* Load strings from string table */
  79.    if( ! InitStrings( gbl_hab ) )
  80.       return FALSE ;
  81.  
  82.    /* Register window class */
  83.    if( ! WinRegisterClass( gbl_hab,
  84.            (PSZ) gbl_psz( IDS_NAME ),   /* Class name */
  85.            (PFNWP) ExamplPMWndProc,      /* Window function for class */
  86.            (ULONG) 0L,                  /* Class style bits */
  87.            (USHORT) 0                   /* Count of extra bytes for each */
  88.                                         /*  window instance in the class */
  89.            )
  90.      )
  91.       return FALSE;
  92.  
  93.    /* Fill in additional style bits for frame window */     
  94.    CtlData = FCF_STANDARD & ~FCF_TASKLIST ;
  95.  
  96.    gbl_hwndAppFrame = WinCreateStdWindow(
  97.       HWND_DESKTOP,                 /* Parent window handle */
  98.       WS_VISIBLE,                   /* Frame window style bits */
  99.       (PVOID) &CtlData,             /* Pointer to more style info */
  100.       (PSZ) gbl_psz( IDS_NAME ),    /* Client window class name */
  101.       (PSZ) NULL,                   /* Caption text (NULL uses .EXE file name */
  102.       0L,                           /* Client style bits */
  103.       (HMODULE) 0,                  /* Resource module id: 0 means .EXE file */
  104.       IDS_NAME,                     /* Menu, Accel, Icon Identifier */
  105.       (HWND FAR *) &gbl_hwndApp     /* Handle for client window */
  106.       );
  107.  
  108.  
  109.    /* According to the documentation, we should be able to set the title */
  110.    /* text by specifying a non-null caption text pointer in the above    */
  111.    /* call to WinCreateStdWindow.  That used to work in the 1.05 SDK.    */
  112.    /* In the 1.06 SDK, however, instead of replacing the caption, the    */
  113.    /* result is to append the text to the default caption, which is the  */
  114.    /* executable module name.  Anyway, this is what's needed as of 1.06. */
  115.  
  116.    WinSetWindowText( gbl_hwndAppFrame, (PSZ) gbl_psz( IDS_TITLE ) );
  117.  
  118.    /* Because we specifically did not specify FCF_TASKLIST in the frame  */
  119.    /* window style bits, we have to add the application to the task list */
  120.    /* ourselves.  Why do it ourselves?  Because if we had specified      */
  121.    /* FCF_TASKLIST, the application would have been added to the task    */
  122.    /* switch list under the name of the .EXE file, and that's ugly.      */
  123.    /* When we add the application ourselves, we get to choose the name.  */
  124.    /* Moreover, we get back a handle that will let us change the name in */
  125.    /* the switch list whenever we want to.  For example, we might decide */
  126.    /* to show status information in the task list.                       */
  127.    {
  128.       SWCNTRL swctl;
  129.       PID pid;
  130.       TID tid;
  131.  
  132.       WinQueryWindowProcess(gbl_hwndAppFrame, &pid, &tid);
  133.  
  134.       swctl.hwnd = gbl_hwndAppFrame;                  /* window handle      */
  135.       swctl.hwndIcon = NULL;                          /* icon handle        */
  136.       swctl.hprog = NULL;                             /* program handle     */
  137.       swctl.idProcess = pid;                          /* process identifier */
  138.       swctl.idSession = NULL;                         /* session identifier */
  139.       swctl.uchVisibility = SWL_VISIBLE;              /* visibility         */
  140.       swctl.fbJump = SWL_JUMPABLE;                    /* jump indicator     */
  141.       strcpy( swctl.szSwtitle, gbl_psz( IDS_TITLE )   /* program name       */
  142.       );
  143.  
  144.       gbl_hswitch = WinAddSwitchEntry( &swctl ) ;
  145.    }
  146.  
  147.    /* The arrow cursor */
  148.    gbl_curArrow = WinQuerySysPointer(
  149.       HWND_DESKTOP,
  150.       SPTR_ARROW,
  151.       FALSE
  152.       );
  153.  
  154.    /* The hourglass cursor */
  155.    gbl_curWait = WinQuerySysPointer(
  156.       HWND_DESKTOP,
  157.       SPTR_WAIT,
  158.       FALSE
  159.       );
  160.  
  161.    /* The application's icon */
  162.    gbl_hptrStd = WinLoadPointer(
  163.       HWND_DESKTOP,
  164.       NULL,
  165.       IDS_NAME
  166.       );
  167.  
  168.  
  169.    /* Add separator and "About" to system menu */
  170.  
  171.    hSysMenu = WinWindowFromID( gbl_hwndAppFrame, FID_SYSMENU );
  172.  
  173.    idSysMenu = SHORT1FROMMR( WinSendMsg(
  174.       hSysMenu,
  175.       MM_ITEMIDFROMPOSITION,
  176.       (MPARAM) 0,
  177.       (MPARAM) 0
  178.       ) );
  179.  
  180.    WinSendMsg( hSysMenu,
  181.       MM_QUERYITEM,
  182.       MPFROM2SHORT( idSysMenu, FALSE ),
  183.       MPFROMP( &miSysMenu )
  184.       );
  185.  
  186.    WinSendMsg( miSysMenu.hwndSubMenu,
  187.       MM_INSERTITEM,
  188.       MPFROMP( &menuitem[ 0 ] ),
  189.       MPFROMSHORT( 0 )
  190.       );
  191.  
  192.    WinSendMsg( miSysMenu.hwndSubMenu,
  193.       MM_INSERTITEM,
  194.       MPFROMP( &menuitem[ 1 ] ),
  195.       MPFROMP( gbl_psz( IDS_ABOUT ) )
  196.       );
  197.  
  198.    WinShowWindow( gbl_hwndApp, TRUE );
  199.    WinUpdateWindow( gbl_hwndApp );
  200.  
  201.    return( TRUE );
  202. }
  203.  
  204.  
  205.  
  206. /*   E N D   O F   E X A M I N I T . C   */
  207.