|
|
Microsoft OS/2 SDK PM 08-08-1988
/*----------------------------------------
BUTTONS.C -- Push Button Demonstration
----------------------------------------*/
#define INCL_WIN
#define INCL_GPI
#include <os2.h>
#include <stddef.h>
MRESULT EXPENTRY ClientWndProc (HWND, USHORT, MPARAM, MPARAM) ;
int main (void)
{
static CHAR szClientClass[] = "Buttons" ;
HAB hab ;
HMQ hmq ;
HWND hwndFrame, hwndClient ;
QMSG qmsg ;
ULONG flFrameFlags = FCF_STANDARD & ~FCF_MENU ;
ULONG flFrameStyle = WS_VISIBLE ;
hab = WinInitialize (0) ;
hmq = WinCreateMsgQueue (hab, 0) ;
WinRegisterClass (hab, szClientClass, ClientWndProc, CS_SIZEREDRAW, 0) ;
hwndFrame = WinCreateStdWindow (HWND_DESKTOP, flFrameStyle,
&flFrameFlags, szClientClass,
"Push Button Demo",
0L, NULL, 0, &hwndClient) ;
while (WinGetMsg (hab, &qmsg, NULL, 0, 0))
WinDispatchMsg (hab, &qmsg) ;
WinDestroyWindow (hwndFrame) ;
WinDestroyMsgQueue (hmq) ;
WinTerminate (hab) ;
return 0 ;
}
MRESULT EXPENTRY ClientWndProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
{
static CHAR *szButtonLabel [] = { "Smaller", "Larger" } ;
static HWND hwndFrame, hwndButton [2] ;
static SHORT cxClient, cyClient, cxChar, cyChar ;
FONTMETRICS fm ;
HPS hps ;
SHORT s ;
RECTL rcl ;
switch (msg)
{
case WM_CREATE :
hwndFrame = WinQueryWindow (hwnd, QW_PARENT, FALSE) ;
hps = WinGetPS (hwnd) ;
GpiQueryFontMetrics (hps, (LONG) sizeof fm, &fm) ;
cxChar = (SHORT) fm.lAveCharWidth ;
cyChar = (SHORT) fm.lMaxBaselineExt ;
WinReleasePS (hps) ;
for (s = 0 ; s < 2 ; s++)
hwndButton [s] = WinCreateWindow (
hwnd, /* Parent */
WC_BUTTON, /* Class */
szButtonLabel [s], /* Text */
WS_VISIBLE | /* Style */
BS_PUSHBUTTON,
0, 0, /* Position */
10 * cxChar, /* Width */
7 * cyChar / 4, /* Height */
hwnd, /* Owner */
HWND_BOTTOM, /* Placement */
s, /* ID */
NULL, /* Ctrl Data */
NULL) ; /* Pres Params */
return 0 ;
case WM_SIZE :
cxClient = SHORT1FROMMP (mp2) ;
cyClient = SHORT2FROMMP (mp2) ;
for (s = 0 ; s < 2 ; s++)
WinSetWindowPos (hwndButton [s], NULL,
cxClient / 2 + (12 * s - 11) * cxChar,
cyClient / 2 - 7 * cyChar / 8,
0, 0, SWP_MOVE) ;
return 0 ;
case WM_COMMAND:
WinQueryWindowRect (hwnd, &rcl) ;
WinMapWindowPoints (hwnd, HWND_DESKTOP, (PPOINTL) &rcl, 2) ;
switch (COMMANDMSG(&msg)->cmd)
{
case 0:
rcl.xLeft += cxClient / 20 ;
rcl.xRight -= cxClient / 20 ;
rcl.yBottom += cyClient / 20 ;
rcl.yTop -= cyClient / 20 ;
break ;
case 1:
rcl.xLeft -= cxClient / 20 ;
rcl.xRight += cxClient / 20 ;
rcl.yBottom -= cyClient / 20 ;
rcl.yTop += cyClient / 20 ;
break ;
}
WinCalcFrameRect (hwndFrame, &rcl, FALSE) ;
WinSetWindowPos (hwndFrame, NULL,
(SHORT) rcl.xLeft, (SHORT) rcl.yBottom,
(SHORT) rcl.xRight - (SHORT) rcl.xLeft,
(SHORT) rcl.yTop - (SHORT) rcl.yBottom,
SWP_MOVE | SWP_SIZE) ;
return 0 ;
case WM_ERASEBACKGROUND:
return 1 ;
}
return WinDefWindowProc (hwnd, msg, mp1, mp2) ;
}
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.