diff options
| author | Pietro Gagliardi <[email protected]> | 2014-07-02 22:53:03 -0400 |
|---|---|---|
| committer | Pietro Gagliardi <[email protected]> | 2014-07-02 22:53:03 -0400 |
| commit | 8a81650b3da7ce00725336df9e03b38e935c5a65 (patch) | |
| tree | 08af843f0460e7226f305cf7162021ef54e8c3f7 /init_windows.go | |
| parent | 4dd5ceb11d62bd6b9af4847936314a9d8c45707f (diff) | |
Moved it all back; the preemptive multitaksing during an event handler kills us on all platforms. Going to have to restrict ALL GUI accss to happening from one t hread, so going to need to drop uitask entirely and have just a start() callback for startup code and a post() function for posting requests to windows (like channel sends but into a perpetual buffer).
Diffstat (limited to 'init_windows.go')
| -rw-r--r-- | init_windows.go | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/init_windows.go b/init_windows.go new file mode 100644 index 0000000..b8f11a5 --- /dev/null +++ b/init_windows.go @@ -0,0 +1,85 @@ +// 8 february 2014 + +package ui + +import ( + "fmt" + "unsafe" +) + +var ( + hInstance _HANDLE + nCmdShow int +) + +// TODO is this documented? +func getWinMainhInstance() (err error) { + r1, _, err := kernel32.NewProc("GetModuleHandleW").Call(uintptr(_NULL)) + if r1 == 0 { // failure + return err + } + hInstance = _HANDLE(r1) + return nil +} + +// this is what MinGW-w64 does (for instance, http://sourceforge.net/p/mingw-w64/code/6604/tree/trunk/mingw-w64-crt/crt/crtexe.c#l320); Burgundy in irc.freenode.net/#winapi said that the Visual C++ runtime does this too +func getWinMainnCmdShow() { + var info struct { + cb uint32 + lpReserved *uint16 + lpDesktop *uint16 + lpTitle *uint16 + dwX uint32 + dwY uint32 + dwXSize uint32 + dwYSzie uint32 + dwXCountChars uint32 + dwYCountChars uint32 + dwFillAttribute uint32 + dwFlags uint32 + wShowWindow uint16 + cbReserved2 uint16 + lpReserved2 *byte + hStdInput _HANDLE + hStdOutput _HANDLE + hStdError _HANDLE + } + + // does not fail according to MSDN + kernel32.NewProc("GetStartupInfoW").Call(uintptr(unsafe.Pointer(&info))) + if info.dwFlags&_STARTF_USESHOWWINDOW != 0 { + nCmdShow = int(info.wShowWindow) + } else { + nCmdShow = _SW_SHOWDEFAULT + } +} + +func doWindowsInit() (err error) { + err = getWinMainhInstance() + if err != nil { + return fmt.Errorf("error getting WinMain hInstance: %v", err) + } + getWinMainnCmdShow() + err = initWndClassInfo() + if err != nil { + return fmt.Errorf("error initializing standard window class auxiliary info: %v", err) + } + err = registerStdWndClass() + if err != nil { + return fmt.Errorf("error registering standard window class (for Window): %v", err) + } + err = registerAreaWndClass() + if err != nil { + return fmt.Errorf("error registering Area window class: %v", err) + } + err = getStandardWindowFonts() + if err != nil { + return fmt.Errorf("error getting standard window fonts: %v", err) + } + err = initCommonControls() + if err != nil { + return fmt.Errorf("error initializing Common Controls (comctl32.dll): %v", err) + } + // others go here + return nil // all ready to go +} |
