Archicad C++ API
About Archicad add-on development using the C++ API.
SOLVED!

Open Webbrowser?

Joel Buehler
Enthusiast

Hehey evryone

 

i hope my question is not to obvious, but im having trouble to start the webbrowser with a given url from a add-on. 

how do i do that?

 

i know so far:

we can save url documentation data in a element with the calls

APIDb_SetElementURLRefID
APIDb_GetElementURLRefID

and the notification example show how to add and retrieve this url data

but it does not show how to open that given url...

 

we can edit the Add-Ons help URL with the DGRegisterAdditionalHelpLocation, but it also does not show how to open that url... or am i missing something? 

1 ACCEPTED SOLUTION

Accepted Solutions
Solution
Viktor Kovacs
Graphisoft
Graphisoft

Not sure if I understand the question correctly, but you can open any url with the default web browser by using the OSUtils::OpenWithDefaultBrowser call from the DefaultProgramRunner.hpp header.

View solution in original post

9 REPLIES 9
Solution
Viktor Kovacs
Graphisoft
Graphisoft

Not sure if I understand the question correctly, but you can open any url with the default web browser by using the OSUtils::OpenWithDefaultBrowser call from the DefaultProgramRunner.hpp header.

works like a charm! thank you very much! 

 

i recommend to add this to one of the examples. 

kolioi
Booster

I did something similar few months ago. In general, you can execute any app from within your plugin using ShellExecute() in Windows and std::system() for Mac, something like this

#if defined (WINDOWS)
		LPCWSTR command = L"https://graphisoft.com";
		ShellExecute(NULL, L"open", command, NULL, NULL, SW_SHOWNORMAL);
#elif defined (macintosh)
		GS::UniString command = "open https://graphisoft.com";
		std::system(command.ToCStr().Get());
#endif

 

Miklos Vegh
Graphisoft
Graphisoft

And you can also show a webpage inside your dialog by adding a DG::Browser dialog item and loading the URL by calling the LoadURL (const GS::UniString& url) member function.

thanks 😄 

im a big fan of the DG::Browser Dialog and i made the whole gui as a browser dialog since i like html a lot better then the DG Framework 😄

JoelBuehler_0-1696496319638.png

 

i thought to open a new dialog to show help documents would be unusual behavior since archicad also opens a webbroser for help resources.  

 

 

Hi Joel, in your pluggin do you open a local HTML file or an outside webpage on the browser?

im hosting the html on a subdomain.

with the html.LoadHTML(htmlstring) method you can load local html, waht is very cool. but i was never able to have a html file and feed this to the ressources compiler tool. =(

 

i developed the following hacks:

 

1. you can have your html in the "AddOnFix.grc". like this:

 

JoelBuehler_0-1699170947917.png

this html can you then call with somethink like this:

JoelBuehler_1-1699170997580.png

 

2. you can have your html directly in your code and consume it with the LoadHTML function. something like this:

 

JoelBuehler_2-1699171469450.png

 

 

 

 

You can add a html file as a resource by adding it as a DATA resource. For example:

'DATA' 2024 "HTML Resource" {
	"BrowserContent.html"
}

The resource can be loaded like this (I did not compile it):

GS::UniString htmlStr;
GSHandle resHandle = RSLoadResource ('DATA', resModule, 2024);
if (resHandle != nullptr) {
	USize hdlSize = BMGetHandleSize (resHandle);
	const char* p = (const char*) *resHandle;
	htmlStr = GS::UniString (p, hdlSize);
	BMKillHandle (&resHandle);
}

The loaded resource data does not contain a terminating zero, so a length is needed to the UniString constructor.

The string can then be loaded to a browser control.

Viktor Kovacs
Graphisoft
Graphisoft

Also, you can check the Browser_Control example Add-On in the Development Kit. It's a full example of using a browser control, and storing a html file as a resource.