home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / template.zip / DLG.C next >
C/C++ Source or Header  |  1998-04-20  |  5KB  |  157 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.  *  Copyright (C) 1991 IBM Corporation
  23.  *
  24.  *      DISCLAIMER OF WARRANTIES.  The following [enclosed] code is
  25.  *      sample code created by IBM Corporation. This sample code is not
  26.  *      part of any standard or IBM product and is provided to you solely
  27.  *      for  the purpose of assisting you in the development of your
  28.  *      applications.  The code is provided "AS IS", without
  29.  *      warranty of any kind.  IBM shall not be liable for any damages
  30.  *      arising out of your use of the sample code, even if they have been
  31.  *      advised of the possibility of such damages.                                                    *
  32.  *************************************************************************/
  33. /*
  34.  *  Include files, macros, defined constants, and externs
  35.  */
  36.  
  37. #define  INCL_WINMENUS
  38. #define  INCL_WINFRAMEMGR
  39. #include <os2.h>
  40. #include <string.h>
  41. #include "main.h"
  42. #include "dlg.h"
  43. #include "xtrn.h"
  44.  
  45. /*
  46.  *  Global variables
  47.  */
  48.  
  49. /*
  50.  *  Entry point declarations
  51.  */
  52.  
  53. MRESULT EXPENTRY ProductInfoDlgProc(HWND hwnd, USHORT msg,
  54.                                   MPARAM mp1, MPARAM mp2);
  55. VOID SetSysMenu( HWND hDlg );
  56.  
  57. /**************************************************************************
  58.  *
  59.  *  Name       : ProductInfoDlgProc(hwnd, msg, mp1, mp2)
  60.  *
  61.  *  Description: Processes all messages sent to the Product information
  62.  *               dialog
  63.  *
  64.  *  Concepts:  The Product information dialog has only a button control,
  65.  *             so this routine processes only WM_COMMAND messages.  Any
  66.  *             WM_COMMAND posted must have come from the OK
  67.  *             button, so we dismiss the dialog upon receiving it.
  68.  *
  69.  *  API's      :  WinDismissDlg
  70.  *                WinDefDlgProc
  71.  *
  72.  *  Parameters :  hwnd     = window handle
  73.  *                msg      = message i.d.
  74.  *                mp1      = first message parameter
  75.  *                mp2      = second message parameter
  76.  *
  77.  *  Return     :  dependent on message sent
  78.  *
  79.  *************************************************************************/
  80. MRESULT EXPENTRY ProductInfoDlgProc(
  81.                          HWND hwnd,      /* handle of window */
  82.                          USHORT msg,     /* id of message */
  83.                          MPARAM mp1,     /* first message parameter */
  84.                          MPARAM mp2)     /* second message parameter */
  85. {
  86.    switch(msg)
  87.    {
  88.       case WM_INITDLG:
  89.          SetSysMenu(hwnd);       /* system menu for this dialog  */
  90.          return MRFROMSHORT(FALSE);
  91.  
  92.       case WM_COMMAND:
  93.            /* no matter what the command, close the dialog */
  94.          WinDismissDlg(hwnd, TRUE);
  95.          break;
  96.  
  97.       default:
  98.          return(WinDefDlgProc(hwnd, msg, mp1, mp2));
  99.          break;
  100.    }
  101.    return (MRESULT)NULL;
  102. }   /*  End of ProductInfoDlgProc   */
  103.  
  104.  
  105. /**************************************************************************
  106.  *
  107.  *  Name       : SetSysMenu(hDlg)
  108.  *
  109.  *  Description: Sets only the Move and Close items of the system menu
  110.  *
  111.  *  Concepts:  Any dialog box is free to call this routine, to edit
  112.  *             which menu items will appear on its System Menu pulldown.
  113.  *
  114.  *  API's      :  WinWindowFromID
  115.  *                WinSendMsg
  116.  *
  117.  *  Parameters :  hDlg     = window handle of the dialog
  118.  *
  119.  *  Return     :  [none]
  120.  *
  121.  *************************************************************************/
  122. VOID SetSysMenu(HWND hDlg)
  123. {
  124.     HWND     hSysMenu;
  125.     MENUITEM Mi;
  126.     ULONG    Pos;
  127.     MRESULT  Id;
  128.     SHORT    cItems;
  129.  
  130.     /******************************************************************/
  131.     /*  We only want Move and Close in the system menu.               */
  132.     /******************************************************************/
  133.  
  134.     hSysMenu = WinWindowFromID(hDlg, FID_SYSMENU);
  135.     WinSendMsg( hSysMenu, MM_QUERYITEM
  136.               , MPFROM2SHORT(SC_SYSMENU, FALSE), MPFROMP((PCH) & Mi));
  137.     Pos = 0L;
  138.     cItems = (SHORT)WinSendMsg( Mi.hwndSubMenu, MM_QUERYITEMCOUNT,
  139.                                 (MPARAM)NULL, (MPARAM)NULL);
  140.     while (cItems--)
  141.     {
  142.         Id = WinSendMsg( Mi.hwndSubMenu, MM_ITEMIDFROMPOSITION
  143.                           , MPFROMLONG(Pos), (MPARAM)NULL);
  144.         switch (SHORT1FROMMR(Id))
  145.         {
  146.         case SC_MOVE:
  147.         case SC_CLOSE:
  148.             Pos++;  /* Don't delete that one. */
  149.             break;
  150.         default:
  151.             WinSendMsg( Mi.hwndSubMenu, MM_DELETEITEM
  152.                       , MPFROM2SHORT((USHORT)Id, TRUE), (MPARAM)NULL);
  153.         }
  154.     }
  155. }   /*  End of SetSysMenu  */
  156. /***************************  End of dlg.c  ****************************/
  157.