diff options
Diffstat (limited to 'unmigrated')
| -rw-r--r-- | unmigrated/controls_windows.go | 404 | ||||
| -rw-r--r-- | unmigrated/cursors_windows.go | 41 | ||||
| -rw-r--r-- | unmigrated/icons_windows.go | 35 | ||||
| -rw-r--r-- | unmigrated/menus_windows.go | 12 | ||||
| -rw-r--r-- | unmigrated/messagebox_windows.go | 85 | ||||
| -rw-r--r-- | unmigrated/messages_windows.go | 72 | ||||
| -rw-r--r-- | unmigrated/painting_windows.go | 20 | ||||
| -rw-r--r-- | unmigrated/rectangles_windows.go | 21 | ||||
| -rw-r--r-- | unmigrated/stdfont_windows.go | 74 | ||||
| -rw-r--r-- | unmigrated/wndproc_windows.go | 24 |
10 files changed, 788 insertions, 0 deletions
diff --git a/unmigrated/controls_windows.go b/unmigrated/controls_windows.go new file mode 100644 index 0000000..f2c778b --- /dev/null +++ b/unmigrated/controls_windows.go @@ -0,0 +1,404 @@ +// 9 february 2014 +package main + +import ( +// "syscall" +// "unsafe" +) + +// Button styles. +const ( + // from winuser.h + BS_PUSHBUTTON = 0x00000000 + BS_DEFPUSHBUTTON = 0x00000001 + BS_CHECKBOX = 0x00000002 + BS_AUTOCHECKBOX = 0x00000003 + BS_RADIOBUTTON = 0x00000004 + BS_3STATE = 0x00000005 + BS_AUTO3STATE = 0x00000006 + BS_GROUPBOX = 0x00000007 + BS_USERBUTTON = 0x00000008 + BS_AUTORADIOBUTTON = 0x00000009 + BS_PUSHBOX = 0x0000000A + BS_OWNERDRAW = 0x0000000B + BS_TYPEMASK = 0x0000000F + BS_LEFTTEXT = 0x00000020 + BS_TEXT = 0x00000000 + BS_ICON = 0x00000040 + BS_BITMAP = 0x00000080 + BS_LEFT = 0x00000100 + BS_RIGHT = 0x00000200 + BS_CENTER = 0x00000300 + BS_TOP = 0x00000400 + BS_BOTTOM = 0x00000800 + BS_VCENTER = 0x00000C00 + BS_PUSHLIKE = 0x00001000 + BS_MULTILINE = 0x00002000 + BS_NOTIFY = 0x00004000 + BS_FLAT = 0x00008000 + BS_RIGHTBUTTON = BS_LEFTTEXT + // from commctrl.h +// BS_SPLITBUTTON = 0x0000000C // Windows Vista and newer and(/or?) comctl6 only +// BS_DEFSPLITBUTTON = 0x0000000D // Windows Vista and newer and(/or?) comctl6 only +// BS_COMMANDLINK = 0x0000000E // Windows Vista and newer and(/or?) comctl6 only +// BS_DEFCOMMANDLINK = 0x0000000F // Windows Vista and newer and(/or?) comctl6 only +) + +// Button WM_COMMAND notifications. +const ( + // from winuser.h + BN_CLICKED = 0 + BN_PAINT = 1 + BN_HILITE = 2 + BN_UNHILITE = 3 + BN_DISABLE = 4 + BN_DOUBLECLICKED = 5 + BN_PUSHED = BN_HILITE + BN_UNPUSHED = BN_UNHILITE + BN_DBLCLK = BN_DOUBLECLICKED + BN_SETFOCUS = 6 + BN_KILLFOCUS = 7 +) + +// Button check states. +const ( + // from winuser.h + BST_UNCHECKED = 0x0000 + BST_CHECKED = 0x0001 + BST_INDETERMINATE = 0x0002 +) + +var ( + checkDlgButton = user32.NewProc("CheckDlgButton") + checkRadioButton = user32.NewProc("CheckRadioButton") + isDlgButtonChecked = user32.NewProc("IsDlgButtonChecked") +) + +func CheckDlgButton(hDlg HWND, nIDButton int, uCheck uint32) (err error) { + r1, _, err := checkDlgButton.Call( + uintptr(hDlg), + uintptr(nIDButton), + uintptr(uCheck)) + if r1 == 0 { // failure + return err + } + return nil +} + +func CheckRadioButton(hDlg HWND, nIDFirstButton int, nIDLastButton int, nIDCheckButton int) (err error) { + r1, _, err := checkRadioButton.Call( + uintptr(hDlg), + uintptr(nIDFirstButton), + uintptr(nIDLastButton), + uintptr(nIDCheckButton)) + if r1 == 0 { // failure + return err + } + return nil +} + +// TODO handle errors +func IsDlgButtonChecked(hDlg HWND, nIDButton int) (state uint32, err error) { + r1, _, _ := isDlgButtonChecked.Call( + uintptr(hDlg), + uintptr(nIDButton)) + return uint32(r1), nil +} + +// Combobox styles. +const ( + // from winuser.h + CBS_SIMPLE = 0x0001 + CBS_DROPDOWN = 0x0002 + CBS_DROPDOWNLIST = 0x0003 + CBS_OWNERDRAWFIXED = 0x0010 + CBS_OWNERDRAWVARIABLE = 0x0020 + CBS_AUTOHSCROLL = 0x0040 + CBS_OEMCONVERT = 0x0080 + CBS_SORT = 0x0100 + CBS_HASSTRINGS = 0x0200 + CBS_NOINTEGRALHEIGHT = 0x0400 + CBS_DISABLENOSCROLL = 0x0800 + CBS_UPPERCASE = 0x2000 + CBS_LOWERCASE = 0x4000 +) + +// Combobox messages. +// TODO filter out messages not provided in windows 2000 +const ( + // from winuser.h + CB_GETEDITSEL = 0x0140 + CB_LIMITTEXT = 0x0141 + CB_SETEDITSEL = 0x0142 + CB_ADDSTRING = 0x0143 + CB_DELETESTRING = 0x0144 + CB_DIR = 0x0145 + CB_GETCOUNT = 0x0146 + CB_GETCURSEL = 0x0147 + CB_GETLBTEXT = 0x0148 + CB_GETLBTEXTLEN = 0x0149 + CB_INSERTSTRING = 0x014A + CB_RESETCONTENT = 0x014B + CB_FINDSTRING = 0x014C + CB_SELECTSTRING = 0x014D + CB_SETCURSEL = 0x014E + CB_SHOWDROPDOWN = 0x014F + CB_GETITEMDATA = 0x0150 + CB_SETITEMDATA = 0x0151 + CB_GETDROPPEDCONTROLRECT = 0x0152 + CB_SETITEMHEIGHT = 0x0153 + CB_GETITEMHEIGHT = 0x0154 + CB_SETEXTENDEDUI = 0x0155 + CB_GETEXTENDEDUI = 0x0156 + CB_GETDROPPEDSTATE = 0x0157 + CB_FINDSTRINGEXACT = 0x0158 + CB_SETLOCALE = 0x0159 + CB_GETLOCALE = 0x015A + CB_GETTOPINDEX = 0x015B + CB_SETTOPINDEX = 0x015C + CB_GETHORIZONTALEXTENT = 0x015D + CB_SETHORIZONTALEXTENT = 0x015E + CB_GETDROPPEDWIDTH = 0x015F + CB_SETDROPPEDWIDTH = 0x0160 + CB_INITSTORAGE = 0x0161 + CB_MULTIPLEADDSTRING = 0x0163 + CB_GETCOMBOBOXINFO = 0x0164 +) + +// Combobox WM_COMMAND notificaitons. +// TODO filter out notifications not provided in windows 2000 +const ( + // from winuser.h + CBN_ERRSPACE = (-1) // TODO this will blow up the Go compiler if it's used + CBN_SELCHANGE = 1 + CBN_DBLCLK = 2 + CBN_SETFOCUS = 3 + CBN_KILLFOCUS = 4 + CBN_EDITCHANGE = 5 + CBN_EDITUPDATE = 6 + CBN_DROPDOWN = 7 + CBN_CLOSEUP = 8 + CBN_SELENDOK = 9 + CBN_SELENDCANCEL = 10 +) + +// Edit control styles. +const ( + // from winuser.h + ES_LEFT = 0x0000 + ES_CENTER = 0x0001 + ES_RIGHT = 0x0002 + ES_MULTILINE = 0x0004 + ES_UPPERCASE = 0x0008 + ES_LOWERCASE = 0x0010 + ES_PASSWORD = 0x0020 + ES_AUTOVSCROLL = 0x0040 + ES_AUTOHSCROLL = 0x0080 + ES_NOHIDESEL = 0x0100 + ES_OEMCONVERT = 0x0400 + ES_READONLY = 0x0800 + ES_WANTRETURN = 0x1000 + ES_NUMBER = 0x2000 +) + +// Edit control messages. +// TODO filter out messages not provided in windows 2000 +const ( + // from winuser.h + EM_GETSEL = 0x00B0 + EM_SETSEL = 0x00B1 + EM_GETRECT = 0x00B2 + EM_SETRECT = 0x00B3 + EM_SETRECTNP = 0x00B4 + EM_SCROLL = 0x00B5 + EM_LINESCROLL = 0x00B6 + EM_SCROLLCARET = 0x00B7 + EM_GETMODIFY = 0x00B8 + EM_SETMODIFY = 0x00B9 + EM_GETLINECOUNT = 0x00BA + EM_LINEINDEX = 0x00BB + EM_SETHANDLE = 0x00BC + EM_GETHANDLE = 0x00BD + EM_GETTHUMB = 0x00BE + EM_LINELENGTH = 0x00C1 + EM_REPLACESEL = 0x00C2 + EM_GETLINE = 0x00C4 + EM_LIMITTEXT = 0x00C5 + EM_CANUNDO = 0x00C6 + EM_UNDO = 0x00C7 + EM_FMTLINES = 0x00C8 + EM_LINEFROMCHAR = 0x00C9 + EM_SETTABSTOPS = 0x00CB + EM_SETPASSWORDCHAR = 0x00CC + EM_EMPTYUNDOBUFFER = 0x00CD + EM_GETFIRSTVISIBLELINE = 0x00CE + EM_SETREADONLY = 0x00CF + EM_SETWORDBREAKPROC = 0x00D0 + EM_GETWORDBREAKPROC = 0x00D1 + EM_GETPASSWORDCHAR = 0x00D2 + EM_SETMARGINS = 0x00D3 + EM_GETMARGINS = 0x00D4 + EM_SETLIMITTEXT = EM_LIMITTEXT // [;win40 Name change] + EM_GETLIMITTEXT = 0x00D5 + EM_POSFROMCHAR = 0x00D6 + EM_CHARFROMPOS = 0x00D7 + EM_SETIMESTATUS = 0x00D8 + EM_GETIMESTATUS = 0x00D9 +) + +// Edit control WM_COMMAND notifications. +// TODO filter out notifications not provided in windows 2000 +const ( + // from winuser.h + EN_SETFOCUS = 0x0100 + EN_KILLFOCUS = 0x0200 + EN_CHANGE = 0x0300 + EN_UPDATE = 0x0400 + EN_ERRSPACE = 0x0500 + EN_MAXTEXT = 0x0501 + EN_HSCROLL = 0x0601 + EN_VSCROLL = 0x0602 + EN_ALIGN_LTR_EC = 0x0700 + EN_ALIGN_RTL_EC = 0x0701 + EC_LEFTMARGIN = 0x0001 + EC_RIGHTMARGIN = 0x0002 + EC_USEFONTINFO = 0xFFFF + EMSIS_COMPOSITIONSTRING = 0x0001 + EIMES_GETCOMPSTRATONCE = 0x0001 + EIMES_CANCELCOMPSTRINFOCUS = 0x0002 + EIMES_COMPLETECOMPSTRKILLFOCUS = 0x0004 +) + +// Listbox styles. +const ( + // from winuser.h + LBS_NOTIFY = 0x0001 + LBS_SORT = 0x0002 + LBS_NOREDRAW = 0x0004 + LBS_MULTIPLESEL = 0x0008 + LBS_OWNERDRAWFIXED = 0x0010 + LBS_OWNERDRAWVARIABLE = 0x0020 + LBS_HASSTRINGS = 0x0040 + LBS_USETABSTOPS = 0x0080 + LBS_NOINTEGRALHEIGHT = 0x0100 + LBS_MULTICOLUMN = 0x0200 + LBS_WANTKEYBOARDINPUT = 0x0400 + LBS_EXTENDEDSEL = 0x0800 + LBS_DISABLENOSCROLL = 0x1000 + LBS_NODATA = 0x2000 + LBS_NOSEL = 0x4000 + LBS_COMBOBOX = 0x8000 + LBS_STANDARD = (LBS_NOTIFY | LBS_SORT | WS_VSCROLL | WS_BORDER) +) + +// Listbox messages. +// TODO filter out messages not provided in windows 2000 +const ( + // from winuser.h + LB_ADDSTRING = 0x0180 + LB_INSERTSTRING = 0x0181 + LB_DELETESTRING = 0x0182 + LB_SELITEMRANGEEX = 0x0183 + LB_RESETCONTENT = 0x0184 + LB_SETSEL = 0x0185 + LB_SETCURSEL = 0x0186 + LB_GETSEL = 0x0187 + LB_GETCURSEL = 0x0188 + LB_GETTEXT = 0x0189 + LB_GETTEXTLEN = 0x018A + LB_GETCOUNT = 0x018B + LB_SELECTSTRING = 0x018C + LB_DIR = 0x018D + LB_GETTOPINDEX = 0x018E + LB_FINDSTRING = 0x018F + LB_GETSELCOUNT = 0x0190 + LB_GETSELITEMS = 0x0191 + LB_SETTABSTOPS = 0x0192 + LB_GETHORIZONTALEXTENT = 0x0193 + LB_SETHORIZONTALEXTENT = 0x0194 + LB_SETCOLUMNWIDTH = 0x0195 + LB_ADDFILE = 0x0196 + LB_SETTOPINDEX = 0x0197 + LB_GETITEMRECT = 0x0198 + LB_GETITEMDATA = 0x0199 + LB_SETITEMDATA = 0x019A + LB_SELITEMRANGE = 0x019B + LB_SETANCHORINDEX = 0x019C + LB_GETANCHORINDEX = 0x019D + LB_SETCARETINDEX = 0x019E + LB_GETCARETINDEX = 0x019F + LB_SETITEMHEIGHT = 0x01A0 + LB_GETITEMHEIGHT = 0x01A1 + LB_FINDSTRINGEXACT = 0x01A2 + LB_SETLOCALE = 0x01A5 + LB_GETLOCALE = 0x01A6 + LB_SETCOUNT = 0x01A7 + LB_INITSTORAGE = 0x01A8 + LB_ITEMFROMPOINT = 0x01A9 + LB_MULTIPLEADDSTRING = 0x01B1 + LB_GETLISTBOXINFO = 0x01B2 +) + +// Listbox WM_COMMAND notifications and message returns. +// TODO filter out notifications not provided in windows 2000 +const ( + // from winuser.h + LB_OKAY = 0 + LB_ERR = (-1) // TODO this will blow up the Go compiler if it's used + LBN_ERRSPACE = (-2) // TODO this will blow up the Go compiler if it's used + LBN_SELCHANGE = 1 + LBN_DBLCLK = 2 + LBN_SELCANCEL = 3 + LBN_SETFOCUS = 4 + LBN_KILLFOCUS = 5 +) + +// Static control styles. +const ( + // from winuser.h + SS_LEFT = 0x00000000 + SS_CENTER = 0x00000001 + SS_RIGHT = 0x00000002 + SS_ICON = 0x00000003 + SS_BLACKRECT = 0x00000004 + SS_GRAYRECT = 0x00000005 + SS_WHITERECT = 0x00000006 + SS_BLACKFRAME = 0x00000007 + SS_GRAYFRAME = 0x00000008 + SS_WHITEFRAME = 0x00000009 + SS_USERITEM = 0x0000000A + SS_SIMPLE = 0x0000000B + SS_LEFTNOWORDWRAP = 0x0000000C + SS_OWNERDRAW = 0x0000000D + SS_BITMAP = 0x0000000E + SS_ENHMETAFILE = 0x0000000F + SS_ETCHEDHORZ = 0x00000010 + SS_ETCHEDVERT = 0x00000011 + SS_ETCHEDFRAME = 0x00000012 + SS_TYPEMASK = 0x0000001F + SS_REALSIZECONTROL = 0x00000040 + SS_NOPREFIX = 0x00000080 + SS_NOTIFY = 0x00000100 + SS_CENTERIMAGE = 0x00000200 + SS_RIGHTJUST = 0x00000400 + SS_REALSIZEIMAGE = 0x00000800 + SS_SUNKEN = 0x00001000 + SS_EDITCONTROL = 0x00002000 + SS_ENDELLIPSIS = 0x00004000 + SS_PATHELLIPSIS = 0x00008000 + SS_WORDELLIPSIS = 0x0000C000 + SS_ELLIPSISMASK = 0x0000C000 +) + +// Static control messages and WM_COMMAND notifications. +const ( + // from winuser.h + STM_SETICON = 0x0170 + STM_GETICON = 0x0171 + STM_SETIMAGE = 0x0172 + STM_GETIMAGE = 0x0173 + STN_CLICKED = 0 + STN_DBLCLK = 1 + STN_ENABLE = 2 + STN_DISABLE = 3 +) diff --git a/unmigrated/cursors_windows.go b/unmigrated/cursors_windows.go new file mode 100644 index 0000000..78fb1f8 --- /dev/null +++ b/unmigrated/cursors_windows.go @@ -0,0 +1,41 @@ +// 8 february 2014 +package main + +import ( +// "syscall" +// "unsafe" +) + +// Predefined cursor resource IDs. +const ( + IDC_APPSTARTING = 32650 + IDC_ARROW = 32512 + IDC_CROSS = 32515 + IDC_HAND = 32649 + IDC_HELP = 32651 + IDC_IBEAM = 32513 +// IDC_ICON = 32641 // [Obsolete for applications marked version 4.0 or later.] + IDC_NO = 32648 +// IDC_SIZE = 32640 // [Obsolete for applications marked version 4.0 or later. Use IDC_SIZEALL.] + IDC_SIZEALL = 32646 + IDC_SIZENESW = 32643 + IDC_SIZENS = 32645 + IDC_SIZENWSE = 32642 + IDC_SIZEWE = 32644 + IDC_UPARROW = 32516 + IDC_WAIT = 32514 +) + +var ( + loadCursor = user32.NewProc("LoadCursorW") +) + +func LoadCursor_ResourceID(hInstance HANDLE, lpCursorName uint16) (cursor HANDLE, err error) { + r1, _, err := loadCursor.Call( + uintptr(hInstance), + MAKEINTRESOURCE(lpCursorName)) + if r1 == 0 { // failure + return NULL, err + } + return HANDLE(r1), nil +} diff --git a/unmigrated/icons_windows.go b/unmigrated/icons_windows.go new file mode 100644 index 0000000..c28f158 --- /dev/null +++ b/unmigrated/icons_windows.go @@ -0,0 +1,35 @@ +// 8 february 2014 +package main + +import ( +// "syscall" +// "unsafe" +) + +// Predefined icon resource IDs. +const ( + IDI_APPLICATION = 32512 + IDI_ASTERISK = 32516 + IDI_ERROR = 32513 + IDI_EXCLAMATION = 32515 + IDI_HAND = 32513 + IDI_INFORMATION = 32516 + IDI_QUESTION = 32514 + IDI_SHIELD = 32518 + IDI_WARNING = 32515 + IDI_WINLOGO = 32517 +) + +var ( + loadIcon = user32.NewProc("LoadIconW") +) + +func LoadIcon_ResourceID(hInstance HANDLE, lpIconName uint16) (icon HANDLE, err error) { + r1, _, err := loadIcon.Call( + uintptr(hInstance), + MAKEINTRESOURCE(lpIconName)) + if r1 == 0 { // failure + return NULL, err + } + return HANDLE(r1), nil +} diff --git a/unmigrated/menus_windows.go b/unmigrated/menus_windows.go new file mode 100644 index 0000000..4f6c059 --- /dev/null +++ b/unmigrated/menus_windows.go @@ -0,0 +1,12 @@ +// 10 february 2014 +package main + +import ( +// "syscall" +// "unsafe" +) + +// Menu notifications. +const ( + WM_COMMAND = 0x0111 +) diff --git a/unmigrated/messagebox_windows.go b/unmigrated/messagebox_windows.go new file mode 100644 index 0000000..ba50f61 --- /dev/null +++ b/unmigrated/messagebox_windows.go @@ -0,0 +1,85 @@ +// 7 february 2014 +package main + +import ( + "syscall" + "unsafe" +) + +// MessageBox button types. +const ( + MB_ABORTRETRYIGNORE = 0x00000002 + MB_CANCELTRYCONTINUE = 0x00000006 + MB_HELP = 0x00004000 + MB_OK = 0x00000000 + MB_OKCANCEL = 0x00000001 + MB_RETRYCANCEL = 0x00000005 + MB_YESNO = 0x00000004 + MB_YESNOCANCEL = 0x00000003 +) + +// MessageBox icon types. +const ( + MB_ICONEXCLAMATION = 0x00000030 + MB_ICONWARNING = 0x00000030 + MB_ICONINFORMATION = 0x00000040 + MB_ICONASTERISK = 0x00000040 + MB_ICONQUESTION = 0x00000020 + MB_ICONSTOP = 0x00000010 + MB_ICONERROR = 0x00000010 + MB_ICONHAND = 0x00000010 +) + +// MessageBox default button types. +const ( + MB_DEFBUTTON1 = 0x00000000 + MB_DEFBUTTON2 = 0x00000100 + MB_DEFBUTTON3 = 0x00000200 + MB_DEFBUTTON4 = 0x00000300 +) + +// MessageBox modality types. +const ( + MB_APPLMODAL = 0x00000000 + MB_SYSTEMMODAL = 0x00001000 + MB_TASKMODAL = 0x00002000 +) + +// MessageBox miscellaneous types. +const ( + MB_DEFAULT_DESKTOP_ONLY = 0x00020000 + MB_RIGHT = 0x00080000 + MB_RTLREADING = 0x00100000 + MB_SETFOREGROUND = 0x00010000 + MB_TOPMOST = 0x00040000 + MB_SERVICE_NOTIFICATION = 0x00200000 +) + +// MessageBox return values. +const ( + IDABORT = 3 + IDCANCEL = 2 + IDCONTINUE = 11 + IDIGNORE = 5 + IDNO = 7 + IDOK = 1 + IDRETRY = 4 + IDTRYAGAIN = 10 + IDYES = 6 +) + +var ( + messageBox = user32.NewProc("MessageBoxW") +) + +func MessageBox(hWnd HWND, lpText string, lpCaption string, uType uint32) (result int, err error) { + r1, _, err := messageBox.Call( + uintptr(unsafe.Pointer(hWnd)), + uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(lpText))), + uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(lpCaption))), + uintptr(uType)) + if r1 == 0 { // failure + return 0, err + } + return int(r1), nil +} diff --git a/unmigrated/messages_windows.go b/unmigrated/messages_windows.go new file mode 100644 index 0000000..e74b9fa --- /dev/null +++ b/unmigrated/messages_windows.go @@ -0,0 +1,72 @@ +// 9 february 2014 +package main + +import ( +// "syscall" + "unsafe" +) + +// SendMessage constants. +const ( + HWND_BROADCAST = HWND(0xFFFF) +) + +type MSG struct { + Hwnd HWND + Message uint32 + WParam WPARAM + LParam LPARAM + Time uint32 + Pt POINT +} + +var ( + dispatchMessage = user32.NewProc("DispatchMessageW") + getMessage = user32.NewProc("GetMessageW") + postQuitMessage = user32.NewProc("PostQuitMessage") + sendMessage = user32.NewProc("SendMessageW") + translateMessage = user32.NewProc("TranslateMessage") +) + +// TODO handle errors +func DispatchMessage(lpmsg *MSG) (result LRESULT, err error) { + r1, _, _ := dispatchMessage.Call(uintptr(unsafe.Pointer(lpmsg))) + return LRESULT(r1), nil +} + +var getMessageFail = -1 // because Go doesn't let me + +func GetMessage(hWnd HWND, wMsgFilterMin uint32, wMsgFilterMax uint32) (lpMsg *MSG, quit bool, err error) { + lpMsg = new(MSG) + r1, _, err := getMessage.Call( + uintptr(unsafe.Pointer(lpMsg)), + uintptr(hWnd), + uintptr(wMsgFilterMin), + uintptr(wMsgFilterMax)) + if r1 == uintptr(getMessageFail) { // failure + return nil, false, err + } + return lpMsg, r1 == 0, nil +} + +// TODO handle errors +func PostQuitMessage(nExitCode int) (err error) { + postQuitMessage.Call(uintptr(nExitCode)) + return nil +} + +// TODO handle errors +func SendMessage(hWnd HWND, Msg uint32, wParam WPARAM, lParam LPARAM) (result LRESULT, err error) { + r1, _, _ := sendMessage.Call( + uintptr(hWnd), + uintptr(Msg), + uintptr(wParam), + uintptr(lParam)) + return LRESULT(r1), nil +} + +// TODO handle errors +func TranslateMessage(lpMsg *MSG) (translated bool, err error) { + r1, _, _ := translateMessage.Call(uintptr(unsafe.Pointer(lpMsg))) + return r1 != 0, nil +} diff --git a/unmigrated/painting_windows.go b/unmigrated/painting_windows.go new file mode 100644 index 0000000..069fd2d --- /dev/null +++ b/unmigrated/painting_windows.go @@ -0,0 +1,20 @@ +// 9 february 2014 +package main + +import ( +// "syscall" +// "unsafe" +) + +var ( + updateWindow = user32.NewProc("UpdateWindow") +) + +// TODO is error handling valid here? MSDN just says zero on failure; syscall.LazyProc.Call() always returns non-nil +func UpdateWindow(hWnd HWND) (err error) { + r1, _, err := updateWindow.Call(uintptr(hWnd)) + if r1 == 0 { // failure + return err + } + return nil +} diff --git a/unmigrated/rectangles_windows.go b/unmigrated/rectangles_windows.go new file mode 100644 index 0000000..c0c29d5 --- /dev/null +++ b/unmigrated/rectangles_windows.go @@ -0,0 +1,21 @@ +// 9 february 2014 +package main + +import ( +// "syscall" +// "unsafe" +) + +// TODO merge with common.go? + +type POINT struct { + X int32 + Y int32 +} + +type RECT struct { + Left int32 + Top int32 + Right int32 + Bottom int32 +} diff --git a/unmigrated/stdfont_windows.go b/unmigrated/stdfont_windows.go new file mode 100644 index 0000000..8dcba9f --- /dev/null +++ b/unmigrated/stdfont_windows.go @@ -0,0 +1,74 @@ +// 10 february 2014 +package main + +import ( +// "syscall" + "unsafe" +) + +const ( + SPI_GETNONCLIENTMETRICS = 0x0029 + LF_FACESIZE = 32 // from wingdi.h +) + +type LOGFONT struct { + lfHeight int32 + lfWidth int32 + lfEscapement int32 + lfOrientation int32 + lfWeight int32 + lfItalic byte + lfUnderline byte + lfStrikeOut byte + lfCharSet byte + lfOutPrecision byte + lfClipPrecision byte + lfQuality byte + lfPitchAndFamily byte + lfFaceName [LF_FACESIZE]uint16 +} + +type NONCLIENTMETRICS struct { + cbSize uint32 + iBorderWidth int + iScrollWidth int + iScrollHeight int + iCaptionWidth int + iCaptionHeight int + lfCaptionFont LOGFONT + iSmCaptionWidth int + iSmCaptionHeight int + lfSmCaptionFont LOGFONT + iMenuWidth int + iMenuHeight int + lfMenuFont LOGFONT + lfStatusFont LOGFONT + lfMessageFont LOGFONT +} + +var ( + systemParametersInfo = user32.NewProc("SystemParametersInfoW") + createFontIndirect = gdi32.NewProc("CreateFontIndirectW") +) + +// TODO adorn errors with which step failed? +// TODO this specific font doesn't seem like the right one but that's all I could find for what people actually use; also I need to return the other ones and check HWND types to make sure I apply the right font to the right thing... +func getStandardWindowFont() (hfont HANDLE, err error) { + var ncm NONCLIENTMETRICS + + ncm.cbSize = uint32(unsafe.Sizeof(ncm)) + r1, _, err := systemParametersInfo.Call( + uintptr(SPI_GETNONCLIENTMETRICS), + uintptr(unsafe.Sizeof(ncm)), + uintptr(unsafe.Pointer(&ncm)), + 0) + if r1 == 0 { // failure + return NULL, err + } + // TODO does this specify an error? + r1, _, err = createFontIndirect.Call(uintptr(unsafe.Pointer(&ncm.lfMessageFont))) + if r1 == 0 { // failure + return NULL, err + } + return HANDLE(r1), nil +} diff --git a/unmigrated/wndproc_windows.go b/unmigrated/wndproc_windows.go new file mode 100644 index 0000000..b9c13f2 --- /dev/null +++ b/unmigrated/wndproc_windows.go @@ -0,0 +1,24 @@ +// 8 february 2014 +package main + +import ( +// "syscall" +// "unsafe" +) + +// TODO error handling +type WNDPROC func(hwnd HWND, uMsg uint32, wParam WPARAM, lParam LPARAM) LRESULT + +var ( + defWindowProc = user32.NewProc("DefWindowProcW") +) + +// TODO error handling +func DefWindowProc(hwnd HWND, uMsg uint32, wParam WPARAM, lParam LPARAM) LRESULT { + r1, _, _ := defWindowProc.Call( + uintptr(hwnd), + uintptr(uMsg), + uintptr(wParam), + uintptr(lParam)) + return LRESULT(r1) +} |
