⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 win32集成.cpp

📁 VC读写文件 等值线等值线等值线等值线等值线等值线等值线等值线等值线等值线等值线
💻 CPP
📖 第 1 页 / 共 2 页
字号:
			rear++;que[rear].x=x2;que[rear].y=y2;QP[x2][y2]=2;
			flag=1;
		}
		while(rear>=front&&flag==1){
			int m=que[front].x;
			int n=que[front].y;
			front++;
			for(int h=0;h<4;h++){
				int x2=m+di[h][0];int y2=n+di[h][1];
				if(QP[x2][y2]==wb){
					rear++;que[rear].x=x2;que[rear].y=y2;QP[x2][y2]=2;
				}
				else if(QP[x2][y2]==0){
					flag=0;
					break;
				}
			}
		}
		for(int k=0;k<=rear;k++){
			int m,n;
			if(flag==0){//证明有出路
				m=que[k].x;n=que[k].y;
				QP[m][n]=wb;
			}
			else{//证明没有出路
				cankill=1;
				m=que[k].x;n=que[k].y;
				QP[m][n]=0;
			}
		}
	}
	return cankill;
}
int WqQP::canplace(HDC hdc,int wb){
	struct QUEUE{
		int x;int y;
	};
	struct QUEUE que[200];
	int front;int rear;
	front=0;rear=-1;
	int flag=0;
	int di[4][2]={{-1,0},{0,-1},{1,0},{0,1}};
	int i=XX();int j=YY();
	rear++;que[rear].x=i;que[rear].y=j;QP[i][j]=2;
	flag=1;
	while(rear>=front&&flag==1){
			i=que[front].x;
			j=que[front].y;
			front++;
			for(int h=0;h<4;h++){
				int x2=i+di[h][0];int y2=j+di[h][1];
				if(QP[x2][y2]==wb){
					rear++;que[rear].x=x2;que[rear].y=y2;QP[x2][y2]=2;
				}
				else if(QP[x2][y2]==0){
					flag=0;
					break;
				}
			}
	}
	for(int k=0;k<=rear;k++){
		int m,n;
		m=que[k].x;n=que[k].y;
		QP[m][n]=wb;
	}
	if(flag==0) return 	1;//说明该点能下
	else{ 
		QP[XX()][YY()]=0;
		return 0;//说明该点不能下
	}
}
//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
	WqQP wqqpdy;
	WqQP wqqpmj;
	int wqdy=0;
	int fraction=0;
	int wqmj=0;
	int endWq=0;
	int missile=0;
	int n=1;

	char temp_str[10];
// Global Variables:
HINSTANCE hInst;								// current instance
TCHAR szTitle[MAX_LOADSTRING];								// The title bar text
TCHAR szWindowClass[MAX_LOADSTRING];								// The title bar text

// 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);
LRESULT CALLBACK    WQWndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK    Input(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
 	// TODO: Place code here.
	MSG msg;
	HACCEL hAccelTable;
	// Initialize global strings
	LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
	LoadString(hInstance, IDC_WIN32, szWindowClass, MAX_LOADSTRING);
	MyRegisterClass(hInstance);
	// Perform application initialization:
	if (!InitInstance (hInstance, nCmdShow)) {
		return FALSE;
	}
	hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_WIN32);
	// Main message loop:
	while (GetMessage(&msg, NULL, 0, 0)) 
	{
		if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) 
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
	}

	return msg.wParam;
}

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_WIN32);
	wcex.hCursor		= LoadCursor(NULL, IDC_ARROW);
	wcex.hbrBackground	= (HBRUSH)(COLOR_WINDOW+1);
	wcex.lpszMenuName	= (LPCSTR)IDC_WIN32;
	wcex.lpszClassName	= szWindowClass;
	wcex.hIconSm		= LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);

	return RegisterClassEx(&wcex);
}

BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
   HWND hWnd;
   hInst = hInstance; // Store instance handle in our global variable
   hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
      CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
   if (!hWnd){
      return FALSE;
   }
   ShowWindow(hWnd, nCmdShow);
   UpdateWindow(hWnd);

   return TRUE;
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	int wmId, wmEvent;
	PAINTSTRUCT ps;
	HDC hdc;
	TCHAR szHello[MAX_LOADSTRING];
	LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING);
	int i=0,j;
	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_WQJS:
				   DialogBox(hInst, (LPCTSTR)IDD_DIALOG2, hWnd, (DLGPROC)Input);
				   break;
				case IDM_EXIT:
				   DestroyWindow(hWnd);
				   break;
				case IDM_WQMJ:
					wqmj=1;
					wqdy=0;step=0;
					fraction=0;missile=0;
					transfile(hWnd);			
					wqqpmj.play3(GetDC(hWnd),hWnd);//棋谱
					InvalidateRect(hWnd,NULL,1);
					UpdateWindow(hWnd);
					break;
				case IDM_WQDY:
                 	wqdy=1;
					wqmj=0;
					fraction=0;
					for(i=1;i<20;i++)
						for(j=1;j<20;j++){
							wqqpdy.QP[i][j]=0;
							wqqpmj.QP[i][j]=0;
						}
					i=0;step=0;missile=0;
					InvalidateRect(hWnd,NULL,1);
					UpdateWindow(hWnd);
					break;
				case IDM_EXITFRACTION:
					fraction=0;
					for(i=1;i<20;i++)
						for(j=1;j<20;j++){
							wqqpdy.QP[i][j]=0;
							wqqpmj.QP[i][j]=0;
						}
					i=0;step=0;missile=0;
					InvalidateRect(hWnd,NULL,1);
					UpdateWindow(hWnd);
					break;
				case IDM_QUITWQ:
					step=0;
					wqdy=0;
					wqmj=0;
					for(i=1;i<20;i++)
						for(j=1;j<20;j++){
							wqqpdy.QP[i][j]=0;
							wqqpmj.QP[i][j]=0;
						}
					i=0;
					step=0;
					missile=0;
	               	InvalidateRect(hWnd,NULL,1);
					UpdateWindow(hWnd);
					break;
				case IDM_DT:
					missile=1;
					wqdy=0;wqmj=0;fraction=0;
					for(i=1;i<20;i++)
						for(j=1;j<20;j++){
							wqqpdy.QP[i][j]=0;
							wqqpmj.QP[i][j]=0;
						}
					i=0;step=0;
	               	InvalidateRect(hWnd,NULL,1);
					UpdateWindow(hWnd);
					break;
				case IDM_LEAF:
					fraction=1;
					missile=0;
					wqmj=0;
					wqdy=0;
					for(i=1;i<20;i++)
						for(j=1;j<20;j++){
							wqqpdy.QP[i][j]=0;
							wqqpmj.QP[i][j]=0;
						}
					i=0;step=0;
                	InvalidateRect(hWnd,NULL,1);
					UpdateWindow(hWnd);
					break;

				default:
				   return DefWindowProc(hWnd, message, wParam, lParam);
			}
			break;
		case WM_PAINT:
			hdc = BeginPaint(hWnd, &ps);
			if(wqmj==1){

				wqqpmj.drawQP(hdc);
			}
			if(wqdy==1){
				wqqpdy.drawQP(hdc);
			}
			if(fraction==1){
				HPEN hPen,hOldPen;
				hPen=CreatePen(PS_DOT,1,RGB(0,255,0));
				hOldPen=(HPEN)SelectObject(hdc,hPen);//使用绿色画笔画图
				SelectObject(hdc,hPen);
			    DrawTree(hdc, 400, 550, 100, 1.57,20);
				SelectObject(hdc,hOldPen);
				DeleteObject(hPen);
			}
			if(missile==1){
				HPEN hPen,hOldPen;
				hPen=CreatePen(PS_DOT,1,RGB(0,255,0));
				hOldPen=(HPEN)SelectObject(hdc,hPen);//使用绿色画笔画图
				SelectObject(hdc,hPen);
				purse(hdc);
			}
			EndPaint(hWnd, &ps);
			break;
		case WM_LBUTTONDOWN:
			if(wqdy==1){
					wqqpdy.transSB(LOWORD(lParam),HIWORD(lParam));//将鼠标坐标换算为棋盘坐标(XX(),YY())           
					wqqpdy.play1(GetDC(hWnd),hWnd);//二人对弈
			}
			break;
		case WM_DESTROY:
			PostQuitMessage(0);
			break;
		default:
			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;
}
LRESULT CALLBACK Input(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
	switch (message)
	{
		case WM_INITDIALOG:
				return TRUE;
		case WM_COMMAND:
		switch(LOWORD(wParam))
		{
			case IDOK:
				EndDialog(hDlg,0);
				temp_str[0]='\0';
				str[0]='\0';
				GetDlgItemText(hDlg,IDC_EDIT1,temp_str,3);
				strcat(str,"Qp5_");
				strcat(str,temp_str);
				strcat(str,".gos");
				
				return 1;
			case IDCANCEL:
				EndDialog(hDlg,0);
				return 1;
		}
	}
	return 0;
}
			
			
			

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -