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

📄 housekeeper.c

📁 minigui 1.6.10 游戏例子 能对编程有很大启发
💻 C
📖 第 1 页 / 共 2 页
字号:
    mii.typedata    = (DWORD)pcollection_menu[6];    InsertMenuItem(hmnu, 5, TRUE, &mii);    memset (&mii, 0, sizeof(MENUITEMINFO));    mii.type        = MFT_STRING ;    mii.state       = 0;    mii.id          = ID_MAP_G;    mii.typedata    = (DWORD)pcollection_menu[7];    InsertMenuItem(hmnu, 6, TRUE, &mii);    memset (&mii, 0, sizeof(MENUITEMINFO));    mii.type        = MFT_STRING ;    mii.state       = 0;    mii.id          = ID_MAP_H;    mii.typedata    = (DWORD)pcollection_menu[8];    InsertMenuItem(hmnu, 7, TRUE, &mii);    return hmnu;}int TestMyWinProc(HWND hWnd, int message, WPARAM wParam, LPARAM lParam){	HDC hdc;	int iRet;	int x,y;	ptagLevelCollection pTempColl;	ptagLevel pTempLev;	int iDir = 0;	//char strTemp[50];	switch(message){	case MSG_CREATE:		if(!InitializeApp()){            return 1;		}        CtrlInputLevel[0].caption =pmessagebox[1];        CtrlInputLevel[2].caption =pmessagebox[2];        CtrlInputLevel[3].caption =pmessagebox[3];    	DlgInputLevel.controls = CtrlInputLevel;        DlgInputLevel.caption =pmessagebox[0];		break;	case MSG_COMMAND:		switch(LOWORD(wParam)){			case ID_GOTO:    			iRet = DialogBoxIndirectParam(&DlgInputLevel, hWnd, DialogInputLevelProc, 0L);			if ((iRet > 0) && (iRet <= theMap->current->iNoOfLevels)) {				pTempLev = theMap->current->head;				if (pTempLev->iNo != iRet) {					pTempLev = pTempLev->next;					while(pTempLev != theMap->current->head) {						if(pTempLev->iNo == iRet) 							break;						pTempLev = pTempLev->next;					}				}				        if ((pTempLev->iNo == iRet) && (pTempLev != theMap->currentLevel)) {					theMap->current->current = pTempLev;					PlayRestart();					InvalidateRect(hWnd, NULL, TRUE);				}					}			break;		case ID_NEXT:			theMap->current->current = theMap->current->current->next;			PlayRestart();			InvalidateRect(hWnd, NULL, TRUE);			break;		case ID_PREVIOUS:			theMap->current->current = theMap->current->current->prev;			PlayRestart();			InvalidateRect(hWnd, NULL, TRUE);			break;		case ID_RESTART:			PlayRestart();			InvalidateRect(hWnd, NULL, TRUE);			break;		case ID_UNDO:			PlayUndo(hWnd); 			break;		case ID_EXIT:		 	OnClose(hWnd);			break;		case ID_MAP_A:			pTempColl = theMap->head;			if (GotoCollection(pTempColl)) InvalidateRect(hWnd, NULL, TRUE);			break;		case ID_MAP_B:			pTempColl = theMap->head->next;			if (GotoCollection(pTempColl)) InvalidateRect(hWnd, NULL, TRUE);			break;		case ID_MAP_C:			pTempColl = theMap->head->next->next;			if (GotoCollection(pTempColl)) InvalidateRect(hWnd, NULL, TRUE);			break;		case ID_MAP_D:			pTempColl = theMap->head->next->next->next;			if (GotoCollection(pTempColl)) InvalidateRect(hWnd, NULL, TRUE);			break;		case ID_MAP_E:			pTempColl = theMap->tail->prev->prev->prev;			if (GotoCollection(pTempColl)) InvalidateRect(hWnd, NULL, TRUE);			break;		case ID_MAP_F:			pTempColl = theMap->tail->prev->prev;			if (GotoCollection(pTempColl)) InvalidateRect(hWnd, NULL, TRUE);			break;		case ID_MAP_G:			pTempColl = theMap->tail->prev;			if (GotoCollection(pTempColl)) InvalidateRect(hWnd, NULL, TRUE);			break;		case ID_MAP_H:			pTempColl = theMap->tail;			if (GotoCollection(pTempColl)) InvalidateRect(hWnd, NULL, TRUE);			break;		case ID_ABOUT:				            MessageBox (hWnd,                 pmessagebox[4],                pmessagebox[5],                MB_OK | MB_ICONINFORMATION);			break;		}				return 0;	case MSG_LBUTTONDOWN:		x = LOWORD(lParam);		y = HIWORD(lParam);		if (!ptChoosePlace(hWnd, &x, &y))			return 0;		//snprintf(strTemp, 50, "%d:%d", x, y);		//MessageBox(HDC_SCREEN, strTemp, strTemp, MB_OK);		PlayMove(hWnd, x, y);		return 0;	case MSG_RBUTTONDOWN:		PlayUndo(hWnd); 		return 0;	case MSG_PAINT:		hdc = BeginPaint(hWnd);		OnDraw(hWnd,hdc);		EndPaint(hWnd,hdc);		return 0;	case MSG_KEYDOWN:		switch (wParam) {			case SCANCODE_CURSORBLOCKUP:     				iDir = DIR_UP;				break;			case SCANCODE_CURSORBLOCKLEFT:        				iDir = DIR_LEFT;				break;			case SCANCODE_CURSORBLOCKRIGHT:      				iDir = DIR_RIGHT;				break;			case SCANCODE_CURSORBLOCKDOWN:        				iDir = DIR_DOWN;				break;			default:				iDir = -1;		}				if ((iDir != -1) && (PlayKeyboard(hWnd, iDir) == STEP_TYPE_PUSH)){			if (CheckMissionComplete()) {				MessageBox(HDC_SCREEN, pmessagebox[6], pmessagebox[7], MB_OK);				theMap->current->current = theMap->current->current->next;				PlayRestart();				InvalidateRect(hWnd, NULL, TRUE);			}			return 0;		}				if (wParam == SCANCODE_U) 			PlayUndo(hWnd); 		return 0;				case MSG_TIMER:		return 0;			    case MSG_CLOSE:		 OnClose(hWnd);	    	 return 0;	}	return DefaultMainWinProc(hWnd, message, wParam, lParam);}void OnDraw(HWND hWnd,HDC hDC) {	RECT rect;	POINT poStart1;	int iSideLength;	ptagLevel cur_level;	char strText[50];	int iRow;	int iCol;	int i, j;	int iBmp;	GetClientRect(hWnd,&rect);	SetBkColor(hDC,RGB2Pixel(HDC_SCREEN, 102, 102, 102));	//SetTextColor(hDC,COLOR_green);		SetPenColor(hDC,COLOR_black);	poStart1.x = rect.left;	poStart1.y = rect.top;		cur_level = theMap->currentLevel;	snprintf(strText, 50, "Collection %s, Level %d ", theMap->current->strName, cur_level->iNo);		TextOut(hDC, rect.left + 40, rect.bottom - 20, strText);	rect.bottom -= 20;		if (rect.bottom - rect.top < 100)		return;	iRow = cur_level->row;	iCol = cur_level->col;	i = RECTH(rect)/iRow;	j = RECTW(rect)/iCol;	if (i <= j) 		iSideLength = i;	else 			iSideLength = j;		for (i = 0; i < iRow; i++) {		for (j = 0; j < iCol; j++) {			iBmp = cur_level->data[i * iCol + j];			if (iBmp < B_NOTHING) {				FillBoxWithBitmap(hDC, poStart1.x + iSideLength * j \						, poStart1.y + iSideLength * i, iSideLength, iSideLength, &bitmapAll[iBmp]);            }		}    }}void InitMyWinCreateInfo(PMAINWINCREATE pCreateInfo){    pCreateInfo->dwStyle = WS_CAPTION | WS_BORDER | WS_SYSMENU |  WS_VISIBLE| WS_DLGFRAME;    pCreateInfo->dwExStyle = WS_EX_NONE;    pCreateInfo->spCaption=pmessagebox[5];    pCreateInfo->hMenu = createmenu1();    pCreateInfo->hCursor = GetSystemCursor(0);    pCreateInfo->hIcon = 0;    pCreateInfo->MainWindowProc = TestMyWinProc;    pCreateInfo->lx = 512 -WIDTH_LARGEWIN/2;    pCreateInfo->ty = 384 -HEIGHT_LARGEWIN/2;    pCreateInfo->rx =pCreateInfo->lx+ WIDTH_LARGEWIN;    pCreateInfo->by =pCreateInfo->ty+ HEIGHT_LARGEWIN;    pCreateInfo->iBkColor = RGB2Pixel(HDC_SCREEN, 102, 102, 102);     pCreateInfo->dwAddData = 0;    pCreateInfo->hHosting = HWND_DESKTOP;}#ifndef _LITE_VERSION#include <minigui/dti.c>#endifint MiniGUIMain (int args, const char* arg[]){    MSG Msg;    MAINWINCREATE CreateInfo;    HWND hMainWnd;#if defined(_LITE_VERSION) && !(_STAND_ALONE)    int i;    const char* layer = NULL;        for (i = 1; i < args; i++) {        if (strcmp (arg[i], "-layer") == 0) {            layer = arg[i + 1];           // break;        }        else if( strcmp( arg[i], "-lang") == 0)             lang = arg[i+1];    }    //GetLayerInfo (layer, NULL, NULL, NULL);    if (JoinLayer (layer, arg[0], 0, 0) == INV_LAYER_HANDLE) {        printf ("JoinLayer: invalid layer handle.\n");        exit (1);    }#endif    if(strcasecmp(lang,"zh_cn")==0){        printf("\nlanguage=%s",lang);        pmain_menu =main_menu_cn;        pgame_menu =game_menu_cn;        pabout_menu =about_menu_cn;        pcollection_menu =collection_menu_cn;        pmessagebox =messagebox_cn;        printf("\n2language=%s",lang);    }    else if(strcasecmp(lang,"zh_tw")==0){        pmain_menu =main_menu_tw;        pgame_menu =game_menu_tw;        pabout_menu =about_menu_tw;        pcollection_menu =collection_menu_tw;        pmessagebox =messagebox_tw;    }    else if(strcasecmp(lang,"en")==0){        pmain_menu =main_menu_en;        pgame_menu =game_menu_en;        pabout_menu =about_menu_en;        pcollection_menu =collection_menu_en;        pmessagebox =messagebox_en;    }    init_housekeeper();    InitMyWinCreateInfo(&CreateInfo);    hMainWnd = CreateMainWindow(&CreateInfo);    if (hMainWnd == HWND_INVALID)        return -1;    ShowWindow(hMainWnd,SW_SHOWNORMAL);    while( GetMessage(&Msg, hMainWnd) ) {        TranslateMessage (&Msg);        DispatchMessage(&Msg);    }    release_housekeeper();    MainWindowThreadCleanup(hMainWnd);    return 0;}BOOL InitializeApp(void){	if(LoadBitmap(HDC_SCREEN, &bitmapAll[B_GOAL], "res/goal.gif"))		return FALSE;	if(LoadBitmap(HDC_SCREEN, &bitmapAll[B_MAN], "res/man.gif"))		return FALSE;	if(LoadBitmap(HDC_SCREEN, &bitmapAll[B_OBJECT], "res/object.gif"))		return FALSE;	if(LoadBitmap(HDC_SCREEN, &bitmapAll[B_SAVEMAN], "res/saveman.gif"))		return FALSE;	if(LoadBitmap(HDC_SCREEN, &bitmapAll[B_STONE], "res/stone.gif"))		return FALSE;	if(LoadBitmap(HDC_SCREEN, &bitmapAll[B_TREASURE], "res/treasure.gif"))		return FALSE;	InitMap();	return TRUE;}void OnClose(HWND hWnd){	DestroyMap();	UnloadBitmap(&bitmapAll[B_GOAL]);	UnloadBitmap(&bitmapAll[B_MAN]);	UnloadBitmap(&bitmapAll[B_OBJECT]);	UnloadBitmap(&bitmapAll[B_SAVEMAN]);	UnloadBitmap(&bitmapAll[B_STONE]);	UnloadBitmap(&bitmapAll[B_TREASURE]);	DestroyMainWindow (hWnd);	PostQuitMessage (hWnd);}void CovertCoord(HWND hWnd,int *px, int *py){	RECT rect;	int iSideLength;	ptagLevel cur_level;	int iRow;	int iCol;	int i, j;	GetClientRect(hWnd,&rect);	rect.bottom -= 20;		if (rect.bottom - rect.top < 100)		return;	cur_level = theMap->currentLevel;	iRow = cur_level->row;	iCol = cur_level->col;	i = RECTH(rect)/iRow;	j = RECTW(rect)/iCol;	if (i <= j) 		iSideLength = i;	else 			iSideLength = j;		i = *px;	j = *py;	*px = rect.left + i * iSideLength;	*py = rect.top  + j * iSideLength;}BOOL ptChoosePlace(HWND hWnd, int *px, int *py) {	RECT rect;	int iSideLength;	ptagLevel cur_level;	int iRow;	int iCol;	int i, j;	GetClientRect(hWnd,&rect);	rect.bottom -= 20;		if (rect.bottom - rect.top < 100)		return FALSE;	cur_level = theMap->currentLevel;	iRow = cur_level->row;	iCol = cur_level->col;	i = RECTH(rect)/iRow;	j = RECTW(rect)/iCol;	if (i <= j) 		iSideLength = i;	else 			iSideLength = j;		i = *px;	j = *py;	if ( (i > rect.left) && (i < rect.left + iSideLength * iCol) &&	     (j > rect.top ) && (j < rect.top  + iSideLength * iRow) ) {		 *px = (i - rect.left) / iSideLength;		 *py = (j - rect.top ) / iSideLength;		 return TRUE;	}	return FALSE;}void DrawALittleBlock(HWND hWnd, int x, int y, int itype)	{	HDC hdc;	RECT rect;	int iSideLength;	ptagLevel cur_level;	int iRow;	int iCol;	int i, j;	GetClientRect(hWnd,&rect);	rect.bottom -= 20;		if (rect.bottom - rect.top < 100)		return;	cur_level = theMap->currentLevel;	iRow = cur_level->row;	iCol = cur_level->col;	i = RECTH(rect)/iRow;	j = RECTW(rect)/iCol;	if (i <= j) 		iSideLength = i;	else 			iSideLength = j;		i = x;	j = y;	x = rect.left + i * iSideLength;	y = rect.top  + j * iSideLength;	hdc = GetClientDC(hWnd);	if(itype <= B_NOTHING) {		if(itype == B_NOTHING) {			SetBrushColor(hdc,RGB2Pixel(HDC_SCREEN, 102, 102, 102));			FillBox(hdc, x, y, iSideLength, iSideLength);		}		else {			FillBoxWithBitmap(hdc, x, y, iSideLength, iSideLength, &bitmapAll[itype]);        }	}	ReleaseDC(hdc);}

⌨️ 快捷键说明

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