下面是测试代码,是我哪里弄错了,请高手指教,谢谢。
```go
package main
import (
"github.com/lxn/walk"
"github.com/lxn/walk/declarative"
"github.com/lxn/win"
)
func main() {
form := new(walk.MainWindow)
declarative.MainWindow{
AssignTo: &form,
Title: "test",
Size: declarative.Size{300, 300},
}.Create()
setFormStyle(form)
form.Run()
}
func setFormStyle(form *walk.MainWindow) {
// 设置窗口样式
style := win.GetWindowLong(form.Handle(), win.GWL_STYLE)
style = style | win.WS_EX_TOOLWINDOW
win.SetWindowLong(form.Handle(), win.GWL_STYLE, style)
}
```
```cpp
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
g_hInst = hInstance; // 将实例句柄存储在全局变量中
HWND hWnd = CreateWindowW(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, nullptr, nullptr, hInstance, nullptr);
if (hWnd == nullptr)
{
return FALSE;
}
LONG_PTR exstyle = GetWindowLongPtr(hWnd, GWL_EXSTYLE);
exstyle |= WS_EX_TOOLWINDOW;
SetWindowLongPtr(hWnd, GWL_EXSTYLE, exstyle);
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
return TRUE;
}
```
我试了一下,用 C++ 直接调用 Windows API 没问题,可能是这个 go 库封装得不好吧
#5