example.cc 993 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. // +build ignore
  2. #include "webview.h"
  3. #ifdef _WIN32
  4. int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
  5. LPSTR lpCmdLine, int nCmdShow)
  6. #else
  7. int main()
  8. #endif
  9. {
  10. webview::webview w(true, nullptr);
  11. w.set_title("Example");
  12. w.set_size(480, 320, true);
  13. w.bind("noop", [](std::string s) -> std::string { printf("%s\n", s.c_str());return s; });
  14. w.bind("add", [](std::string s) -> std::string {
  15. auto a = std::stoi(webview::json_parse(s, "", 0));
  16. auto b = std::stoi(webview::json_parse(s, "", 1));
  17. return std::to_string(a + b);
  18. });
  19. w.navigate(R"(data:text/html,
  20. <!doctype html>
  21. <html>
  22. <body>hello</body>
  23. <script>
  24. window.onload = function() {
  25. noop('hello').then(function(res) {
  26. console.log('noop res', res);
  27. });
  28. add(1, 2).then(function(res) {
  29. console.log('add res', res);
  30. });
  31. };
  32. </script>
  33. </html>
  34. )");
  35. w.run();
  36. return 0;
  37. }