home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tolkit45.zip / os2tk45 / samples / bidi / arabic / style / sty_main.c < prev    next >
C/C++ Source or Header  |  1999-05-11  |  12KB  |  362 lines

  1. /*************************************************************************
  2. *
  3. *  File Name   : Sty_main.c
  4. *
  5. *  Description : This PM sample application demonstates the
  6. *                standard menus, dialogs, and controls found
  7. *                in most PM applications.
  8. *                BIDI - Added: Bidirectional Language processing sample code.
  9. *
  10. *  Concepts    : PM window creation
  11. *                Menu Creation
  12. *                Dialog box creation
  13. *                Presentation parameters
  14. *                Initizalition and display of PM controls
  15. *                Help creation and initialization
  16. *
  17. *  API's       :
  18. *  -------------
  19. *  DosAllocMem              WinFontDlg             WinCreateStdWindow
  20. *  DosBeep                  WinGetMsg              WinCreateWindow
  21. *  DosClose                 WinGetPs               WinDefDlgProc
  22. *  DosExit                  WinInitialize          WinDefDlgProc
  23. *  DosExitList              WinIsWindow            WinDefWindowProc
  24. *  DosFreeMem               WinLoadMenu            WinDestroyHelpINstance
  25. *  DosOpen                  WinLoadString          WinDestroyWIndow
  26. *  DosRead                  WinMapWIndowPoints     WinDismissDlg
  27. *  DosWrite                 WinMessageBox          WinDispatchMsg
  28. *  GpiCreateLogFont         WinOpenClipbrd         WinDlgBox
  29. *  GpiDeleteSetID           WinPopupMenu           WinEndPaint
  30. *  GpiQueryFontMetrics      WinPostMsg             WinSendMsg
  31. *  GpiQueryFonts            WinQueryClipbrdFmtInfo WinSetDlgItemText
  32. *  GpiSetCharSet            WinQueryFocus          WinSetFocus
  33. *  WinSendDlgItemMsg        WinQueryTaskTitle      WinSetPresParms
  34. *  WinTerminate             WinQueryWindowPos      WinSetWindosPos
  35. *  WinAlarm                 WinQueryWindowRect     WinSetWindowText
  36. *  WinAssociateHelpInstance WinQueryWindowText     WinTerminate
  37. *  WinBeginPaint            WinQueryWindowUShort   WinWindosFormID
  38. *  WinCloseClipbrd          WinRegisterClass       WinDestroyMsgQueue
  39. *  WinCreateHelpInstance    WinReleasePS           WinFileDlg
  40. *  WinCreateMsgQueue        WinRemovePresParms     WinFillRect
  41. *
  42. *  Copyright (C) 1992 IBM Corporation
  43. *
  44. *      DISCLAIMER OF WARRANTIES.  The following [enclosed] code is
  45. *      sample code created by IBM Corporation. This sample code is not
  46. *      part of any standard or IBM product and is provided to you solely
  47. *      for  the purpose of assisting you in the development of your
  48. *      applications.  The code is provided "AS IS", without
  49. *      warranty of any kind.  IBM shall not be liable for any damages
  50. *      arising out of your use of the sample code, even if they have been
  51. *      advised of the possibility of such damages.                                                    *
  52. *
  53. ************************************************************************/
  54.  
  55. /* Include files, macros, defined constants, and externs                */
  56.  
  57. #define  INCL_WINHELP
  58.  
  59. #include <os2.h>
  60. #include "sty_main.h"
  61. #include "sty_xtrn.h"
  62. #include "sty_help.h"
  63.  
  64. #define RETURN_SUCCESS      0            /* successful return in DosExit */
  65. #define RETURN_ERROR        1            /* error return in DosExit      */
  66. #define BEEP_WARN_FREQ      60           /* frequency of warning beep    */
  67. #define BEEP_WARN_DUR      100           /* duration of warning beep     */
  68.  
  69.  
  70. /*  Global variables                                                     */
  71.  
  72. HWND hwndMainFrame;                  /* handle to the main frame window */
  73. HWND hwndMain;                       /* handle to the main client window */
  74. HDC  hdcMain;                        /* handle to the DC of the client */
  75. HAB hab;                             /* anchor block for the process */
  76. HMQ hmq;                             /* handle to the process' message queue */
  77. CHAR szAppName[MAXNAMEL];            /* buffer for application name string */
  78. CHAR szUntitled[MESSAGELEN];         /* buffer for "Untitled" string */
  79. BOOL fHelpEnabled;                   /* flag to determine if help is enabled */
  80.  
  81. /****************************************************************
  82.  *  Name:   main()
  83.  *
  84.  *  Description: Entry point of program.
  85.  *
  86.  *  Concepts: Obtains anchor block handle and creates message
  87.  *            queue.  Calls the initialization routine.
  88.  *            Creates the main frame window which creates the
  89.  *            main client window.  Polls the message queue
  90.  *            via Get/Dispatch Msg loop.  Upon exiting the
  91.  *            loop, exits.
  92.  *
  93.  *  API's   :  WinInitilize
  94.  *             DosBeep
  95.  *             WinCreateMsgQueue
  96.  *             WinTerminate
  97.  *             WinCreateStdWindow
  98.  *             WinSetWindowText
  99.  *             WinGetMsg
  100.  *             WinDispatchMsg
  101.  *
  102.  *  Parameters: None
  103.  *
  104.  *  Returns:
  105.  *          1 - if sucessful execution completed
  106.  *          0 - if error
  107. \****************************************************************/
  108. int main (VOID)
  109. {
  110.    QMSG qmsg;          /* message structure */
  111.    ULONG ulCtlData;      /* frame control data */
  112.  
  113.    hab = WinInitialize(0);
  114.    if(!hab)
  115.    {
  116.       DosBeep(BEEP_WARN_FREQ, BEEP_WARN_DUR);
  117.       return(RETURN_ERROR);
  118.    }
  119.  
  120.    hmq = WinCreateMsgQueue(hab, 0);
  121.    if(!hmq)
  122.    {
  123.       DosBeep(BEEP_WARN_FREQ, BEEP_WARN_DUR);
  124.       WinTerminate(hab);
  125.       return(RETURN_ERROR);
  126.    }
  127.  
  128.    if(!Init())
  129.    {
  130.       MessageBox(HWND_DESKTOP, IDMSG_INITFAILED, MB_OK | MB_ERROR, TRUE);
  131.       return(RETURN_ERROR);
  132.    }
  133.  
  134.    /* NOTE:  clean up from here is handled by the DosExitList processing */
  135.  
  136.    /* create the main window */
  137.    ulCtlData = FCF_STANDARD;
  138.  
  139.    hwndMainFrame = WinCreateStdWindow(HWND_DESKTOP, WS_VISIBLE,
  140.                                       (PVOID)&ulCtlData, (PSZ)szAppName,
  141.                                       (PSZ)NULL, WS_VISIBLE,
  142.                                       (HMODULE)NULL, IDR_MAIN,
  143.                                       (PHWND)&hwndMain);
  144.  
  145.    if(!hwndMainFrame)
  146.    {
  147.       MessageBox(HWND_DESKTOP, IDMSG_MAINWINCREATEFAILED, MB_OK | MB_ERROR,
  148.                   TRUE);
  149.       return(RETURN_ERROR);
  150.    }
  151.  
  152.    WinSetWindowText(hwndMainFrame, szAppName);
  153.  
  154.    InitHelp();
  155.  
  156.    /* Get/Dispatch Message loop                                  */
  157.    while(WinGetMsg(hmq, (PQMSG)&qmsg, 0, 0, 0))
  158.        WinDispatchMsg(hmq, (PQMSG)&qmsg);
  159.  
  160.    DestroyHelpInstance();
  161.  
  162.    return(RETURN_SUCCESS);
  163.  
  164. } /* End of main porcedure  */
  165.  
  166.  
  167.  
  168. /****************************************************************
  169.  *  Name:   MainWndProc
  170.  *
  171.  *  Description : Window procedure for the main clent window.
  172.  *
  173.  *  Concepts : Processes the messages sent to the main client
  174.  *             window.  This routine processes the basic
  175.  *             messages all client windows should process and
  176.  *             passes all others onto UserWndProc where the
  177.  *             developer can process any others.
  178.  *
  179.  *  API's : None
  180.  *
  181.  * Parameters   : hwnd - Window handle to which message is addressed
  182.  *                msg - Message type
  183.  *                mp1 - First message parameter
  184.  *                mp2 - Second message parameter
  185.  *
  186.  *  Returns:  Return values are determined by each message
  187.  *
  188.  ****************************************************************/
  189. MRESULT EXPENTRY MainWndProc(HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
  190. {
  191.    switch(msg)
  192.    {
  193.       case WM_CREATE:
  194.          return(InitMainWindow(hwnd, mp1, mp2));
  195.          break;
  196.  
  197.       case WM_PAINT:
  198.          MainPaint(hwnd);
  199.          break;
  200.  
  201.       case WM_COMMAND:
  202.          MainCommand(mp1, mp2);
  203.          break;
  204.  
  205.       case WM_INITMENU:
  206.          InitMenu(mp1, mp2);
  207.          break;
  208.  
  209.       case HM_QUERY_KEYS_HELP:
  210.          return (MRESULT)PANEL_HELPKEYS;     /* return id of key help panel */
  211.          break;
  212.  
  213.     /*
  214.      * Any messages not processed are passed on
  215.      * to the user's window proc.  It is
  216.      * responsible for passing any messages it
  217.      * doesn't handle onto WinDefWindowProc()
  218.      */
  219.       default:
  220.          return(UserWndProc(hwnd, msg, mp1, mp2));
  221.          break;
  222.  
  223.    }
  224.    return (MRESULT)0; /* all window procedures should return 0 as a default */
  225.  
  226. }   /* End of MainWndProc() */
  227.  
  228. /*********************************************************************
  229.  *  Name:   MessageBox
  230.  *
  231.  *  Description : Message Box procedure
  232.  *
  233.  *  Concepts : Displays the warning message box with the message
  234.  *             given in idMsg retrived from the message table
  235.  *             Called whever an error occurs and a message wishes
  236.  *             to be displayed to the user
  237.  *
  238.  *  API's : WinLoadString
  239.  *          WinAlarm
  240.  *          WinMessageBox
  241.  *
  242.  *  Parameters :  hwndOwner - window handle of the owner of the
  243.  *                            message box
  244.  *                idMsg     - id of message to be retrieved from
  245.  *                            resource file
  246.  *                fsStyle   - message box style
  247.  *                fBeep     - flag to sound alarm
  248.  *
  249.  *  Returns: SHORT
  250.  *
  251. \****************************************************************/
  252. SHORT MessageBox(HWND hwndOwner, SHORT idMsg, SHORT fsStyle, BOOL fBeep)
  253. {
  254.    CHAR szText[MESSAGELEN];
  255.  
  256.    if(!WinLoadMessage(hab, (HMODULE)NULL, idMsg, MESSAGELEN, (PSZ)szText))
  257.    {
  258.       WinAlarm(HWND_DESKTOP, WA_ERROR);
  259.       return MBID_ERROR;
  260.    }
  261.  
  262.    if(fBeep)
  263.       WinAlarm(HWND_DESKTOP, WA_ERROR);
  264.  
  265.    return(WinMessageBox(HWND_DESKTOP, hwndOwner, szText, (PSZ)szAppName,
  266.           IDD_MSGBOX, fsStyle));
  267.  
  268. }   /* End of MessageBox() */
  269.  
  270. /****************************************************************\
  271.  *  Name:   MainCommand
  272.  *
  273.  *  Purpose: Main window WM_COMMAND processing procedure
  274.  *
  275.  *  Concepts : Routine is called whenever a WM_COMMAND message is
  276.  *             posted to the main window.  A switch statement
  277.  *             branches on the id of the menu item that posted the
  278.  *             message and the appropriate action for that item is
  279.  *             taken.  Any menu ids that are not part of the
  280.  *             standard menu set are passed onto the user defined
  281.  *             WM_COMMAND processing procedure.
  282.  *
  283.  *  API's : WinPostMsg
  284.  *
  285.  *  Parameters :  mp1 - First message parameter
  286.  *                mp2 - Second message parameter
  287.  *
  288.  *  Returns: VOID
  289.  *
  290. \****************************************************************/
  291. VOID MainCommand(MPARAM mp1, MPARAM mp2)
  292. {
  293.    switch(SHORT1FROMMP(mp1))
  294.    {
  295.       case IDM_EXIT:
  296.          WinPostMsg( hwndMain, WM_QUIT, NULL, NULL );
  297.          break;
  298.  
  299.       case IDM_FILENEW:
  300.          FileNew(mp2);
  301.          break;
  302.  
  303.       case IDM_FILEOPEN:
  304.          FileOpen(mp2);
  305.          break;
  306.  
  307.       case IDM_FILESAVE:
  308.          FileSave(mp2);
  309.          break;
  310.  
  311.       case IDM_FILESAVEAS:
  312.          FileSaveAs(mp2);
  313.          break;
  314.  
  315. //BIDI
  316.       case IDM_EDITCOPY_NOCONV:
  317.       case IDM_EDITCOPY_AUTOCONV:
  318.       case IDM_EDITCOPY_CONV_VISUAL:
  319.       case IDM_EDITCOPY_CONV_IMPLICIT:
  320.          EditCopy(mp1, mp2);
  321.           break;
  322.  
  323.       case IDM_EDITPASTE_NOCONV:
  324.       case IDM_EDITPASTE_AUTOCONV:
  325.       case IDM_EDITPASTE_CONV_VISUAL:
  326.       case IDM_EDITPASTE_CONV_IMPLICIT:
  327.          EditPaste(mp1, mp2);
  328.          break;
  329. //BIDI
  330.  
  331.  
  332.       case IDM_HELPUSINGHELP:
  333.          HelpUsingHelp(mp2);
  334.          break;
  335.  
  336.       case IDM_HELPGENERAL:
  337.          HelpGeneral(mp2);
  338.          break;
  339.  
  340.       case IDM_HELPKEYS:
  341.          HelpKeys(mp2);
  342.          break;
  343.  
  344.       case IDM_HELPINDEX:
  345.          HelpIndex(mp2);
  346.          break;
  347.  
  348.       case IDM_HELPPRODINFO:
  349.          HelpProdInfo(mp2);
  350.          break;
  351.  
  352.     /*
  353.      * User command processing routine is called
  354.      * here so any ids not procecessed here can be
  355.      * processed
  356.      */
  357.       default:
  358.          UserCommand(mp1, mp2);
  359.          break;
  360.    }
  361. }   /* MainCommand() */
  362.