home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 8 Other
/
08-Other.zip
/
kwikstik.zip
/
UTILS.C
< prev
next >
Wrap
C/C++ Source or Header
|
1994-03-24
|
3KB
|
102 lines
/*
* utils.c
*
* This file contains a number of helper routines. Among them:
*
* - EnableMenuItem - Enables or disables a menu item
* - CheckMenuItem - Checks or unchecks a menu item
* - ErrorMessage - vararg message box using resource ID as format
* - ReportWinError - present message box w/WinGetErrInfo info
*
* Written 900228 by John W. Cocula
*
*/
#define INCL_DEV
#define INCL_GPILOGCOLORTABLE
#define INCL_WINERRORS
#define INCL_WINFRAMEMGR
#define INCL_WINMENUS
#define INCL_WINMESSAGEMGR
#define INCL_WINSHELLDATA
#define INCL_WINSYS
#include <os2.h>
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include "main.h"
/*************************** EnableMenuItem *****************************/
VOID EnableMenuItem( HWND hwnd, SHORT iMenuItem, BOOL fEnable )
{
HWND hwndParent = WinQueryWindow( hwnd, QW_PARENT, FALSE );
HWND hwndMenu = WinWindowFromID( hwndParent, FID_MENU );
WinSendMsg( hwndMenu, MM_SETITEMATTR, MPFROM2SHORT(iMenuItem, TRUE),
MPFROM2SHORT(MIA_DISABLED, fEnable ? ~MIA_DISABLED : MIA_DISABLED) );
} /* EnableMenuItem */
/*************************** CheckMenuItem ******************************/
VOID CheckMenuItem( HWND hwnd, SHORT iMenuItem, BOOL fEnable )
{
HWND hwndParent = WinQueryWindow( hwnd, QW_PARENT, FALSE );
HWND hwndMenu = WinWindowFromID( hwndParent, FID_MENU );
WinSendMsg( hwndMenu, MM_SETITEMATTR, MPFROM2SHORT(iMenuItem, TRUE),
MPFROM2SHORT(MIA_CHECKED, fEnable ? MIA_CHECKED : 0) );
} /* CheckMenuItem */
/************************** ErrorMessage ********************************/
VOID cdecl ErrorMessage(
USHORT usStringId, /* ID of string in resource file */
... /* variable arguments for vsprintf function */
)
{
static CHAR achBuffer1[MAXSTRING];
static CHAR achBuffer2[MAXSTRING];
va_list arg_ptr;
va_start(arg_ptr, usStringId);
WinLoadString( habMain, NULL, usStringId, MAXSTRING, achBuffer1 );
vsprintf( achBuffer2, achBuffer1, arg_ptr );
WinMessageBox( HWND_DESKTOP, hwndFrame, achBuffer2, szWindowTitle,
usStringId, MB_ICONHAND | MB_OK | MB_HELP );
va_end(arg_ptr);
} /* ErrorMessage */
/************************** ReportWinError *****************************/
VOID ReportWinError( HAB hab )
{
PERRINFO perri;
PSZ psz;
USHORT offs;
static CHAR achBuffer[MAXSTRING];
perri = WinGetErrorInfo( hab );
offs = *((USHORT *)MAKEP(SELECTOROF(perri),perri->offaoffszMsg));
psz = MAKEP(SELECTOROF(perri), 20); // offs);
sprintf( achBuffer, "Error %04lx: %Fs\n", perri->idError, psz );
WinMessageBox( HWND_DESKTOP, hwndFrame, achBuffer, szWindowTitle,
0, MB_ICONHAND | MB_OK );
WinFreeErrorInfo( perri );
} /* ReportWinError */