0
0

More than 3 years have passed since last update.

Go から Windows の MessageBox を呼び出す

Last updated at Posted at 2020-04-24

Go + Qt は前回の記事から実用は難しそうなので、結局 GUI は Win32 API をたたく方向にした。
Windows でしか動かなくなるが、自分はサービスを作ったり Hotkey 登録したり API フックしたりいろいろやりたいけど C++ 使うほど大仰にはしたくないって用途なのと Go に対して C++ と同じレベルのポテンシャルを感じているので Go を使いたいってだけなのでこれでよしとする。

一から作るよりはある程度あったほうがいいので、以下を利用する。
https://github.com/lxn/win

main.go
package main

import (
    "syscall"

    "github.com/lxn/win"
)

func UTF16PtrFromString(s string) *uint16 {
    result, _ := syscall.UTF16PtrFromString(s)

    return result
}

func main() {
    win.MessageBox(win.HWND(0), UTF16PtrFromString("メッセージ"), UTF16PtrFromString("タイトル"), win.MB_OKCANCEL)
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0