Форум программистов
 

Восстановите пароль или Зарегистрируйтесь на форуме, о проблемах и с заказом рекламы пишите сюда - alarforum@yandex.ru, проверяйте папку спам!

Вернуться   Форум программистов > Низкоуровневое программирование > Win Api
Регистрация

Восстановить пароль
Повторная активизация e-mail

Купить рекламу на форуме - 42 тыс руб за месяц

Ответ
 
Опции темы Поиск в этой теме
Старый 14.11.2010, 17:28   #1
valdemar593
Пользователь
 
Регистрация: 22.12.2009
Сообщений: 20
По умолчанию Beta версия флеш игры =)

Здравствуйте граждане.
Не кидает в обработку сообщения TIMER не пойму почему
Код:
//2.cpp#include <Windows.h>
#include "resource.h"



class Wnd
{
protected:
	WNDCLASSEX wc;
	HWND hWnd;
public:
	Wnd(LPCTSTR windowName, HINSTANCE hInst, int cmdShow, LRESULT (WINAPI *pWndProc)(HWND, UINT, WPARAM, LPARAM),
		LPCTSTR menuName = NULL, int x = CW_USEDEFAULT, int y = 0, int width = CW_USEDEFAULT, int height = 0,
		UINT classStyle = CS_HREDRAW | CS_VREDRAW, DWORD windowStyle = WS_OVERLAPPEDWINDOW, HWND hParent = NULL)
	{
		wc.cbClsExtra = 0;
		wc.cbSize = sizeof(WNDCLASSEX);
		wc.cbWndExtra = 0;
		wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
		wc.hCursor = LoadCursor(NULL, IDC_ARROW);
		wc.hIcon = LoadIcon(hInst, MAKEINTRESOURCE(IDI_ICON));
		wc.hIconSm = LoadIcon(hInst, MAKEINTRESOURCE(IDI_ICON));
		wc.hInstance = hInst;
		wc.lpfnWndProc = pWndProc;
		wc.lpszClassName = "Wnd";
		wc.lpszMenuName = menuName;
		wc.style = classStyle;
		if (!RegisterClassEx(&wc))
			MessageBox(NULL, "Не получается зарегестрировать класс Wnd", "Error", MB_OK | MB_SYSTEMMODAL | MB_ICONERROR);
		hWnd = CreateWindow("Wnd", windowName, windowStyle, x, y, width, height, hParent, (HMENU)NULL, hInst, NULL); 
		if (!hWnd)
		{
			char text[100] = "Не получается создать окно ";
			strcat(text, windowName);
			MessageBox(NULL, text, "Error", MB_SYSTEMMODAL | MB_ICONERROR | MB_OK);
		}
		ShowWindow(hWnd, cmdShow);
	}
	HWND GetHwnd() { return hWnd; }
};

Код:
//1.cpp
#include "2.cpp"
#include <cstdlib>
#include <time.h>



BOOL CALLBACK DifficultyDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
int InitOneCR(RECT &rect);
int IsInRect(int x, int y);
bool MaxPops();
void Draw(HDC &hDC, HDC &hMeMDC, HBITMAP &hBitmap, int i);



static struct CnT
{
	int rTIMER;
	RECT *rShotRects;
} *cnt;
static const int TIMER = WM_TIMER + 100;
static const int TIMER1 = WM_TIMER + 1;
static const int TIMER2 = WM_TIMER + 2;
static const int TIMER3 = WM_TIMER + 3;
static const int TIMER4 = WM_TIMER + 4;
static const int TIMER5 = WM_TIMER + 5;
static bool bStart = false, gameover = false;
static int difficulty;
static int amount;
static int speed;



int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int iShowCmd)
{
	MSG msg;
	Wnd("Робин Гуд", hInstance, iShowCmd, WndProc, MAKEINTRESOURCE(IDR_MENU1),
		200, 200, 700, 700);
	while (GetMessage(&msg, NULL, 0, 0))
	{
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}
	return msg.wParam;
}


/*
// Определить объект совместимого контекста 
HDC hMemDC; 
// Создать совместимый контекст 
hMemDC = CreateCompatibleDC(hDC); 
// Выбрать DDB-растр в совместимый контекст 
SelectObject(hMemDC. hBitmap); 
// Скопировать изображение из hMemDC в hDC 
BitBltChOC, 0. 0, bmpWidth, bmpHeight. hMemDC. 0, 0, SRCCOPY): 
// Удалить совместимый контекст 
DeleteDC(hMemDC): 
*/


BOOL CALLBACK DifficultyDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	switch (uMsg)
	{
	case WM_INITDIALOG:
		return TRUE;
	case WM_COMMAND:
		switch (LOWORD(wParam))
		{
		case IDC_GOSU:
		case IDC_HASU:
		case IDC_NOOB:
			bStart = true;
			CheckRadioButton(hDlg, IDC_GOSU, IDC_NOOB, LOWORD(wParam));
			difficulty = LOWORD(wParam);
			return TRUE;
		case IDOK:
			EndDialog(hDlg, 1);
			return TRUE;
		}
		return FALSE;
	default:
		break;
	}
	return FALSE;
}



int IsInRect(int x, int y)
{
	for (int i = 0; i < amount; i++)
		if ((y < cnt[i].rShotRects->top && y > cnt[i].rShotRects->bottom)
			&& (x > cnt[i].rShotRects->left && x < cnt[i].rShotRects->right))
			return i;
	return 0;
}



bool MaxPops()
{
	for (int i = 0; i < amount; i++)
		if (cnt[i].rShotRects == NULL)
			return false;
	return true;
}



int InitOneCR(RECT &rect)
{
	int i;
	srand(time(NULL));
	int x = rand() % (rect.right - 30) + rect.left;
	srand(time(NULL));
	int y = rand() % (rect.bottom - 30) + rect.top;
	for (i = 0; i < amount; i++)
		if (cnt[i].rShotRects == NULL)
			break;
	cnt[i].rShotRects = new RECT();
	cnt[i].rShotRects->left = x;
	cnt[i].rShotRects->top = y;
	cnt[i].rShotRects->right = x + 30;
	cnt[i].rShotRects->bottom = y + 30;
	return i;
}



void Draw(HDC &hDC, HDC &hMemDC, HBITMAP &hBitmap, int i)
{
	hMemDC = CreateCompatibleDC(hDC);
	SelectObject(hMemDC, hBitmap);
	BitBlt(hDC, cnt[i].rShotRects->left, cnt[i].rShotRects->top, 
		30, 30, hMemDC, 0, 0, SRCCOPY);
	DeleteDC(hMemDC);
}
}
valdemar593 вне форума Ответить с цитированием
Старый 14.11.2010, 17:29   #2
valdemar593
Пользователь
 
Регистрация: 22.12.2009
Сообщений: 20
По умолчанию

Код:
LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	RECT rect;
	PAINTSTRUCT ps;
	static HDC hDC;
	static HDC hMemDC;
	int i;
	static HBITMAP hBitmap, hEBitmap;
	switch (uMsg)
	{
	case WM_CREATE:
		hBitmap = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_BITMAP1));
		hEBitmap = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_BITMAP2));
		break;
	case WM_COMMAND:
		switch (LOWORD(wParam))
		{
		case IDM_SETD:
			DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_DIALOG1), hWnd, DifficultyDlgProc);
			break;
		case IDM_NEWG:
			if (!bStart)
			{
				MessageBox(NULL, "А сложность кто выбирать будет?", "", MB_OK | MB_ICONWARNING);
				break;
			}
			switch (difficulty)
			{
			case IDC_GOSU:
				amount = 5;
				speed = 700;
				break;
			case IDC_HASU:
				amount = 4;
				speed = 1000;
				break;
			case IDC_NOOB:
				amount = 3;
				speed = 1500;
				break;
			}
			cnt = new CnT[amount];
			for (int i = 0; i < amount; i++)
			{
				cnt[i].rTIMER = WM_TIMER + i + 1;
				cnt[i].rShotRects = new RECT;
			}
			SetTimer(hWnd, TIMER, speed, NULL);
			break;
		}
		break;
	case WM_LBUTTONDOWN:
		{
			int x = LOWORD(lParam);
			int y = HIWORD(lParam);
			int I = IsInRect(x, y);
			if (I)
			{
				KillTimer(hWnd, cnt[i].rTIMER);
				Draw(hDC, hMemDC, hEBitmap, I);
				delete cnt[i].rShotRects;
				cnt[i].rShotRects = NULL;
				InvalidateRect(hWnd, NULL, FALSE);
			}
		}
		break;
	case TIMER:
		if (!MaxPops())
		{
			GetClientRect(hWnd, &rect);
			i = InitOneCR(rect);
			SetTimer(hWnd, cnt[i].rTIMER, speed, NULL);
			Draw(hDC, hMemDC, hBitmap, i);
			InvalidateRect(hWnd, NULL, FALSE);
		}
		break;
	case TIMER1:
	case TIMER2:
	case TIMER3:
	case TIMER4:
	case TIMER5:
		gameover = true;
		KillTimer(hWnd, TIMER);
		GetClientRect(hWnd, &rect);
		InvalidateRect(hWnd, NULL, TRUE);
		break;
	case WM_PAINT:
		hDC = BeginPaint(hWnd, &ps);
		if (gameover)
			DrawText(hDC, "GAME OVER", -1, &rect, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
		EndPaint(hWnd, &ps);
		break;
	case WM_DESTROY:
		PostQuitMessage(0);
		break;
	default:
		return DefWindowProc(hWnd, uMsg, wParam, lParam);
	}
	return 0;
}
valdemar593 вне форума Ответить с цитированием
Ответ


Купить рекламу на форуме - 42 тыс руб за месяц



Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
совместим ли Microsoft Office Professional Plus 2010 Beta (x86) с Windows Xp Professional версия 2002 Ser syperman Microsoft Office Word 1 17.10.2010 17:00
Загрузка Флеш игры dima1 Свободное общение 1 13.08.2010 16:30
Аудиобайт 0.8 beta версия Манжосов Денис :) Софт 15 14.10.2009 17:26
Почему лицензионная версия продукта дороже чем пиратская версия продукта? multik Свободное общение 13 13.07.2008 14:40
У меня свой сайт я хочу зделать онлайн игру! помогите те кто умеет делать флеш игры! Denfer Свободное общение 1 07.08.2007 14:06