home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
pres.zip
/
PRESPRMS.C
Wrap
Text File
|
1993-09-23
|
22KB
|
458 lines
// PresPrms.c
//
// John Clark 09/93
//
//
// procedures to handle presentation parameters
//
// include: INCL_WINSYS
//
// definitions:
//
// presentation parameters:
//
// #define PP_FOREGROUNDCOLOR 0x00000001L
// #define PP_FOREGROUNDCOLORINDEX 0x00000002L
// #define PP_BACKGROUNDCOLOR 0x00000003L
// #define PP_BACKGROUNDCOLORINDEX 0x00000004L
// #define PP_HILITEFOREGROUNDCOLOR 0x00000005L
// #define PP_HILITEFOREGROUNDCOLORINDEX 0x00000006L
// #define PP_HILITEBACKGROUNDCOLOR 0x00000007L
// #define PP_HILITEBACKGROUNDCOLORINDEX 0x00000008L
// #define PP_DISABLEDFOREGROUNDCOLOR 0x00000009L
// #define PP_DISABLEDFOREGROUNDCOLORINDEX 0x0000000aL
// #define PP_DISABLEDBACKGROUNDCOLOR 0x0000000bL
// #define PP_DISABLEDBACKGROUNDCOLORINDEX 0x0000000cL
// #define PP_BORDERCOLOR 0x0000000dL
// #define PP_BORDERCOLORINDEX 0x0000000eL
// #define PP_FONTNAMESIZE 0x0000000fL
// #define PP_FONTHANDLE 0x00000010L
// #define PP_RESERVED 0x00000011L
// #define PP_ACTIVECOLOR 0x00000012L
// #define PP_ACTIVECOLORINDEX 0x00000013L
// #define PP_INACTIVECOLOR 0x00000014L
// #define PP_INACTIVECOLORINDEX 0x00000015L
// #define PP_ACTIVETEXTFGNDCOLOR 0x00000016L
// #define PP_ACTIVETEXTFGNDCOLORINDEX 0x00000017L
// #define PP_ACTIVETEXTBGNDCOLOR 0x00000018L
// #define PP_ACTIVETEXTBGNDCOLORINDEX 0x00000019L
// #define PP_INACTIVETEXTFGNDCOLOR 0x0000001aL
// #define PP_INACTIVETEXTFGNDCOLORINDEX 0x0000001bL
// #define PP_INACTIVETEXTBGNDCOLOR 0x0000001cL
// #define PP_INACTIVETEXTBGNDCOLORINDEX 0x0000001dL
// #define PP_SHADOW 0x0000001eL
// #define PP_MENUFOREGROUNDCOLOR 0x0000001fL
// #define PP_MENUFOREGROUNDCOLORINDEX 0x00000020L
// #define PP_MENUBACKGROUNDCOLOR 0x00000021L
// #define PP_MENUBACKGROUNDCOLORINDEX 0x00000022L
// #define PP_MENUHILITEFGNDCOLOR 0x00000023L
// #define PP_MENUHILITEFGNDCOLORINDEX 0x00000024L
// #define PP_MENUHILITEBGNDCOLOR 0x00000025L
// #define PP_MENUHILITEBGNDCOLORINDEX 0x00000026L
// #define PP_MENUDISABLEDFGNDCOLOR 0x00000027L
// #define PP_MENUDISABLEDFGNDCOLORINDEX 0x00000028L
// #define PP_MENUDISABLEDBGNDCOLOR 0x00000029L
// #define PP_MENUDISABLEDBGNDCOLORINDEX 0x0000002aL
//
// #define PP_USER 0x00008000L
//
//
// WinQueryPresParam option flags:
//
// #define QPF_NOINHERIT 0x0001 // Don't inherit
// #define QPF_ID1COLORINDEX 0x0002 // Convert id1 color index into RGB
// #define QPF_ID2COLORINDEX 0x0004 // Convert id2 color index into RGB
// #define QPF_PURERGBCOLOR 0x0008 // Return pure RGB colors
// #define QPF_VALIDFLAGS 0x000F // Valid WinQueryPresParams() flags.
//
//
//
// structures:
//
// typedef struct _PARAM // param
// {
// ULONG id; // 4 bytes
// ULONG cb; // 4 bytes
// BYTE ab[1]; // 4 bytes
// } PARAM;
// typedef PARAM *NPPARAM;
// typedef PARAM *PPARAM;
//
//
// typedef struct _PRESPARAMS // pres
// {
// ULONG cb; // 4 bytes
// PARAM aparam[1]; // 4 bytes
// } PRESPARAMS;
// typedef PRESPARAMS *NPPRESPARAMS;
// typedef PRESPARAMS *PPRESPARAMS;
//
//
#define INCL_WINSYS
#include <os2.h>
// internal constants
#define DEF_FGCOLOR 0x00000000L // black
#define DEF_BKCOLOR 0x00ccccccL // grey
#define WM_USER_GETWNDPARAMS 0x00001000L // WM_USER
// internal prototypes
MRESULT EXPENTRY YourWndProc(HWND hwnd, ULONG ulMsg, MPARAM mp1, MPARAM mp2);
LONG lStoreWndPresParams(HWND hwnd, ULONG ulBufLen, PVOID pvBuf);
// window proc handler, splice in the WM_PRESPARAMCHANGED case
// define any PP_ value you choose to keep track of
MRESULT EXPENTRY YourWndProc(HWND hwnd, ULONG ulMsg, MPARAM mp1, MPARAM mp2)
{
ULONG ulPPFound;
static LONG lFgColor = DEF_FGCOLOR;
static LONG lBkColor = DEF_BKCOLOR;
switch(ulMsg)
{
case WM_PRESPARAMCHANGED: // a presentation parameter has changed
switch(LONGFROMMP(mp1))
{
case PP_FOREGROUNDCOLOR:
case PP_FOREGROUNDCOLORINDEX:
if(WinQueryPresParam(hwnd, PP_FOREGROUNDCOLOR, PP_FOREGROUNDCOLORINDEX, &ulPPFound, sizeof(LONG), (PVOID)&lFgColor, QPF_NOINHERIT | QPF_ID2COLORINDEX))
{
if(lFgColor == DEF_FGCOLOR)
WinRemovePresParam(hwnd, ulPPFound); // remove if default
WinInvalidateRect(hwnd, (PRECTL)NULL, FALSE); // redraw window
}
break;
case PP_BACKGROUNDCOLOR:
case PP_BACKGROUNDCOLORINDEX:
if(WinQueryPresParam(hwnd, PP_BACKGROUNDCOLOR, PP_BACKGROUNDCOLORINDEX, &ulPPFound, sizeof(LONG), (PVOID)&lBkColor, QPF_NOINHERIT | QPF_ID2COLORINDEX))
{
if(lBkColor == DEF_BKCOLOR)
WinRemovePresParam(hwnd, ulPPFound); // remove if default
WinInvalidateRect(hwnd, (PRECTL)NULL, FALSE); // redraw window
}
break;
default: // non applicable parameter
break;
}
break;
case WM_USER_GETWNDPARAMS: // mp1 = buffer length, mp2 = buffer address
return MRFROMLONG(lStoreWndPresParams(hwnd, (ULONG)LONGFROMMP(mp1), PVOIDFROMMP(mp2)));
break;
default:
return(WinDefWindowProc(hwnd, ulMsg, mp1, mp2));
break;
}
return (MRESULT)NULL; // all window procedures return 0 as a default
}
//
// max ulBufLen = 288L (for all possible params)
// this routine will fill pvBuf with all defined window pres params
// the array returned is suitable to be passed as pPresParams
// ie. WinCreateWindow(,,,,,,,,,,,, PVOID pPresParams)
//
LONG lStoreWndPresParams(HWND hwnd, ULONG ulBufLen, PVOID pvBuf)
{
LONG lTmp;
PPARAM pparam;
PPRESPARAMS ppresparams;
// the least possible query is 16 bytes
if(ulBufLen < 16L || pvBuf == (PVOID)NULL)
return -1L; // error, not enough memory
// test window validity
if(!WinIsWindow(hab, hwnd))
return -1L; // error, invalid window handle
// setup memory access
ppresparams = (PPRESPARAMS)pvBuf; // cast structure onto memory
ppresparams->cb = 0L; // no entries yet
pparam = ppresparams->aparam; // cast structure onto memory
ulBufLen -= 4L; // used 4 bytes in PRESPARAMS struct
/////////////////////////////////////////////////////
//
// query every possible presentation parameter...
//
/////////////////////////////////////////////////////
// ────────────────────────────────────────────────────────────────────────────────────────────────
// foreground color -- takes 12 bytes
if((ulBufLen - ppresparams->cb) < 12L)
return -1L; // error, not enough memory
pparam->cb = WinQueryPresParam(hwnd, PP_FOREGROUNDCOLOR, PP_FOREGROUNDCOLORINDEX,
&pparam->id, sizeof(LONG), (PVOID)pparam->ab, QPF_NOINHERIT);
if(pparam->cb) // was the param found?
{
ppresparams->cb += 12L; // used 12 bytes
pparam = (PPARAM)(((ULONG)pparam) + 12L); // advance 12 bytes to next memory location
}
// ────────────────────────────────────────────────────────────────────────────────────────────────
// background color -- takes 12 bytes
if((ulBufLen - ppresparams->cb) < 12L)
return -1L; // error, not enough memory
pparam->cb = WinQueryPresParam(hwnd, PP_BACKGROUNDCOLOR, PP_BACKGROUNDCOLORINDEX,
&pparam->id, sizeof(LONG), (PVOID)pparam->ab, QPF_NOINHERIT);
if(pparam->cb) // was the param found?
{
ppresparams->cb += 12L; // used 12 bytes
pparam = (PPARAM)(((ULONG)pparam) + 12L); // advance 12 bytes to next memory location
}
// ────────────────────────────────────────────────────────────────────────────────────────────────
// hilited foreground color -- takes 12 bytes
if((ulBufLen - ppresparams->cb) < 12L)
return -1L; // error, not enough memory
pparam->cb = WinQueryPresParam(hwnd, PP_HILITEFOREGROUNDCOLOR, PP_HILITEFOREGROUNDCOLORINDEX,
&pparam->id, sizeof(LONG), (PVOID)pparam->ab, QPF_NOINHERIT);
if(pparam->cb) // was the param found?
{
ppresparams->cb += 12L; // used 12 bytes
pparam = (PPARAM)(((ULONG)pparam) + 12L); // advance 12 bytes to next memory location
}
// ────────────────────────────────────────────────────────────────────────────────────────────────
// hilited background color -- takes 12 bytes
if((ulBufLen - ppresparams->cb) < 12L)
return -1L; // error, not enough memory
pparam->cb = WinQueryPresParam(hwnd, PP_HILITEBACKGROUNDCOLOR, PP_HILITEBACKGROUNDCOLORINDEX,
&pparam->id, sizeof(LONG), (PVOID)pparam->ab, QPF_NOINHERIT);
if(pparam->cb) // was the param found?
{
ppresparams->cb += 12L; // used 12 bytes
pparam = (PPARAM)(((ULONG)pparam) + 12L); // advance 12 bytes to next memory location
}
// ────────────────────────────────────────────────────────────────────────────────────────────────
// disabled foreground color -- takes 12 bytes
if((ulBufLen - ppresparams->cb) < 12L)
return -1L; // error, not enough memory
pparam->cb = WinQueryPresParam(hwnd, PP_DISABLEDFOREGROUNDCOLOR, PP_DISABLEDFOREGROUNDCOLORINDEX,
&pparam->id, sizeof(LONG), (PVOID)pparam->ab, QPF_NOINHERIT);
if(pparam->cb) // was the param found?
{
ppresparams->cb += 12L; // used 12 bytes
pparam = (PPARAM)(((ULONG)pparam) + 12L); // advance 12 bytes to next memory location
}
// ────────────────────────────────────────────────────────────────────────────────────────────────
// disabled background color -- takes 12 bytes
if((ulBufLen - ppresparams->cb) < 12L)
return -1L; // error, not enough memory
pparam->cb = WinQueryPresParam(hwnd, PP_DISABLEDBACKGROUNDCOLOR, PP_DISABLEDBACKGROUNDCOLORINDEX,
&pparam->id, sizeof(LONG), (PVOID)pparam->ab, QPF_NOINHERIT);
if(pparam->cb) // was the param found?
{
ppresparams->cb += 12L; // used 12 bytes
pparam = (PPARAM)(((ULONG)pparam) + 12L); // advance 12 bytes to next memory location
}
// ────────────────────────────────────────────────────────────────────────────────────────────────
// border color -- takes 12 bytes
if((ulBufLen - ppresparams->cb) < 12L)
return -1L; // error, not enough memory
pparam->cb = WinQueryPresParam(hwnd, PP_BORDERCOLOR, PP_BORDERCOLORINDEX,
&pparam->id, sizeof(LONG), (PVOID)pparam->ab, QPF_NOINHERIT);
if(pparam->cb) // was the param found?
{
ppresparams->cb += 12L; // used 12 bytes
pparam = (PPARAM)(((ULONG)pparam) + 12L); // advance 12 bytes to next memory location
}
// ────────────────────────────────────────────────────────────────────────────────────────────────
// font name & size -- maximum 44 bytes (32 for face name, 4 for point size) + 8 for data
if((ulBufLen - ppresparams->cb) < 44L)
return -1L; // error, not enough memory
pparam->cb = WinQueryPresParam(hwnd, PP_FONTNAMESIZE, 0L,
&pparam->id, 36L, (PVOID)pparam->ab, QPF_NOINHERIT);
if(pparam->cb) // was the param found?
{
ppresparams->cb += (pparam->cb + 8L); // used cb + 8 bytes
pparam = (PPARAM)(((ULONG)pparam) + pparam->cb + 8L); // advance to next memory location
}
// ────────────────────────────────────────────────────────────────────────────────────────────────
// active color -- takes 12 bytes
if((ulBufLen - ppresparams->cb) < 12L)
return -1L; // error, not enough memory
pparam->cb = WinQueryPresParam(hwnd, PP_ACTIVECOLOR, PP_ACTIVECOLORINDEX,
&pparam->id, sizeof(LONG), (PVOID)pparam->ab, QPF_NOINHERIT);
if(pparam->cb) // was the param found?
{
ppresparams->cb += 12L; // used 12 bytes
pparam = (PPARAM)(((ULONG)pparam) + 12L); // advance 12 bytes to next memory location
}
// ────────────────────────────────────────────────────────────────────────────────────────────────
// inactive color -- takes 12 bytes
if((ulBufLen - ppresparams->cb) < 12L)
return -1L; // error, not enough memory
pparam->cb = WinQueryPresParam(hwnd, PP_INACTIVECOLOR, PP_INACTIVECOLORINDEX,
&pparam->id, sizeof(LONG), (PVOID)pparam->ab, QPF_NOINHERIT);
if(pparam->cb) // was the param found?
{
ppresparams->cb += 12L; // used 12 bytes
pparam = (PPARAM)(((ULONG)pparam) + 12L); // advance 12 bytes to next memory location
}
// ────────────────────────────────────────────────────────────────────────────────────────────────
// active text foreground color -- takes 12 bytes
if((ulBufLen - ppresparams->cb) < 12L)
return -1L; // error, not enough memory
pparam->cb = WinQueryPresParam(hwnd, PP_ACTIVETEXTFGNDCOLOR, PP_ACTIVETEXTFGNDCOLORINDEX,
&pparam->id, sizeof(LONG), (PVOID)pparam->ab, QPF_NOINHERIT | QPF_PURERGBCOLOR);
if(pparam->cb) // was the param found?
{
ppresparams->cb += 12L; // used 12 bytes
pparam = (PPARAM)(((ULONG)pparam) + 12L); // advance 12 bytes to next memory location
}
// ────────────────────────────────────────────────────────────────────────────────────────────────
// active text background color -- takes 12 bytes
if((ulBufLen - ppresparams->cb) < 12L)
return -1L; // error, not enough memory
pparam->cb = WinQueryPresParam(hwnd, PP_ACTIVETEXTBGNDCOLOR, PP_ACTIVETEXTBGNDCOLORINDEX,
&pparam->id, sizeof(LONG), (PVOID)pparam->ab, QPF_NOINHERIT | QPF_PURERGBCOLOR);
if(pparam->cb) // was the param found?
{
ppresparams->cb += 12L; // used 12 bytes
pparam = (PPARAM)(((ULONG)pparam) + 12L); // advance 12 bytes to next memory location
}
// ────────────────────────────────────────────────────────────────────────────────────────────────
// inactive text foreground color -- takes 12 bytes
if((ulBufLen - ppresparams->cb) < 12L)
return -1L; // error, not enough memory
pparam->cb = WinQueryPresParam(hwnd, PP_INACTIVETEXTFGNDCOLOR, PP_INACTIVETEXTFGNDCOLORINDEX,
&pparam->id, sizeof(LONG), (PVOID)pparam->ab, QPF_NOINHERIT | QPF_PURERGBCOLOR);
if(pparam->cb) // was the param found?
{
ppresparams->cb += 12L; // used 12 bytes
pparam = (PPARAM)(((ULONG)pparam) + 12L); // advance 12 bytes to next memory location
}
// ────────────────────────────────────────────────────────────────────────────────────────────────
// inactive text background color -- takes 12 bytes
if((ulBufLen - ppresparams->cb) < 12L)
return -1L; // error, not enough memory
pparam->cb = WinQueryPresParam(hwnd, PP_INACTIVETEXTBGNDCOLOR, PP_INACTIVETEXTBGNDCOLORINDEX,
&pparam->id, sizeof(LONG), (PVOID)pparam->ab, QPF_NOINHERIT | QPF_PURERGBCOLOR);
if(pparam->cb) // was the param found?
{
ppresparams->cb += 12L; // used 12 bytes
pparam = (PPARAM)(((ULONG)pparam) + 12L); // advance 12 bytes to next memory location
}
// ────────────────────────────────────────────────────────────────────────────────────────────────
// shadow color -- takes 12 bytes
if((ulBufLen - ppresparams->cb) < 12L)
return -1L; // error, not enough memory
pparam->cb = WinQueryPresParam(hwnd, PP_SHADOW, 0L,
&pparam->id, sizeof(LONG), (PVOID)pparam->ab, QPF_NOINHERIT);
if(pparam->cb) // was the param found?
{
ppresparams->cb += 12L; // used 12 bytes
pparam = (PPARAM)(((ULONG)pparam) + 12L); // advance 12 bytes to next memory location
}
// ────────────────────────────────────────────────────────────────────────────────────────────────
// menu foreground color -- takes 12 bytes
if((ulBufLen - ppresparams->cb) < 12L)
return -1L; // error, not enough memory
pparam->cb = WinQueryPresParam(hwnd, PP_MENUFOREGROUNDCOLOR, PP_MENUFOREGROUNDCOLORINDEX,
&pparam->id, sizeof(LONG), (PVOID)pparam->ab, QPF_NOINHERIT);
if(pparam->cb) // was the param found?
{
ppresparams->cb += 12L; // used 12 bytes
pparam = (PPARAM)(((ULONG)pparam) + 12L); // advance 12 bytes to next memory location
}
// ────────────────────────────────────────────────────────────────────────────────────────────────
// menu background color -- takes 12 bytes
if((ulBufLen - ppresparams->cb) < 12L)
return -1L; // error, not enough memory
pparam->cb = WinQueryPresParam(hwnd, PP_MENUBACKGROUNDCOLOR, PP_MENUBACKGROUNDCOLORINDEX,
&pparam->id, sizeof(LONG), (PVOID)pparam->ab, QPF_NOINHERIT);
if(pparam->cb) // was the param found?
{
ppresparams->cb += 12L; // used 12 bytes
pparam = (PPARAM)(((ULONG)pparam) + 12L); // advance 12 bytes to next memory location
}
// ────────────────────────────────────────────────────────────────────────────────────────────────
// menu hilite foreground color -- takes 12 bytes
if((ulBufLen - ppresparams->cb) < 12L)
return -1L; // error, not enough memory
pparam->cb = WinQueryPresParam(hwnd, PP_MENUHILITEFGNDCOLOR, PP_MENUHILITEFGNDCOLORINDEX,
&pparam->id, sizeof(LONG), (PVOID)pparam->ab, QPF_NOINHERIT);
if(pparam->cb) // was the param found?
{
ppresparams->cb += 12L; // used 12 bytes
pparam = (PPARAM)(((ULONG)pparam) + 12L); // advance 12 bytes to next memory location
}
// ────────────────────────────────────────────────────────────────────────────────────────────────
// menu hilite background color -- takes 12 bytes
if((ulBufLen - ppresparams->cb) < 12L)
return -1L; // error, not enough memory
pparam->cb = WinQueryPresParam(hwnd, PP_MENUHILITEBGNDCOLOR, PP_MENUHILITEBGNDCOLORINDEX,
&pparam->id, sizeof(LONG), (PVOID)pparam->ab, QPF_NOINHERIT);
if(pparam->cb) // was the param found?
{
ppresparams->cb += 12L; // used 12 bytes
pparam = (PPARAM)(((ULONG)pparam) + 12L); // advance 12 bytes to next memory location
}
// ────────────────────────────────────────────────────────────────────────────────────────────────
// menu disabled foreground color -- takes 12 bytes
if((ulBufLen - ppresparams->cb) < 12L)
return -1L; // error, not enough memory
pparam->cb = WinQueryPresParam(hwnd, PP_MENUDISABLEDFGNDCOLOR, PP_MENUDISABLEDFGNDCOLORINDEX,
&pparam->id, sizeof(LONG), (PVOID)pparam->ab, QPF_NOINHERIT);
if(pparam->cb) // was the param found?
{
ppresparams->cb += 12L; // used 12 bytes
pparam = (PPARAM)(((ULONG)pparam) + 12L); // advance 12 bytes to next memory location
}
// ────────────────────────────────────────────────────────────────────────────────────────────────
// menu disabled background color -- takes 12 bytes
if((ulBufLen - ppresparams->cb) < 12L)
return -1L; // error, not enough memory
pparam->cb = WinQueryPresParam(hwnd, PP_MENUDISABLEDBGNDCOLOR, PP_MENUDISABLEDBGNDCOLORINDEX,
&pparam->id, sizeof(LONG), (PVOID)pparam->ab, QPF_NOINHERIT);
if(pparam->cb) // was the param found?
{
ppresparams->cb += 12L; // used 12 bytes
pparam = (PPARAM)(((ULONG)pparam) + 12L); // advance 12 bytes to next memory location
}
return 0L; // success, no message to return
}