home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 32 Periodic
/
32-Periodic.zip
/
rvue1b.zip
/
EXEMPLE1.ZIP
/
EXEMPLE1.CPP
< prev
next >
Wrap
Text File
|
1993-11-28
|
6KB
|
251 lines
#define INCL_PM
#define INCL_DOS)
#define INCL_WINDIALOGS
#define INCL_GPI
#define INCL_GPIPRIMITIVES
/*********************************
changer le répertoire suivant
change the next directory
*********************************/
#include "c:\data\programme\exemple1\exemple1.h"
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <mem.h>
#include <os2.h>
HWND hwndTrace;
int hypote=0;
PFNWP GenericDlgProc;
double x = 0;
double y = 0;
double resultat = 0;
MRESULT EXPENTRY WinPrincipal( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 );
MRESULT EXPENTRY WinTrace( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 );
MRESULT EXPENTRY WinCalcul ( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 );
hypotenuse(HWND hwnd, int hypote);
hypotenuse(HWND hwnd, int hypote)
{
HWND hEntree;
char Buffer[50];
memset(Buffer, 0, sizeof(Buffer));
hEntree = WinWindowFromID(hwnd, ID_CALCUL_Xin);
WinQueryWindowText(hEntree, sizeof(Buffer), Buffer);
x = atof(Buffer);
memset(Buffer, 0, sizeof(Buffer));
hEntree = WinWindowFromID(hwnd, ID_CALCUL_Yin);
WinQueryWindowText(hEntree, sizeof(Buffer), Buffer);
y = atof(Buffer);
switch (hypote)
{
case 0:
resultat = hypot(x, y);
break;
case 1:
resultat = pow(x, y);
break;
default:
break;
}
sprintf(Buffer,"%f", resultat);
hEntree = WinWindowFromID(hwnd, ID_CALCUL_OUT);
WinSetWindowText(hEntree, Buffer);
return (0);
}
MRESULT EXPENTRY WinPrincipal( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 )
{
switch( msg )
{
case WM_CREATE: /* crée la fenêtre */
break;
case WM_COMMAND:
switch (SHORT1FROMMP(mp1))
{
case ID_MENU_HYP:
x = 0; y = 0;
WinSetWindowPos(hwndTrace,
0, 328,8, 160,208,
SWP_SIZE | SWP_MOVE | SWP_SHOW);
hypote=0;
WinDlgBox(HWND_DESKTOP, hwnd, WinCalcul,
NULLHANDLE, ID_HYPOTE, NULL);
return (MRESULT) TRUE;
case ID_MENU_EXP:
WinSetWindowPos(hwndTrace,
0, 0,0, 160,208, SWP_HIDE);
hypote=1;
WinDlgBox(HWND_DESKTOP, hwnd, WinCalcul,
NULLHANDLE, ID_HYPOTE, NULL);
return (MRESULT) TRUE;
case ID_TERMINE:
if(WinMessageBox(HWND_DESKTOP, hwnd,
"Voulez-vous vraiment quitter cette application?",
"Juste pour être certain...", 0,
MB_YESNO | MB_QUERY)
== MBID_YES) WinPostMsg(hwnd,WM_CLOSE,MPVOID,MPVOID);
break;
case ID_ABOUT:
WinDlgBox(HWND_DESKTOP, hwnd, GenericDlgProc,
0L, IDD_ABOUT, NULL);
return (MRESULT) TRUE;
default:
return WinDefWindowProc( hwnd, msg, mp1, mp2 );
}
case WM_ERASEBACKGROUND:
return(MRESULT)(TRUE);
default:
return WinDefWindowProc( hwnd, msg, mp1, mp2 );
}
return (0);
}
MRESULT EXPENTRY WinTrace( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 )
{
POINTL aptl[4];
RECTL rcl;
HPS hps;
WinInvalidateRegion( hwnd, (HRGN)NULL, FALSE);
switch( msg )
{
case WM_CREATE: /* crée la fenêtre */
break;
case WM_ERASEBACKGROUND:
return(MRESULT)(TRUE);
case WM_PAINT:
if (hypote == 0)
{
if ((fabs(y) >= fabs(x)) && (y != 0))
{
x = fabs(130 * (x / y));
y = 130;
}
else
if ((fabs(x) > fabs(y)) && (x != 0))
{
y = fabs(130 * (y / x));
x = 130;
}
hps=WinBeginPaint(hwnd, (HPS)NULL, &rcl);
aptl[0].x=10; aptl[0].y=12;
aptl[1].x=(x+10); aptl[1].y=12;
aptl[2].x=(x+10); aptl[2].y=(y+10);
aptl[3].x=10; aptl[3].y=12;
GpiMove(hps, aptl);
GpiPolyLine(hps,sizeof(aptl) / sizeof(POINTL),aptl);
WinEndPaint(hps);
}
break;
default : return WinDefWindowProc( hwnd, msg, mp1, mp2);
}
return(0);
}
MRESULT EXPENTRY WinCalcul ( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 )
{
HWND hEntree;
double x, y, resultat;
char Buffer[50];
switch( msg )
{
case WM_INITDLG:
hEntree = WinWindowFromID(hwnd, ID_CALCUL_STITRE);
if (hypote == 0)
WinSetWindowText(hEntree, "hypoténuse");
else
WinSetWindowText(hEntree, "Exposant");
return (MRESULT) FALSE;
case WM_COMMAND:
switch(SHORT1FROMMP(mp1))
{
case ID_CALCUL_OK:
WinInvalidateRegion( hwndTrace, (HRGN)NULL, FALSE);
hypotenuse(hwnd, hypote);
return (MRESULT) TRUE;
case ID_CALCUL_AIDE:
{
for (int i=1;i < 8; ++i) DosBeep(i*100,20*i);
}
return (MRESULT) TRUE;
case ID_CALCUL_TERMINE:
WinSetWindowPos(hwndTrace,
0, 0,0, 160,208, SWP_HIDE);
WinPostMsg(hwnd,WM_CLOSE,MPVOID,MPVOID);
break;
default: break;
}
default:
break;
}
return (MRESULT) WinDefDlgProc(hwnd, msg, mp1, mp2);
}
int main(void)
{
HAB hab;
HMQ hmq;
HWND hwndClient;
HWND hwndFrame;
QMSG qmsg;
ULONG flCreate;
char titre1[] = "Calcul";
hab = WinInitialize(0);
if (!hab) return 1;
hmq = WinCreateMsgQueue(hab, 0);
if (!hmq) return 1;
WinRegisterClass( hab, (PSZ)"Principale", WinPrincipal, CS_SIZEREDRAW, 0);
WinRegisterClass( hab, (PSZ)"Secondaire", WinTrace, CS_SIZEREDRAW, 0);
flCreate = FCF_DLGBORDER | FCF_SYSMENU | FCF_SHELLPOSITION |
FCF_TITLEBAR | FCF_MENU;
hwndFrame = WinCreateStdWindow(HWND_DESKTOP, 0, &flCreate,
"Principale", titre1, 0L, NULLHANDLE, 100, &hwndClient);
WinSetWindowPos(hwndFrame, HWND_TOP, 0,0, 500,300, SWP_SIZE | SWP_SHOW);
flCreate = FCF_DLGBORDER;
hwndTrace = WinCreateStdWindow(hwndFrame, 0, &flCreate, "Secondaire",
0, 0L, NULLHANDLE, 0L, &hwndTrace);
while( WinGetMsg( hab, &qmsg, 0L, 0, 0 ) )
WinDispatchMsg( hab, &qmsg );
WinDestroyWindow(hwndFrame);
WinDestroyWindow(hwndTrace);
WinDestroyMsgQueue( hmq );
WinTerminate( hab );
return 0;
}