Introduction
I made these classes so that I could easily handle HTML and CSS in my programs. But because they are so useful for me, I figured they might be for someone else as well. This isn't a tutorial, so the code, my documentation, and the quick examples will have to do. If you notice any errors in my article or code, please don't hesitate to letting me know.
Using the code
HTML class documentation:
BOOL newdoc();
<br /><br />
void deldoc();
<br /><br />
BOOL div(char *arga, char *argb);
<br /><br />
BOOL tag(char *arga, char *argb);
<br /><br />
BOOL extmem(DWORD arga, DWORD argb);
<br /><br />
char *text();
<br /><br />
BOOL raw(char *arga);
CSS class documentation:
BOOL newdoc();
<br /><br />
void deldoc();
<br /><br />
BOOL div(char *arga);
<br /><br />
BOOL tag(char *arga, char *argb);
<br /><br />
BOOL extmem(DWORD arga, DWORD argb);
<br /><br />
char *text();
All of the boolean functions return TRUE or FALSE depending on their success.
An example of how to use the
HTML class:
HTML html; html.newdoc(); html.raw("<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">"); html.div("html"); html.div("head"); html.tag("meta", "http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\""); html.div("title"); html.raw("Hello World"); html.div(); html.tag("link", "rel=\"stylesheet\" type=\"text/css\" href=\"./style.css\" media=\"screen\""); html.div(); html.div("body"); html.raw("Hello World."); html.tag("br"); html.div(); html.div(); SetWindowText(hChild, html.text()); html.deldoc();
An example of how to use the
CSS class:
CSS css; css.newdoc(); css.div("body"); css.tag("background-color", "#2f2f2f"); css.tag("font-size", "1.01em"); css.tag("margin", "0"); css.tag("padding", "0"); css.div("table"); css.tag("background-color", "#010101"); css.div(); SetWindowText(hChild, css.text()); css.deldoc();
A nice feature of both the
HTML and
CSS classes, is that they automatically indent, so editing the result by hand, or viewing the results, you'll see it's really manageable.