') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); })(); GitHub - Leadrive/GVCL: Golang Windows GUI Bindings Like Delphi VCL · GitHub
Skip to content

Latest commit

History

29 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

GVCL

Golang Windows GUI Bindings Like Delphi VCL
Windows的GUI界面Go语言封装,目标是实现一个类似Delphi VCL版本效果的界面库

使用方法

msgbox.go
typeGForm1struct {
controls.GFormButton1*controls.GButtonEdit1*controls.GEdit
}
funcNewForm1(app*controls.WApplication)*GForm1{
frm:=new(GForm1)
frm.SubInit()
frm.Button1=controls.NewButton(frm)
frm.Button1.SetWidth(80)
frm.Button1.SetHeight(30)
frm.Button1.SetLeft(frm.Width() -90)
frm.Button1.SetTop(frm.Height() -80)
frm.Button1.SetCaption("确定关闭")
frm.Edit1=controls.NewEdit(frm)
frm.OnClose=func(senderinterface{},closeAction*int8) {
*closeAction=controls.CAFree
}
frm.Button1.OnClick=func(senderinterface{}) {
WinApi.MessageBox(frm.GetWindowHandle(),"sadf","Asdf",64)
frm.SetModalResult(controls.MrOK)
}
returnfrm
}
funcmain() {
app:=new(controls.WApplication)
app.ShowMainForm=truem:=app.CreateForm()
m.SetLeft(200)
m.SetTop(50)
m.SetCaption("测试窗体")
e:=controls.NewEdit(m)
e.SetName("Edit1")
e.SetLeft(10)
e.SetWidth(100)
e.SetHeight(20)
e.SetCaption("测试")
b:=controls.NewButton(m)
b.SetDefault(true)
b.SetLeft(120)
b.SetCaption("创建窗体")
b.OnClick=func(senderinterface{}) {
tmpm:=NewForm1(app)
tmpm.SetCaption(e.GetText())
iftmpm.ShowModal() ==controls.MrOK{
WinApi.MessageBox(tmpm.GetWindowHandle(),"程序确定退出","消息",64)
}
}
b1:=controls.NewButton(m)
b1.SetCaption("关闭")
b1.SetLeft(100)
b1.SetTop(40)
b1.OnClick=func(senderinterface{}) {
b.SetVisible(!b.Visible())
b.SetCaption("测试")
}
app.Run()
}
Create Manifest test.manifest
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assemblyxmlns="urn:schemas-microsoft-com:asm.v1"manifestVersion="1.0">
<assemblyIdentityversion="1.0.0.0"processorArchitecture="*"name="SomeFunkyNameHere"type="win32"/>
<dependency>
<dependentAssembly>
<assemblyIdentitytype="win32"name="Microsoft.Windows.Common-Controls"version="6.0.0.0"processorArchitecture="*"publicKeyToken="6595b64144ccf1df"language="*"/>
</dependentAssembly>
</dependency>
</assembly>

Then either compile the manifest using the rsrc tool, like this:

go get github.com/akavel/rsrc
rsrc -manifest test.manifest -o rsrc.syso

or rename the test.manifest file to test.exe.manifest and distribute it with the application instead.

使用Go Build 建立文件,会将这个manifest资源包含进去,以使用系统皮肤

Font使用

b1.Font.BeginUpdate()
b1.Font.SetSize(10)
b1.Font.Underline=1b1.Font.EndUpdate()

增加弹出菜单组件

菜单使用方法

//菜单pop:=NVisbleControls.NewPopupMenu(m)
tmpitem:=pop.Items().AddItem("测试1")
citem:=tmpitem.AddItem("子测试1")
citem.OnClick=func(senderinterface{}) {
WinApi.MessageBox(m.GetWindowHandle(),"菜单测试"+sender.(*NVisbleControls.GMenuItem).Caption(),"消息",64)
}
citem=pop.Items().AddItem("测试2")
citem.OnClick=func(senderinterface{}) {
WinApi.MessageBox(m.GetWindowHandle(),"菜单测试"+sender.(*NVisbleControls.GMenuItem).Caption(),"消息",64)
}
m.PopupMenu=pop

目前整体组件框架已经具备雏形,要增加其他组件库按照扩展的Button和Edit以及Label增加则可,下一步做完托盘就暂时放一段落

增加托盘组件完成,使用方法

//菜单pop:=NVisbleControls.NewPopupMenu(m)
tmpitem:=pop.Items().AddItem("测试1")
citem:=tmpitem.AddItem("子测试1")
citem.OnClick=func(senderinterface{}) {
WinApi.MessageBox(m.GetWindowHandle(),"菜单测试"+sender.(*NVisbleControls.GMenuItem).Caption(),"消息",64)
}
citem=pop.Items().AddItem("测试2")
citem.OnClick=func(senderinterface{}) {
WinApi.MessageBox(m.GetWindowHandle(),"菜单测试"+sender.(*NVisbleControls.GMenuItem).Caption(),"消息",64)
}
//托盘图标,结合弹出菜单icon:=NVisbleControls.NewTrayIcon(m)
icon.SetIcon(app.AppIcon()) //设置托盘图标//icon.SetIcon(WinApi.LoadIcon(controls.Hinstance,uintptr(5))) icon.SetVisible(true)
icon.PopupMenu=pop//设置托盘的右键弹出菜单icon.OnDblClick=func(senderinterface{}) {
if!m.Visible(){
m.Show()
}else{
m.SetVisible(false)
}
}

增加注册表操作类库,使用方法

reg := NVisbleControls.NewRegistry(0)
reg.SetRootKey(WinApi.HKEY_LOCAL_MACHINE)
if reg.OpenKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",false){
if reg.ValueExists("SynTPEnh"){
WinApi.MessageBox(m.GetWindowHandle(),"SynTPEnh自动启动: "+reg.ReadString("SynTPEnh"),"消息",64) }
WinApi.MessageBox(m.GetWindowHandle(),"打开注册表测试"+sender.(*NVisbleControls.GMenuItem).Caption(),"消息",6)
}
reg.Free()

运行效果 运行效果

About

Golang Windows GUI Bindings Like Delphi VCL

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages