Golang Developing Windows Apps

Source: Internet
Author: User

Idle boring and play go language to find abuse ... --Develop Windows applications with Go

To develop a Windows app with go, you must first install the necessary components:

Walk integrates a lot of Windows controls

Go get Github.com/lxn/walk

Win is an implementation of Go call WindowsAPI

Go get Github.com/lxn/win

RSRC is a tool for connecting Walk/win and Windows dynamic connections

Go get github.com/akavel/rsrc

With this, we can actually encode it.

Test the effectiveness of the WINAPI first:

Look at this write, compare in place, the previous compile and run error problems also found, thank you, but the source has a string misspelled

To correct:

// gowin project gowin.gopackage  mainimport  (     "Github.com/lxn/win"      "StrConv"       "Syscall") Func _text (_str string)  *uint16 {     Return syscall. Stringtoutf16ptr (_STR)}func _tostring (_n int32)  string {    return  strconv. Itoa (int (_n))}func main ()  {    var hwnd win. Hwnd    cxscreen := win. GetSystemMetrics (win. Sm_cxscreen)     cyscreen := win. GetSystemMetrics (win. Sm_cyscreen)     win. MessageBox (Hwnd, _text ("screen length-:" +_tostring (Cxscreen) + "width:" +_tostring (Cyscreen)),  _text ("Message <a  Target=\ "_blank\"  href=\ "http://blog.csdn.net/songbohr\" >http://blog.csdn.net/songbohr</a> "),  win. MB_OK)} 

Note:in the Phd.go in the win component,

This line to comment, if you're not a WIN7 enthusiast//pdh_addenglishcounterw = Libpdhdll.mustfindproc ("Pdhaddenglishcounterw")


http://blog.csdn.net/songbohr/article/details/10511041

Compile run successful, note that this must be the package main or the EXE will not be produced

Package Main

Next try walk can be done:

package mainimport  (     "Github.com/lxn/walk"     .  " Github.com/lxn/walk/declarative "    " Strings ") Func main ()  {     var inte, outte *walk. textedit    mainwindow{        title:     "SCREAMO",        minsize: size{600, 400},         Layout:  VBox{},         children: []widget{            hsplitter{                 children:  []Widget{                     textedit{assignto: &inte},     &nbSp;              textedit{assignto:  &outTE, ReadOnly: true},                 },            },             PushButton{                 Text:  "SCREAM",                 onclicked: func ()  {                      outte.settext (Strings. ToUpper (Inte.text ()))                  },            },        },    }. Run ()}

The compilation ran successfully, but the operation did not result,

After a while, I took a closer look at walk's documentation.

The original is to do this:

First create a new file such as Test.manifest (feel absolutely an android powder) fill in the following code

<?xml version= "1.0"  encoding= "UTF-8"  standalone= "yes"?>    < assembly xmlns= "Urn:schemas-microsoft-com:asm.v1"  manifestversion= "1.0" >         <assemblyidentity version= "1.0.0.0"  processorarchitecture= "*"  name= " Somefunkynamehere " type=" Win32 "/>        <dependency>             <dependentAssembly>                 <assemblyIdentity  Type= "Win32"  name= "Microsoft.windows.common-controls"  version= "6.0.0.0"  processorarchitecture= " * " publickeytoken=" 6595B64144CCF1DF " language=" * "/>             </dependentassembly>        </ dependency>    </assembly> 

Run the following command

Rsrc-manifest the name you applied. Manifest-o Rsrc.sysogo Buildgo build-ldflags= "-H Windowsgui"

Run the generated EXE and you'll see the familiar Windows interface.

It's not easy to feel like go developing Windows apps, and it's not very economical, and debugging and compiling is a lot of effort,

Look forward to future development tools can be further optimized


Golang Developing Windows Apps

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.