📄 escape.cpp
字号:
/*********************** Escape.cpp **************************
* Created Date : 1998/07/27
* Last Update : 1999/08/28
* 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 "Escape.H"
#include "resource.h"
/********************************************************************
define globe variables
********************************************************************/
HINSTANCE hInst = NULL;
HWND hwndMain = NULL;
HWND hPass = NULL,
hNew = NULL,
hExit = NULL,
hPrev = NULL,
hNext = NULL,
hwndCB = NULL;
HMENU hMenu = NULL;
HBITMAP hbk;
HDC hDC, hdcMem;
BITMAP bm;
RECT rect, Client_rect;
int bmp_size = 18,
x, y,
stickx, sticky,
x1, y1,
level = 1;
POINT brick1, brick2;
BOOL can_move, have_moved,
press, out_flag = FALSE,
have_add = FALSE,
flag = TRUE;
BUT temp[6][9];
BUT Gate_1[6][9]={{{5,5,0},{5,5,0},{5,5,0},{5,5,0},{5,5,0},{5,5,0},{5,5,0},{6,0,0},{6,0,0}},
{{5,5,0},{3,3,1},{0,3,2},{4,4,0},{4,4,0},{4,4,0},{6,1,0},{6,0,0},{6,0,0}},
{{5,5,0},{1,1,1},{0,1,2},{4,4,0},{4,4,0},{4,4,0},{6,1,0},{6,0,0},{6,0,0}},
{{5,5,0},{0,1,3},{0,1,4},{4,4,0},{4,4,0},{6,0,0},{5,5,0},{6,0,0},{6,0,0}},
{{5,5,0},{3,3,1},{0,3,2},{4,4,0},{4,4,0},{6,0,0},{5,5,0},{6,0,0},{6,0,0}},
{{5,5,0},{5,5,0},{5,5,0},{5,5,0},{5,5,0},{5,5,0},{5,5,0},{6,0,0},{6,0,0}}};
BUT Gate_2[6][9]={{{5,5,0},{5,5,0},{5,5,0},{5,5,0},{5,5,0},{5,5,0},{5,5,0},{6,0,0},{6,0,0}},
{{5,5,0},{3,3,1},{0,3,2},{4,4,0},{4,4,0},{6,0,0},{5,5,0},{6,0,0},{6,0,0}},
{{5,5,0},{1,1,1},{0,1,2},{4,4,0},{4,4,0},{6,0,0},{6,1,0},{6,0,0},{6,0,0}},
{{5,5,0},{0,1,3},{0,1,4},{4,4,0},{4,4,0},{4,4,0},{6,1,0},{6,0,0},{6,0,0}},
{{5,5,0},{3,3,1},{0,3,2},{3,3,1},{0,3,2},{4,4,0},{5,5,0},{6,0,0},{6,0,0}},
{{5,5,0},{5,5,0},{5,5,0},{5,5,0},{5,5,0},{5,5,0},{5,5,0},{6,0,0},{6,0,0}}};
BUT Gate_3[6][9]={{{5,5,0},{5,5,0},{5,5,0},{5,5,0},{5,5,0},{5,5,0},{5,5,0},{6,0,0},{6,0,0}},
{{5,5,0},{3,3,1},{0,3,2},{4,4,0},{4,4,0},{6,0,0},{6,1,0},{6,0,0},{6,0,0}},
{{5,5,0},{1,1,1},{0,1,2},{2,2,1},{4,4,0},{4,4,0},{6,1,0},{6,0,0},{6,0,0}},
{{5,5,0},{0,1,3},{0,1,4},{0,2,2},{4,4,0},{4,4,0},{5,5,0},{6,0,0},{6,0,0}},
{{5,5,0},{3,3,1},{0,3,2},{4,4,0},{4,4,0},{6,0,0},{5,5,0},{6,0,0},{6,0,0}},
{{5,5,0},{5,5,0},{5,5,0},{5,5,0},{5,5,0},{5,5,0},{5,5,0},{6,0,0},{6,0,0}}};
BUT Gate_4[6][9]={{{5,5,0},{5,5,0},{5,5,0},{5,5,0},{5,5,0},{5,5,0},{5,5,0},{6,0,0},{6,0,0}},
{{5,5,0},{3,3,1},{0,3,2},{3,3,1},{0,3,2},{4,4,0},{5,5,0},{6,0,0},{6,0,0}},
{{5,5,0},{1,1,1},{0,1,2},{4,4,0},{4,4,0},{4,4,0},{5,5,0},{6,0,0},{6,0,0}},
{{5,5,0},{0,1,3},{0,1,4},{4,4,0},{4,4,0},{6,0,0},{6,1,0},{6,0,0},{6,0,0}},
{{5,5,0},{3,3,1},{0,3,2},{3,3,1},{0,3,2},{6,0,0},{6,1,0},{6,0,0},{6,0,0}},
{{5,5,0},{5,5,0},{5,5,0},{5,5,0},{5,5,0},{5,5,0},{5,5,0},{6,0,0},{6,0,0}}};
BUT Gate_5[6][9]={{{5,5,0},{5,5,0},{5,5,0},{5,5,0},{5,5,0},{5,5,0},{5,5,0},{6,0,0},{6,0,0}},
{{5,5,0},{3,3,1},{0,3,2},{4,4,0},{4,4,0},{4,4,0},{6,1,0},{6,0,0},{6,0,0}},
{{5,5,0},{1,1,1},{0,1,2},{2,2,1},{4,4,0},{4,4,0},{6,1,0},{6,0,0},{6,0,0}},
{{5,5,0},{0,1,3},{0,1,4},{0,2,2},{4,4,0},{6,0,0},{5,5,0},{6,0,0},{6,0,0}},
{{5,5,0},{3,3,1},{0,3,2},{3,3,1},{0,3,2},{6,0,0},{5,5,0},{6,0,0},{6,0,0}},
{{5,5,0},{5,5,0},{5,5,0},{5,5,0},{5,5,0},{5,5,0},{5,5,0},{6,0,0},{6,0,0}}};
BUT Gate_6[6][9]={{{5,5,0},{5,5,0},{5,5,0},{5,5,0},{5,5,0},{5,5,0},{5,5,0},{6,0,0},{6,0,0}},
{{5,5,0},{3,3,1},{0,3,2},{4,4,0},{4,4,0},{4,4,0},{5,5,0},{6,0,0},{6,0,0}},
{{5,5,0},{1,1,1},{0,1,2},{2,2,1},{2,2,1},{4,4,0},{6,1,0},{6,0,0},{6,0,0}},
{{5,5,0},{0,1,3},{0,1,4},{0,2,2},{0,2,2},{6,0,0},{6,1,0},{6,0,0},{6,0,0}},
{{5,5,0},{3,3,1},{0,3,2},{4,4,0},{4,4,0},{6,0,0},{5,5,0},{6,0,0},{6,0,0}},
{{5,5,0},{5,5,0},{5,5,0},{5,5,0},{5,5,0},{5,5,0},{5,5,0},{6,0,0},{6,0,0}}};
BUT Gate_7[6][9]={{{5,5,0},{5,5,0},{5,5,0},{5,5,0},{5,5,0},{5,5,0},{5,5,0},{6,0,0},{6,0,0}},
{{5,5,0},{3,3,1},{0,3,2},{3,3,1},{0,3,2},{6,0,0},{5,5,0},{6,0,0},{6,0,0}},
{{5,5,0},{1,1,1},{0,1,2},{2,2,1},{4,4,0},{6,0,0},{6,1,0},{6,0,0},{6,0,0}},
{{5,5,0},{0,1,3},{0,1,4},{0,2,2},{4,4,0},{4,4,0},{6,1,0},{6,0,0},{6,0,0}},
{{5,5,0},{3,3,1},{0,3,2},{3,3,1},{0,3,2},{4,4,0},{5,5,0},{6,0,0},{6,0,0}},
{{5,5,0},{5,5,0},{5,5,0},{5,5,0},{5,5,0},{5,5,0},{5,5,0},{6,0,0},{6,0,0}}};
BUT Gate_8[6][9]={{{5,5,0},{5,5,0},{5,5,0},{5,5,0},{5,5,0},{5,5,0},{6,0,0},{6,0,0},{6,0,0}},
{{5,5,0},{10,10,1},{0,10,2},{0,10,3},{4,4,0},{5,5,0},{6,0,0},{6,0,0},{6,0,0}},
{{5,5,0},{4,4,0},{2,2,1},{2,2,1},{4,4,0},{5,5,0},{6,0,0},{6,0,0},{6,0,0}},
{{5,5,0},{4,4,0},{0,2,2},{0,2,2},{4,4,0},{5,5,0},{6,0,0},{6,0,0},{6,0,0}},
{{5,5,0},{4,4,0},{6,0,0},{6,0,0},{6,0,0},{6,1,0},{6,0,0},{6,0,0},{6,0,0}},
{{5,5,0},{5,5,0},{5,5,0},{5,5,0},{5,5,0},{5,5,0},{6,0,0},{6,0,0},{6,0,0}}};
BUT Gate_9[6][9]={{{5,5,0},{5,5,0},{5,5,0},{5,5,0},{5,5,0},{5,5,0},{5,5,0},{6,0,0},{6,0,0}},
{{5,5,0},{12,12,1},{0,12,2},{3,3,1},{0,3,2},{4,4,0},{5,5,0},{6,0,0},{6,0,0}},
{{5,5,0},{4,4,0},{4,4,0},{4,4,0},{2,2,1},{2,2,1},{5,5,0},{6,0,0},{6,0,0}},
{{5,5,0},{4,4,0},{4,4,0},{2,2,1},{0,2,2},{0,2,2},{5,5,0},{6,0,0},{6,0,0}},
{{5,5,0},{3,3,1},{0,3,2},{0,2,2},{6,0,0},{6,0,0},{6,1,0},{6,0,0},{6,0,0}},
{{5,5,0},{5,5,0},{5,5,0},{5,5,0},{5,5,0},{5,5,0},{5,5,0},{6,0,0},{6,0,0}}};
BUT Gate_10[6][9]={{{5,5,0},{5,5,0},{5,5,0},{5,5,0},{5,5,0},{5,5,0},{5,5,0},{5,5,0},{6,0,0}},
{{5,5,0},{1,1,1},{0,1,2},{4,4,0},{4,4,0},{13,13,1},{0,13,2},{5,5,0},{6,0,0}},
{{5,5,0},{0,1,3},{0,1,4},{4,4,0},{4,4,0},{0,13,3},{0,13,4},{6,1,0},{6,0,0}},
{{5,5,0},{4,4,0},{4,4,0},{13,13,1},{0,13,2},{4,4,0},{6,0,0},{6,1,0},{6,0,0}},
{{5,5,0},{4,4,0},{4,4,0},{0,13,3},{0,13,4},{4,4,0},{6,0,0},{5,5,0},{6,0,0}},
{{5,5,0},{5,5,0},{5,5,0},{5,5,0},{5,5,0},{5,5,0},{5,5,0},{5,5,0},{6,0,0}}};
BUT Gate_11[6][9]={{{5,5,0},{5,5,0},{5,5,0},{5,5,0},{5,5,0},{5,5,0},{5,5,0},{5,5,0},{6,0,0}},
{{5,5,0},{1,1,1},{0,1,2},{4,4,0},{2,2,1},{13,13,1},{0,13,2},{5,5,0},{6,0,0}},
{{5,5,0},{0,1,3},{0,1,4},{4,4,0},{0,2,2},{0,13,3},{0,13,4},{6,1,0},{6,0,0}},
{{5,5,0},{4,4,0},{4,4,0},{13,13,1},{0,13,2},{4,4,0},{6,0,0},{6,1,0},{6,0,0}},
{{5,5,0},{4,4,0},{4,4,0},{0,13,3},{0,13,4},{4,4,0},{6,0,0},{5,5,0},{6,0,0}},
{{5,5,0},{5,5,0},{5,5,0},{5,5,0},{5,5,0},{5,5,0},{5,5,0},{5,5,0},{6,0,0}}};
BUT Gate_12[6][9]={{{5,5,0},{5,5,0},{5,5,0},{5,5,0},{5,5,0},{5,5,0},{5,5,0},{5,5,0},{6,0,0}},
{{5,5,0},{12,12,1},{0,12,2},{3,3,1},{0,3,2},{4,4,0},{4,4,0},{5,5,0},{6,0,0}},
{{5,5,0},{2,2,1},{2,2,1},{3,3,1},{0,3,2},{4,4,0},{4,4,0},{5,5,0},{6,0,0}},
{{5,5,0},{0,2,2},{0,2,2},{4,4,0},{2,2,1},{13,13,1},{0,13,2},{6,1,0},{6,0,0}},
{{5,5,0},{6,0,0},{6,0,0},{4,4,0},{0,2,2},{0,13,3},{0,13,4},{5,5,0},{6,0,0}},
{{5,5,0},{5,5,0},{5,5,0},{5,5,0},{5,5,0},{5,5,0},{5,5,0},{5,5,0},{6,0,0}}};
BUT Gate_13[6][9]={{{5,5,0},{5,5,0},{5,5,0},{5,5,0},{5,5,0},{5,5,0},{5,5,0},{5,5,0},{6,0,0}},
{{5,5,0},{4,4,0},{4,4,0},{3,3,1},{0,3,2},{3,3,1},{0,3,2},{5,5,0},{6,0,0}},
{{5,5,0},{1,1,1},{0,1,2},{2,2,1},{2,2,1},{4,4,0},{6,0,0},{6,1,0},{6,0,0}},
{{5,5,0},{0,1,3},{0,1,4},{0,2,2},{0,2,2},{4,4,0},{6,0,0},{6,1,0},{6,0,0}},
{{5,5,0},{3,3,1},{0,3,2},{4,4,0},{4,4,0},{4,4,0},{4,4,0},{5,5,0},{6,0,0}},
{{5,5,0},{5,5,0},{5,5,0},{5,5,0},{5,5,0},{5,5,0},{5,5,0},{5,5,0},{6,0,0}}};
TCHAR szAppName[30];
TCHAR szTitle[30];
TCHAR string[30];
enum WAY {left, right, up, down};
WAY section;
int startx = 25, starty = 50;
ULONG step = 0, steps = 0;
/********************************************************************
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=NULL;
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;
Init_level(hwndMain);
step=0;
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);
hwndCB=CommandBar_Create(hInst,hwnd,1);
CommandBar_InsertMenubar(hwndCB,hInst,IDM_MENU,0);
CommandBar_AddAdornments(hwndCB,0,0);
hNew=CreateWindow(TEXT("BUTTON"),
TEXT("&New"),
WS_VISIBLE|WS_CHILD&~(WS_CAPTION)|BS_DEFPUSHBUTTON,
30,220,//300,40,
40,20,
hwnd,
(HMENU)IDM_NEW,
hInst,
NULL);
hPass=CreateWindow(TEXT("BUTTON"),
TEXT("&Pass"),
WS_VISIBLE|WS_CHILD&~(WS_CAPTION)|BS_DEFPUSHBUTTON,
80, 220,//300,65,
40,20,
hwnd,
(HMENU)IDM_PASS,
hInst,
NULL);
hPrev=CreateWindow(TEXT("BUTTON"),
TEXT("&Prev"),
WS_VISIBLE|WS_CHILD&~(WS_CAPTION)|BS_DEFPUSHBUTTON,
130,220,//300,90,
40,20,
hwnd,
(HMENU)IDM_PREV,
hInst,
NULL);
hNext=CreateWindow(TEXT("BUTTON"),
TEXT("&Next"),
WS_VISIBLE|WS_CHILD&~(WS_CAPTION)|BS_DEFPUSHBUTTON,
180,220,//300,115,
40,20,
hwnd,
(HMENU)IDM_NEXT,
hInst,
NULL);
hExit=CreateWindow(TEXT("BUTTON"),
TEXT("E&xit"),
WS_VISIBLE|WS_CHILD&~(WS_CAPTION)|BS_DEFPUSHBUTTON,
150,260,//300,140,
40,20,
hwnd,
(HMENU)IDM_EXIT,
hInst,
NULL);
break;
case WM_PAINT:
hDC=BeginPaint(hwnd,&ps);
DrawBkground(hwnd,hDC);
EndPaint(hwnd,&ps);
break;
case WM_LBUTTONDOWN:
POINTSTOPOINT(Pos,lp);
brick1=Pos;
x=stickx=int((brick1.y-starty)/bmp_size);
y=sticky=int((brick1.x-startx)/bmp_size);
press=TRUE;
break;
case WM_MOUSEMOVE:
if((steps==1) && (!have_add))
{
step++;
have_add=TRUE;
hDC=GetDC(hwnd);
Fill_rect(200,250,180,195);
_ltow(step,string,10);
DrawText(hDC,string,-1,&rect,DT_CENTER);
ReleaseDC(hwnd,hDC);
}
brick2.x=LOWORD(lp);
brick2.y=HIWORD(lp);
out_flag=FALSE;
flag=TRUE;
x1=int((brick2.y-starty)/bmp_size);
y1=int((brick2.x-startx)/bmp_size);
if(brick2.x>(startx+(sticky+1)*bmp_size))
{
if((brick2.y>(starty+(stickx+1)*bmp_size))||
(brick2.y<(starty+stickx*bmp_size)))
{
if(temp[stickx][sticky+1].sign_1==0)
flag=FALSE;
else
flag=TRUE;
}
else
flag=TRUE;
section=right;
out_flag=TRUE;
}
if(brick2.x<(startx+sticky*bmp_size))
{
if((temp[stickx-1][sticky].sign_1!=0)||
(temp[stickx+1][sticky].sign_1!=0))
{
if(temp[stickx][sticky-1].sign_1==0)
flag=FALSE;
else
flag=TRUE;
}
else
flag=TRUE;
section=left;
out_flag=TRUE;
}
if((brick2.y>(starty+(stickx+1)*bmp_size))&&flag)
{
section=down;
out_flag=TRUE;
}
if((brick2.y<(starty+stickx*bmp_size))&&flag)
{
section=up;
out_flag=TRUE;
}
if(out_flag)
{
if((section==left)||(section==right))
{
x1=x;
y1=int((brick2.x-startx)/bmp_size);
}
if((section==up)||(section==down))
{
x1=int((brick2.y-starty)/bmp_size);
y1=y;
}
if(temp[x1][y1].sign_1==0)
can_move=TRUE;
else
can_move=FALSE;
}
else
can_move=FALSE;
if(press && can_move)
{
Move(hwnd);
if(have_moved)
{
stickx=x1;
sticky=y1;
x=x1;
y=y1;
}
}
break;
case WM_LBUTTONUP:
press = FALSE;
steps=0;
have_add=FALSE;
break;
case WM_COMMAND:
Command(hwnd,msg,wp,lp);
break;
case WM_CLOSE:
CommandBar_Destroy(hwndCB);
DestroyWindow(hwnd);
break;
case WM_DESTROY:
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<6;i++)
for(j=0;j<9;j++)
{
if(temp[i][j].sign!=0)
{
hbk=LoadBitmap(hInst,MAKEINTRESOURCE(temp[i][j].sign));
SelectObject(hdcMem,hbk);
GetObject(hbk,sizeof(BITMAP),(LPSTR)&bm);
StretchBlt(hDC, startx+bmp_size*j, starty+bmp_size*i,
bm.bmWidth, bm.bmHeight, hdcMem, 0, 0,
bm.bmWidth, bm.bmHeight, SRCCOPY);
DeleteObject(hbk);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -