home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
bitmap1.zip
/
APP1.CPP
next >
Wrap
Text File
|
1993-12-02
|
4KB
|
143 lines
// bitmap test program
// Copyright (C) Joel Barnum, Descriptor Systems, 1993
#define INCL_WIN
#define INCL_GPI
#include <os2.h>
#include "app1.h"
#include "bitmap.hpp"
#include "bitfile.hpp"
/* Internal function prototypes */
MRESULT EXPENTRY App1WindowProc( HWND hwnd,ULONG msg
, MPARAM mp1,MPARAM mp2 );
int main ( int argc, char *argv[] );
int main ( int argc, char *argv[] )
{
HAB hab; // anchor block handle
HWND hwndFrame; // frame window handle
HWND hwndClient; // client window handle
HMQ hmq; // message queue handle
QMSG qmsg; // message from message queue
ULONG flCreate; // window creation control flags
hab = WinInitialize ( 0 );
hmq = WinCreateMsgQueue ( hab, 0 );
WinRegisterClass( hab, "App1Window", App1WindowProc
, CS_SIZEREDRAW, 0 );
flCreate = FCF_SYSMENU |
FCF_SIZEBORDER |
FCF_TITLEBAR |
FCF_MINMAX |
FCF_SHELLPOSITION |
FCF_ICON |
FCF_TASKLIST;
hwndFrame = WinCreateStdWindow( HWND_DESKTOP, WS_VISIBLE
, &flCreate ,"App1Window"
, "Descriptor Systems Bitmap Example", 0, 0
, ID_APP1, &hwndClient );
while( WinGetMsg( hab, &qmsg, (HWND)0, 0, 0 ) != FALSE )
WinDispatchMsg( hab, &qmsg );
WinDestroyWindow( hwndFrame );
WinDestroyMsgQueue( hmq );
WinTerminate( hab );
return 0;
}
//******************************************************
MRESULT EXPENTRY App1WindowProc ( HWND hwnd, ULONG msg
, MPARAM mp1, MPARAM mp2 )
{
static bitmap *pb1; // bitmap object
static bitmap *pb2; // bitmap object
switch( msg )
{
case WM_CREATE:
{
HPS hps = WinGetPS ( hwnd );
HDC hdc = GpiQueryDevice ( hps );
// create a bitmap from a resource
pb1 = new bitmap ( hdc, NULLHANDLE, ID_BITMAP );
// create a bitmap file object
bitmapfile *pbmfile = new bitmapfile ( "TEST1.BMP" );
// create a bitmap from the file data
switch ( pbmfile->gettype() )
{
case BITMAP:
pb2 = new bitmap ( hdc
, pbmfile->getbitmapinfo()
, pbmfile->getbitmapbits() );
break;
case UNKNOWN:
WinMessageBox ( HWND_DESKTOP, hwnd
, "Not a bitmap file", "Error", 0
, MB_OK | MB_MOVEABLE | MB_ERROR );
break;
case ERROR:
WinMessageBox ( HWND_DESKTOP, hwnd
, "Error opening file", "Error", 0
, MB_OK | MB_MOVEABLE | MB_ERROR );
break;
}
delete pbmfile;
WinReleasePS ( hps );
}
return FALSE;
case WM_PAINT:
{
HPS hps;
hps = WinBeginPaint ( hwnd , (HPS)0, NULL );
GpiErase ( hps );
// draw the bitmaps
POINTL ptl;
if ( pb1 )
{
ptl.x = ptl.y = 50;
pb1->draw ( hps, ptl );
}
if ( pb2 )
{
ptl.x = ptl.y = 250;
pb2->draw ( hps, ptl );
}
WinEndPaint ( hps );
}
return (MRESULT) NULL;
case WM_CLOSE:
WinPostMsg( hwnd, WM_QUIT, 0L, 0L );
return (MRESULT) NULL;
case WM_DESTROY:
delete pb1;
delete pb2;
return 0;
default:
return WinDefWindowProc ( hwnd, msg, mp1, mp2 );
}
}