下载安装 go-sciter 包

go get github.com/oskca/sciter

修改 sciter-x-api.c ,添加如下代码:

HSARCHIVE SCAPI SciterOpenArchive (LPCBYTE archiveData, UINT archiveDataLength) { return SAPI(NULL)->SciterOpenArchive (archiveData,archiveDataLength); }

BOOL SCAPI SciterGetArchiveItem (HSARCHIVE harc, LPCWSTR path, LPCBYTE* pdata, UINT* pdataLength){return SAPI(NULL)->SciterGetArchiveItem (harc,path,pdata,pdataLength); }

修改 sciter.go,添加如下代码:

func (s *Sciter) OpenArchive(data []byte) {

s.har = C.SciterOpenArchive((*C.BYTE)(&data[0]), C.UINT(len(data)))

}

func (s *Sciter) GetArchiveItem(uri string) []byte {

var pv uintptr = 0

var length uint = 0

pBytes := (*C.LPCBYTE)(unsafe.Pointer(&pv))

pnBytes := (*C.UINT)(unsafe.Pointer(&length))

r := C.SciterGetArchiveItem(s.har, StringToWcharPtr(uri), pBytes, pnBytes)

if r == 0 {

return nil

}

ret := []byte{}

for i := 0; i < int(length); i++ {

b := *(*byte)(unsafe.Pointer(pv + uintptr(i)))

ret = append(ret, b)

}

return ret

}

用sciter自带工具打包 资源:

packfolder.exe res resources.cpp -v "res"

//packfolder.exe “资源文件夹”,“输出cpp文件名” -v "变量名"

拷贝cpp内容存为res.go:

// res.go

package main

var res = []byte{

编写main.go

package main

import (

"log"

"strings"

"github.com/oskca/sciter"

"github.com/oskca/sciter/window"

)

func OnLoadData(s *sciter.Sciter) func(ld *sciter.ScnLoadData) int {

return func(ld *sciter.ScnLoadData) int {

uri := ld.Uri()

log.Println("loading:", uri)

if strings.HasPrefix(uri, "this://app/") {

path := uri[11:]

log.Println("path:", path)

data := s.GetArchiveItem(path)

if data == nil {

log.Println("GetArchiveItem:False")

return sciter.LOAD_OK

}

s.DataReady(uri, data)

}

return sciter.LOAD_OK

}

}

func newHandler(s *sciter.Sciter) *sciter.CallbackHandler {

return &sciter.CallbackHandler{

OnLoadData: OnLoadData(s),

}

}

func main() {

w, err := window.New(sciter.SW_TITLEBAR|sciter.SW_RESIZEABLE|sciter.SW_CONTROLS|sciter.SW_MAIN, sciter.NewRect(300, 300, 600, 400))

if err != nil {

log.Fatal("Create Window Error: ", err)

}

w.SetCallback(newHandler(w.Sciter))

w.OpenArchive(res)

w.LoadFile("app/main.htm")

w.Show()

w.Run()

}