shootgal.c
来自「开放源码的编译器open watcom 1.6.0版的源代码」· C语言 代码 · 共 1,095 行 · 第 1/3 页
C
1,095 行
case WM_CREATE:
inst_handle = GetWindowWord( window_handle, GWW_HINSTANCE );
/*
* make sure message window is turned OFF to start
*/
MessagesOn = FALSE;
CheckMenuItem ( GetMenu( window_handle ), MENU_MESSAGE_WINDOW_ON,
MF_BYCOMMAND | MF_UNCHECKED );
break;
case WM_LBUTTONDOWN:
/*
* zap the target with a lightning bolt!
*/
edata_ptr = (extra_data *) GetWindowLong( window_handle,
EXTRA_DATA_OFFSET );
/*
* set the aim point to where the mouse was just clicked
* set the bolt start point to the top left corner of the window
*/
edata_ptr->aim = MAKEPOINT( lparam );
edata_ptr->bolt.x = edata_ptr->client_rect.right - BOLTWIDTH;
edata_ptr->bolt.y = edata_ptr->client_rect.top;
/*
* shoot the bolt from the current bolt position to the aim point
*/
ShootBolt( window_handle );
break;
case WM_SIZE:
edata_ptr = (extra_data *) GetWindowLong( window_handle,
EXTRA_DATA_OFFSET );
/*
* store the new size of the window
*/
GetClientRect( window_handle, &edata_ptr->client_rect );
SetScrollRange( window_handle, SB_HORZ, edata_ptr->client_rect.left,
edata_ptr->client_rect.right, TRUE );
SetScrollRange( window_handle, SB_VERT, edata_ptr->client_rect.top,
edata_ptr->client_rect.bottom, TRUE );
break;
case WM_COMMAND:
switch( wparam ) {
case MENU_ABOUT:
inst_handle = GetWindowWord( window_handle, GWW_HINSTANCE );
proc = MakeProcInstance( (FARPROC)About, inst_handle );
DialogBox( inst_handle,"AboutBox", window_handle, (DLGPROC)proc );
FreeProcInstance( proc );
break;
case MENU_EXIT:
SendMessage( window_handle, WM_CLOSE, 0, 0L );
break;
case MENU_SET_TARGET_SPEED:
inst_handle = GetWindowWord( window_handle, GWW_HINSTANCE );
proc = MakeProcInstance( (FARPROC)SpeedDlgProc, inst_handle );
DialogBoxParam( inst_handle,"SpeedDlg", window_handle, (DLGPROC)proc,
(DWORD)SET_TARGET_SPEED );
FreeProcInstance( proc );
break;
case MENU_SET_BOLT_SPEED:
inst_handle = GetWindowWord( window_handle, GWW_HINSTANCE );
proc = MakeProcInstance( (FARPROC)SpeedDlgProc, inst_handle );
DialogBoxParam( inst_handle,"SpeedDlg", window_handle, (DLGPROC)proc,
(DWORD)SET_BOLT_SPEED );
FreeProcInstance( proc );
break;
case MENU_SCORE_WINDOW_ON:
/*
* toggle the score window on or off
*/
edata_ptr = (extra_data *) GetWindowLong( window_handle,
EXTRA_DATA_OFFSET );
if( !edata_ptr->score_on ) {
TurnScoreWindowOn( window_handle );
CheckMenuItem ( GetMenu( window_handle ),
wparam, MF_BYCOMMAND | MF_CHECKED );
edata_ptr->score_on = TRUE;
} else {
SendMessage( ScoreWnd, WM_CLOSE, 0, 0L );
CheckMenuItem ( GetMenu( window_handle ), wparam,
MF_BYCOMMAND | MF_UNCHECKED );
edata_ptr->score_on = FALSE;
}
break;
case MENU_SOUND_ON:
/*
* toggle the sound on or off
*/
edata_ptr = (extra_data *) GetWindowLong( window_handle,
EXTRA_DATA_OFFSET );
if( !edata_ptr->sound_on ) {
CheckMenuItem ( GetMenu( window_handle ),
wparam, MF_BYCOMMAND | MF_CHECKED );
edata_ptr->sound_on = TRUE;
} else {
CheckMenuItem ( GetMenu( window_handle ), wparam,
MF_BYCOMMAND | MF_UNCHECKED );
edata_ptr->sound_on = FALSE;
}
break;
case MENU_MESSAGE_WINDOW_ON:
/*
* toggle the message window on or off
*/
if( !MessagesOn ) {
TurnMessageWindowOn( window_handle );
CheckMenuItem ( GetMenu( window_handle ),
wparam, MF_BYCOMMAND | MF_CHECKED );
MessagesOn = TRUE;
} else {
SendMessage( MessageWnd, WM_CLOSE, 0, 0L );
CheckMenuItem ( GetMenu( window_handle ), wparam,
MF_BYCOMMAND | MF_UNCHECKED );
MessagesOn = FALSE;
}
break;
}
break;
case WM_PAINT:
edata_ptr = (extra_data *) GetWindowLong( window_handle,
EXTRA_DATA_OFFSET );
hdc = BeginPaint (window_handle, &ps);
/*
* paint the invalid area with the background colour
*/
brush = CreateSolidBrush( BACKGROUND );
FillRect( hdc, &ps.rcPaint, brush );
DeleteObject( brush );
rect.left = edata_ptr->target.x;
rect.top = edata_ptr->target.y;
rect.right = rect.left + edata_ptr->size.x;
rect.bottom = rect.top + edata_ptr->size.y;
/*
* if part of the target bitmap is invalid, redraw it
*/
if( IntersectRect( &rect, &rect, &ps.rcPaint ) ) {
DrawBitmap( hdc, edata_ptr->target_bmp,
edata_ptr->target.x, edata_ptr->target.y );
}
EndPaint(window_handle, &ps);
break;
case WM_HSCROLL:
case WM_VSCROLL:
/*
* use the scrollbars to move the target around
*/
{
short position; /* the x or y position of the scrollbar */
short max;
short min;
edata_ptr = (extra_data *) GetWindowLong( window_handle,
EXTRA_DATA_OFFSET );
position = ( msg == WM_HSCROLL ) ?
edata_ptr->target.x : edata_ptr->target.y;
switch( wparam ) {
case SB_PAGEDOWN:
position += 15;
break;
case SB_LINEDOWN:
position++;
break;
case SB_PAGEUP:
position -= 15;
break;
case SB_LINEUP:
position--;
break;
case SB_THUMBPOSITION:
case SB_THUMBTRACK:
position = LOWORD( lparam );
break;
default:
return( 0L );
}
if( msg == WM_HSCROLL ) {
GetScrollRange( window_handle, SB_HORZ, (LPINT)&min, (LPINT)&max );
edata_ptr->target.x = max( min( position, max ), min );
SetScrollPos( window_handle, SB_HORZ, edata_ptr->target.x , TRUE );
} else {
GetScrollRange( window_handle, SB_VERT, (LPINT)&min, (LPINT)&max );
edata_ptr->target.y = max( min( position, max ), min );
SetScrollPos( window_handle, SB_VERT, edata_ptr->target.y, TRUE );
}
InvalidateRect( window_handle, &edata_ptr->client_rect, FALSE );
}
break;
case WM_MOVE_TARGET:
/*
* move the target to a random location on the screen
*/
edata_ptr = (extra_data *) GetWindowLong( window_handle,
EXTRA_DATA_OFFSET );
rect.left = edata_ptr->target.x;
rect.top = edata_ptr->target.y;
rect.right = rect.left + edata_ptr->size.x;
rect.bottom = rect.top + edata_ptr->size.y;
InvalidateRect( window_handle, &rect, TRUE );
edata_ptr->target = RandPoint( edata_ptr->client_rect, edata_ptr->size );
rect.left = edata_ptr->target.x;
rect.top = edata_ptr->target.y;
rect.right = rect.left + edata_ptr->size.x;
rect.bottom = rect.top + edata_ptr->size.y;
InvalidateRect( window_handle, &rect, TRUE );
/* set the scrollbars to indicate the new position */
SetScrollPos( window_handle, SB_HORZ, edata_ptr->target.x , TRUE );
SetScrollPos( window_handle, SB_VERT, edata_ptr->target.y, TRUE );
break;
case WM_TIMER:
SendMessage( window_handle, WM_MOVE_TARGET, 0, 0L );
break;
break;
case WM_DESTROY:
edata_ptr = (extra_data *) GetWindowLong( window_handle,
EXTRA_DATA_OFFSET );
KillTimer( window_handle, TARGET_TIMER ); /* Stops the timer */
FreeProcInstance( edata_ptr->message_window_proc );
FreeProcInstance( edata_ptr->score_window_proc );
PostQuitMessage( 0 );
break;
default:
return( DefWindowProc( window_handle, msg, wparam, lparam ) );
}
return( 0L );
} /* WindowProc */
/*
* TurnMessageWindowOn - create the Message window, which will display
* messages received by WindowProc
* this window is a modeless dialog box
*/
BOOL TurnMessageWindowOn( HWND window_handle )
/********************************************/
{
HANDLE inst_handle;
extra_data *edata_ptr;
edata_ptr = (extra_data *) GetWindowLong( window_handle, EXTRA_DATA_OFFSET );
inst_handle = GetWindowWord( window_handle, GWW_HINSTANCE );
MessageWnd = CreateDialog( inst_handle,"MessageWindow", window_handle,
edata_ptr->message_window_proc );
return( MessageWnd != NULL );
} /* TurnMessageWindowOn */
/*
* TurnMessageWindowOn - create the score window, which will display
* the number of shots the user has taken and what locations they have hit
* this window is a modeless dialog box
*/
BOOL TurnScoreWindowOn( HWND window_handle )
/******************************************/
{
HANDLE inst_handle;
extra_data *edata_ptr;
edata_ptr = (extra_data *) GetWindowLong( window_handle, EXTRA_DATA_OFFSET );
inst_handle = GetWindowWord( window_handle, GWW_HINSTANCE );
ScoreWnd = CreateDialog( inst_handle,"ScoreWindow", window_handle,
edata_ptr->score_window_proc );
return( ScoreWnd != NULL );
} /* TurnScoreWindowOn */
/*
* processes messages for the score dialog box
*/
BOOL _EXPORT FAR PASCAL ScoreProc( HWND window_handle, unsigned msg,
WORD wparam, LONG lparam )
/********************************************************************/
{
extra_data *edata_ptr;
wparam = wparam;
lparam = lparam;
edata_ptr = (extra_data *) GetWindowLong(
GetWindow( window_handle, GW_OWNER ), EXTRA_DATA_OFFSET );
switch (msg) {
case WM_INITDIALOG:
SetDlgItemInt( window_handle, SHOTS, 0, FALSE );
SetDlgItemInt( window_handle, YELLOW, 0, FALSE );
SetDlgItemInt( window_handle, RED, 0, FALSE );
SetDlgItemInt( window_handle, BLUE, 0, FALSE );
SetDlgItemInt( window_handle, BLACK, 0, FALSE );
SetDlgItemInt( window_handle, WHITE, 0, FALSE );
SetDlgItemInt( window_handle, MISSED, 0, FALSE );
return( TRUE );
case WM_CLOSE:
CheckMenuItem ( GetMenu( GetWindow( window_handle, GW_OWNER ) ),
MENU_SCORE_WINDOW_ON, MF_BYCOMMAND | MF_UNCHECKED );
DestroyWindow( window_handle );
/* not EndDialog, since this is a MODELESS dialog box */
edata_ptr->score_on = FALSE;
ScoreWnd = NULL;
break;
}
return( FALSE );
} /* ScoreProc */
BOOL _EXPORT FAR PASCAL MessageWindowProc( HWND window_handle, unsigned msg,
WORD wparam, LONG lparam )
/********************************************************************/
{
char textbuffer[48];
/* buffer to hold strings before they are sent to dialog box controls */
static unsigned long timercount = 0;
/* counter - incremented each time a timer message is recieved */
/*
* other than WM_INITDIALOG & WM_CLOSE, all messages should be displayed
* in the dialog box, in the appropriate location
* so use wsprintf to format the message & then send the string to a
* static text control
*/
switch (msg) {
case WM_INITDIALOG:
return( TRUE );
case WM_CLOSE:
CheckMenuItem ( GetMenu( GetWindow( window_handle, GW_OWNER ) ),
MENU_MESSAGE_WINDOW_ON, MF_BYCOMMAND | MF_UNCHECKED );
DestroyWindow( window_handle );
/* not EndDialog, since this is a MODELESS dialog box */
MessagesOn = FALSE;
MessageWnd = NULL;
break;
case WM_MOUSEMOVE:
wsprintf(textbuffer, "WM_MOUSEMOVE: %x, %x, %x",
wparam , LOWORD(lparam ), HIWORD(lparam ));
SetDlgItemText( window_handle, MOUSE_MOVE_BOX, (LPSTR)textbuffer );
return( TRUE );
case WM_LBUTTONDOWN:
wsprintf(textbuffer, "WM_LBUTTONDOWN: %x, %x, %x",
wparam , LOWORD(lparam ), HIWORD(lparam ));
SetDlgItemText( window_handle, L_BUTTON_BOX, (LPSTR)textbuffer );
return( TRUE );
case WM_LBUTTONUP:
wsprintf(textbuffer, "WM_LBUTTONUP: %x, %x, %x",
wparam , LOWORD(lparam ), HIWORD(lparam ));
SetDlgItemText( window_handle, L_BUTTON_BOX, (LPSTR)textbuffer );
return( TRUE );
case WM_LBUTTONDBLCLK:
wsprintf(textbuffer, "WM_LBUTTONDBLCLK: %x, %x, %x",
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?