home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Simtel MSDOS 1992 September
/
Simtel20_Sept92.cdr
/
msdos
/
ddjmag
/
ddj8903.arc
/
EXAMROOM.LST
< prev
next >
Wrap
File List
|
1989-02-10
|
11KB
|
363 lines
_EXAMINING ROOM - THE PORTABILITIY DREAM_
by Margaret Johnson
[LISTING ONE]
/**********************************************************************
XVT "Hello World"
**********************************************************************/
#include "xvt.h" /* standard XVT header */
#include "xvtmenu.h" /* standard XVT menu tags */
/*
Required application setup structure.
*/
APPL_SETUP appl_setup = {
0, /* menu bar resource ID (use default) */
0, /* about box resource ID (use default) */
"Hello World!", /* application's name */
W_DOC, /* type of initial window */
TRUE, /* size box on initial window? */
FALSE, /* vert. scroll bar on initial window? */
FALSE, /* horz. scroll bar on initial window? */
TRUE, /* close box on initial window? */
FALSE, /* want std. font menu? (includes sizes) */
FALSE /* want std. style menu? */
};
/*********************************************************************
* Main application entry point.
*********************************************************************/
void main_event(win, ep)
WINDOW win;
EVENT *ep;
{ RCT rct;
switch(ep->type)
{
case E_UPDATE:
get_client_rect(win,&rct);
set_pen(&white_pen);
draw_rect(&rct);
draw_text(10,100, "Hello World!", -1);
break;
case E_COMMAND:
if (ep->v.cmd.tag == M_FILE_QUIT)
terminate();
break;
case E_CLOSE:
terminate();
break;
case E_QUIT:
if (ep->v.query)
quit_OK();
else
terminate();
break;
}
}
/***********************************************************************
* Application cleanup. Nothing to do.
***********************************************************************/
void appl_cleanup()
{
}
/**********************************************************************
* Application initialization.
**********************************************************************/
BOOLEAN appl_init()
{
return(TRUE);
}
[LISTING TWO]
/***********************************************************************
* Mac "Hello World"
***********************************************************************/
#include <QuickDraw.h>
#include <WindowMgr.h>
#include <ControlMgr.h>
#include <EventMgr.h>
#include <DeskMgr.h>
#include <MenuMgr.h>
GrafPtr w_port;
Rect drag_rect, grow_bounds;
WindowRecord w_record; /* storage for a window's information */
WindowPtr hello_window; /* a pointer to that storage */
#define mk_long(x) (*((long *)&(x)))
main()
{
init_process(); /* do all the initialization */
make_window();
event_loop();
}
/**********************************************************************/
init_process()
{
init_mgrs();
set_parameters();
}
/**********************************************************************/
init_mgrs()
{
InitGraf(&thePort);
InitFonts();
FlushEvents(everyEvent,0);
InitWindows();
InitCursor();
}
/**********************************************************************/
set_parameters()
{
drag_rect = thePort->portRect;
SetRect(&grow_bounds, 64, 64, thePort->portRect.right,
thePort->portRect.bottom);
}
/**********************************************************************/
make_window()
{
hello_window = GetNewWindow(128,&w_record,-1L);
}
/**********************************************************************/
event_loop()
{
EventRecord event;
while (1)
{SystemTask();
GetNextEvent(everyEvent, &event);
switch(event.what)
{
case mouseDown:
do_mouse_down(&event);
break;
case updateEvt:
do_update(&event);
break;
case activateEvt:
do_activate(&event);
break;
default:
break;
}
}
}
/**********************************************************************/
do_mouse_down(eventp)
EventRecord *eventp;
{
WindowPtr mouse_window;
switch(FindWindow(mk_long(eventp->where),&mouse_window))
{
case inContent:
if (mouse_window != FrontWindow())
SelectWindow(mouse_window);
break;
case inDrag:
DragWindow(mouse_window, mk_long(eventp->where),&drag_rect);
break;
case inGrow:
grow_window(mouse_window, mk_long(eventp->where), &drag_rect);
break;
case inGoAway:
if (TrackGoAway(mouse_window,mk_long(eventp->where)))
finish();
break;
default:
break;
}
}
/**********************************************************************/
do_update(event)
EventRecord *event;
{
GrafPtr save_graf;
WindowPtr update_window;
if (FindWindow(mk_long(event->where),&update_window) != inSysWindow)
{if (update_window == hello_window)
{GetPort(&save_graf);
SetPort(update_window);
BeginUpdate(update_window);
ClipRect(&update_window->portRect);
EraseRect(&update_window->portRect);
DrawGrowIcon(update_window);
draw_content(update_window);
EndUpdate(update_window);
SetPort(save_graf);
}
}
}
/**********************************************************************/
do_activate(event)
EventRecord *event;
{
WindowPtr event_window = (WindowPtr)event->message;
if (event_window == hello_window)
{DrawGrowIcon(event_window);
if (event->modifiers & 1)
SetPort(event_window);
}
}
/**********************************************************************/
grow_window(window,mouse_point)
WindowPtr window;
Point mouse_point;
{
long new_bounds;
inval_bars(window);
new_bounds = GrowWindow(window, mk_long(mouse_point),&grow_bounds);
if (0 == new_bounds)
return;
SizeWindow(window,LoWord(new_bounds),HiWord(new_bounds),TRUE);
inval_bars(window);
}
/**********************************************************************/
inval_bars(window)
WindowPtr window;
{
Rect temp_rect, port_rect;
port_rect = window->portRect;
SetRect(&temp_rect,port_rect.left,port_rect.bottom-16,port_rect.right,port_rect.bottom);
InvalRect(&temp_rect);
SetRect(&temp_rect,port_rect.right-16,port_rect.top,port_rect.right,port_rect.bottom);
InvalRect(&temp_rect);
}
/**********************************************************************/
draw_content(window)
WindowPtr window;
{
MoveTo(100,100);
DrawString("\pHello World!");
}
/**********************************************************************/
finish()
{
exit(0);
}
[LISTING THREE]
#include <windows.h>
#include "hello.h"
BOOL NEAR Initialize( HANDLE hInst, HANDLE hPrevInst, int nCmdShow );
long FAR PASCAL WndProc ( HWND hWnd, WORD wMessage, WORD wParam, LONG lParam);
static char szClass[40];
static char szTitle[40];
int PASCAL WinMain( hInst, hPrevInst, lpszCmdLine, nCmdShow )
HANDLE hInst; /* Our instance handle */
HANDLE hPrevInst; /* Previous instance of this application */
LPSTR lpszCmdLine; /* Pointer to any command line params */
int nCmdShow; /* Parameter to use for first ShowWindow */
{
MSG msg; /* Message structure */
if( ! Initialize( hInst, hPrevInst, nCmdShow ) )
return FALSE;
while( GetMessage( &msg, NULL, 0, 0 ) ) {
TranslateMessage( &msg );
DispatchMessage( &msg );
}
return msg.wParam;
}
/************************************************************************
Initialize the application.
Returns TRUE if initialization succeeded, FALSE if failed.
************************************************************************/
BOOL NEAR Initialize( hInst, hPrevInst, nCmdShow )
HANDLE hInst; /* Our Instance handle */
HANDLE hPrevInst; /* Previous instance handle, 0 if first */
int nCmdShow; /* Parameter from WinMain for ShowWindow */
{
WNDCLASS WndClass; /* Class structure for RegisterClass */
HWND hWnd; /* The window handle */
HMENU hMenu; /* Handle to the (system) menu */
if( ! hPrevInst )
{
LoadString( hInst, IDS_CLASS, szClass, sizeof(szClass) );
LoadString( hInst, IDS_TITLE, szTitle, sizeof(szTitle) );
WndClass.style = CS_HREDRAW | CS_VREDRAW;
WndClass.lpfnWndProc = WndProc;
WndClass.cbClsExtra = 0;
WndClass.cbWndExtra = 0;
WndClass.hInstance = hInst;
WndClass.hIcon = LoadIcon( NULL, IDI_APPLICATION );
WndClass.hCursor = LoadCursor( NULL, IDC_ARROW );
WndClass.hbrBackground = GetStockObject(WHITE_BRUSH);
WndClass.lpszMenuName = NULL;
WndClass.lpszClassName = szClass;
if( ! RegisterClass( &WndClass ) )
return FALSE;
}
else
{
GetInstanceData(hPrevInst, szClass, sizeof(szClass));
GetInstanceData(hPrevInst, szTitle, sizeof(szTitle));
}
hWnd = CreateWindow(
szClass, /* Class name */
szTitle, /* Window title */
WS_OVERLAPPEDWINDOW, /* window style */
CW_USEDEFAULT, /* x */
0, /* y */
CW_USEDEFAULT, /* x width */
0, /* y width */
NULL, /* Parent hWnd (none for top-level) */
NULL, /* Menu handle */
hInst, /* Owning instance handle */
NULL /* Parameter to pass in WM_CREATE (none) */
);
ShowWindow( hWnd, nCmdShow );
UpdateWindow( hWnd );
return TRUE;
}
/***********************************************************************
Process the messages
***********************************************************************/
long FAR PASCAL WndProc(hWnd, wMessage, wParam, lParam)
HWND hWnd;
WORD wMessage, wParam;
LONG lParam;
{PAINTSTRUCT ps;
switch (wMessage)
{case WM_PAINT:
BeginPaint(hWnd,&ps);
TextOut(ps.hdc,10,100,"Hello World!",12);
EndPaint(hWnd,&ps);
break;
default:
return DefWindowProc( hWnd, wMessage, wParam, lParam );
break;
}
return 0L;
}