home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / CNRMNU.ZIP / COMMON.C < prev    next >
Text File  |  1993-01-01  |  9KB  |  202 lines

  1. /*********************************************************************
  2.  *                                                                   *
  3.  * MODULE NAME :  common.c               AUTHOR:  Rick Fishman       *
  4.  * DATE WRITTEN:  10-24-92                                           *
  5.  *                                                                   *
  6.  * DESCRIPTION:                                                      *
  7.  *                                                                   *
  8.  *  This module is part of CNRMENU.EXE. It contains common functions *
  9.  *  used by all modules in the EXE.                                  *
  10.  *                                                                   *
  11.  * CALLABLE FUNCTIONS:                                               *
  12.  *                                                                   *
  13.  *  VOID SetWindowTitle( HWND hwndClient, PSZ szFormat, ... );       *
  14.  *  VOID Msg           ( PSZ szFormat, ... );                        *
  15.  *  VOID FullyQualify  ( PSZ szBuf, HWND hwndCnr, PCNRITEM pci );    *
  16.  *                                                                   *
  17.  * HISTORY:                                                          *
  18.  *                                                                   *
  19.  *  10-24-92 - Source copied from CNRBASE.EXE sample.                *
  20.  *             Added sending Msg to stderr besides the msgbox.       *
  21.  *             Added FullyQualify function.                          *
  22.  *                                                                   *
  23.  *  Rick Fishman                                                     *
  24.  *  Code Blazers, Inc.                                               *
  25.  *  4113 Apricot                                                     *
  26.  *  Irvine, CA. 92720                                                *
  27.  *  CIS ID: 72251,750                                                *
  28.  *                                                                   *
  29.  *********************************************************************/
  30.  
  31. #pragma strings(readonly)   // used for debug version of memory mgmt routines
  32.  
  33. /*********************************************************************/
  34. /*------- Include relevant sections of the OS/2 header files --------*/
  35. /*********************************************************************/
  36.  
  37. #define  INCL_WINERRORS
  38. #define  INCL_WINFRAMEMGR
  39. #define  INCL_WINSTDCNR
  40. #define  INCL_WINWINDOWMGR
  41.  
  42. /**********************************************************************/
  43. /*----------------------------- INCLUDES -----------------------------*/
  44. /**********************************************************************/
  45.  
  46. #include <os2.h>
  47. #include <stdarg.h>
  48. #include <stdio.h>
  49. #include <stdlib.h>
  50. #include <string.h>
  51. #include "cnrmenu.h"
  52.  
  53. /*********************************************************************/
  54. /*------------------- APPLICATION DEFINITIONS -----------------------*/
  55. /*********************************************************************/
  56.  
  57. /**********************************************************************/
  58. /*---------------------------- STRUCTURES ----------------------------*/
  59. /**********************************************************************/
  60.  
  61. /**********************************************************************/
  62. /*----------------------- FUNCTION PROTOTYPES ------------------------*/
  63. /**********************************************************************/
  64.  
  65. /**********************************************************************/
  66. /*------------------------ GLOBAL VARIABLES --------------------------*/
  67. /**********************************************************************/
  68.  
  69. /**********************************************************************/
  70. /*-------------------------- SetWindowTitle --------------------------*/
  71. /*                                                                    */
  72. /*  SET THE FRAME WINDOW'S TITLEBAR TEXT.                             */
  73. /*                                                                    */
  74. /*  INPUT: client window handle,                                      */
  75. /*         a message in printf format with its parms                  */
  76. /*                                                                    */
  77. /*  1. Format the message using vsprintf.                             */
  78. /*  2. Set the text into the titlebar.                                */
  79. /*                                                                    */
  80. /*  OUTPUT: nothing                                                   */
  81. /*                                                                    */
  82. /*--------------------------------------------------------------------*/
  83. /**********************************************************************/
  84.  
  85. #define TITLEBAR_TEXTLEN (CCHMAXPATH + 50)
  86.  
  87. VOID SetWindowTitle( HWND hwndClient, PSZ szFormat,... )
  88. {
  89.     PSZ     szMsg;
  90.     va_list argptr;
  91.  
  92.     if( (szMsg = (PSZ) malloc( TITLEBAR_TEXTLEN )) == NULL )
  93.     {
  94.         DosBeep( 1000, 1000 );
  95.  
  96.         return;
  97.     }
  98.  
  99.     va_start( argptr, szFormat );
  100.  
  101.     vsprintf( szMsg, szFormat, argptr );
  102.  
  103.     va_end( argptr );
  104.  
  105.     szMsg[ TITLEBAR_TEXTLEN - 1 ] = 0;
  106.  
  107.     (void) WinSetWindowText( PARENT( hwndClient ), szMsg );
  108.  
  109.     free( szMsg );
  110.  
  111.     return;
  112. }
  113.  
  114. /**********************************************************************/
  115. /*------------------------------- Msg --------------------------------*/
  116. /*                                                                    */
  117. /*  DISPLAY A MESSAGE TO THE USER.                                    */
  118. /*                                                                    */
  119. /*  INPUT: a message in printf format with its parms                  */
  120. /*                                                                    */
  121. /*  1. Format the message using vsprintf.                             */
  122. /*  2. Sound a warning sound.                                         */
  123. /*  3. Display the message in a message box.                          */
  124. /*                                                                    */
  125. /*  OUTPUT: nothing                                                   */
  126. /*                                                                    */
  127. /*--------------------------------------------------------------------*/
  128. /**********************************************************************/
  129.  
  130. #define MESSAGE_SIZE 1024
  131.  
  132. VOID Msg( PSZ szFormat,... )
  133. {
  134.     PSZ     szMsg;
  135.     va_list argptr;
  136.  
  137.     if( (szMsg = (PSZ) malloc( MESSAGE_SIZE )) == NULL )
  138.     {
  139.         DosBeep( 1000, 1000 );
  140.  
  141.         return;
  142.     }
  143.  
  144.     va_start( argptr, szFormat );
  145.  
  146.     vsprintf( szMsg, szFormat, argptr );
  147.  
  148.     va_end( argptr );
  149.  
  150.     szMsg[ MESSAGE_SIZE - 1 ] = 0;
  151.  
  152.     fprintf( stderr, "\n%s", szMsg );
  153.  
  154.     (void) WinAlarm( HWND_DESKTOP, WA_WARNING );
  155.  
  156.     (void) WinMessageBox(  HWND_DESKTOP, HWND_DESKTOP, szMsg,
  157.                            PROGRAM_TITLE, 1, MB_OK | MB_MOVEABLE );
  158.  
  159.     free( szMsg );
  160.  
  161.     return;
  162. }
  163.  
  164. /**********************************************************************/
  165. /*--------------------------- FullyQualify ---------------------------*/
  166. /*                                                                    */
  167. /*  RECURSIVELY BUILD A FULLY QUALIFIED DIRECTORY NAME.               */
  168. /*                                                                    */
  169. /*  INPUT: directory name buffer,                                     */
  170. /*         container window handle,                                   */
  171. /*         pointer to current CNRITEM container record (subdirectory) */
  172. /*                                                                    */
  173. /*  1.                                                                */
  174. /*                                                                    */
  175. /*  OUTPUT: nothing                                                   */
  176. /*                                                                    */
  177. /*--------------------------------------------------------------------*/
  178. /**********************************************************************/
  179. VOID FullyQualify( PSZ szDirectory, HWND hwndCnr, PCNRITEM pci )
  180. {
  181.     PCNRITEM pciParent = WinSendMsg( hwndCnr, CM_QUERYRECORD, MPFROMP( pci ),
  182.                                      MPFROM2SHORT(CMA_PARENT, CMA_ITEMORDER) );
  183.  
  184.     if( (INT) pciParent == -1 )
  185.         Msg( "FullyQualify... CM_QUERYRECORD RC(%X)", HWNDERR( hwndCnr ) );
  186.     else
  187.     {
  188.         if( pciParent )
  189.             FullyQualify( szDirectory, hwndCnr, pciParent );
  190.  
  191.         (void) strcat( szDirectory, "\\" );
  192.  
  193.         (void) strcat( szDirectory, pci->szFileName );
  194.     }
  195.  
  196.     return;
  197. }
  198.  
  199. /*************************************************************************
  200.  *                     E N D     O F     S O U R C E                     *
  201.  *************************************************************************/
  202.