clicking on a box and displaying a webpage
clicking on a box and displaying a webpage
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
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
use this code: (by code project)
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
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);
}
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
-
- Posts: 277
- Joined: Thu Dec 15, 2005 6:11 pm
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.
-
- Posts: 616
- Joined: Wed Nov 01, 2006 6:26 pm
- Location: Cairo,Egypt
- Contact:
yes so what will u do iskburkhart84 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.
before the loop:
Code: Select all
wopen=false
Code: Select all
if(mouse hit the box && wopen==false)
{
openwebpage("www.fff.com");
wopen=true;
}
Or rather
(most compiler would pick it up, but don't do a comparison check on a bool, it defeats the purpose)
Code: Select all
if(mouse_hit_the_box && !wopen)
thanks for the replies
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
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
im having problems with my mouse event.
im using the collision tutorial
here is what i have written
my event class
then in the raytrace part with the selection node
an ideas as to were im going wrong?
thanks
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;
thanks