windows 平臺(tái) 創(chuàng)建第一個(gè)sciter程序
準(zhǔn)備工作
- 平臺(tái) window10
- IDE Visual studio 2017
- 下載sciter Sdk https://sciter.com/download/
創(chuàng)建工程
導(dǎo)入源碼文件
文件名為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環(huán)境變量
在WIndows10系統(tǒng)環(huán)境變量中增加一個(gè)變量SCITERSDK缠沈,并指向sciter-sdk目錄
SCITERSDK = D:\sciter-sdk
-
配置vs2017 屬性
添加頭文件 $(SCITERSDK)/include
如下圖:
- 將 sciter-sdk/include/sciter-win-main.cpp 文件添加到項(xiàng)目
UI 設(shè)置
-
創(chuàng)建res/main.htm 文件
<html> <head> <title>Test</title> <style></style> <script type="text/tiscript"></script> </head> <body> Hello World! </body> </html>
運(yùn)行工程
-
在項(xiàng)目根目錄下添加 pack-resources.bat . 然后保存運(yùn)行
%SCITERSDK%\bin\packfolder.exe res resources.cpp -v "resources"
程序運(yùn)行是需要sciter.dll的支持异剥,從sciter-sdk的bin.win\x32目錄中拷貝這個(gè)文件戏售,到.exe 程序目錄下
將pack-resources.bat調(diào)用添加為VS中的項(xiàng)目編譯步驟
$(SCITERSDK)\bin.win\packfolder.exe $(ProjectDir)res $(ProjectDir)resources.cpp -v "resources"