File:  [OS/2 SDKs] / os232sdk / toolkt20 / c / samples / template / user.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Thu Aug 9 12:26:31 2018 UTC (7 years, 9 months ago) by root
Branches: msft, MAIN
CVS tags: os2sdk-1990, HEAD
Microsoft OS/2 SDK 2.0 05-30-1990

/*==============================================================*\
 *  User.c - routines for handling messages not processed
 *              by the standard message processing routine
 *      Created 1989, 1990 Microsoft Corp.
 *--------------------------------------------------------------
 *
 *  This module contains the code for processing messages sent
 *  to the standard window that the standard window does not
 *  process.  The application developer need only modify this
 *  file in order to implement new menu items or process
 *  messages not handled by the standard message routine.
 *
 *--------------------------------------------------------------
 *
 *  This source file contains the following functions:
 *
 *      UserWndProc(hwnd, msg, mp1, mp2) - user window procedure
 *      UserCommand(mp1, mp2) - user WM_COMMAND processor
 *
\*==============================================================*/

/*--------------------------------------------------------------*\
 *  Include files, macros, defined constants, and externs
\*--------------------------------------------------------------*/

#define INCL_WINMENUS

#include <os2.h>
#include "main.h"
#include "dlg.h"
#include "xtrn.h"

/*--------------------------------------------------------------*\
 *  Global variables
\*--------------------------------------------------------------*/


/*--------------------------------------------------------------*\
 *  Entry point declarations
\*--------------------------------------------------------------*/


/****************************************************************\
 *  Non-standard window message processing routine
 *--------------------------------------------------------------
 *
 *  Name:   UserWndProc(hwnd, msg, mp1, mp2)
 *
 *  Purpose: Process any messages sent to hwndMain that
 *              are not processed by the standard window
 *              procedure
 *
 *  Usage:  Routine is called for each message MainWndProc
 *          does not process
 *
 *  Method: A switch statement branches control based upon
 *          the message passed.  Any messages not processed
 *          here must be passed onto WinDefWindowProc()
 *
 *  Returns: Return value dependent upon the message processed
 *
\****************************************************************/
MRESULT UserWndProc(hwnd, msg, mp1, mp2)
HWND hwnd;      /* handle of window */
USHORT msg;     /* id of message */
MPARAM mp1;     /* first message parameter */
MPARAM mp2;     /* second message parameter */
{

    switch(msg)  {

    /*--------------------------------------------------------------*\
     *  Add case statements for message ids you wish to process
    \*--------------------------------------------------------------*/


        default:    /* default must call WinDefWindowProc() */
            return(WinDefWindowProc(hwnd, msg, mp1, mp2));
            break;
    }

    return (MRESULT)0;

}   /* UserWndProc() */


/****************************************************************\
 *  Non-standard menu item command processing procedure
 *--------------------------------------------------------------
 *
 *  Name:   UserCommand(mp1, mp2)
 *
 *  Purpose: Process any WM_COMMAND messages sent to hwndMain
 *              that are not processed by MainCommand
 *
 *  Usage:  Routine is called for each WM_COMMAND that is
 *          not posted by a standard menu item
 *
 *  Method: A switch statement branches control based upon
 *          the id of the control which posted the message
 *
 *  Returns:
\****************************************************************/
VOID UserCommand(mp1, mp2)
MPARAM mp1;     /* first message parameter */
MPARAM mp2;     /* second message parameter */
{

    switch(SHORT1FROMMP(mp1))  {

    /*--------------------------------------------------------------*\
     *  Add case statements for menuitem ids you wish to process
    \*--------------------------------------------------------------*/



        default:
            break;
    }

    /* This routine currently doesn't use the mp2 parameter but       *\
     *  it is referenced here to prevent an 'Unreferenced Parameter'
    \*  warning at compile time.                                      */
    mp2;

}   /* UserCommand() */

/****************************************************************\
 *  Menu item intialization routine
 *--------------------------------------------------------------
 *
 *  Name:   InitMenu(mp1, mp2)
 *
 *  Purpose: Processes the WM_INITMENU message for the main window,
 *              disabling any menus that are not active
 *
 *  Usage:  Routine is called each time a menu is dropped
 *
 *  Method: A switch statement branches control based upon
 *          the id of the menu that is being displayed
 *
 *  Returns:
\****************************************************************/
VOID InitMenu(mp1, mp2)
MPARAM mp1;     /* first message parameter */
MPARAM mp2;     /* second message parameter */
{

/* define a shorthand way of denoting the menu handle */
#define hwndMenu        HWNDFROMMP(mp2)

    switch(SHORT1FROMMP(mp1))  {
        case IDM_FILE:
            /*
             * The Print, Print Setup, and Page Setup menu items of the
             * File menu will be enabled if printing is enabled, otherwise
             * they will be disabled
             */

            EnableMenuItem(hwndMenu, IDM_FILEPRINT, fPrintEnabled);
            EnableMenuItem(hwndMenu, IDM_FILEPRINTSETUP, fPrintEnabled);
            EnableMenuItem(hwndMenu, IDM_FILEPAGESETUP, fPrintEnabled);

            break;

        case IDM_HELP:
            /*
             * Enable or disable the Help menu depending upon whether the
             * help manager has been enabled
             */
            EnableMenuItem(hwndMenu, IDM_HELPHELPFORHELP, fHelpEnabled);
            EnableMenuItem(hwndMenu, IDM_HELPEXTENDED, fHelpEnabled);
            EnableMenuItem(hwndMenu, IDM_HELPKEYS, fHelpEnabled);
            EnableMenuItem(hwndMenu, IDM_HELPINDEX, fHelpEnabled);

            /** REMEMBER: add a case for IDM_HELPTUTORIAL if you include
                the Tutorial menu item   **/

            break;

        default:
            break;
    }

#undef hwndMenu

}   /* InitMenu() */

/****************************************************************\
 *  Enables/Disables the menu item of the given menu
 *--------------------------------------------------------------
 *
 *  Name:   EnableMenuItem(hwndMenu, idItem, fEnable)
 *
 *  Purpose: Enables or disables the menu item
 *
 *  Usage:  Called whenever a menu item is to be enabled or
 *          disabled
 *
 *  Method: Sends a MM_SETITEMATTR to the menu with the
 *          given item id.  Sets the MIA_DISABLED attribute
 *          flag if the item is to be disabled, clears the flag
 *          if enabling
 *
 *  Returns:
 *
\****************************************************************/
VOID EnableMenuItem(hwndMenu, idItem, fEnable)
HWND hwndMenu;      /* Handle to the menu */
SHORT idItem;       /* Id of the menu item to be enabled/disabled */
BOOL fEnable;       /* flag to set enable or disable bit */
{
    SHORT fsFlag;

    if(fEnable)
        fsFlag = 0;
    else
        fsFlag = MIA_DISABLED;

    WinSendMsg(hwndMenu,
               MM_SETITEMATTR,
               MPFROM2SHORT(idItem, TRUE),
               MPFROM2SHORT(MIA_DISABLED, fsFlag));

}   /* EnableMenuItem() */

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.