windows 平台 创建第一个sciter程序
准备工作
- 平台 window10
- IDE Visual studio 2017
- 下载sciter Sdk https://sciter.com/download/
创建工程
导入源码文件
文件名为main.cpp
#include "sciter-x.h"
#include "sciter-x-window.hpp"
class frame : public sciter::window {
public:
frame() : window(SW_TITLEBAR | SW_RESIZEABLE | SW_CONTROLS | SW_MAIN | SW_ENABLE_DEBUG) {}
// passport - lists native functions and properties exposed to script:
SOM_PASSPORT_BEGIN(frame)
SOM_FUNCS(
SOM_FUNC(nativeMessage)
)
SOM_PASSPORT_END
// function expsed to script:
sciter::string nativeMessage() { return WSTR("Hello C++ World"); }
};
#include "resources.cpp" // resources packaged into binary blob.
int uimain(std::function<int()> run) {
sciter::archive::instance().open(aux::elements_of(resources)); // bind resources[] (defined in "resources.cpp") with the archive
sciter::om::hasset<frame> pwin = new frame();
// note: this:://app URL is dedicated to the sciter::archive content associated with the application
pwin->load(WSTR("this://app/main.htm"));
//or use this to load UI from
// pwin->load( WSTR("file:///home/andrew/Desktop/Project/res/main.htm") );
pwin->expand();
return run();
}
配置工程
-
配置window环境变量
在WIndows10系统环境变量中增加一个变量SCITERSDK,并指向sciter-sdk目录
SCITERSDK = D:\sciter-sdk
-
配置vs2017 属性
添加头文件 $(SCITERSDK)/include
如下图:
- 将 sciter-sdk/include/sciter-win-main.cpp 文件添加到项目
UI 设置
-
创建res/main.htm 文件
<html> <head> <title>Test</title> <style></style> <script type="text/tiscript"></script> </head> <body> Hello World! </body> </html>
运行工程
-
在项目根目录下添加 pack-resources.bat . 然后保存运行
%SCITERSDK%\bin\packfolder.exe res resources.cpp -v "resources"
程序运行是需要sciter.dll的支持,从sciter-sdk的bin.win\x32目录中拷贝这个文件,到.exe 程序目录下
将pack-resources.bat调用添加为VS中的项目编译步骤
$(SCITERSDK)\bin.win\packfolder.exe $(ProjectDir)res $(ProjectDir)resources.cpp -v "resources"