home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / startapp.zip / DLG.C next >
Text File  |  1998-09-10  |  7KB  |  189 lines

  1. /**************************************************************************
  2.  *  File name  :  dlg.c
  3.  *
  4.  *  Description:  This module contains the Dialog Procedures for the user
  5.  *                defined dialogs as well as any support code they need.
  6.  *
  7.  *                This source file contains the following functions:
  8.  *
  9.  *                ProductInfoDlgProc(hwnd, msg, mp1, mp2)
  10.  *                SetSysMenu(hDlg)
  11.  *
  12.  *  Concepts   :  dialog box
  13.  *
  14.  *  API's      :  WinDismissDlg
  15.  *                WinDefDlgProc
  16.  *                WinWindowFromID
  17.  *                WinSendMsg
  18.  *
  19.  *  Required
  20.  *    Files    :  OS2.H, STRING.H, MAIN.H, DLG.H, XTRN.H
  21.  *
  22.  *  (c) Copyright IBM Corp. 1991, 1998  All rights reserved.
  23.  *
  24.  *  These sample programs are owned by International Business Machines
  25.  *  Corporation or one of its subsidiaries ("IBM") and are copyrighted and
  26.  *  licensed, not sold.
  27.  *
  28.  *  You may copy, modify, and distribute these sample programs in any
  29.  *  form without payment to IBM, for any purpose including developing,
  30.  *  using, marketing or distributing programs that include or are
  31.  *  derivative works of the sample programs.
  32.  *
  33.  *  The sample programs are provided to you on an "AS IS" basis, without
  34.  *  warranty of any kind.  IBM HEREBY EXPRESSLY DISCLAIMS ALL WARRANTIES,
  35.  *  EITHER EXPRESS OR IMPLIED, INCLUDING , BUT NOT LIMITED TO, THE IMPLIED
  36.  *  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  37.  *  Some jurisdictions do not allow for the exclusion or limitation of
  38.  *  implied warranties, so the above limitations or exclusions may not
  39.  *  apply to you.  IBM shall not be liable for any damages you suffer
  40.  *  as a result of using, modifying or distributing the sample programs
  41.  *  or their derivatives.
  42.  *************************************************************************/
  43. /*
  44.  *  Include files, macros, defined constants, and externs
  45.  */
  46.  
  47. #define  INCL_WINMENUS
  48. #define  INCL_WINFRAMEMGR
  49. #include <os2.h>
  50. #include <string.h>
  51. #include "main.h"
  52. #include "dlg.h"
  53. #include "xtrn.h"
  54.  
  55. /*
  56.  *  Global variables
  57.  */
  58.  
  59. /*
  60.  *  Entry point declarations
  61.  */
  62.  
  63. MRESULT EXPENTRY ProductInfoDlgProc(HWND hwnd, USHORT msg,
  64.                                   MPARAM mp1, MPARAM mp2);
  65. VOID SetSysMenu( HWND hDlg );
  66.  
  67. /**************************************************************************
  68.  *
  69.  *  Name       : ProductInfoDlgProc(hwnd, msg, mp1, mp2)
  70.  *
  71.  *  Description: Processes all messages sent to the Product information
  72.  *               dialog
  73.  *
  74.  *  Concepts:  The Product information dialog has only a button control,
  75.  *             so this routine processes only WM_COMMAND messages.  Any
  76.  *             WM_COMMAND posted must have come from the OK
  77.  *             button, so we dismiss the dialog upon receiving it.
  78.  *
  79.  *  API's      :  WinDismissDlg
  80.  *                WinDefDlgProc
  81.  *
  82.  *  Parameters :  hwnd     = window handle
  83.  *                msg      = message i.d.
  84.  *                mp1      = first message parameter
  85.  *                mp2      = second message parameter
  86.  *
  87.  *  Return     :  dependent on message sent
  88.  *
  89.  *  Comments   :  This dialog is the Code Information submenu item
  90.  *                from the Help menu bar item
  91.  *************************************************************************/
  92. MRESULT EXPENTRY ProductInfoDlgProc(
  93.                          HWND hwnd,      /* handle of window */
  94.                          USHORT msg,     /* id of message */
  95.                          MPARAM mp1,     /* first message parameter */
  96.                          MPARAM mp2)     /* second message parameter */
  97. {
  98.    switch(msg)
  99.    {
  100.       case WM_INITDLG:
  101.          SetSysMenu(hwnd);       /* system menu for this dialog  */
  102.          return MRFROMSHORT(FALSE);
  103.  
  104.       case WM_COMMAND:
  105.            /* no matter what the command, close the dialog */
  106.          WinDismissDlg(hwnd, TRUE);
  107.          break;
  108.  
  109.       default:
  110.          return(WinDefDlgProc(hwnd, msg, mp1, mp2));
  111.          break;
  112.    }
  113.    return (MRESULT)NULL;
  114. }   /*  End of ProductInfoDlgProc   */
  115.  
  116.  
  117. /**************************************************************************
  118.  *
  119.  *  Name       : SetSysMenu(hDlg)
  120.  *
  121.  *  Description: Sets only the Move and Close items of the system menu
  122.  *
  123.  *  Concepts:  Any dialog box is free to call this routine, to edit
  124.  *             which menu items will appear on its System Menu pulldown.
  125.  *
  126.  *  API's      :  WinWindowFromID
  127.  *                WinSendMsg
  128.  *
  129.  *  Parameters :  hDlg     = window handle of the dialog
  130.  *
  131.  *  Return     :  [none]
  132.  *
  133.  *  Comments   :  In this sample, this procedure gets invoked when
  134.  *                the "Code Information" menu item is selected off of
  135.  *                the HELP Menu Bar.  It modifies the system menu by
  136.  *                eliminating one or more items from the system menu.
  137.  *
  138.  *************************************************************************/
  139.  
  140. VOID SetSysMenu(HWND hDlg)
  141. {
  142.     HWND     hSysMenu;
  143.     MENUITEM Mi;
  144.     ULONG    Pos;
  145.     MRESULT  Id;
  146.     SHORT    cItems;
  147.  
  148.     /******************************************************************/
  149.     /*  We only want Move and Close in the system menu.               */
  150.     /******************************************************************/
  151.  
  152.     /*  Obtain the handle of the system menu within the dialog        */
  153.     hSysMenu = WinWindowFromID(hDlg, FID_SYSMENU);
  154.  
  155.     /*  Build a list of submenu items from the system menu            */
  156.     /*  A pointer will be established to Mi.hwndSubMenu               */
  157.     WinSendMsg( hSysMenu, MM_QUERYITEM,
  158.                 MPFROM2SHORT(SC_SYSMENU, FALSE), MPFROMP((PCH) & Mi));
  159.     Pos = 0L;   /* Initialize the menu item position to the top       */
  160.     /*  Obtain a count of items in the menu                           */
  161.     cItems = (SHORT)WinSendMsg( Mi.hwndSubMenu, MM_QUERYITEMCOUNT,
  162.                                 (MPARAM)NULL, (MPARAM)NULL);
  163.     while (cItems--)  /* loop through the list items */
  164.     {   /* Using the current position in the list, obtain its menu id */
  165.         Id = WinSendMsg( Mi.hwndSubMenu, MM_ITEMIDFROMPOSITION,
  166.                          MPFROMLONG(Pos), (MPARAM)NULL);
  167.  
  168.         /* We want to delete all submenu items except Move and Close  */
  169.         /* The following case statement will pass these items and by  */
  170.         /* default delete the rest.  Note, normally we would use      */
  171.         /* MM_REMOVEITEM rather than MM_DELETEITEM so that we could   */
  172.         /* add the menu item back later.  The MM_DELETEITEM prevents  */
  173.         /* us from doing this without recreating the dialog.          */
  174.         switch (SHORT1FROMMR(Id))
  175.         {
  176.         case SC_MOVE:
  177.             Pos++;  /* Don't delete that one. */
  178.             break;
  179.         case SC_CLOSE:
  180.             Pos++;  /* Don't delete that one. */
  181.             break;
  182.         default:
  183.             WinSendMsg( Mi.hwndSubMenu, MM_DELETEITEM,
  184.                         MPFROM2SHORT((USHORT)Id, TRUE), (MPARAM)NULL);
  185.         }
  186.     }
  187. }   /*  End of SetSysMenu  */
  188. /***************************  End of dlg.c  ****************************/
  189.