Set up initialization on Windows (1/2) and fixed a leftover error in sysdata_windows.go.

This commit is contained in:
Pietro Gagliardi 2014-02-11 16:23:38 -05:00
parent 9b19ee7245
commit af22eea889
2 changed files with 33 additions and 15 deletions

View File

@ -43,7 +43,7 @@ func (s *sysData) show() (err error) {
ret := make(chan uiret) ret := make(chan uiret)
defer close(ret) defer close(ret)
uitask <- &uimsg{ uitask <- &uimsg{
call: os_showWindow, call: _showWindow,
p: []uintptr{uintptr(s.hwnd, _SW_SHOW}, p: []uintptr{uintptr(s.hwnd, _SW_SHOW},
ret: ret, ret: ret,
} }

View File

@ -2,28 +2,30 @@
package main package main
import ( import (
"fmt"
// "syscall" // "syscall"
"unsafe" "unsafe"
) )
// this provides the hInstance and nCmdShow that are normally passed to WinMain()
const ( const (
STARTF_USESHOWWINDOW = 0x00000001 windowclass = "gouiwndclass"
) )
var ( var (
getModuleHandle = kernel32.NewProc("GetModuleHandleW") hInstance HANDLE
getStartupInfo = kernel32.NewProc("GetStartupInfoW") nCmdShow int
// TODO font
// TODO common window class
) )
// TODO is this trick documented in MSDN? // TODO is this trick documented in MSDN?
func getWinMainhInstance() (hInstance HANDLE, err error) { func getWinMainhInstance() (err error) {
r1, _, err := getModuleHandle.Call(uintptr(NULL)) r1, _, err := kernel32.NewProc("GetModuleHandleW").Call(uintptr(NULL))
if r1 == 0 { if r1 == 0 { // failure
return NULL, err return err
} }
return HANDLE(r1), nil hInstance = HANDLE(r1)
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 xxx) does; is it best? is any of this documented anywhere on MSDN?
@ -49,11 +51,27 @@ func getWinMainnCmdShow() (nCmdShow int, err error) {
hStdOutput HANDLE hStdOutput HANDLE
hStdError HANDLE hStdError HANDLE
} }
const _STARTF_USESHOWWINDOW = 0x00000001
// does not fail according to MSDN // does not fail according to MSDN
getStartupInfo.Call(uintptr(unsafe.Pointer(&info))) kernel32.NewProc("GetStartupInfoW").Call(uintptr(unsafe.Pointer(&info)))
if info.dwFlags & STARTF_USESHOWWINDOW != 0 { if info.dwFlags & _STARTF_USESHOWWINDOW != 0 {
return int(info.wShowWindow), nil nCmdShow = int(info.wShowWindow)
return nil
} }
return SW_SHOWDEFAULT, nil nCmdShow = _SW_SHOWDEFAULT
return nil
}
func doWindowsInit() (err error) {
err = getWinMainhInstance()
if err != nil {
return fmt.Errorf("error getting WinMain hInstance: %v", err)
}
err = getWinMainnCmdShow()
if err != nil {
return fmt.Errorf("error getting WinMain nCmdShow: %v", err)
}
// TODO others
return nil // all ready to go
} }