|
|
Microsoft OS/2 SDK PM 08-08-1988
/****************************** Module Header ******************************\
* Module Name: tempnres.c
*
* Non-resident portion of Presentation Manager Template Application
*
* It illustrates the building of a class record, the registering of
* that class record with Presentattion Manager and the creation of a window
* of that class. See TEMPLATE.DEF for the associated module definition
* file
*
* This is a MIDDLE model application, it has three code segments _RES, _INIT
* and _NRES and one data segment _DATA.
*
* For MIDDLE model, procedures that are accessed from another segment
* must be declared FAR (see template.h).
*
* Code that is NOT part of the template but is merely for demo purposes is
* marked as being for demo purposes and should be replaced/removed when this
* template is converted to a real application.
*
* Created by Microsoft Corp., 1988
*
\***************************************************************************/
#define INCL_GPI
#define INCL_WIN
#include <os2.h>
#include "template.h"
/* min and max macros */
#define max(a,b) (((a) > (b)) ? (a) : (b))
#define min(a,b) (((a) < (b)) ? (a) : (b))
HAB hAB;
HMQ hMsgQ;
HWND hwndTemplate;
HWND hwndTemplateFrame;
/************************************************************************\
* The following following are variables and definitions that are part of
* the template only for demo purposes and will be replaced when the
* template is converted to an application
\************************************************************************/
#define RGBBLACK 0L
#define CCHSTR 15
#define CSTR 7
#define POSMIN 0
#define POSMAX 100
#define LINEINC 5
#define PAGEINC 25
CHAR szContent[31];
CHAR szStr[CCHSTR+1];
CHAR szDefault[CCHSTR+1];
CHAR szAppName[10];
BOOL bCheckBox = TRUE;
BOOL fDoAsync = FALSE;
BOOL fDoFlash = FALSE;
SHORT fDisplay = IDMCOLOR;
SHORT cchContent;
SHORT idRadioButton = IDDRBRIGHT;
SHORT iSel = 2;
SHORT posV = 50;
SHORT posH = 50;
/*********** End of demo purpose variables and definitions ************/
/***********************************************************************\
*
* Procedures in alphabetical order
*
\***********************************************************************/
/******* The code below is for demo purposes only *******/
VOID ShowAsyncMessage(hWnd)
HWND hWnd;
{
CHAR szOkAsync[CCHMAXSTRING];
CHAR szAsync[CCHMAXSTRING];
/* we have an outstanding message for user */
WinStopTimer( hAB, hWnd, IDTASYNC );
WinFlashWindow( hWnd, FALSE );
WinLoadString(hAB, NULL, IDSOKASYNC, CCHMAXSTRING, (PCH)szOkAsync);
WinLoadString(hAB, NULL, IDSASYNC, CCHMAXSTRING, (PCH)szAsync);
WinMessageBox(HWND_DESKTOP, hWnd, (PCH)szOkAsync, (PCH)szAsync, NULL,
MB_OK|MB_ICONEXCLAMATION );
if ( fDoAsync ) /* restart timer to get another message */
WinStartTimer( hAB, hWnd, IDTASYNC, CMSECASYNC );
}
/******* The code above is for demo purposes only *******/
MRESULT EXPENTRY TemplateAboutDlg( hWndDlg, message, mp1, mp2 )
HWND hWndDlg;
USHORT message;
MPARAM mp1;
MPARAM mp2;
{
switch( message )
{
case WM_COMMAND: /* the user has pressed a button */
switch( SHORT1FROMMP( mp1 ) ) /* which button? */
{
case DID_OK:
case DID_CANCEL:
WinDismissDlg( hWndDlg, TRUE );
break;
default:
return( FALSE );
}
break;
default:
return( WinDefDlgProc( hWndDlg, message, mp1, mp2 ) );
}
return( FALSE );
}
VOID TemplateCharInput( hWnd, ch, flags, cRepeat )
HWND hWnd;
SHORT ch;
SHORT flags;
SHORT cRepeat;
{
/* ignore cRepeat if you want to ignore auto-repeated keys */
while (cRepeat-- != 0)
{
}
}
VOID TemplateCommand(hWnd, id, source, mouse)
HWND hWnd;
SHORT id;
SHORT source;
BOOL mouse;
{
/******* The code below is for demo purposes only *******/
RECTL rect;
HPS hPS;
switch( id )
{
case IDMFLASH:
WinQueryWindowRect( hWnd, (PRECTL)&rect );
hPS = WinGetPS(hWnd );
WinInvertRect( hPS, (PRECTL)&rect );
WinInvertRect( hPS, (PRECTL)&rect );
WinReleasePS( hPS );
break;
case IDMABOUT:
WinDlgBox( HWND_DESKTOP, hWnd, (PFNWP)TemplateAboutDlg, NULL,
IDD_ABOUT, NULL );
break;
case IDMCOLOR:
case IDMBLACK:
if ( fDisplay != id )
{
fDisplay = id;
WinSendDlgItemMsg( hwndTemplateFrame, FID_MENU, MM_SETITEMATTR,
MPFROM2SHORT(IDMCOLOR, TRUE),
MPFROM2SHORT(MIA_CHECKED, (id == IDMCOLOR ? MIA_CHECKED : NULL)) );
WinSendDlgItemMsg( hwndTemplateFrame, FID_MENU, MM_SETITEMATTR,
MPFROM2SHORT(IDMBLACK, TRUE),
MPFROM2SHORT(MIA_CHECKED, (id != IDMCOLOR ? MIA_CHECKED : NULL)) );
/* this will cause repaint of entire window */
WinInvalidateRect(hWnd, (PRECTL)NULL, TRUE );
}
break;
case IDMSTART:
/************************************************************\
* start a timer, when it goes off:
* if window has focus then post message box
* else start flashing window/icon and wait until the
* window DOES have the focus before posting the message box,
* i.e, a template for an async message box
\************************************************************/
WinSendDlgItemMsg( hwndTemplateFrame, FID_MENU,
MM_SETITEMATTR, MPFROM2SHORT(IDMSTART, TRUE),
MPFROM2SHORT(MIA_DISABLED, MIA_DISABLED) );
WinSendDlgItemMsg( hwndTemplateFrame, FID_MENU,
MM_SETITEMATTR, MPFROM2SHORT(IDMEND, TRUE),
MPFROM2SHORT(MIA_DISABLED, NULL) );
fDoAsync = TRUE;
WinStartTimer( hAB, hWnd, IDTASYNC, CMSECASYNC );
break;
case IDMEND:
WinStopTimer( hAB, hWnd, IDTASYNC );
fDoAsync = FALSE;
WinSendDlgItemMsg( hwndTemplateFrame, FID_MENU,
MM_SETITEMATTR, MPFROM2SHORT(IDMSTART, TRUE),
MPFROM2SHORT(MIA_DISABLED, NULL) );
WinSendDlgItemMsg( hwndTemplateFrame, FID_MENU,
MM_SETITEMATTR, MPFROM2SHORT(IDMEND, TRUE),
MPFROM2SHORT(MIA_DISABLED, MIA_DISABLED) );
break;
case IDMDIALOG:
WinDlgBox( HWND_DESKTOP, hWnd, (PFNWP)TemplateDlg, NULL,
IDD_TEMPLATE, NULL );
}
/******* The code above is for demo purposes only *******/
}
VOID TemplateCreate(hWnd, lParam)
HWND hWnd;
LONG lParam;
{
char *pch1;
char *pch2;
/******* The code below is for demo purposes only *******/
cchContent = WinLoadString(hAB, NULL, IDSCONTENT, sizeof(szContent),
(PCH)szContent);
WinLoadString(hAB, NULL, IDSDEFAULT, sizeof(szDefault), (PCH)szDefault);
/* copy default string into szStr */
for (pch1 = szStr, pch2 = szDefault; *pch1++ = *pch2++; )
;
/******* The code above is for demo purposes only *******/
}
/******* The code below is for demo purposes only *******/
MRESULT EXPENTRY TemplateDlg( hWndDlg, message, mp1, mp2 )
HWND hWndDlg;
USHORT message;
MPARAM mp1;
MPARAM mp2;
{
CHAR szWaters[12];
SHORT i;
SHORT pos;
switch( message )
{
case WM_INITDLG:
WinSetWindowText( WinWindowFromID( hWndDlg, IDDTEXT ), (PCH)szStr );
WinSendDlgItemMsg( hWndDlg, IDDCHECKBOX, BM_SETCHECK,
MPFROM2SHORT(bCheckBox, 0), 0L );
WinSendDlgItemMsg( hWndDlg, idRadioButton,
BM_SETCHECK, MPFROM2SHORT(TRUE, 0), 0L );
for (i = 0; i < CSTR; i++) {
WinLoadString(hAB, NULL, IDSSTR1+i, 12 , (PCH)szWaters);
WinSendDlgItemMsg( hWndDlg, IDDLISTBOX, LM_INSERTITEM,
(MPARAM)-1L, (MPARAM)(PCH)szWaters );
}
WinSendDlgItemMsg( hWndDlg, IDDLISTBOX, LM_SELECTITEM, (MPARAM)iSel,
(MPARAM)TRUE );
WinSendDlgItemMsg( hWndDlg, IDDSBH, SBM_SETSCROLLBAR,
MPFROM2SHORT(posH, 0), MPFROM2SHORT(POSMIN, POSMAX) );
WinSendDlgItemMsg( hWndDlg, IDDSBV, SBM_SETSCROLLBAR,
MPFROM2SHORT(posV, 0), MPFROM2SHORT(POSMIN, POSMAX) );
return( FALSE );
case WM_COMMAND:
switch( SHORT1FROMMP(mp1) )
{
case IDDDEFAULTS:
WinSetWindowText( WinWindowFromID( hWndDlg, IDDTEXT ),
(PCH)szDefault );
WinSendDlgItemMsg( hWndDlg, IDDCHECKBOX, BM_SETCHECK,
MPFROM2SHORT(TRUE, 0), 0L );
i = IDDRBLEFT + (SHORT)WinSendDlgItemMsg(hWndDlg,
IDDRBLEFT,
BM_QUERYCHECKINDEX,
0L, 0L );
WinSendDlgItemMsg( hWndDlg, i, BM_SETCHECK, MPFROMSHORT(FALSE), 0L);
WinSendDlgItemMsg( hWndDlg, (idRadioButton=IDDRBRIGHT),
BM_SETCHECK, MPFROMSHORT(TRUE), 0L );
WinSendDlgItemMsg( hWndDlg, IDDLISTBOX, LM_SELECTITEM, (MPARAM)2L,
(MPARAM)TRUE);
WinSendDlgItemMsg( hWndDlg, IDDSBH, SBM_SETSCROLLBAR,
MPFROM2SHORT(50, 0), MPFROM2SHORT(POSMIN, POSMAX) );
WinSendDlgItemMsg( hWndDlg, IDDSBV, SBM_SETSCROLLBAR,
MPFROM2SHORT(50, 0), MPFROM2SHORT(POSMIN, POSMAX) );
break;
case DID_OK:
bCheckBox = (SHORT)WinSendDlgItemMsg( hWndDlg, IDDCHECKBOX, BM_QUERYCHECK,
0L, 0L );
idRadioButton = IDDRBLEFT + (SHORT)WinSendDlgItemMsg(hWndDlg,
IDDRBLEFT,
BM_QUERYCHECKINDEX,
0L, 0L );
i = WinQueryWindowText(WinWindowFromID( hWndDlg, IDDTEXT ), CCHSTR,
(PCH)szStr);
iSel = (SHORT)WinSendDlgItemMsg( hWndDlg, IDDLISTBOX, LM_QUERYSELECTION,
0L, 0L);
iSel = max(0, min(CSTR-1, iSel));
posH = (USHORT)WinSendDlgItemMsg( hWndDlg, IDDSBH, SBM_QUERYPOS, 0L, 0L );
posV = (USHORT)WinSendDlgItemMsg( hWndDlg, IDDSBV, SBM_QUERYPOS, 0L, 0L );
WinDismissDlg( hWndDlg, TRUE );
break;
case DID_CANCEL:
WinDismissDlg( hWndDlg, TRUE );
break;
default:
return( FALSE );
}
break;
/* scroll bar controls send messages here as WM_HSCROLL instead of WM_COMMAND */
case WM_HSCROLL:
case WM_VSCROLL:
switch ( SHORT1FROMMP(mp1) )
{
case IDDSBH:
case IDDSBV:
pos = (USHORT)WinSendDlgItemMsg(hWndDlg, SHORT1FROMMP(mp1),
SBM_QUERYPOS, 0L, 0L );
switch ( SHORT2FROMMP(mp2) )
{
case SB_LINEUP: /* and SB_LINELEFT */
pos -= LINEINC;
break;
case SB_LINEDOWN: /* and SB_LINERIGHT */
pos += LINEINC;
break;
case SB_PAGEUP: /* and SB_PAGELEFT */
pos -= PAGEINC;
break;
case SB_PAGEDOWN: /* and SB_PAGERIGHT */
pos += PAGEINC;
break;
case SB_SLIDERPOSITION:
pos = SHORT1FROMMP(mp2);
break;
}
pos = max(POSMIN, min(POSMAX, pos));
WinSendDlgItemMsg(hWndDlg, SHORT1FROMMP(mp1),
SBM_SETPOS, MPFROM2SHORT(pos, 0), 0L );
break;
default:
return( FALSE );
}
default:
return( WinDefDlgProc( hWndDlg, message, mp1, mp2 ) );
}
return( FALSE );
}
/******* The code above is for demo purposes only *******/
VOID TemplateSetFocus( hWnd )
HWND hWnd;
{
if ( fDoFlash )
{
fDoFlash = FALSE;
ShowAsyncMessage(hWnd);
}
}
VOID TemplateHorzScroll( hWnd, code, posNew )
HWND hWnd;
SHORT code;
SHORT posNew;
{
switch( code )
{
case SB_LINEUP: /* line left */
break;
case SB_LINEDOWN: /* line right */
break;
case SB_PAGEUP: /* page left */
break;
case SB_PAGEDOWN: /* page right */
break;
case SB_SLIDERPOSITION: /* position to posNew */
break;
case SB_SLIDERTRACK:
break;
}
}
VOID TemplatePaint( hWnd, hPS )
HWND hWnd;
HPS hPS;
{
/* Here the application paints its window. */
/******* The code below is for demo purposes only *******/
long cx;
long cy;
RECTL rect;
POINTL pt;
CHARBUNDLE cb;
WinQueryWindowRect( hWnd, (PRECTL)&rect );
cx = (SHORT)(rect.xRight - rect.xLeft) >> 2;
cy = (SHORT)(rect.yTop - rect.yBottom) >> 2;
pt.x = 0L;
pt.y = rect.yTop - 12L;
cb.lColor = CLR_BLACK;
GpiSetAttrs(hPS, PRIM_CHAR, CBB_COLOR, 0L, (PBUNDLE)&cb);
GpiCharStringAt( hPS, (PPOINTL)&pt, (long)cchContent, (PCH)szContent );
/***********************************************************\
* The vertical and horizontal lines on this rectangle are
* "one" pixel wide and on displays that do NOT have a 1:1
* aspect ratio, the lines will NOT be the same thickness
\***********************************************************/
pt.x = rect.xLeft + cx;
pt.y = rect.yTop - cy;
GpiSetCurrentPosition( hPS, (PPOINTL)&pt );
pt.x = rect.xRight - cx;
pt.y = rect.yBottom + cy;
GpiBox( hPS, 2L, (PPOINTL)&pt, 0L, 0L);
/***********************************************************\
* Now we drawn a "rectangle" with uniformly thick lines
\***********************************************************/
cx = cx >> 1;
cy = cy >> 1;
GpiSetLineWidthGeom( hPS, 2L );
pt.x = rect.xLeft + cx;
pt.y = rect.yTop - cy;
GpiSetCurrentPosition( hPS, (PPOINTL)&pt );
pt.x = rect.xRight - cx;
GpiLine( hPS, (PPOINTL)&pt );
pt.y = rect.yBottom + cy;
GpiLine( hPS, (PPOINTL)&pt );
pt.x = rect.xLeft + cx;
GpiLine( hPS, (PPOINTL)&pt );
pt.y = rect.yTop - cy;
GpiLine( hPS, (PPOINTL)&pt );
/******* The code above is for demo purposes only *******/
}
/******* The code below is for demo purposes only *******/
VOID TemplateQueryQuit( hWnd )
HWND hWnd;
{
CHAR szOkClose[CCHMAXSTRING];
CHAR szClose[CCHMAXSTRING];
WinLoadString(hAB, NULL, IDSOKCLOSE, CCHMAXSTRING , (PCH)szOkClose);
WinLoadString(hAB, NULL, IDSCLOSE, CCHMAXSTRING , (PCH)szClose );
WinAlarm( HWND_DESKTOP, WA_WARNING );
if ( WinMessageBox(HWND_DESKTOP, hWnd, (PCH)szOkClose, (PCH)szClose,
NULL, MB_OKCANCEL|MB_ICONQUESTION ) == DID_OK )
WinPostMsg( hWnd, WM_QUIT, 0L, 0L );
}
/******* The code above is for demo purposes only *******/
/******* The code below is for demo purposes only *******/
VOID TemplateTimer( hWnd, id )
HWND hWnd;
USHORT id;
{
WinStopTimer( hAB, hWnd, IDTASYNC );
if ( WinQueryFocus(HWND_DESKTOP, FALSE ) == hWnd )
ShowAsyncMessage( hWnd );
else
{
fDoFlash = TRUE;
WinFlashWindow( hWnd, TRUE );
}
}
/******* The code above is for demo purposes only *******/
VOID TemplateVertScroll( hWnd, code, posNew )
HWND hWnd;
SHORT code;
USHORT posNew;
{
switch( code )
{
case SB_LINEUP:
break;
case SB_LINEDOWN:
break;
case SB_PAGEUP:
break;
case SB_PAGEDOWN:
break;
case SB_SLIDERPOSITION:
break;
case SB_SLIDERTRACK:
break;
}
}
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.