代码拉取完成,页面将自动刷新
// +build windows
package main
import (
"fmt"
"github.com/go-ole/go-ole"
"github.com/go-ole/go-ole/oleutil"
_ "github.com/ying32/govcl/pkgs/winappres"
"github.com/ying32/govcl/vcl"
)
type TMainForm struct {
*vcl.TForm
Btn1 *vcl.TButton
}
var mainForm *TMainForm
func (f *TMainForm) OnFormCreate(object vcl.IObject) {
f.SetCaption("WinOLE")
f.ScreenCenter()
f.Btn1 = vcl.NewButton(f)
f.Btn1.SetParent(f)
f.Btn1.SetBounds(10, 10, 100, 30)
f.Btn1.SetCaption("打开记事本")
f.Btn1.SetOnClick(f.OnBtn1Click)
}
func (f *TMainForm) OnBtn1Click(object vcl.IObject) {
ole.CoInitializeEx(0, 0)
defer ole.CoUninitialize()
unknown, err := oleutil.CreateObject("WScript.Shell")
if err != nil {
fmt.Println(err)
return
}
shell, _ := unknown.QueryInterface(ole.IID_IDispatch)
shell.CallMethod("Run", "notepad")
}
func main() {
vcl.RunApp(&mainForm)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。