Omnimaga
General Discussion => Technology and Development => Computer Programming => Topic started by: Munchor on May 14, 2011, 02:57:47 pm
-
I was wondering how you open a website in C++. I need it to be cross-platform, no "windows.h" please.
Thanks :)
-
Maybe it's the easyest to detect the platform, and make a function for every platform
-
Maybe it's the easyest to detect the platform, and make a function for every platform
Well, there are lots of platforms (Windows, Linux, Mac, Solaris) and I hope there's a way to do this.
In Python, webbrowser.open("url") will open in the default browser on any platform so I guess there is a way to do that in C/C++.
-
That's because Python gets interpreted the same way, remember. C++ is compiled to assembly, which is different on each OS. I don't think there's a real cross-platform way to do it. Since you're going to have to release separate versions for each platform anyway (you can't release an .exe for Mac users, for instance) what about keeping different versions for each? I think that's what most devvers do.
I don't know C++ though, so I might be wrong.
-
I guess I'll check that later, it's not a priority at the moment, but I hope there's a library or something.
Anybody has had to do this before?
-
just make for windows or Linux for now, and later do it hardcore by using '#ifdef', '#elseif', '#endif' expressions to keep it as one source file ;)
And, for start, windows:
#include <windows.h>
using namespace std;
void main()
{
ShellExecute(NULL, "open", "http://www.thebest404pageever.com/swf/index.php", NULL, NULL, SW_SHOWNORMAL);
}
-
Well I really need a Linux one then because the Windows one is easily found with Google. Who knows how to or had better success searching?
-
You need to execute xdg-open http://example.com . I think you can do this with os.system (or whatever is used to run shell commands)
-
Thanks a lot jimbauwen :D I'll find the shell executing code for C++ (os.system() is Python :P))
-
Maybe it's the easyest to detect the platform, and make a function for every platform
Well, there are lots of platforms (Windows, Linux, Mac, Solaris) and I hope there's a way to do this.
In Python, webbrowser.open("url") will open in the default browser on any platform so I guess there is a way to do that in C/C++.
That's because Python gets interpreted the same way, remember. C++ is compiled to assembly, which is different on each OS. I don't think there's a real cross-platform way to do it. Since you're going to have to release separate versions for each platform anyway (you can't release an .exe for Mac users, for instance) what about keeping different versions for each? I think that's what most devvers do.
I don't know C++ though, so I might be wrong.
Python's webbrowser module is in fact, pure source.
http://hg.python.org/cpython/file/d71476b9a55d/Lib/webbrowser.py
Technically, if you translated all of this source code (by HAND, not by program, since there is no such thing as automated Python => C++), you could probably achieve a Python webbrowser-like library for inclusion into your program. :) Of course, translating (and possibly writing a LOT of code) is a whole different thing...
-
Woah, the webbrowser module is in Python? Had no idea.
-
You can use cURL. Or just use sockets to write your own request over HTTP.
just make for windows or Linux for now, and later do it hardcore by using '#ifdef', '#elseif', '#endif' expressions to keep it as one source file ;)
And, for start, windows:
#include <windows.h>
using namespace std;
void main()
{
ShellExecute(NULL, "open", "http://www.thebest404pageever.com/swf/index.php", NULL, NULL, SW_SHOWNORMAL);
}
Sorry to say, but that is just a horrible way. Also, void main()? I'm not even sure most compilers will accept that.
-
I managed to open it, but only works in Linux. I found a Windows-only way too and can probably find a Mac too. Maybe I'll go with try blocks I don't know because it's impossible to find out the user OS during runtime.
-
I managed to open it, but only works in Linux. I found a Windows-only way too and can probably find a Mac too. Maybe I'll go with try blocks I don't know because it's impossible to find out the user OS during runtime.
You'll have to compile seperately anyway, so it'll be known at compile time.
-
I managed to open it, but only works in Linux. I found a Windows-only way too and can probably find a Mac too. Maybe I'll go with try blocks I don't know because it's impossible to find out the user OS during runtime.
You'll have to compile seperately anyway, so it'll be known at compile time.
Yeah I figured out I'll have to make separate releases.