|
|
Microsoft OS/2 SDK 2.0 05-30-1990
/*==============================================================*\
* Main.c - Sample PM style application
*
* Created 1990, Microsoft, IBM Corp.
*
* DISCLAIMER OF WARRANTIES. The following [enclosed] code is
* sample code created by Microsoft Corporation and/or IBM
* Corporation. This sample code is not part of any standard
* Microsoft or IBM product and is provided to you solely for
* the purpose of assisting you in the development of your
* applications. The code is provided "AS IS", without
* warranty of any kind. Neither Microsoft nor IBM shall be
* liable for any damages arising out of your use of the sample
* code, even if they have been advised of the possibility of
* such damages.
*
*--------------------------------------------------------------
*
* This application serves two distinct purposes. First, it
* demonstrates the standard menus and dialogs that most PM
* applications will contain. The Demo menu calls dialog
* boxes that demonstrate all of the controls available for
* use in a dialog box. There is also a dialog box which
* demonstrates the setting and removing of control
* Presentation Parameters. Finally, the demo menu also has
* menu items that demonstrate the various types of message
* boxes that the system supports.
*
* This application also serves as a template than can be
* easily modified by an application developer. The source
* files are organized so that the overhead code that should
* be in all applications is located in the same files so
* that these files do not need to be modified. The routines
* that deal with application specific code are also located
* in their own modules. An application developer need only
* change these files in order to modify this template for
* his application.
*
*--------------------------------------------------------------
*
* This source file contains the following functions:
*
* main() - main routine
* MainWndProc(hwnd, msg, mp1, mp2) - main window procedure
* MessageBox(hwnd, id, fsShort, fBeep) - Message box routine
* MainCommand(mp1, mp2) - WM_COMMAND processing of Main
*
\*==============================================================*/
/*--------------------------------------------------------------*\
* Include files, macros, defined constants, and externs
\*--------------------------------------------------------------*/
#define INCL_WINHELP
#include <os2.h>
#include "sty_main.h"
#include "sty_xtrn.h"
#include "sty_help.h"
#define RETURN_SUCCESS 0 /* successful return in DosExit */
#define RETURN_ERROR 1 /* error return in DosExit */
#define BEEP_WARN_FREQ 60 /* frequency of warning beep */
#define BEEP_WARN_DUR 100 /* duration of warning beep */
/* The comments around this line should be removed when the import/export
bug in MLEs is fixed */
/* #define MLE_BUGS_FIXED */
/* #define PRINT_DLGS_ENABLED */
/*--------------------------------------------------------------*\
* Global variables
\*--------------------------------------------------------------*/
HWND hwndMainFrame; /* handle to the main frame window */
HWND hwndMain; /* handle to the main client window */
HDC hdcMain; /* handle to the DC of the client */
HAB hab; /* anchor block for the process */
HMQ hmq; /* handle to the process' message queue */
CHAR szAppName[MAXNAMEL]; /* buffer for application name string */
CHAR szUntitled[MESSAGELEN]; /* buffer for "Untitled" string */
BOOL fPrintEnabled; /* flag to determine if we can print */
BOOL fHelpEnabled; /* flag to determine if help is enabled */
/*--------------------------------------------------------------*\
* Entry point declarations
\*--------------------------------------------------------------*/
/****************************************************************\
* Main routine
*--------------------------------------------------------------
*
* Name: main()
*
* Purpose: Initializes the PM environment, calls the
* initialization routine, creates the main
* window, and polls the message queue
*
* Usage:
*
* Method:
* - obtains anchor block handle and creates message
* queue
* - calls the initialization routine
* - creates the main frame window which creates the
* main client window
* - polls the message queue via Get/Dispatch Msg loop
* - upon exiting the loop, exits
*
* Returns:
* 1 - if sucessful execution completed
* 0 - if error
\****************************************************************/
BOOL cdecl main(VOID)
{
QMSG qmsg; /* message structure */
ULONG ctlData; /* frame control data */
hab = WinInitialize(0);
if(!hab) {
DosBeep(BEEP_WARN_FREQ, BEEP_WARN_DUR);
return(RETURN_ERROR);
}
hmq = WinCreateMsgQueue(hab, 0);
if(!hmq) {
DosBeep(BEEP_WARN_FREQ, BEEP_WARN_DUR);
WinTerminate(hab);
return(RETURN_ERROR);
}
if(!Init()) {
MessageBox(HWND_DESKTOP, IDMSG_INITFAILED, MB_OK | MB_ERROR, TRUE);
return(RETURN_ERROR);
}
/* NOTE: clean up from here is handled by the DosExitList processing */
/* create the main window */
ctlData = FCF_STANDARD;
hwndMainFrame = WinCreateStdWindow(HWND_DESKTOP,
WS_VISIBLE,
(PVOID)&ctlData,
(PSZ)szAppName,
(PSZ)NULL,
WS_VISIBLE,
(HMODULE)NULL,
IDR_MAIN,
(PHWND)&hwndMain);
if(!hwndMainFrame) {
MessageBox(HWND_DESKTOP,
IDMSG_MAINWINCREATEFAILED,
MB_OK | MB_ERROR,
TRUE);
return(RETURN_ERROR);
}
hdcMain = WinOpenWindowDC(hwndMain);
InitHelp();
/* Get/Dispatch Message loop */
while(WinGetMsg(hmq, (PQMSG)&qmsg, NULL, NULL, NULL))
WinDispatchMsg(hmq, (PQMSG)&qmsg);
DestroyHelpInstance();
return(RETURN_SUCCESS);
} /* main() */
/****************************************************************\
* Main client window procedure
*--------------------------------------------------------------
*
* Name: MainWndProc(hwnd, msg, mp1, mp2)
*
* Purpose: Processes the messages sent to the main client
* window. This routine processes the basic
* messages all client windows should process
* and passes all others onto UserWndProc where
* the developer can process any others.
*
* Usage: Called for each message placed in the main
* window's message queue
*
* Method: a switch statement branches to the routines to be
* performed for each message processed. Any messages
* not specifically process are passed to the user's
* message processing procedure UserWndProc().
*
* Returns: Return values are determined by each message
*
\****************************************************************/
MRESULT EXPENTRY MainWndProc(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) {
case WM_CREATE:
return(InitMainWindow(hwnd, mp1, mp2));
break;
case WM_PAINT:
MainPaint(hwnd);
break;
case WM_COMMAND:
MainCommand(mp1, mp2);
break;
case WM_INITMENU:
InitMenu(mp1, mp2);
break;
case HM_QUERY_KEYS_HELP:
return (MRESULT)PANEL_HELPKEYS; /* return id of key help panel */
break;
/*--------------------------------------------------*\
* Any messages not processed are passed on
* to the user's window proc. It is
* responsible for passing any messages it
* doesn't handle onto WinDefWindowProc()
\*--------------------------------------------------*/
default:
return(UserWndProc(hwnd, msg, mp1, mp2));
break;
}
return 0L; /* all window procedures should return 0 as a default */
} /* MainWndProc() */
/****************************************************************\
* Message Box procedure
*--------------------------------------------------------------
*
* Name: MessageBox(hwndOwner, idMsg, fsStyle, fBeep)
*
* Purpose: Displays the warning message box with the message
* given in idMsg retrived from the message table
*
* Usage: Called whever an error occurs and a message wishes
* to be displayed to the user
*
* Method: - Message string is loaded from the process'
* message table
* - Alarm beep is sounded if desired
* - Message box with the message is displayed
*
* Returns:
*
\****************************************************************/
SHORT MessageBox(hwndOwner, idMsg, fsStyle, fBeep)
HWND hwndOwner; /* handle of the message box's owner */
SHORT idMsg; /* id if the message in the message table */
SHORT fsStyle; /* style of the message box */
BOOL fBeep; /* if TRUE, beep before message box is displayed */
{
CHAR szText[MESSAGELEN];
if(!WinLoadMessage(hab,
(HMODULE)NULL,
idMsg,
MESSAGELEN,
(PSZ)szText)) {
WinAlarm(HWND_DESKTOP, WA_ERROR);
return MBID_ERROR;
}
if(fBeep)
WinAlarm(HWND_DESKTOP, WA_ERROR);
return(WinMessageBox(HWND_DESKTOP,
hwndOwner,
szText,
(PSZ)NULL,
IDD_MSGBOX,
fsStyle));
} /* MessageBox() */
/****************************************************************\
* Main window WM_COMMAND processing procedure
*--------------------------------------------------------------
*
* Name: MainCommand(mp1, mp2)
*
* Purpose: Calls the appropriate procedures that deal with
* the selected menu item.
*
* Usage: Routine is called whenever a WM_COMMAND message
* is posted to the main window.
*
* Method: a switch statement branches on the id of the
* menu item that posted the message and the
* appropriate action for that item is taken. Any
* menu ids that are not part of the standard menu
* set are passed onto the user defined WM_COMMAND
* processing procedure.
*
* Returns:
*
\****************************************************************/
VOID MainCommand(mp1, mp2)
MPARAM mp1; /* first parameter of WM_COMMAND message */
MPARAM mp2; /* second parameter of WM_COMMAND message */
{
switch(SHORT1FROMMP(mp1)) {
case IDM_FILENEW:
FileNew(mp2);
break;
#ifdef MLE_BUGS_FIXED
case IDM_FILEOPEN:
FileOpen(mp2);
break;
case IDM_FILESAVE:
FileSave(mp2);
break;
case IDM_FILESAVEAS:
FileSaveAs(mp2);
break;
#endif
#ifdef PRINT_DIALOGS_ENABLED
case IDM_FILEPRINT:
FilePrint(mp2);
break;
case IDM_FILEPAGESETUP:
FilePageSetup(mp2);
break;
case IDM_FILEPRINTSETUP:
FilePrintSetup(mp2);
break;
#endif
case IDM_FILEEXIT:
FileExit(mp2);
break;
case IDM_EDITUNDO:
EditUndo(mp2);
break;
case IDM_EDITCUT:
EditCut(mp2);
break;
case IDM_EDITCOPY:
EditCopy(mp2);
break;
case IDM_EDITPASTE:
EditPaste(mp2);
break;
case IDM_EDITCLEAR:
EditClear(mp2);
break;
case IDM_HELPHELPFORHELP:
HelpHelpForHelp(mp2);
break;
case IDM_HELPEXTENDED:
HelpExtended(mp2);
break;
case IDM_HELPKEYS:
HelpKeys(mp2);
break;
case IDM_HELPINDEX:
HelpIndex(mp2);
break;
case IDM_HELPTUTORIAL:
HelpTutorial(mp2);
break;
case IDM_HELPABOUT:
HelpAbout(mp2);
break;
/*--------------------------------------------------*\
* User command processing routine is called
* here so any ids not procecessed here can be
* processed
\*--------------------------------------------------*/
default:
UserCommand(mp1, mp2);
break;
}
} /* MainCommand() */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.