📄 pipe.cpp
字号:
/************************ Pipe.cpp ***************************
* Created Date : 1998/03/16
* Last Update : 1999/04/17
* Version : 1.00
* Author : Acer Softech(Shanghai). M7c830/Cyndi
* Modifier : Acer Softech(Shanghai). M7c830/Cyndi
* Comment : Provide main dialog process and self-defined
functions
**************************************************************/
#include <windows.h>
#include <windowsx.h>
#include <stdlib.h>
#include <Winuser.h>
#include <Commctrl.h>
#include "PIPE.H"
#include "resource.h"
/********************************************************************
define the globe variables
********************************************************************/
HINSTANCE hInst = NULL;
HWND hwndMain = NULL,
hstatic = NULL,
hwndCB = NULL;
HMENU hMenu = NULL;
HBITMAP hbk;
HDC hDC, hdcMem;
BITMAP bm;
RECT rect, Client_rect;
int big_x, big_y, small_x, small_y;
int x, y,
r[5],
startx, starty,
number,
x1, y1, x2, y2,
start, internal,
bmp_size=25;
static int i, j, pause = 1;
typedef struct tagBUT{
int sign;
BOOL select;
BOOL correct;
} BUT;
BUT B[7][9];
BOOL time = TRUE,
out = FALSE;
ULONG sum, level;
TCHAR szAppName[30];
TCHAR szTitle[30];
TCHAR string[30];
enum MENUVIEW { Level1,Level2,Level3,Level4,Level5};
MENUVIEW menuview;
DWORD Premenu = NULL;
static int count9=12,count3_1=0,count3_2=24,count4_1=0,count4_2=9,
count5_1=24,count5_2=9,count5_3=0,count5_4=14,count6_1=0,
count6_3=24,count6_4=9,count7_1=24,count7_2=14,
count8_1=0,count8_2=24;
//**********add by christine 2001/2/12 on Palm-size*****************
#define LEFT 10
#define TOP 275
#define RIGHT 190
#define BOTTOM 290
/********************************************************************
InitInstance(): create the main window
********************************************************************/
BOOL InitInstance(HINSTANCE hInstance,int CmdShow)
{
hInst=hInstance;
#ifdef _WIN32_WCE_EMULATION
hwndMain=CreateWindow(szAppName,
szTitle,
WS_POPUP,
0,0,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL);
#else
hwndMain=CreateWindow(szAppName,
szTitle,
WS_VISIBLE,
0,0,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL);
#endif
if(!hwndMain) return FALSE;
ShowWindow(hwndMain,CmdShow);
UpdateWindow(hwndMain);
return TRUE;
}
/********************************************************************
InitApplication(): creat the window class and register it
********************************************************************/
BOOL InitApplication(HINSTANCE hInstance)
{
WNDCLASS wc;
LoadString(hInstance,IDS_APPNAME,szAppName,sizeof(szAppName)/sizeof(TCHAR));
LoadString(hInstance,IDS_TITLE,szTitle,sizeof(szTitle)/sizeof(TCHAR));
wc.style=CS_HREDRAW|CS_VREDRAW;
wc.lpfnWndProc=(WNDPROC)WndProc;
wc.cbClsExtra=0;
wc.cbWndExtra=0;
wc.hIcon=LoadIcon(hInst,MAKEINTRESOURCE(IDI_ICON));
wc.hInstance=hInstance;
wc.hCursor=NULL;
wc.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wc.lpszMenuName=NULL;
wc.lpszClassName=szAppName;
return(RegisterClass(&wc));
}
/********************************************************************
WinMain(): main function and initialize some variables
********************************************************************/
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPWSTR lpCmdLine,
int CmdShow)
{
MSG msg;
start_new(hwndMain);
if(!hPrevInstance)
if(!InitApplication(hInstance)) return (FALSE);
if(!InitInstance(hInstance,CmdShow)) return(FALSE);
while(GetMessage(&msg,NULL,0,0)==TRUE)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return(msg.wParam);
}
/********************************************************************
WndProc(): deal with the system message or user message
********************************************************************/
LRESULT CALLBACK WndProc(HWND hwnd,
UINT msg,
WPARAM wp,
LPARAM lp)
{
LRESULT lResult=TRUE;
POINT Pos;
PAINTSTRUCT ps;
switch(msg)
{
case WM_CREATE:
GetClientRect(hwnd,&Client_rect);
/*
big_x=200;
big_y=30;
small_x=25;
small_y=135;
*/
big_x = 10;
big_y = 30;
small_x = 10;
small_y = 210;
hwndCB=CommandBar_Create(hInst,hwnd,1);
CommandBar_InsertMenubar(hwndCB,hInst,IDM_MENU,0);
CommandBar_AddAdornments(hwndCB,0,0);
hMenu=CommandBar_GetMenu(hwndCB,0);
CheckMenuItem(hMenu,IDM_LEVEL1,MF_CHECKED);
menuview=Level1;
Premenu=IDM_LEVEL1;
sum=50;
level=1;
start=15000;
internal=150;
SetTimer(hwnd,IDT_TIMER1,start,NULL);
x1=startx;
y1=starty;
break;
case WM_CHAR:
switch(wp)
{
case 0x70:
if(pause==1)
{
KillTimer(hwnd,IDT_TIMER2);
pause=2;
}
else
{
SetTimer(hwnd,IDT_TIMER2,internal,NULL);
pause=1;
}
break;
}
break;
case WM_PAINT:
hDC=BeginPaint(hwnd,&ps);
DrawBkground(hwnd,hDC);
EndPaint(hwnd,&ps);
break;
case WM_TIMER:
if(time)
{
time=FALSE;
KillTimer(hwnd,IDT_TIMER1);
x1=startx;
y1=starty;
SetTimer(hwnd,IDT_TIMER2,internal,NULL);
}
Liquid(hwnd);
break;
case WM_LBUTTONDOWN:
POINTSTOPOINT(Pos,lp);
y=int((Pos.x-big_x)/bmp_size);
x=int((Pos.y-big_y)/bmp_size);
if((y>=0)&&(y<=14))
Draw(hwnd);
break;
case WM_COMMAND:
Command(hwnd,msg,wp,lp);
break;
case WM_CLOSE:
CommandBar_Destroy(hwndCB);
DestroyWindow(hwnd);
break;
case WM_DESTROY:
KillTimer(hwnd,IDT_TIMER2);
KillTimer(hwnd,IDT_TIMER3);
PostQuitMessage(0);
break;
default: lResult=DefWindowProc(hwnd,msg,wp,lp);
break;
}
return(lResult);
}
/********************************************************************
DrawBkground(): redraw the whole window interface
********************************************************************/
void DrawBkground(HWND hwnd,HDC hDC)
{
int i,j;
hdcMem=CreateCompatibleDC(hDC);
for(i=0;i<7;i++)
//for(j=0;j<15;j++)
for(j=0;j<9;j++) // wellington modify this line for testing
{
hbk=LoadBitmap(hInst,MAKEINTRESOURCE(B[i][j].sign));
SelectObject(hdcMem,hbk);
GetObject(hbk,sizeof(BITMAP),(LPSTR)&bm);
StretchBlt(hDC,big_x+bmp_size*j,big_y+bmp_size*i,bm.bmWidth,bm.bmHeight,
hdcMem,0,0,bm.bmWidth,bm.bmHeight,SRCCOPY);
DeleteObject(hbk);
}
for(i=0;i<5;i++)
{
hbk=LoadBitmap(hInst,MAKEINTRESOURCE(r[i]));
SelectObject(hdcMem,hbk);
GetObject(hbk,sizeof(BITMAP),(LPSTR)&bm);
StretchBlt(hDC,small_x+bmp_size*4-i*bmp_size,small_y,bm.bmWidth,bm.bmHeight,
hdcMem,0,0,bm.bmWidth,bm.bmHeight,SRCCOPY);
DeleteObject(hbk);
}
hbk=LoadBitmap(hInst,MAKEINTRESOURCE(13));
SelectObject(hdcMem,hbk);
GetObject(hbk,sizeof(BITMAP),(LPSTR)&bm);
//StretchBlt(hDC,75,30,bm.bmWidth,bm.bmHeight,
// hdcMem,0,0,bm.bmWidth,bm.bmHeight,SRCCOPY);
DeleteObject(hbk);
DeleteDC(hdcMem);
if(level==1)
{
rect.left=LEFT;
rect.top=TOP;
rect.right=RIGHT;
rect.bottom=BOTTOM;
DrawText(hDC,TEXT("Destination score: 100"),
-1,&rect,DT_LEFT);
}
else
if(level==2)
{
rect.left=LEFT;
rect.top=TOP;
rect.right=RIGHT;
rect.bottom=BOTTOM;
DrawText(hDC,TEXT("Destination score: 150"),
-1,&rect,DT_LEFT);
}
else
if(level==3)
{
rect.left=LEFT;
rect.top=TOP;
rect.right=RIGHT;
rect.bottom=BOTTOM;
DrawText(hDC,TEXT("Destination score: 190"),
-1,&rect,DT_LEFT);
}
else
if(level==4)
{
rect.left=LEFT;
rect.top=TOP;
rect.right=RIGHT;
rect.bottom=BOTTOM;
DrawText(hDC,TEXT("Destination score: 210"),
-1,&rect,DT_LEFT);
}
else
{
rect.left=20;
rect.top=180;
rect.right=200;
rect.bottom=195;
DrawText(hDC,TEXT("Destination score: 230"),
-1,&rect,DT_LEFT);
}
/***********modify by christine 2001/2/12 on Palm-size****************
rect.left=25;
rect.top=70;
rect.right=80;
rect.bottom=85;
DrawText(hDC,TEXT("Level:"),-1,&rect,DT_LEFT);
rect.left=80;
rect.top=70;
rect.right=160;
rect.bottom=85;
_ltow(level,string,10);
DrawText(hDC,string,-1,&rect,DT_CENTER);
rect.left=25;
rect.top=95;
rect.right=80;
rect.bottom=110;
DrawText(hDC,TEXT("Score:"),-1,&rect,DT_LEFT);
rect.left=80;
rect.top=95;
rect.right=160;
rect.bottom=110;
_ltow(sum,string,10);
DrawText(hDC,string,-1,&rect,DT_CENTER);
*/
rect.left=10;
rect.top=240;
rect.right=65;
rect.bottom=255;
DrawText(hDC,TEXT("Level:"),-1,&rect,DT_LEFT);
rect.left=65;
rect.top=240;
rect.right=145;
rect.bottom=255;
_ltow(level,string,10);
DrawText(hDC,string,-1,&rect,DT_CENTER);
rect.left=10;
rect.top=255;
rect.right=65;
rect.bottom=270;
DrawText(hDC,TEXT("Score:"),-1,&rect,DT_LEFT);
rect.left=65;
rect.top=255;
rect.right=145;
rect.bottom=270;
_ltow(sum,string,10);
DrawText(hDC,string,-1,&rect,DT_CENTER);
}
/********************************************************************
Liquid(): deal with the liquid moving
********************************************************************/
void Liquid(HWND hwnd)
{
if((B[x1][y1].correct) && (!out))
{
switch(B[x1][y1].sign)
{
case 9:
B[x1][y1].select=FALSE;
if(count9<0)
{
B[x1][y1].correct=FALSE;
if((B[x1-1][y1].sign==3)||
(B[x1-1][y1].sign==6)||
(B[x1-1][y1].sign==7)||
(B[x1-1][y1].sign==8))
B[x1-1][y1].correct=TRUE;
x2=x1;
y2=y1;
x1=x2-1;
y1=y2;
count9=12;
sum=sum+3;
}
else
{
rect.left=big_x+bmp_size*y1+10;
rect.top=big_y+bmp_size*x1+count9;
rect.right=big_x+bmp_size*y1+14;
rect.bottom=rect.top+1;
count9--;
hDC=GetDC(hwnd);
Draw1(hwnd,hDC,11);
ReleaseDC(hwnd,hDC);
}
break;
case 2:
B[x1][y1].select=FALSE;
if((y1==(y2+1))&&(x1==x2))
if(count3_1>24)
{
B[x1][y1].correct=FALSE;
if((y1+1)>14) out=TRUE;
else
{
if((B[x1][y1+1].sign==2)||
(B[x1][y1+1].sign==3)||
(B[x1][y1+1].sign==4)||
(B[x1][y1+1].sign==6))
B[x1][y1+1].correct=TRUE;
x2=x1;
y2=y1;
x1=x2;
y1=y2+1;
}
count3_1=0;
sum=sum+6;
}
else
{
rect.left=big_x+bmp_size*y1+count3_1;
rect.top=big_y+bmp_size*x1+10;
rect.right=rect.left+1;
rect.bottom=big_y+bmp_size*x1+15;
count3_1++;
hDC=GetDC(hwnd);
Draw1(hwnd,hDC,12);
ReleaseDC(hwnd,hDC);
}
if((y1==(y2-1))&&(x1==x2))
if(count3_2<0)
{
B[x1][y1].select=FALSE;
B[x1][y1].correct=FALSE;
if((y1-1)<0) out=TRUE;
else
{
if((B[x1][y1-1].sign==2)||
(B[x1][y1-1].sign==3)||
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -