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

📄 q11evc.cpp

📁 涉及的代码是针对WINCE3.0(PPC2002)平台
💻 CPP
📖 第 1 页 / 共 2 页
字号:
					//没有则添加
					SendMessage(hWndFocus,CB_ADDSTRING,0,(LPARAM)strInput);


				}
				break;

		#if _WIN32_WCE
				;	//WINCE下不允许设置
		#else
			case IDC_EDIT_UP:
			case IDC_EDIT_DOWN:
			case IDC_EDIT_LEFT:
			case IDC_EDIT_RIGHT:
			case IDC_EDIT_BOMB:
			case IDC_EDIT_FIRE:
				if(HIWORD(wParam) == EN_SETFOCUS)
				{
					GetCursorPos(&p);
					ScreenToClient(hWndSet,&p);
					GetClientRect(hWndSet,&rcDlg);
					rc.left = p.x;
					rc.right = rc.left + 80;
					if(rc.right>rcDlg.right)
					{
						rc.right = rcDlg.right;
						rc.left = rc.right - 80;
					}
					rc.top = p.y;
					rc.bottom = rc.top + 20;
					hDC = GetDC(hWndSet);
					SetBkMode(hDC, TRANSPARENT);
					SetTextColor(hDC, RGB(255,0,0));
					DrawText(hDC,TEXT("按任意键"),-1,&rc,DT_LEFT);
					do
					{
						//等待键盘按下消息
						MSG msg;
						GetMessage(&msg,NULL,0,0);
						if(msg.message == WM_KEYDOWN)
						{	
							if((vKey = LOWORD(msg.wParam)) != -1)
								bPress = TRUE;
						}
					}while(bPress == FALSE);
					
					swprintf(str,TEXT("%d"),vKey);
					//只检测这些特殊键值,其他特殊的几乎不用
					if( 0 == wcscmp(str,TEXT("16")) )
						wcscpy(str,TEXT("SHIFT"));
					else if( 0 == wcscmp(str,TEXT("17")) )
						wcscpy(str,TEXT("CONTROL"));
					else if( 0 == wcscmp(str,TEXT("32")) )
						wcscpy(str,TEXT("SPACE"));
					else if( 0 == wcscmp(str,TEXT("37")) )
						wcscpy(str,TEXT("LEFT"));
					else if( 0 == wcscmp(str,TEXT("38")) )
						wcscpy(str,TEXT("UP"));
					else if( 0 == wcscmp(str,TEXT("39")) )
						wcscpy(str,TEXT("RTGHT"));
					else if( 0 == wcscmp(str,TEXT("40")) )
						wcscpy(str,TEXT("DOWN"));
					else	
						swprintf(str,TEXT("%c"),vKey);

					SetWindowText(::GetFocus(),str);

					//SendMessage(hWndSet,WM_NEXTDLGCTL,0,0);
					InvalidateRect(hWndSet,&rc,TRUE);

					DeleteDC(hDC);

				} //end if(HIWORD(wParam) == EN_SETFOCUS) here

				break;
		#endif

			} //end switch(LOWORD(wParam)) here

			break;
	
	}

    return FALSE;

}
//------------------------------------------------------------------------------
//关于窗口回调函数
LRESULT CALLBACK About(HWND hDlg,UINT message,WPARAM wParam,LPARAM lParam)
{
	#if _WIN32_WCE
	SHINITDLGINFO shidi;
	#endif

	switch (message)
	{
		case WM_INITDIALOG:
			// Create a Done button and size it.  
			#if _WIN32_WCE
			shidi.dwMask = SHIDIM_FLAGS;
			shidi.dwFlags = SHIDIF_DONEBUTTON | SHIDIF_SIPDOWN | SHIDIF_SIZEDLGFULLSCREEN;
			shidi.hDlg = hDlg;
			SHInitDialog(&shidi);
			#endif
			return TRUE; 
		case WM_COMMAND:
			if (LOWORD(wParam)==IDOK || LOWORD(wParam)==IDCANCEL)
			{
				EndDialog(hDlg, LOWORD(wParam));
				return TRUE;
			}
			break;
	}
    return FALSE;

}
//------------------------------------------------------------------------------
//使一个窗口相对于另外一个窗口居中,并不一定要父子关系
void CenterWindow(HWND hWndChild, HWND hWndParent)
{
	POINT pt;
	RECT rectChild, rectParent;

	//ASSERT(hWndChild != NULL && hWndParent != NULL );

	GetWindowRect(hWndChild, &rectChild);
	GetWindowRect(hWndParent, &rectParent);

	pt.x = ((rectParent.right - rectParent.left) - (rectChild.right - rectChild.left))/2;
	pt.y = ((rectParent.bottom - rectParent.top) - (rectChild.bottom - rectChild.top))/2;

	MoveWindow(hWndChild, rectParent.left + pt.x, rectParent.top + pt.y, 
				rectChild.right-rectChild.left, rectChild.bottom-rectChild.top,	TRUE);
}
//------------------------------------------------------------------------------
//创建菜单条
HWND CreateRpCommandBar(HWND hwnd)
{
	#if _WIN32_WCE
	SHMENUBARINFO mbi;

	memset(&mbi, 0, sizeof(SHMENUBARINFO));
	mbi.cbSize     = sizeof(SHMENUBARINFO);
	mbi.hwndParent = hwnd;
	mbi.nToolBarId = IDR_MENU_MAIN;
	mbi.hInstRes   = g_hInst;
	mbi.nBmpId     = 0;
	mbi.cBmpImages = 0;

	if (!SHCreateMenuBar(&mbi)) 
		return NULL;

	return mbi.hwndMB;
	#else
	return NULL;
	#endif

}
//------------------------------------------------------------------------------
//释放资源
void FreeAll(void)
{
	if(NULL != game)
		delete game;

}
//------------------------------------------------------------------------------
//读配置文件
void IniRead()
{
	HWND hWndChild;
	DWORD dwRd;
	int a,i;

	CGameSet *gameset = new struct CGameSet;
	ZeroMemory(gameset,sizeof(CGameSet));

	HANDLE hf = CreateFile(iniFile, GENERIC_READ, FILE_SHARE_WRITE|FILE_SHARE_READ, NULL, 
			          OPEN_ALWAYS, 0, NULL);
	if (hf == INVALID_HANDLE_VALUE) return;

	SetFilePointer(hf, 0, NULL, FILE_BEGIN);
	ReadFile(hf, gameset, sizeof(CGameSet), &dwRd, NULL);
	
	//user
	hWndChild = GetDlgItem(hWndDlgSet,IDC_CMBUSER);
	a = gameset->iUserTotal;
	for(i=0;i<a;i++)
		SendMessage(hWndChild,CB_ADDSTRING,0,(LPARAM)gameset->User[i]); 
	
	SendMessage(hWndChild,CB_SETCURSEL,gameset->iUserIndex,0);

	//级别
	hWndChild = GetDlgItem(hWndDlgSet,IDC_CMBLEVEL);
	for(i=0;i<4;i++)
		SendMessage(hWndChild,CB_ADDSTRING,0,(LPARAM)gameset->Level[i]); 

	SendMessage(hWndChild,CB_SETCURSEL,gameset->iLevelIndex,0);

	//控制
	int id = 2000; //resouce.h IDC_EDIT_UP必须从这个值开始
	for(i=0;i<7;i++)
	{
		hWndChild = GetDlgItem(hWndDlgSet,id);
		SetWindowText(hWndChild,gameset->Key[i] );
		
		id++;
	}

	#if !_WIN32_WCE
		if( 0 == gameset->iAutoFire )
			CheckDlgButton(hWndDlgSet,IDC_CHECK_AUTOFIRE,BST_UNCHECKED);
		else
			CheckDlgButton(hWndDlgSet,IDC_CHECK_AUTOFIRE,BST_CHECKED);
	#endif

	CloseHandle(hf);
	ZeroMemory(gameset,sizeof(CGameSet));
	if(NULL != gameset)
		delete gameset;


}
//------------------------------------------------------------------------------
//写配置文件
void IniWrite()
{
	CGameSet *gameset = new CGameSet;

	HWND hWndChild;
	DWORD dwWt;
	int a,i;

	HANDLE hf = CreateFile(iniFile, GENERIC_WRITE, FILE_SHARE_WRITE|FILE_SHARE_READ, NULL, 
			          OPEN_ALWAYS, 0, NULL);
	if (hf == INVALID_HANDLE_VALUE) return;
	
	//user
	hWndChild = GetDlgItem(hWndDlgSet,IDC_CMBUSER);
	GetWindowText(hWndChild,gameset->UserCur,256);
	a = SendMessage(hWndChild,CB_GETCURSEL,0,0); 
	gameset->iUserIndex = a;
	a = SendMessage(hWndChild,CB_GETCOUNT,0,0);	
	gameset->iUserTotal = a;
	for(i=0;i<a;i++)
		SendMessage(hWndChild,CB_GETLBTEXT,i,(LPARAM)(LPCSTR)gameset->User[i]);
		
	//级别
	hWndChild = GetDlgItem(hWndDlgSet,IDC_CMBLEVEL);
	a = SendMessage(hWndChild,CB_GETCURSEL,0,0); 
	gameset->iLevelIndex = a;
	gameset->iLevelTotal = 4;
	for(i=0;i<4;i++)
		SendMessage(hWndChild,CB_GETLBTEXT,i,(LPARAM)(LPCSTR)gameset->Level[i]);

	//控制
	int id = 2000; //resouce.h IDC_EDIT_UP必须从这个值开始
	for(i=0;i<7;i++)
	{
		hWndChild = GetDlgItem(hWndDlgSet,id);
		GetWindowText(hWndChild,gameset->Key[i],256);

		id++;
	}

	#if !_WIN32_WCE
		if( BST_CHECKED == IsDlgButtonChecked(hWndDlgSet,IDC_CHECK_AUTOFIRE) )
			gameset->iAutoFire = 1;
		else
			gameset->iAutoFire = 0;
	#endif
	

	WriteFile(hf,gameset,sizeof(CGameSet),&dwWt,NULL);

	CloseHandle(hf);

	if(NULL != gameset)
		delete gameset;


}
//------------------------------------------------------------------------------
//键值检测,是否重复
//这里检测有点小小问题,如果自动开火是选择的,还是计算了IDC_EDIT_FIRE的键值,
//没有过滤,不想去判断了:-)
BOOL KeyCheck()
{
	#if !_WIN32_WCE

	HWND hWndChild;
	TCHAR tmp[256]={'\0'};
	TCHAR str1[256]={'\0'};
	TCHAR str2[256]={'\0'};

	//resouce.h IDC_EDIT_UP必须从这个值开始
	for(int i=2000;i<2006;i++)
	{
		hWndChild = GetDlgItem(hWndDlgSet,i);
		GetWindowText(hWndChild,str1,256);
		if( 0 == wcscmp(str1,TEXT("")) ) continue;

		for(int x=2000;x<2006;x++)
		{
			if(i == x) 
				x++;

			hWndChild = GetDlgItem(hWndDlgSet,x);
			GetWindowText(hWndChild,str2,256);
			if( 0 == wcscmp(str2,TEXT("")) ) continue;

			if( 0 == wcscmp(str1,str2) )
			{
				wcscpy(tmp,TEXT("存在重复键值:"));
				wcscat(tmp,str1);
				Msg(tmp);
				return FALSE;
			}

		}

	}

	#endif

	return TRUE;
}
//------------------------------------------------------------------------------
//缺省设置
void KeyDefault()
{
	HWND hWndChild;
	//USER就不管了
	//级别
	hWndChild = GetDlgItem(hWndDlgSet,IDC_CMBLEVEL);
	int a = 4;
	while(a>=0)
	{
		//清空先
		SendMessage(hWndChild,CB_DELETESTRING,a,0);
		a--;
	}
	SendMessage(hWndChild,CB_ADDSTRING,0,(LPARAM)TEXT("正常级")); 
	SendMessage(hWndChild,CB_ADDSTRING,1,(LPARAM)TEXT("高手级"));
	SendMessage(hWndChild,CB_ADDSTRING,2,(LPARAM)TEXT("魔鬼级")); 
	SendMessage(hWndChild,CB_ADDSTRING,3,(LPARAM)TEXT("不可能级")); 
	SendMessage(hWndChild,CB_SETCURSEL,0,0);
	//控制
	int id = 2000; //resouce.h IDC_EDIT_UP必须从这个值开始
	hWndChild = GetDlgItem(hWndDlgSet,id);
	SetWindowText(hWndChild,TEXT("UP"));
	id++;
	hWndChild = GetDlgItem(hWndDlgSet,id);
	SetWindowText(hWndChild,TEXT("DOWN"));
	id++;
	hWndChild = GetDlgItem(hWndDlgSet,id);
	SetWindowText(hWndChild,TEXT("LEFT"));
	id++;
	hWndChild = GetDlgItem(hWndDlgSet,id);
	SetWindowText(hWndChild,TEXT("RIGHT"));
	id++;
	hWndChild = GetDlgItem(hWndDlgSet,id);
	SetWindowText(hWndChild,TEXT("CONTROL"));
	id++;
	hWndChild = GetDlgItem(hWndDlgSet,id);
	SetWindowText(hWndChild,TEXT("SPACE"));
	id++;
	hWndChild = GetDlgItem(hWndDlgSet,id);
	SetWindowText(hWndChild,TEXT("3"));	//3个雷

	#if !_WIN32_WCE
	CheckDlgButton(hWndDlgSet,IDC_CHECK_AUTOFIRE,BST_UNCHECKED);
	#endif
	
}

⌨️ 快捷键说明

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