EventReceiver trouble.

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Roman B.
Posts: 9
Joined: Wed Mar 10, 2010 8:04 am
Location: Russia
Contact:

EventReceiver trouble.

Post by Roman B. »

Sorry for language, English is not my native.

I use irrlicht in win32 window and get problems with EventReceiver.
All my code is like tutorials and everything works, but if my program lost focus and then focused back, EventReceiver not works, and program not response thats any key pressed.

my code:

Receiver:

Code: Select all

class MyEventReceiver : public IEventReceiver
{
public:
	virtual bool OnEvent(const SEvent& event)
	{
	if (event.EventType == EET_KEY_INPUT_EVENT && !event.KeyInput.PressedDown)
	{
	switch (event.KeyInput.Key)
	{
		case KEY_UP:
		{
			int i = tours.hotelindexdec(device);
			return true;
		}
		case KEY_DOWN:
		{
			int i = tours.hotelindexinc(device);
			return true;
		}
		case KEY_LEFT:
		{
			int i = tours.tourindexdec(device);
			return true;
		}
		case KEY_RIGHT:
		{			
			int i = tours.tourindexinc(device);
			return true;
		}
		case KEY_SPACE:
		{	
			int i = tours.StartTimer(device);
			i = tours.tourrunswitch();
			return true;
		}
	}	
	}

	if (event.EventType == EET_KEY_INPUT_EVENT && event.KeyInput.PressedDown)
	{
	switch (event.KeyInput.Key)
	{
		case KEY_KEY_W:
		{
			//move = 1;
			return true;
		}
		case KEY_KEY_S:
		{
			//move = -1;
			return true;
		}
		case KEY_KEY_A:
		{
			//rotate = -1;
			return true;
		}
		case KEY_KEY_D:
		{
			//rotate = 1;
			return true;
		}
		case KEY_ESCAPE:
		{
			DestroyWindow(hWnd);
			PostQuitMessage(0);
			device->drop();

			if (cc) closesocket(cc);
			if (cc1) closesocket(cc1);
			exit(-1);
		}
	}
	}
	return false;
    }
 };
Create window and device:

Code: Select all

int main()
{

	//Объявление переменных:
	int i;
	HINSTANCE hInstance = 0;
	const wchar_t* Win32ClassName = L"CIrrlichtWindowsTestDialog";
	//int windowWidth = 1280;
	//int windowHeight = 1024;
	int windowWidth = 1920;
	int windowHeight = 1200;

	HWND hIrrlichtWindow;
	SIrrlichtCreationParameters param;
	MyEventReceiver receiver;

	WNDCLASSEX wcex;
	wcex.cbSize			= sizeof(WNDCLASSEX);
	wcex.style			= CS_HREDRAW | CS_VREDRAW;
	wcex.lpfnWndProc	= (WNDPROC)CustomWndProc;
	wcex.cbClsExtra		= 0;
	wcex.cbWndExtra		= DLGWINDOWEXTRA;
	wcex.hInstance		= hInstance;
	wcex.hIcon			= NULL;
	wcex.hCursor		= LoadCursor(NULL, IDC_ARROW);
	wcex.hbrBackground	= (HBRUSH)(COLOR_WINDOW);
	wcex.lpszMenuName	= 0;
	wcex.lpszClassName	= Win32ClassName;
	wcex.hIconSm		= 0;

	RegisterClassEx(&wcex);

	DWORD style = WS_SYSMENU | WS_BORDER | WS_CAPTION | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_MAXIMIZEBOX | WS_MINIMIZEBOX | WS_SIZEBOX;
	//DWORD style = WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_MAXIMIZEBOX | WS_MINIMIZEBOX | WS_SIZEBOX;

	hWnd = CreateWindow( Win32ClassName, L"ООО 'Техногрупп' SunWings TourInformer",style, 0, 0, windowWidth, windowHeight, NULL, NULL, hInstance, NULL);

	RECT clientRect;
	GetClientRect(hWnd, &clientRect);
	windowWidth = clientRect.right;
	windowHeight = clientRect.bottom;

	//Создания окна для вывода графики через IrrLight
	hIrrlichtWindow = CreateWindow(L"BUTTON", L"", WS_CHILD | WS_VISIBLE | BS_OWNERDRAW, 0, 0, 1919, 1199, hWnd, NULL, hInstance, NULL);

	param.WindowId = reinterpret_cast<void*>(hIrrlichtWindow); // hColorButton
	//param.DriverType = video::EDT_DIRECT3D9;
	param.DriverType = video::EDT_OPENGL;
	param.Stencilbuffer = false;
	param.AntiAlias =false;
	param.Bits = 16;
	param.HighPrecisionFPU = true;
	param.ZBufferBits = 8;
	param.EventReceiver = &receiver;
	
	//param.Bits = 32;

	//printf("Waiting 10 seconds for system start... \n");
	//Sleep(10000);
	device = createDeviceEx(param);
    if (device == 0) return 1; // could not create selected driver.

	driver = device->getVideoDriver();
	smgr = device->getSceneManager();
	guienv = device->getGUIEnvironment();
	//device->getCursorControl()->setVisible(false); //Прячем указатель мыши.


	////////////////////////////////////////////////////////////////////////
	i = WSAStartup(0x0101,&Wsa); //Инициализация Winsock. Без этой функции сеть работать не будет. Ошибка возможна из-за неправильной настройки сети или случайного удаления файла winsock.dll

	//инициализация структуры типа сообщений, адреса и порта для передачи и приёма данных
	Addr.sin_family=AF_INET;
	Addr.sin_addr.s_addr=INADDR_ANY;
	Addr.sin_port=htons(PORT);

	Addr1.sin_family=AF_INET;
	Addr1.sin_addr.s_addr=INADDR_ANY;
	Addr1.sin_port=htons(PORT1);

	m_Port1=PORT1;
    m_Address1=DEF_HOSTADDR; //в графе IP ADRESS прописывается адрес LOOPBACK по умолчанию 127.0.0.1, т.е.локальный адрес
    m_Mask1="255.255.255.0"; //в графе MASK задаётся маска сети
	m_Interface1="2"; //в графе № Interface задаётся интерфейс, изначально 2, применяется для создания дополнительного нового IP адреса интерфейс вы можете посмотреть, нажав клавишу INFO

	m_Port=PORT;
    m_Address=DEF_HOSTADDR; //в графе IP ADRESS прописывается адрес LOOPBACK по умолчанию 127.0.0.1, т.е.локальный адрес
    m_Mask="255.255.255.0"; //в графе MASK задаётся маска сети
	m_Interface="2"; //в графе № Interface задаётся интерфейс, изначально 2, применяется для создания дополнительного но

	InitServer();
	InitServer1();

	////////////////////////////////////////////////////////////////////////

	i = tours.Init("c:/Tour3DforWindows/tourinfo.xml", false, false, true, driver);

	i = LoadData(); //Загрузка данных.
	i = CreateScene(); //Создание сцены.
	i = tours.CreateScene(smgr,font,font1);
	i = tours.StartTimer(device);

	ShowWindow(hWnd , SW_SHOW);
	UpdateWindow(hWnd);
How to solve this problem and teach program response events, after unfocus?
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Is this a problem with the external window usage, or does it also happen when using the simple Irrlicht window creation procedure?
Roman B.
Posts: 9
Joined: Wed Mar 10, 2010 8:04 am
Location: Russia
Contact:

Post by Roman B. »

This is a problem with external window usage.

I solve it with simple modification of tutorial code.
Just needs tp add to CustomWndProc this code

Code: Select all

	case WM_SETFOCUS:
	{
		SetFocus(hIrrlichtWindow);
	}
Post Reply