Skip to content

Commit

Permalink
Add clipboard example
Browse files Browse the repository at this point in the history
  • Loading branch information
zzl committed Oct 1, 2023
1 parent 31ae18a commit 9db1b59
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions examples/clipboard/clipboard.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package main

import (
"fmt"
"github.com/zzl/go-winrtapi/winrt"
)

func main() {

winrt.Initialize()

htmlDescription := "<h1>Hello WinRT clipboard</h1><hr/>" +
"<div><em>Powered by go-winrtapi</em></div>"

textDescription := "Hello WinRT clipboard\n---------------------\n" +
"Powered by go-winrtapi"

//
dataPackage := winrt.NewDataPackage()

htmlFormatHelperStatics := winrt.NewIHtmlFormatHelperStatics()
htmlFormat := htmlFormatHelperStatics.CreateHtmlFormat(htmlDescription)
dataPackage.SetHtmlFormat(htmlFormat)
dataPackage.SetText(textDescription)

//
print("Press ENTER to set clipboard content..")
_, _ = fmt.Scanln()
clipboard := winrt.NewIClipboardStatics()
clipboard.SetContent(dataPackage.IDataPackage)
clipboard.Flush()
println("clipboard content set.\n")

//
print("Press ENTER to clear the clipboard..")
_, _ = fmt.Scanln()
clipboard.Clear()
println("clipboard cleared.\n")

//
print("Press ENTER to exit..")
_, _ = fmt.Scanln()

}

0 comments on commit 9db1b59

Please sign in to comment.