home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 8 Other / 08-Other.zip / kwikstik.zip / UTILS.C < prev    next >
C/C++ Source or Header  |  1994-03-24  |  3KB  |  102 lines

  1. /*
  2.  * utils.c
  3.  *
  4.  * This file contains a number of helper routines.  Among them:
  5.  *
  6.  * - EnableMenuItem        - Enables or disables a menu item
  7.  * - CheckMenuItem         - Checks or unchecks a menu item
  8.  * - ErrorMessage          - vararg message box using resource ID as format
  9.  * - ReportWinError        - present message box w/WinGetErrInfo info
  10.  *
  11.  * Written 900228 by John W. Cocula
  12.  *
  13.  */
  14.  
  15. #define INCL_DEV
  16. #define INCL_GPILOGCOLORTABLE
  17. #define INCL_WINERRORS
  18. #define INCL_WINFRAMEMGR
  19. #define INCL_WINMENUS
  20. #define INCL_WINMESSAGEMGR
  21. #define INCL_WINSHELLDATA
  22. #define INCL_WINSYS
  23. #include <os2.h>
  24.  
  25. #include <stdio.h>
  26. #include <stdarg.h>
  27. #include <string.h>
  28.  
  29. #include "main.h"
  30.                      
  31. /*************************** EnableMenuItem *****************************/
  32.  
  33. VOID EnableMenuItem( HWND hwnd, SHORT iMenuItem, BOOL fEnable )
  34. {
  35.     HWND hwndParent = WinQueryWindow( hwnd, QW_PARENT, FALSE );
  36.     HWND hwndMenu   = WinWindowFromID( hwndParent, FID_MENU );
  37.  
  38.     WinSendMsg( hwndMenu, MM_SETITEMATTR, MPFROM2SHORT(iMenuItem, TRUE),
  39.         MPFROM2SHORT(MIA_DISABLED, fEnable ? ~MIA_DISABLED : MIA_DISABLED) );
  40.  
  41. }    /* EnableMenuItem */
  42.  
  43. /*************************** CheckMenuItem ******************************/
  44.  
  45. VOID CheckMenuItem( HWND hwnd, SHORT iMenuItem, BOOL fEnable )
  46. {
  47.     HWND hwndParent = WinQueryWindow( hwnd, QW_PARENT, FALSE );
  48.     HWND hwndMenu   = WinWindowFromID( hwndParent, FID_MENU );
  49.  
  50.     WinSendMsg( hwndMenu, MM_SETITEMATTR, MPFROM2SHORT(iMenuItem, TRUE),
  51.         MPFROM2SHORT(MIA_CHECKED, fEnable ? MIA_CHECKED : 0) );
  52.  
  53. }    /* CheckMenuItem */
  54.  
  55. /************************** ErrorMessage ********************************/
  56.  
  57. VOID cdecl ErrorMessage(
  58.    USHORT   usStringId, /* ID of string in resource file                */
  59.    ...                  /* variable arguments for vsprintf function     */
  60.    )
  61. {
  62.    static CHAR achBuffer1[MAXSTRING];
  63.    static CHAR achBuffer2[MAXSTRING];
  64.    va_list arg_ptr;
  65.    va_start(arg_ptr, usStringId);
  66.  
  67.     WinLoadString( habMain, NULL, usStringId, MAXSTRING, achBuffer1 );
  68.  
  69.    vsprintf( achBuffer2, achBuffer1, arg_ptr );
  70.  
  71.    WinMessageBox( HWND_DESKTOP, hwndFrame, achBuffer2, szWindowTitle, 
  72.          usStringId, MB_ICONHAND | MB_OK | MB_HELP );
  73.  
  74.    va_end(arg_ptr);
  75.  
  76. }  /* ErrorMessage */
  77.  
  78. /************************** ReportWinError *****************************/
  79.  
  80. VOID ReportWinError( HAB hab )
  81. {
  82.    PERRINFO    perri;
  83.    PSZ         psz;
  84.    USHORT      offs;
  85.    static CHAR achBuffer[MAXSTRING];
  86.  
  87.    perri = WinGetErrorInfo( hab );
  88.  
  89.    offs  = *((USHORT *)MAKEP(SELECTOROF(perri),perri->offaoffszMsg));
  90.  
  91.    psz = MAKEP(SELECTOROF(perri), 20); // offs);
  92.  
  93.    sprintf( achBuffer, "Error %04lx: %Fs\n", perri->idError, psz );
  94.  
  95.    WinMessageBox( HWND_DESKTOP, hwndFrame, achBuffer, szWindowTitle,
  96.          0, MB_ICONHAND | MB_OK );
  97.  
  98.    WinFreeErrorInfo( perri );
  99.  
  100. }  /* ReportWinError */
  101.  
  102.