📄 bank.cpp
字号:
// Bank.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
#include "bank.h"
#define MAX_LOADSTRING 100
// Global Variables:
HINSTANCE hInst; // current instance
TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
TCHAR szWindowClass[MAX_LOADSTRING]; // The title bar text
TCHAR szExePath[256];
// Foward declarations of functions included in this code module:
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM);
char sIni[15][64]=
{
"[扫雷]",
"Difficulty=",
"Height=",
"Width=",
"Mines=",
"Mark=",
"Color=",
"Xpos=",
"Ypos=",
"Time1=",
"Time2=",
"Time3=",
"Name1=",
"Name2=",
"Name3="
};
//*/
S_ini Ini_Null=
{
3,16,30,99,
1,1,
80,76 ,
999,999,999,0,
"匿名","匿名","匿名","匿名"
};
#include "TExicCB.h"
TExicCB ExicCB ;
TExic* PExic=&ExicCB;
S_ini Ini;
S_ini& GetIni(){return Ini;}
bool S_ini::Read()
{
Name[3][0]=0;
Time[3]=0;
char cc[128],ini[128];
GetWindowsDirectory(cc,127);
wsprintf(ini,"%s\\winmine.ini",cc);
int i;
bool bRead=false;
FILE* f1=fopen(ini,"rt");
if(f1)
{
bRead=true;
char ss[15][64];
for(i=0;i<15;i++)
{
if(fgets(ss[i],127,f1)==NULL)
{
bRead=false;
break;
}
}
if(bRead)
{
for(i=0;i<15;i++)
{
if(strnicmp(sIni[i],ss[i],strlen(sIni[i]))!=0)
{
bRead=false;
break;
}
for(int w=strlen(ss[i]);w;w--)if(ss[i][w]<' ' && ss[i][w]>0)ss[i][w]=0;
}
if(i==15)//格式正确
{
i=1;
Difficulty=atoi(ss[i]+strlen(sIni[i]));i++;
Height =atoi(ss[i]+strlen(sIni[i]));i++;
Width =atoi(ss[i]+strlen(sIni[i]));i++;
Mines =atoi(ss[i]+strlen(sIni[i]));i++;
Mark =atoi(ss[i]+strlen(sIni[i]));i++;
Color =atoi(ss[i]+strlen(sIni[i]));i++;
Xpos =atoi(ss[i]+strlen(sIni[i]));i++;
Ypos =atoi(ss[i]+strlen(sIni[i]));i++;
Time[0] =atoi(ss[i]+strlen(sIni[i]));i++;
Time[1] =atoi(ss[i]+strlen(sIni[i]));i++;
Time[2] =atoi(ss[i]+strlen(sIni[i]));i++;
strcpy(Name[0],ss[i]+strlen(sIni[i]));i++;
strcpy(Name[1],ss[i]+strlen(sIni[i]));i++;
strcpy(Name[2],ss[i]+strlen(sIni[i]));
}
}
if(!bRead)
{
*this=Ini_Null;
}
fclose(f1);
}
if(!bRead )
{
*this=Ini_Null;
}
return bRead;
}
bool S_ini::Save()
{
char cc[128],ini[128];
GetWindowsDirectory(cc,127);
wsprintf(ini,"%s\\winmine.ini",cc);
int i;
FILE* f1=fopen(ini,"wt");
if(f1)
{
fprintf(f1,sIni[0]);
i=1;
fprintf(f1,"\n%s%d",sIni[i],Difficulty);i++;
fprintf(f1,"\n%s%d",sIni[i],Height );i++;
fprintf(f1,"\n%s%d",sIni[i],Width );i++;
fprintf(f1,"\n%s%d",sIni[i],Mines );i++;
fprintf(f1,"\n%s%d",sIni[i],Mark );i++;
fprintf(f1,"\n%s%d",sIni[i],Color );i++;
fprintf(f1,"\n%s%d",sIni[i],Xpos );i++;
fprintf(f1,"\n%s%d",sIni[i],Ypos );i++;
fprintf(f1,"\n%s%d",sIni[i],Time[0] );i++;
fprintf(f1,"\n%s%d",sIni[i],Time[1] );i++;
fprintf(f1,"\n%s%d",sIni[i],Time[2] );i++;
fprintf(f1,"\n%s%s",sIni[i],Name[0] );i++;
fprintf(f1,"\n%s%s",sIni[i],Name[1] );i++;
fprintf(f1,"\n%s%s",sIni[i],Name[2] );
fclose(f1);
return true;
}
return false;
}
//得到程序的路径,不以“\”结尾
const char* GetExePath()
{
return szExePath;
}
//现在的时间,秒
UINT Now()
{
time_t ltime;
time( <ime );
return ltime;
}
int Rand(int a,int b)
{
if(b<a)return a;
return rand()%(b+1-a)+a;
}
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.2
MSG msg;
HACCEL hAccelTable;
char* p=GetCommandLine()+1;
int n,k;
for(n=k=0;n<255;n++)
{
if(p[n]=='\\')k=n;
if(p[n]==0 || p[n]=='\"')
{
szExePath[k]=0;break;
}
szExePath[n]=p[n];
}
// Initialize global strings
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadString(hInstance, IDC_BANK, szWindowClass, MAX_LOADSTRING);
MyRegisterClass(hInstance);
GetIni().Read();
PExic->m_hIns=hInstance;
// Perform application initialization:
if (!InitInstance (hInstance,nCmdShow)) //SW_SHOWMAXIMIZED))
{
return FALSE;
}
hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_BANK);
// Main message loop:
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
GetIni().Save();
return msg.wParam;
}
//
// FUNCTION: MyRegisterClass()
//
// PURPOSE: Registers the window class.
//
// COMMENTS:
//
// This function and its usage is only necessary if you want this code
// to be compatible with Win32 systems prior to the 'RegisterClassEx'
// function that was added to Windows 95. It is important to call this function
// so that the application will get 'well formed' small icons associated
// with it.
//
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC)WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_BANK);
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_MENU+1);//(COLOR_WINDOW+1);//
wcex.lpszMenuName = (LPCSTR)IDC_BANK;
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);
return RegisterClassEx(&wcex);
}
//
// FUNCTION: InitInstance(HANDLE, int)
//
// PURPOSE: Saves instance handle and creates main window
//
// COMMENTS:
//
// In this function, we save the instance handle in a global variable and
// create and display the main program window.
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
int dh=GetSystemMetrics(SM_CYCAPTION)+
GetSystemMetrics(SM_CYBORDER)*2+
GetSystemMetrics(SM_CYMENU)+1;
int dw=GetSystemMetrics(SM_CXBORDER)*2+1;
GetIni().dh=dh;
GetIni().dw=dw;
GetIni().x0=6;
GetIni().y0=70;
GetIni().uint=32;
ExicCB.Init();
HWND hWnd;
hInst = hInstance; // Store instance handle in our global variable
hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPED | WS_SYSMENU |WS_MINIMIZEBOX ,
GetIni().Xpos-dw,GetIni().Ypos-dh, GetIni().WX(), GetIni().WY(), NULL, NULL, hInstance, NULL);
if (!hWnd)
{
return FALSE;
}
ExicCB.m_hWnd=hWnd;
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
return TRUE;
}
//
// FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
//
// PURPOSE: Processes messages for the main window.
//
// WM_COMMAND - process the application menu
// WM_PAINT - Paint the main window
// WM_DESTROY - post a quit message and return
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
LRESULT b;
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
TCHAR szHello[MAX_LOADSTRING];
LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING);
switch (message)
{
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
case IDM_ABOUT:
DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
break;
case IDM_EXIT:
DestroyWindow(hWnd);
break;
default:
b=PExic && PExic->OnCommand(hWnd, wParam, lParam);
if(b)return b;
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_TIMER:
if(PExic)PExic->OnTimer(hWnd,wParam );
break;
case WM_SIZE:
if(PExic)PExic->OnSize(hWnd,wParam, lParam&0xFFFF, lParam>>16);
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
// TODO: Add any drawing code here...
{
TDC dc(hdc);
if(PExic)PExic->OnDraw(dc);
}
//RECT rt;
//GetClientRect(hWnd, &rt);
//DrawText(hdc, szHello, strlen(szHello), &rt, DT_CENTER);
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
b=PExic && PExic->OnMessage(hWnd,message, wParam, lParam);
if(b)return b;
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
// Mesage handler for about box.
LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_INITDIALOG:
return TRUE;
case WM_COMMAND:
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
{
EndDialog(hDlg, LOWORD(wParam));
return TRUE;
}
break;
}
return FALSE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -