Download webview.h and include it in your C/C++ code: //下载webview。h,并将其包含在C/ c++代码中
// main.c
#define WEBVIEW_IMPLEMENTATION
#include "webview.h"
#ifdef WIN32
int WINAPI WinMain(HINSTANCE hInt, HINSTANCE hPrevInst, LPSTR lpCmdLine,
int nCmdShow) {
#else
int main() {
#endif
/* Open wikipedia in a 800x600 resizable window */
webview("Minimal webview example",
"https://en.m.wikipedia.org/wiki/Main_Page", 800, 600, 1);
return 0;
}
Build it:
# Linux
$ cc main.c -DWEBVIEW_GTK=1 `pkg-config --cflags --libs gtk+-3.0 webkit2gtk-4.0` -o webview-example
# MacOS
$ cc main.c -DWEBVIEW_COCOA=1 -framework WebKit -o webview-example
# Windows (mingw)
$ cc main.c -DWEBVIEW_WINAPI=1 -lole32 -lcomctl32 -loleaut32 -luuid -mwindows -o webview-example.exe
For the most simple use cases there is only one function: //对于最简单的用例,只有一个函数:
int webview(const char *title, const char *url, int width, int height, int resizable);
The following URL schemes are supported: //支持以下网址方案:
http://
and https://
, no surprises here. //http://和https://,这并不奇怪。file:///
can be useful if you want to unpack HTML/CSS assets to some temporary directory and point a webview to open index.html from there.//如果您想将HTML/CSS资产解压到某个临时目录,并指向一个webview从那里打开index.html,那么文件:///将非常有用。data:text/html,...
allows to pass short HTML data inline without using a web server or polluting the file system. Further modifications of the webview contents can be done via JavaScript bindings.