More error corrections; not done yet...

This commit is contained in:
Pietro Gagliardi 2014-02-11 19:09:10 -05:00
parent 09a42e0c34
commit ecb2205e02
7 changed files with 19 additions and 45 deletions

View File

@ -8,24 +8,24 @@ import (
) )
var ( var (
hInstance HANDLE hInstance _HANDLE
nCmdShow int nCmdShow int
// TODO font // TODO font
) )
// TODO is this trick documented in MSDN? // TODO is this trick documented in MSDN?
func getWinMainhInstance() (err error) { func getWinMainhInstance() (err error) {
r1, _, err := kernel32.NewProc("GetModuleHandleW").Call(uintptr(NULL)) r1, _, err := kernel32.NewProc("GetModuleHandleW").Call(uintptr(_NULL))
if r1 == 0 { // failure if r1 == 0 { // failure
return err return err
} }
hInstance = HANDLE(r1) hInstance = _HANDLE(r1)
return nil return nil
} }
// TODO this is what MinGW-w64's crt (svn revision xxx) does; is it best? is any of this documented anywhere on MSDN? // TODO this is what MinGW-w64's crt (svn revision TODO) does; is it best? is any of this documented anywhere on MSDN?
// TODO I highly doubt Windows API functions ever not fail, so figure out what to do should an error actually occur // TODO I highly doubt Windows API functions ever not fail, so figure out what to do should an error actually occur
func getWinMainnCmdShow() (nCmdShow int, err error) { func getWinMainnCmdShow() (err error) {
var info struct { var info struct {
cb uint32 cb uint32
lpReserved *uint16 lpReserved *uint16
@ -42,9 +42,9 @@ func getWinMainnCmdShow() (nCmdShow int, err error) {
wShowWindow uint16 wShowWindow uint16
cbReserved2 uint16 cbReserved2 uint16
lpReserved2 *byte lpReserved2 *byte
hStdInput HANDLE hStdInput _HANDLE
hStdOutput HANDLE hStdOutput _HANDLE
hStdError HANDLE hStdError _HANDLE
} }
const _STARTF_USESHOWWINDOW = 0x00000001 const _STARTF_USESHOWWINDOW = 0x00000001

View File

@ -1,8 +1,8 @@
// +build ignore
// 7 february 2014 // 7 february 2014
package main package main
//+build skip
import ( import (
"fmt" "fmt"
"os" "os"

View File

@ -26,4 +26,5 @@ func (c *cSysData) hide() error {
const ( const (
c_window = iota c_window = iota
c_button c_button
nctypes
) )

View File

@ -26,7 +26,7 @@ type classData struct {
var classTypes = [nctypes]*classData{ var classTypes = [nctypes]*classData{
c_window: &classData{ c_window: &classData{
name: uintptr(unsafe.Pointer(stdWndClass)), name: uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(stdWndClass))),
style: _WS_OVERLAPPEDWINDOW, style: _WS_OVERLAPPEDWINDOW,
xstyle: 0, xstyle: 0,
}, },
@ -57,7 +57,7 @@ func (s *sysData) make() (err error) {
uintptr(hInstance), uintptr(hInstance),
uintptr(_NULL), uintptr(_NULL),
}, },
ret: ret ret: ret,
} }
r := <-ret r := <-ret
if r.err != nil { if r.err != nil {
@ -87,7 +87,7 @@ func (s *sysData) show() (err error) {
defer close(ret) defer close(ret)
uitask <- &uimsg{ uitask <- &uimsg{
call: _showWindow, call: _showWindow,
p: []uintptr{uintptr(s.hwnd, show}, p: []uintptr{uintptr(s.hwnd), show},
ret: ret, ret: ret,
} }
r := <-ret r := <-ret

View File

@ -15,7 +15,7 @@ type sdcEntry struct {
var ( var (
sysDatas = map[_HWND]*sdcEntry{} sysDatas = map[_HWND]*sdcEntry{}
sysDatasLock sys.Mutex sysDatasLock sync.Mutex
) )
func addSysData(hwnd _HWND, s *sysData) { func addSysData(hwnd _HWND, s *sysData) {

View File

@ -2,7 +2,7 @@
package main package main
import ( import (
"syscall" // "syscall"
"unsafe" "unsafe"
) )
@ -173,27 +173,7 @@ var (
_showWindow = user32.NewProc("ShowWindow") _showWindow = user32.NewProc("ShowWindow")
) )
// TODO use lpParam /*
func CreateWindowEx(dwExStyle uint32, lpClassName string, lpWindowName string, dwStyle uint32, x int, y int, nWidth int, nHeight int, hwndParent HWND, hMenu HMENU, hInstance HANDLE, lpParam interface{}) (hwnd HWND, err error) {
r1, _, err := createWindowEx.Call(
uintptr(dwExStyle),
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(lpClassName))),
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(lpWindowName))),
uintptr(dwStyle),
uintptr(x),
uintptr(y),
uintptr(nWidth),
uintptr(nHeight),
uintptr(hwndParent),
uintptr(hMenu),
uintptr(hInstance),
uintptr(0))
if r1 == 0 { // failure
return NULL, err
}
return HWND(r1), nil
}
func DestroyWindow(hWnd HWND) (err error) { func DestroyWindow(hWnd HWND) (err error) {
r1, _, err := destroyWindow.Call(uintptr(hWnd)) r1, _, err := destroyWindow.Call(uintptr(hWnd))
if r1 == 0 { // failure if r1 == 0 { // failure
@ -249,14 +229,7 @@ func SetWindowPos(hWnd HWND, hWndInsertAfter HWND, X int, Y int, cx int, cy int,
} }
return nil return nil
} }
*/
// TODO figure out how to handle errors
func ShowWindow(hWnd HWND, nCmdShow int) (previouslyVisible bool, err error) {
r1, _, _ := showWindow.Call(
uintptr(hWnd),
uintptr(nCmdShow))
return r1 != 0, nil
}
// WM_SETICON and WM_GETICON values. // WM_SETICON and WM_GETICON values.
const ( const (
@ -377,6 +350,6 @@ type _MINMAXINFO struct {
PtMaxTrackSize _POINT PtMaxTrackSize _POINT
} }
func (l _LPARAM) MINMAXINFO() *MINMAXINFO { func (l _LPARAM) MINMAXINFO() *_MINMAXINFO {
return (*_MINMAXINFO)(unsafe.Pointer(l)) return (*_MINMAXINFO)(unsafe.Pointer(l))
} }