clicking on a box and displaying a webpage

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
skelli
Posts: 20
Joined: Sat Jul 07, 2007 7:07 pm

clicking on a box and displaying a webpage

Post by skelli »

hey

i have built a room with a simple box that represents a computer!
i wont the mouse to be able to click on the box and then new window will open with a url.
i have looked at the collision tutorial and modify it a little to ie. instead of disabling the light it on the faires i but in this code:

ShellExecute( NULL, "open", "http://www..google.com/", NULL, NULL, SW_SHOWNORMAL );

this opens loads of web browsers!! i want to add a click event with the mouse to get around this and just open one webpage

not really sure yet on how to use mouse events, a simple example would suffice
any suggestions?

thanks

Any help
catron
Posts: 158
Joined: Mon Feb 19, 2007 1:54 am

Post by catron »

use this code: (by code project)

Code: Select all


#include <windows.h>
#include <string>

bool runApp(char *appName)
{
    STARTUPINFO sinfo;
    FillMemory(&sinfo, sizeof(STARTUPINFO), 0);
    sinfo.cb = sizeof(STARTUPINFO);

    PROCESS_INFORMATION pinfo;

    if (CreateProcess(NULL, appName, NULL, NULL, FALSE,
        NORMAL_PRIORITY_CLASS, NULL,
        NULL, // current dir
        &sinfo,
        &pinfo)
        )
    {
        CloseHandle(pinfo.hProcess);
        CloseHandle(pinfo.hThread);
        return true;
    }
    return false;
}

void openWebpage(char *page)
{
    // modified from http://www.codeproject.com/internet/urlnewwindow.asp

    std::string strBrowser;

    HKEY hKey = NULL;
    if (RegOpenKeyEx(HKEY_CLASSES_ROOT, "http\\shell\\open\\command", 0, KEY_READ, &hKey) == ERROR_SUCCESS)
    {
        DWORD cbData = 0;
        if (RegQueryValueEx(hKey, NULL, NULL, NULL, NULL, &cbData) == ERROR_SUCCESS && cbData > 0)
        {
            TCHAR *psz = new TCHAR[cbData];
            if (psz != NULL)
            {
                if (RegQueryValueEx(hKey, NULL, NULL, NULL, (LPBYTE)psz, &cbData) == ERROR_SUCCESS)
                {
                    strBrowser = psz;
                }
                delete [] psz;
            }
        }
        RegCloseKey(hKey);
    }

    if (strBrowser.length() > 0)
    {
        std::string::size_type nStart = strBrowser.find('"', 0);

        // if first is a quote, then exe path is in quotes, so find the second quote
        if (nStart == 0)
        {
            std::string::size_type nEnd = strBrowser.find('"', 1);
            if (nStart != nEnd && nEnd != std::string::npos)
            {
                strBrowser = strBrowser.substr(nStart+1, nEnd-nStart-1);
            }
        }
        // otherwise if no quotes, 2nd point is the first space after the last backslash
        else
        {
            std::string::size_type nIndex = strBrowser.rfind('\\', strBrowser.length()-1);
            if (nIndex != std::string::npos)
            {
                std::string::size_type nSpace = strBrowser.find(' ', nIndex);
                if (nSpace != std::string::npos)
                {
                    strBrowser = strBrowser.substr(0, nSpace);
                }
            }
        }

        std::string command = "\"";
        command += strBrowser;
        command += "\" \"";
        command += page;
        command += "\"";

        if (runApp((char *)command.c_str()))
        {
            return;
        }
    }

    ShellExecute(NULL, "open", page, NULL, NULL, SW_SHOWNORMAL);
}
openWebpage("http://google.com/");

use that code... its much better.

also im not shure about mouse but with collision, have a variabl that only opens it once while your touching it.



if (collision with comp) {
collision = 1;
OpenPage("html blah blah")
else
collision = 0
skelli
Posts: 20
Joined: Sat Jul 07, 2007 7:07 pm

Post by skelli »

thanks,
ya i saw that code already,my problem more to do with the mouse events

a simple example will help

thanks again
skelli
Posts: 20
Joined: Sat Jul 07, 2007 7:07 pm

Post by skelli »

any help :D

im completly confused about how to do this!!
kburkhart84
Posts: 277
Joined: Thu Dec 15, 2005 6:11 pm

Post by kburkhart84 »

If I understand what is happening, your code for opening the web page is fine, rather it is happening a lot. So what you need to do as a quick fix is to have a variable that is a bool saying whether the page has been opened or not. When you get the click, you open the page, but you set true to the variable. Before this though, you check if the variable is true, and if it is, cancel the page opening code because you already did it. It shouldn't be that complex to implement.
omar shaaban
Posts: 616
Joined: Wed Nov 01, 2006 6:26 pm
Location: Cairo,Egypt
Contact:

Post by omar shaaban »

kburkhart84 wrote:If I understand what is happening, your code for opening the web page is fine, rather it is happening a lot. So what you need to do as a quick fix is to have a variable that is a bool saying whether the page has been opened or not. When you get the click, you open the page, but you set true to the variable. Before this though, you check if the variable is true, and if it is, cancel the page opening code because you already did it. It shouldn't be that complex to implement.
yes so what will u do is
before the loop:

Code: Select all

wopen=false
in the loop:

Code: Select all

if(mouse hit the box && wopen==false)
{
openwebpage("www.fff.com");
wopen=true;
}
Dorth
Posts: 931
Joined: Sat May 26, 2007 11:03 pm

Post by Dorth »

Or rather

Code: Select all

if(mouse_hit_the_box && !wopen)
(most compiler would pick it up, but don't do a comparison check on a bool, it defeats the purpose)
skelli
Posts: 20
Joined: Sat Jul 07, 2007 7:07 pm

Post by skelli »

thanks for the replies :wink:

im currently messing around with the gui tutorial to get the hang of events.

I have a scene set up based on tutorial 2 and i add a quit button but when i run it the mouse cursor is stuck in the middle of the screen.
How do i free up the mouse cursor without losing my direction of the camera?

getting there slowly but surely :D
skelli
Posts: 20
Joined: Sat Jul 07, 2007 7:07 pm

Post by skelli »

in the collision tutorial how do i click on the fairys with the mouse.

how do i give the fairys id no. for the events?
skelli
Posts: 20
Joined: Sat Jul 07, 2007 7:07 pm

Post by skelli »

im having problems with my mouse event.
im using the collision tutorial

here is what i have written
my event class

Code: Select all

class MyEventReceiver : public IEventReceiver 
{ 
public: 
   virtual bool OnEvent(SEvent event) 
   { 
	   if (event.EventType == irr::EET_MOUSE_INPUT_EVENT && !event.MouseInput.Event) 
      {  
            switch(event.MouseInput.Event) 
            { 
			case irr::EMIE_LMOUSE_PRESSED_DOWN:  
ShellExecute( NULL, "open", "http://www.library.nuigalway.ie/", NULL, NULL, SW_SHOWNORMAL );
std::cout<<"clciked"; 
                 device->closeDevice(); 
                 return true; 
      
          } 
            } 
            return false; 
       } 
};

then in the raytrace part with the selection node

Code: Select all

selectedSceneNode = smgr->getSceneCollisionManager()->getSceneNodeFromCameraBB(camera);

		if (lastSelectedSceneNode)
			lastSelectedSceneNode->setMaterialFlag(video::EMF_LIGHTING, true);

		if (selectedSceneNode == q3node || selectedSceneNode == bill)
			selectedSceneNode = 0;

		if (selectedSceneNode &&  receiver.OnEvent=EMIE_LMOUSE_PRESSED_DOWN)
		{
			selectedSceneNode->setMaterialFlag(video::EMF_LIGHTING, false);
		 
			
		}
		lastSelectedSceneNode = selectedSceneNode;
an ideas as to were im going wrong?

thanks
Post Reply