home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / cnradv.zip / COMMON.C < prev    next >
C/C++ Source or Header  |  1993-06-06  |  9KB  |  199 lines

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