1 |
747 |
jeremybenn |
// Copyright 2011 The Go Authors. All rights reserved.
|
2 |
|
|
// Use of this source code is governed by a BSD-style
|
3 |
|
|
// license that can be found in the LICENSE file.
|
4 |
|
|
|
5 |
|
|
// +build windows
|
6 |
|
|
|
7 |
|
|
package main
|
8 |
|
|
|
9 |
|
|
import (
|
10 |
|
|
"syscall"
|
11 |
|
|
"unsafe"
|
12 |
|
|
)
|
13 |
|
|
|
14 |
|
|
type Wndclassex struct {
|
15 |
|
|
Size uint32
|
16 |
|
|
Style uint32
|
17 |
|
|
WndProc uintptr
|
18 |
|
|
ClsExtra int32
|
19 |
|
|
WndExtra int32
|
20 |
|
|
Instance syscall.Handle
|
21 |
|
|
Icon syscall.Handle
|
22 |
|
|
Cursor syscall.Handle
|
23 |
|
|
Background syscall.Handle
|
24 |
|
|
MenuName *uint16
|
25 |
|
|
ClassName *uint16
|
26 |
|
|
IconSm syscall.Handle
|
27 |
|
|
}
|
28 |
|
|
|
29 |
|
|
type Point struct {
|
30 |
|
|
X uintptr
|
31 |
|
|
Y uintptr
|
32 |
|
|
}
|
33 |
|
|
|
34 |
|
|
type Msg struct {
|
35 |
|
|
Hwnd syscall.Handle
|
36 |
|
|
Message uint32
|
37 |
|
|
Wparam uintptr
|
38 |
|
|
Lparam uintptr
|
39 |
|
|
Time uint32
|
40 |
|
|
Pt Point
|
41 |
|
|
}
|
42 |
|
|
|
43 |
|
|
const (
|
44 |
|
|
// Window styles
|
45 |
|
|
WS_OVERLAPPED = 0
|
46 |
|
|
WS_POPUP = 0x80000000
|
47 |
|
|
WS_CHILD = 0x40000000
|
48 |
|
|
WS_MINIMIZE = 0x20000000
|
49 |
|
|
WS_VISIBLE = 0x10000000
|
50 |
|
|
WS_DISABLED = 0x8000000
|
51 |
|
|
WS_CLIPSIBLINGS = 0x4000000
|
52 |
|
|
WS_CLIPCHILDREN = 0x2000000
|
53 |
|
|
WS_MAXIMIZE = 0x1000000
|
54 |
|
|
WS_CAPTION = WS_BORDER | WS_DLGFRAME
|
55 |
|
|
WS_BORDER = 0x800000
|
56 |
|
|
WS_DLGFRAME = 0x400000
|
57 |
|
|
WS_VSCROLL = 0x200000
|
58 |
|
|
WS_HSCROLL = 0x100000
|
59 |
|
|
WS_SYSMENU = 0x80000
|
60 |
|
|
WS_THICKFRAME = 0x40000
|
61 |
|
|
WS_GROUP = 0x20000
|
62 |
|
|
WS_TABSTOP = 0x10000
|
63 |
|
|
WS_MINIMIZEBOX = 0x20000
|
64 |
|
|
WS_MAXIMIZEBOX = 0x10000
|
65 |
|
|
WS_TILED = WS_OVERLAPPED
|
66 |
|
|
WS_ICONIC = WS_MINIMIZE
|
67 |
|
|
WS_SIZEBOX = WS_THICKFRAME
|
68 |
|
|
// Common Window Styles
|
69 |
|
|
WS_OVERLAPPEDWINDOW = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX
|
70 |
|
|
WS_TILEDWINDOW = WS_OVERLAPPEDWINDOW
|
71 |
|
|
WS_POPUPWINDOW = WS_POPUP | WS_BORDER | WS_SYSMENU
|
72 |
|
|
WS_CHILDWINDOW = WS_CHILD
|
73 |
|
|
|
74 |
|
|
WS_EX_CLIENTEDGE = 0x200
|
75 |
|
|
|
76 |
|
|
// Some windows messages
|
77 |
|
|
WM_CREATE = 1
|
78 |
|
|
WM_DESTROY = 2
|
79 |
|
|
WM_CLOSE = 16
|
80 |
|
|
WM_COMMAND = 273
|
81 |
|
|
|
82 |
|
|
// Some button control styles
|
83 |
|
|
BS_DEFPUSHBUTTON = 1
|
84 |
|
|
|
85 |
|
|
// Some color constants
|
86 |
|
|
COLOR_WINDOW = 5
|
87 |
|
|
COLOR_BTNFACE = 15
|
88 |
|
|
|
89 |
|
|
// Default window position
|
90 |
|
|
CW_USEDEFAULT = 0x80000000 - 0x100000000
|
91 |
|
|
|
92 |
|
|
// Show window default style
|
93 |
|
|
SW_SHOWDEFAULT = 10
|
94 |
|
|
)
|
95 |
|
|
|
96 |
|
|
var (
|
97 |
|
|
// Some globally known cursors
|
98 |
|
|
IDC_ARROW = MakeIntResource(32512)
|
99 |
|
|
IDC_IBEAM = MakeIntResource(32513)
|
100 |
|
|
IDC_WAIT = MakeIntResource(32514)
|
101 |
|
|
IDC_CROSS = MakeIntResource(32515)
|
102 |
|
|
|
103 |
|
|
// Some globally known icons
|
104 |
|
|
IDI_APPLICATION = MakeIntResource(32512)
|
105 |
|
|
IDI_HAND = MakeIntResource(32513)
|
106 |
|
|
IDI_QUESTION = MakeIntResource(32514)
|
107 |
|
|
IDI_EXCLAMATION = MakeIntResource(32515)
|
108 |
|
|
IDI_ASTERISK = MakeIntResource(32516)
|
109 |
|
|
IDI_WINLOGO = MakeIntResource(32517)
|
110 |
|
|
IDI_WARNING = IDI_EXCLAMATION
|
111 |
|
|
IDI_ERROR = IDI_HAND
|
112 |
|
|
IDI_INFORMATION = IDI_ASTERISK
|
113 |
|
|
)
|
114 |
|
|
|
115 |
|
|
//sys GetModuleHandle(modname *uint16) (handle syscall.Handle, err error) = GetModuleHandleW
|
116 |
|
|
//sys RegisterClassEx(wndclass *Wndclassex) (atom uint16, err error) = user32.RegisterClassExW
|
117 |
|
|
//sys CreateWindowEx(exstyle uint32, classname *uint16, windowname *uint16, style uint32, x int32, y int32, width int32, height int32, wndparent syscall.Handle, menu syscall.Handle, instance syscall.Handle, param uintptr) (hwnd syscall.Handle, err error) = user32.CreateWindowExW
|
118 |
|
|
//sys DefWindowProc(hwnd syscall.Handle, msg uint32, wparam uintptr, lparam uintptr) (lresult uintptr) = user32.DefWindowProcW
|
119 |
|
|
//sys DestroyWindow(hwnd syscall.Handle) (err error) = user32.DestroyWindow
|
120 |
|
|
//sys PostQuitMessage(exitcode int32) = user32.PostQuitMessage
|
121 |
|
|
//sys ShowWindow(hwnd syscall.Handle, cmdshow int32) (wasvisible bool) = user32.ShowWindow
|
122 |
|
|
//sys UpdateWindow(hwnd syscall.Handle) (err error) = user32.UpdateWindow
|
123 |
|
|
//sys GetMessage(msg *Msg, hwnd syscall.Handle, MsgFilterMin uint32, MsgFilterMax uint32) (ret int32, err error) [failretval==-1] = user32.GetMessageW
|
124 |
|
|
//sys TranslateMessage(msg *Msg) (done bool) = user32.TranslateMessage
|
125 |
|
|
//sys DispatchMessage(msg *Msg) (ret int32) = user32.DispatchMessageW
|
126 |
|
|
//sys LoadIcon(instance syscall.Handle, iconname *uint16) (icon syscall.Handle, err error) = user32.LoadIconW
|
127 |
|
|
//sys LoadCursor(instance syscall.Handle, cursorname *uint16) (cursor syscall.Handle, err error) = user32.LoadCursorW
|
128 |
|
|
//sys SetCursor(cursor syscall.Handle) (precursor syscall.Handle, err error) = user32.SetCursor
|
129 |
|
|
//sys SendMessage(hwnd syscall.Handle, msg uint32, wparam uintptr, lparam uintptr) (lresult uintptr) = user32.SendMessageW
|
130 |
|
|
//sys PostMessage(hwnd syscall.Handle, msg uint32, wparam uintptr, lparam uintptr) (err error) = user32.PostMessageW
|
131 |
|
|
|
132 |
|
|
func MakeIntResource(id uint16) *uint16 {
|
133 |
|
|
return (*uint16)(unsafe.Pointer(uintptr(id)))
|
134 |
|
|
}
|