THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 15/10/2012 at 17:54, xxxxxxxx wrote:
Callback methods can be very confusing unless you see a full working example of them in action.
So maybe this example will help.
This is the entire .cpp code for a very basic dialog plugin example with no external resources.
When the plugin opens. The HtmlViewerCustomGui fetches the Google website and displays it in the plugin.
When the button is clicked. It loads the Maxon website. Plus... it also calls to the htmlViewerCallback() method and runs the code inside of it.
In this case it just prints url.
Example:
// Testing ID# Only!!!! Be sure to use a unique ID obtained from www.plugincafe.com
#define PLUGIN_ID 1000006
#include "c4d.h"
#include "gui.h"
#include "c4d_symbols.h"
#include "customgui_htmlviewer.h"
enum
{
MY_HTML_VIEWER = 5000,
MY_LABEL,
MY_BUTTON,
_dummy
};
class myDialog : public GeDialog
{
private:
HtmlViewerCustomGui *viewer;
C4DGadget *myButton;
public:
myDialog(void);
virtual Bool CreateLayout(void);
virtual Bool InitValues(void);
virtual Bool Command(LONG id,const BaseContainer &msg);
};
//This is a custom callback method that will print the url of the webpage when the button is clicked
void htmlViewerCallback(void* user_data, const String& url, LONG encoding, void* reserved)
{
GePrint(url);
}
//The constructor
myDialog::myDialog(void){}
Bool myDialog::CreateLayout(void)
{
SetTitle("Simple HTML Viewer Example");
GroupBegin(0,BFH_SCALEFIT,2,0,"",0);
{
AddStaticText(0,BFH_LEFT,0,0,"My Viewer",0);
myButton = AddButton( MY_BUTTON, BFH_SCALEFIT, 80, 15, "Load HTML Page");
}
GroupEnd();
//Set up the HtmlViewerCustomGui stuff
BaseContainer htmlc;
viewer = (HtmlViewerCustomGui* )AddCustomGui(MY_HTML_VIEWER, CUSTOMGUI_HTMLVIEWER, "HTML_WINDOW", BFH_SCALEFIT|BFV_SCALEFIT, 512, 250, htmlc);
viewer->SetUrl("https://www.google.com/", URL_ENCODING_UTF16);
return TRUE;
}
Bool myDialog::InitValues(void)
{
return TRUE;
}
Bool myDialog::Command(LONG id,const BaseContainer &msg)
{
switch (id)
{
case MY_BUTTON:
if (MY_BUTTON)
{
viewer->SetUrl("http://maxon.net", URL_ENCODING_UTF16); //Load this HTML page
viewer->SetURLCallback(htmlViewerCallback, NULL); //Execute whatever code is inside the htmlViewerCallback() method
}
break;
}
return TRUE;
}
///////// The plugin registration section ///////////////
class myHTMLviewer : public CommandData
{
private:
myDialog dlg;
public:
virtual Bool Execute(BaseDocument *doc);
virtual Bool RestoreLayout(void *secret);
};
Bool myHTMLviewer::Execute(BaseDocument *doc)
{
return dlg.Open(DLG_TYPE_ASYNC,PLUGIN_ID, -1, -1, 300,150);
}
Bool myHTMLviewer::RestoreLayout(void *secret)
{
return dlg.RestoreLayout(PLUGIN_ID,0,secret);
}
Bool RegistermyHTMLviewer(void)
{
return RegisterCommandPlugin(PLUGIN_ID,GeLoadString(IDS_HTML_VIEWER),0,AutoBitmap("icon.tif"),String("HTML Viewer"),gNew myHTMLviewer);
}
-ScottA