OSDN Git Service

Update to current version of Go library (revision 94d654be2064).
[pf3gnuchains/gcc-fork.git] / libgo / go / exp / wingui / winapi.go
1 // 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 package main
6
7 import (
8         "syscall"
9         "unsafe"
10 )
11
12 func loadDll(fname string) uint32 {
13         h, e := syscall.LoadLibrary(fname)
14         if e != 0 {
15                 abortf("LoadLibrary(%s) failed with err=%d.\n", fname, e)
16         }
17         return h
18 }
19
20 func getSysProcAddr(m uint32, pname string) uintptr {
21         p, e := syscall.GetProcAddress(m, pname)
22         if e != 0 {
23                 abortf("GetProcAddress(%s) failed with err=%d.\n", pname, e)
24         }
25         return uintptr(p)
26 }
27
28 type Wndclassex struct {
29         Size       uint32
30         Style      uint32
31         WndProc    uintptr
32         ClsExtra   int32
33         WndExtra   int32
34         Instance   uint32
35         Icon       uint32
36         Cursor     uint32
37         Background uint32
38         MenuName   *uint16
39         ClassName  *uint16
40         IconSm     uint32
41 }
42
43 type Point struct {
44         X int32
45         Y int32
46 }
47
48 type Msg struct {
49         Hwnd    uint32
50         Message uint32
51         Wparam  int32
52         Lparam  int32
53         Time    uint32
54         Pt      Point
55 }
56
57 const (
58         // Window styles
59         WS_OVERLAPPED   = 0
60         WS_POPUP        = 0x80000000
61         WS_CHILD        = 0x40000000
62         WS_MINIMIZE     = 0x20000000
63         WS_VISIBLE      = 0x10000000
64         WS_DISABLED     = 0x8000000
65         WS_CLIPSIBLINGS = 0x4000000
66         WS_CLIPCHILDREN = 0x2000000
67         WS_MAXIMIZE     = 0x1000000
68         WS_CAPTION      = WS_BORDER | WS_DLGFRAME
69         WS_BORDER       = 0x800000
70         WS_DLGFRAME     = 0x400000
71         WS_VSCROLL      = 0x200000
72         WS_HSCROLL      = 0x100000
73         WS_SYSMENU      = 0x80000
74         WS_THICKFRAME   = 0x40000
75         WS_GROUP        = 0x20000
76         WS_TABSTOP      = 0x10000
77         WS_MINIMIZEBOX  = 0x20000
78         WS_MAXIMIZEBOX  = 0x10000
79         WS_TILED        = WS_OVERLAPPED
80         WS_ICONIC       = WS_MINIMIZE
81         WS_SIZEBOX      = WS_THICKFRAME
82         // Common Window Styles
83         WS_OVERLAPPEDWINDOW = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX
84         WS_TILEDWINDOW      = WS_OVERLAPPEDWINDOW
85         WS_POPUPWINDOW      = WS_POPUP | WS_BORDER | WS_SYSMENU
86         WS_CHILDWINDOW      = WS_CHILD
87
88         WS_EX_CLIENTEDGE = 0x200
89
90         // Some windows messages
91         WM_CREATE  = 1
92         WM_DESTROY = 2
93         WM_CLOSE   = 16
94         WM_COMMAND = 273
95
96         // Some button control styles
97         BS_DEFPUSHBUTTON = 1
98
99         // Some colour constants
100         COLOR_WINDOW  = 5
101         COLOR_BTNFACE = 15
102
103         // Default window position
104         CW_USEDEFAULT = 0x80000000 - 0x100000000
105
106         // Show window default style
107         SW_SHOWDEFAULT = 10
108 )
109
110 var (
111         // Some globaly known cusrors
112         IDC_ARROW = MakeIntResource(32512)
113         IDC_IBEAM = MakeIntResource(32513)
114         IDC_WAIT  = MakeIntResource(32514)
115         IDC_CROSS = MakeIntResource(32515)
116
117         // Some globaly known icons
118         IDI_APPLICATION = MakeIntResource(32512)
119         IDI_HAND        = MakeIntResource(32513)
120         IDI_QUESTION    = MakeIntResource(32514)
121         IDI_EXCLAMATION = MakeIntResource(32515)
122         IDI_ASTERISK    = MakeIntResource(32516)
123         IDI_WINLOGO     = MakeIntResource(32517)
124         IDI_WARNING     = IDI_EXCLAMATION
125         IDI_ERROR       = IDI_HAND
126         IDI_INFORMATION = IDI_ASTERISK
127 )
128
129 //sys   GetModuleHandle(modname *uint16) (handle uint32, errno int) = GetModuleHandleW
130 //sys   RegisterClassEx(wndclass *Wndclassex) (atom uint16, errno int) = user32.RegisterClassExW
131 //sys   CreateWindowEx(exstyle uint32, classname *uint16, windowname *uint16, style uint32, x int32, y int32, width int32, height int32, wndparent uint32, menu uint32, instance uint32, param uintptr) (hwnd uint32, errno int) = user32.CreateWindowExW
132 //sys   DefWindowProc(hwnd uint32, msg uint32, wparam int32, lparam int32) (lresult int32) = user32.DefWindowProcW
133 //sys   DestroyWindow(hwnd uint32) (errno int) = user32.DestroyWindow
134 //sys   PostQuitMessage(exitcode int32) = user32.PostQuitMessage
135 //sys   ShowWindow(hwnd uint32, cmdshow int32) (wasvisible bool) = user32.ShowWindow
136 //sys   UpdateWindow(hwnd uint32) (errno int) = user32.UpdateWindow
137 //sys   GetMessage(msg *Msg, hwnd uint32, MsgFilterMin uint32, MsgFilterMax uint32) (ret int32, errno int) [failretval==-1] = user32.GetMessageW
138 //sys   TranslateMessage(msg *Msg) (done bool) = user32.TranslateMessage
139 //sys   DispatchMessage(msg *Msg) (ret int32) = user32.DispatchMessageW
140 //sys   LoadIcon(instance uint32, iconname *uint16) (icon uint32, errno int) = user32.LoadIconW
141 //sys   LoadCursor(instance uint32, cursorname *uint16) (cursor uint32, errno int) = user32.LoadCursorW
142 //sys   SetCursor(cursor uint32) (precursor uint32, errno int) = user32.SetCursor
143 //sys   SendMessage(hwnd uint32, msg uint32, wparam int32, lparam int32) (lresult int32) = user32.SendMessageW
144 //sys   PostMessage(hwnd uint32, msg uint32, wparam int32, lparam int32) (errno int) = user32.PostMessageW
145
146 func MakeIntResource(id uint16) *uint16 {
147         return (*uint16)(unsafe.Pointer(uintptr(id)))
148 }