From 685f3d4c842426a40c278167b4ecd9bffd41e645 Mon Sep 17 00:00:00 2001 From: Allen Dang Date: Mon, 16 Apr 2012 15:57:19 +0800 Subject: [PATCH] Update "w32" package usage. --- app.go | 18 ++++++---------- bitmap.go | 38 +++++++++++++++----------------- brush.go | 7 +++--- buttons.go | 9 ++++---- canvas.go | 56 +++++++++++++++++++++++------------------------- commondlgs.go | 20 +++++++---------- controlbase.go | 53 +++++++++++++++++++++------------------------ customcontrol.go | 3 +-- dialog.go | 11 +++++----- edit.go | 3 +-- font.go | 15 ++++++------- form.go | 19 ++++++++-------- icon.go | 10 ++++----- imagelist.go | 15 ++++++------- init.go | 10 ++++++--- listview.go | 39 ++++++++++++++++----------------- pen.go | 7 +++--- progressbar.go | 11 +++++----- rect.go | 23 ++++++++++---------- tooltip.go | 5 ++--- utils.go | 24 ++++++++++----------- w32control.go | 9 ++++---- wndproc.go | 16 ++++++-------- 23 files changed, 193 insertions(+), 228 deletions(-) diff --git a/app.go b/app.go index f0d6cac..202fa8b 100644 --- a/app.go +++ b/app.go @@ -2,15 +2,11 @@ package gform import ( "github.com/AllenDang/w32" - "github.com/AllenDang/w32/comctl32" - "github.com/AllenDang/w32/gdiplus" - "github.com/AllenDang/w32/kernel32" - "github.com/AllenDang/w32/user32" "unsafe" ) func Init() { - gAppInstance = kernel32.GetModuleHandle("") + gAppInstance = w32.GetModuleHandle("") if gAppInstance == 0 { panic("Error occurred in App.Init") } @@ -22,7 +18,7 @@ func Init() { w32.ICC_LISTVIEW_CLASSES | w32.ICC_PROGRESS_CLASS | w32.ICC_TAB_CLASSES | w32.ICC_TREEVIEW_CLASSES | w32.ICC_BAR_CLASSES - comctl32.InitCommonControlsEx(&initCtrls) + w32.InitCommonControlsEx(&initCtrls) } func GetAppInstance() w32.HINSTANCE { @@ -57,18 +53,18 @@ func PreTranslateMessage(msg *w32.MSG) bool { func RunMainLoop() int { var m w32.MSG - for user32.GetMessage(&m, 0, 0, 0) != 0 { + for w32.GetMessage(&m, 0, 0, 0) != 0 { if !PreTranslateMessage(&m) { - user32.TranslateMessage(&m) - user32.DispatchMessage(&m) + w32.TranslateMessage(&m) + w32.DispatchMessage(&m) } } - gdiplus.GdiplusShutdown() + w32.GdiplusShutdown() return int(m.WParam) } func Exit() { - user32.PostQuitMessage(0) + w32.PostQuitMessage(0) } diff --git a/bitmap.go b/bitmap.go index 73c1e94..5a60713 100644 --- a/bitmap.go +++ b/bitmap.go @@ -3,10 +3,6 @@ package gform import ( "errors" "github.com/AllenDang/w32" - "github.com/AllenDang/w32/gdi32" - "github.com/AllenDang/w32/gdiplus" - "github.com/AllenDang/w32/kernel32" - "github.com/AllenDang/w32/ole32" "unsafe" ) @@ -17,7 +13,7 @@ type Bitmap struct { func assembleBitmapFromHBITMAP(hbitmap w32.HBITMAP) (*Bitmap, error) { var dib w32.DIBSECTION - if gdi32.GetObject(w32.HGDIOBJ(hbitmap), unsafe.Sizeof(dib), unsafe.Pointer(&dib)) == 0 { + if w32.GetObject(w32.HGDIOBJ(hbitmap), unsafe.Sizeof(dib), unsafe.Pointer(&dib)) == 0 { return nil, errors.New("GetObject for HBITMAP failed") } @@ -32,15 +28,15 @@ func NewBitmapFromFile(filepath string, background Color) (*Bitmap, error) { var gpBitmap *uintptr var err error - gpBitmap, err = gdiplus.GdipCreateBitmapFromFile(filepath) + gpBitmap, err = w32.GdipCreateBitmapFromFile(filepath) if err != nil { return nil, err } - defer gdiplus.GdipDisposeImage(gpBitmap) + defer w32.GdipDisposeImage(gpBitmap) var hbitmap w32.HBITMAP // Reverse gform.RGB to BGR to satisfy gdiplus color schema. - hbitmap, err = gdiplus.GdipCreateHBITMAPFromBitmap(gpBitmap, uint32(RGB(background.B(), background.G(), background.R()))) + hbitmap, err = w32.GdipCreateHBITMAPFromBitmap(gpBitmap, uint32(RGB(background.B(), background.G(), background.R()))) if err != nil { return nil, err } @@ -53,30 +49,30 @@ func NewBitmapFromResource(instance w32.HINSTANCE, resName *uint16, resType *uin var err error var hRes w32.HRSRC - hRes, err = kernel32.FindResource(w32.HMODULE(instance), resName, resType) + hRes, err = w32.FindResource(w32.HMODULE(instance), resName, resType) if err != nil { return nil, err } - resSize := kernel32.SizeofResource(w32.HMODULE(instance), hRes) - pResData := kernel32.LockResource(kernel32.LoadResource(w32.HMODULE(instance), hRes)) - resBuffer := kernel32.GlobalAlloc(w32.GMEM_MOVEABLE, resSize) - pResBuffer := kernel32.GlobalLock(resBuffer) - kernel32.MoveMemory(pResBuffer, pResData, resSize) + resSize := w32.SizeofResource(w32.HMODULE(instance), hRes) + pResData := w32.LockResource(w32.LoadResource(w32.HMODULE(instance), hRes)) + resBuffer := w32.GlobalAlloc(w32.GMEM_MOVEABLE, resSize) + pResBuffer := w32.GlobalLock(resBuffer) + w32.MoveMemory(pResBuffer, pResData, resSize) - stream := ole32.CreateStreamOnHGlobal(resBuffer, false) + stream := w32.CreateStreamOnHGlobal(resBuffer, false) - gpBitmap, err = gdiplus.GdipCreateBitmapFromStream(stream) + gpBitmap, err = w32.GdipCreateBitmapFromStream(stream) if err != nil { return nil, err } defer stream.Release() - defer kernel32.GlobalUnlock(resBuffer) - defer kernel32.GlobalFree(resBuffer) - defer gdiplus.GdipDisposeImage(gpBitmap) + defer w32.GlobalUnlock(resBuffer) + defer w32.GlobalFree(resBuffer) + defer w32.GdipDisposeImage(gpBitmap) var hbitmap w32.HBITMAP // Reverse gform.RGB to BGR to satisfy gdiplus color schema. - hbitmap, err = gdiplus.GdipCreateHBITMAPFromBitmap(gpBitmap, uint32(RGB(background.B(), background.G(), background.R()))) + hbitmap, err = w32.GdipCreateHBITMAPFromBitmap(gpBitmap, uint32(RGB(background.B(), background.G(), background.R()))) if err != nil { return nil, err } @@ -86,7 +82,7 @@ func NewBitmapFromResource(instance w32.HINSTANCE, resName *uint16, resType *uin func (this *Bitmap) Dispose() { if this.handle != 0 { - gdi32.DeleteObject(w32.HGDIOBJ(this.handle)) + w32.DeleteObject(w32.HGDIOBJ(this.handle)) this.handle = 0 } } diff --git a/brush.go b/brush.go index d443956..6a0ad34 100644 --- a/brush.go +++ b/brush.go @@ -2,7 +2,6 @@ package gform import ( "github.com/AllenDang/w32" - "github.com/AllenDang/w32/gdi32" ) type Brush struct { @@ -12,7 +11,7 @@ type Brush struct { func NewSolidColorBrush(color Color) *Brush { lb := w32.LOGBRUSH{LbStyle: w32.BS_SOLID, LbColor: w32.COLORREF(color)} - hBrush := gdi32.CreateBrushIndirect(&lb) + hBrush := w32.CreateBrushIndirect(&lb) if hBrush == 0 { panic("Faild to create solid color brush") } @@ -22,7 +21,7 @@ func NewSolidColorBrush(color Color) *Brush { func NewNullBrush() *Brush { lb := w32.LOGBRUSH{LbStyle: w32.BS_NULL} - hBrush := gdi32.CreateBrushIndirect(&lb) + hBrush := w32.CreateBrushIndirect(&lb) if hBrush == 0 { panic("Failed to create null brush") } @@ -40,7 +39,7 @@ func (this *Brush) GetLOGBRUSH() *w32.LOGBRUSH { func (this *Brush) Dispose() { if this.hBrush != 0 { - gdi32.DeleteObject(w32.HGDIOBJ(this.hBrush)) + w32.DeleteObject(w32.HGDIOBJ(this.hBrush)) this.hBrush = 0 } } diff --git a/buttons.go b/buttons.go index 8718975..3b6bdd5 100644 --- a/buttons.go +++ b/buttons.go @@ -2,7 +2,6 @@ package gform import ( "github.com/AllenDang/w32" - "github.com/AllenDang/w32/user32" ) type Button struct { @@ -10,7 +9,7 @@ type Button struct { } func (this *Button) Checked() bool { - result := user32.SendMessage(this.hwnd, w32.BM_GETCHECK, 0, 0) + result := w32.SendMessage(this.hwnd, w32.BM_GETCHECK, 0, 0) return result == w32.BST_CHECKED } @@ -19,7 +18,7 @@ func (this *Button) SetChecked(checked bool) { if !checked { wparam = w32.BST_UNCHECKED } - user32.SendMessage(this.hwnd, w32.BM_SETCHECK, uintptr(wparam), 0) + w32.SendMessage(this.hwnd, w32.BM_SETCHECK, uintptr(wparam), 0) } type PushButton struct { @@ -55,9 +54,9 @@ func (this *PushButton) WndProc(msg uint, wparam, lparam uintptr) uintptr { case w32.BN_CLICKED: println("Clicked") case w32.WM_LBUTTONDOWN: - user32.SetCapture(this.Handle()) + w32.SetCapture(this.Handle()) case w32.WM_LBUTTONUP: - user32.ReleaseCapture() + w32.ReleaseCapture() } return this.W32Control.WndProc(msg, wparam, lparam) diff --git a/canvas.go b/canvas.go index 6a7874f..c0fb981 100644 --- a/canvas.go +++ b/canvas.go @@ -3,8 +3,6 @@ package gform import ( "fmt" "github.com/AllenDang/w32" - "github.com/AllenDang/w32/gdi32" - "github.com/AllenDang/w32/user32" ) type Canvas struct { @@ -14,7 +12,7 @@ type Canvas struct { } func NewCanvasFromHwnd(hwnd w32.HWND) *Canvas { - hdc := user32.GetDC(hwnd) + hdc := w32.GetDC(hwnd) if hdc == 0 { panic(fmt.Sprintf("Create canvas from %v failed.", hwnd)) } @@ -33,9 +31,9 @@ func NewCanvasFromHDC(hdc w32.HDC) *Canvas { func (this *Canvas) Dispose() { if !this.doNotDispose && this.hdc != 0 { if this.hwnd == 0 { - gdi32.DeleteDC(this.hdc) + w32.DeleteDC(this.hdc) } else { - user32.ReleaseDC(this.hwnd, this.hdc) + w32.ReleaseDC(this.hwnd, this.hdc) } this.hdc = 0 @@ -43,60 +41,60 @@ func (this *Canvas) Dispose() { } func (this *Canvas) DrawBitmap(bmp *Bitmap, x, y int) { - cdc := gdi32.CreateCompatibleDC(0) - defer gdi32.DeleteDC(cdc) + cdc := w32.CreateCompatibleDC(0) + defer w32.DeleteDC(cdc) - hbmpOld := gdi32.SelectObject(cdc, w32.HGDIOBJ(bmp.GetHBITMAP())) - defer gdi32.SelectObject(cdc, w32.HGDIOBJ(hbmpOld)) + hbmpOld := w32.SelectObject(cdc, w32.HGDIOBJ(bmp.GetHBITMAP())) + defer w32.SelectObject(cdc, w32.HGDIOBJ(hbmpOld)) w, h := bmp.Size() - gdi32.BitBlt(this.hdc, x, y, w, h, cdc, 0, 0, w32.SRCCOPY) + w32.BitBlt(this.hdc, x, y, w, h, cdc, 0, 0, w32.SRCCOPY) } func (this *Canvas) DrawStretchedBitmap(bmp *Bitmap, rect *Rect) { - cdc := gdi32.CreateCompatibleDC(0) - defer gdi32.DeleteDC(cdc) + cdc := w32.CreateCompatibleDC(0) + defer w32.DeleteDC(cdc) - hbmpOld := gdi32.SelectObject(cdc, w32.HGDIOBJ(bmp.GetHBITMAP())) - defer gdi32.SelectObject(cdc, w32.HGDIOBJ(hbmpOld)) + hbmpOld := w32.SelectObject(cdc, w32.HGDIOBJ(bmp.GetHBITMAP())) + defer w32.SelectObject(cdc, w32.HGDIOBJ(hbmpOld)) w, h := bmp.Size() rc := rect.GetW32Rect() - gdi32.StretchBlt(this.hdc, rc.Left, rc.Top, rc.Right, rc.Bottom, cdc, 0, 0, w, h, w32.SRCCOPY) + w32.StretchBlt(this.hdc, rc.Left, rc.Top, rc.Right, rc.Bottom, cdc, 0, 0, w, h, w32.SRCCOPY) } func (this *Canvas) DrawIcon(ico *Icon, x, y int) bool { - return user32.DrawIcon(this.hdc, x, y, ico.Handle()) + return w32.DrawIcon(this.hdc, x, y, ico.Handle()) } func (this *Canvas) DrawRect(rect *Rect, pen *Pen, brush *Brush) { w32Rect := rect.GetW32Rect() - previousPen := gdi32.SelectObject(this.hdc, w32.HGDIOBJ(pen.GetHPEN())) - defer gdi32.SelectObject(this.hdc, previousPen) + previousPen := w32.SelectObject(this.hdc, w32.HGDIOBJ(pen.GetHPEN())) + defer w32.SelectObject(this.hdc, previousPen) - previousBrush := gdi32.SelectObject(this.hdc, w32.HGDIOBJ(brush.GetHBRUSH())) - defer gdi32.SelectObject(this.hdc, previousBrush) + previousBrush := w32.SelectObject(this.hdc, w32.HGDIOBJ(brush.GetHBRUSH())) + defer w32.SelectObject(this.hdc, previousBrush) - gdi32.Rectangle(this.hdc, w32Rect.Left, w32Rect.Top, w32Rect.Right, w32Rect.Bottom) + w32.Rectangle(this.hdc, w32Rect.Left, w32Rect.Top, w32Rect.Right, w32Rect.Bottom) } func (this *Canvas) FillRect(rect *Rect, brush *Brush) { - user32.FillRect(this.hdc, rect.GetW32Rect(), brush.GetHBRUSH()) + w32.FillRect(this.hdc, rect.GetW32Rect(), brush.GetHBRUSH()) } // Refer win32 DrawText document for uFormat. func (this *Canvas) DrawText(text string, rect *Rect, format uint, font *Font, textColor Color) { - previousFont := gdi32.SelectObject(this.hdc, w32.HGDIOBJ(font.GetHFONT())) - defer gdi32.SelectObject(this.hdc, w32.HGDIOBJ(previousFont)) + previousFont := w32.SelectObject(this.hdc, w32.HGDIOBJ(font.GetHFONT())) + defer w32.SelectObject(this.hdc, w32.HGDIOBJ(previousFont)) - previousBkMode := gdi32.SetBkMode(this.hdc, w32.TRANSPARENT) - defer gdi32.SetBkMode(this.hdc, previousBkMode) + previousBkMode := w32.SetBkMode(this.hdc, w32.TRANSPARENT) + defer w32.SetBkMode(this.hdc, previousBkMode) - previousTextColor := gdi32.SetTextColor(this.hdc, w32.COLORREF(textColor)) - defer gdi32.SetTextColor(this.hdc, previousTextColor) + previousTextColor := w32.SetTextColor(this.hdc, w32.COLORREF(textColor)) + defer w32.SetTextColor(this.hdc, previousTextColor) - user32.DrawText(this.hdc, text, len(text), rect.GetW32Rect(), format) + w32.DrawText(this.hdc, text, len(text), rect.GetW32Rect(), format) } diff --git a/commondlgs.go b/commondlgs.go index 3714175..5a72ba6 100644 --- a/commondlgs.go +++ b/commondlgs.go @@ -2,10 +2,6 @@ package gform import ( "github.com/AllenDang/w32" - "github.com/AllenDang/w32/comdlg32" - "github.com/AllenDang/w32/ole32" - "github.com/AllenDang/w32/shell32" - "github.com/AllenDang/w32/user32" "syscall" "unsafe" ) @@ -47,7 +43,7 @@ func ShowOpenFileDlg(parent Controller, title, filter string, filterIndex uint, buf := make([]uint16, 1024) ofn := genOFN(parent, title, filter, filterIndex, initialDir, buf) - if accepted = comdlg32.GetOpenFileName(ofn); accepted { + if accepted = w32.GetOpenFileName(ofn); accepted { filePath = syscall.UTF16ToString(buf) } @@ -58,7 +54,7 @@ func ShowSaveFileDlg(parent Controller, title, filter string, filterIndex uint, buf := make([]uint16, 1024) ofn := genOFN(parent, title, filter, filterIndex, initialDir, buf) - if accepted = comdlg32.GetSaveFileName(ofn); accepted { + if accepted = w32.GetSaveFileName(ofn); accepted { filePath = syscall.UTF16ToString(buf) } @@ -71,11 +67,11 @@ func ShowBrowseFolderDlg(parent Controller, title string) (folder string, accept bi.Title = syscall.StringToUTF16Ptr(title) bi.Flags = w32.BIF_RETURNONLYFSDIRS | w32.BIF_NEWDIALOGSTYLE - ole32.CoInitialize() - ret := shell32.SHBrowseForFolder(&bi) - ole32.CoUninitialize() + w32.CoInitialize() + ret := w32.SHBrowseForFolder(&bi) + w32.CoUninitialize() - folder = shell32.SHGetPathFromIDList(ret) + folder = w32.SHGetPathFromIDList(ret) accepted = folder != "" return } @@ -83,9 +79,9 @@ func ShowBrowseFolderDlg(parent Controller, title string) (folder string, accept func MsgBox(parent Controller, title, caption string, flags uint) int { var result int if parent != nil { - result = user32.MessageBox(parent.Handle(), caption, title, flags) + result = w32.MessageBox(parent.Handle(), caption, title, flags) } else { - result = user32.MessageBox(0, caption, title, flags) + result = w32.MessageBox(0, caption, title, flags) } return result diff --git a/controlbase.go b/controlbase.go index 4e5b837..420f894 100644 --- a/controlbase.go +++ b/controlbase.go @@ -2,9 +2,6 @@ package gform import ( "github.com/AllenDang/w32" - "github.com/AllenDang/w32/kernel32" - "github.com/AllenDang/w32/shell32" - "github.com/AllenDang/w32/user32" ) type ControlBase struct { @@ -59,37 +56,37 @@ func (this *ControlBase) Handle() w32.HWND { } func (this *ControlBase) SetCaption(caption string) { - user32.SetWindowText(this.hwnd, caption) + w32.SetWindowText(this.hwnd, caption) } func (this *ControlBase) Caption() string { - return user32.GetWindowText(this.hwnd) + return w32.GetWindowText(this.hwnd) } func (this *ControlBase) Close() { UnRegMsgHandler(this.hwnd) - user32.DestroyWindow(this.hwnd) + w32.DestroyWindow(this.hwnd) } func (this *ControlBase) SetSize(width, height int) { x, y := this.Pos() - user32.MoveWindow(this.hwnd, x, y, width, height, true) + w32.MoveWindow(this.hwnd, x, y, width, height, true) } func (this *ControlBase) Size() (width, height int) { - rect := user32.GetWindowRect(this.hwnd) + rect := w32.GetWindowRect(this.hwnd) width = int(rect.Right - rect.Left) height = int(rect.Bottom - rect.Top) return } func (this *ControlBase) Width() int { - rect := user32.GetWindowRect(this.hwnd) + rect := w32.GetWindowRect(this.hwnd) return int(rect.Right - rect.Left) } func (this *ControlBase) Height() int { - rect := user32.GetWindowRect(this.hwnd) + rect := w32.GetWindowRect(this.hwnd) return int(rect.Bottom - rect.Top) } @@ -101,25 +98,25 @@ func (this *ControlBase) SetPos(x, y int) { if h == 0 { h = 25 } - user32.MoveWindow(this.hwnd, x, y, w, h, true) + w32.MoveWindow(this.hwnd, x, y, w, h, true) } func (this *ControlBase) Pos() (x, y int) { - rect := user32.GetWindowRect(this.hwnd) + rect := w32.GetWindowRect(this.hwnd) x = int(rect.Left) y = int(rect.Top) if !this.isForm && this.parent != nil { - x, y = user32.ScreenToClient(this.parent.Handle(), x, y) + x, y = w32.ScreenToClient(this.parent.Handle(), x, y) } return } func (this *ControlBase) Visible() bool { - return user32.IsWindowVisible(this.hwnd) + return w32.IsWindowVisible(this.hwnd) } func (this *ControlBase) Bounds() *Rect { - rect := user32.GetWindowRect(this.hwnd) + rect := w32.GetWindowRect(this.hwnd) if this.isForm { return &Rect{*rect} } @@ -128,37 +125,37 @@ func (this *ControlBase) Bounds() *Rect { } func (this *ControlBase) ClientRect() *Rect { - rect := user32.GetClientRect(this.hwnd) + rect := w32.GetClientRect(this.hwnd) return ScreenToClientRect(this.hwnd, rect) } func (this *ControlBase) Show() { - user32.ShowWindow(this.hwnd, w32.SW_SHOWDEFAULT) + w32.ShowWindow(this.hwnd, w32.SW_SHOWDEFAULT) } func (this *ControlBase) Hide() { - user32.ShowWindow(this.hwnd, w32.SW_HIDE) + w32.ShowWindow(this.hwnd, w32.SW_HIDE) } func (this *ControlBase) Enabled() bool { - return user32.IsWindowEnabled(this.hwnd) + return w32.IsWindowEnabled(this.hwnd) } func (this *ControlBase) SetEnabled(b bool) { - user32.EnableWindow(this.hwnd, b) + w32.EnableWindow(this.hwnd, b) } func (this *ControlBase) Focus() { - user32.SetFocus(this.hwnd) + w32.SetFocus(this.hwnd) } func (this *ControlBase) Invalidate(erase bool) { - pRect := user32.GetClientRect(this.hwnd) + pRect := w32.GetClientRect(this.hwnd) if this.isForm { - user32.InvalidateRect(this.hwnd, pRect, erase) + w32.InvalidateRect(this.hwnd, pRect, erase) } else { rc := ScreenToClientRect(this.hwnd, pRect) - user32.InvalidateRect(this.hwnd, rc.GetW32Rect(), erase) + w32.InvalidateRect(this.hwnd, rc.GetW32Rect(), erase) } } @@ -171,12 +168,12 @@ func (this *ControlBase) Font() *Font { } func (this *ControlBase) SetFont(font *Font) { - user32.SendMessage(this.hwnd, w32.WM_SETFONT, uintptr(font.hfont), 1) + w32.SendMessage(this.hwnd, w32.WM_SETFONT, uintptr(font.hfont), 1) this.font = font } func (this *ControlBase) EnableDragAcceptFiles(b bool) { - shell32.DragAcceptFiles(this.hwnd, b) + w32.DragAcceptFiles(this.hwnd, b) } func (this *ControlBase) InvokeRequired() bool { @@ -184,8 +181,8 @@ func (this *ControlBase) InvokeRequired() bool { return false } - windowThreadId, _ := user32.GetWindowThreadProcessId(this.hwnd) - currentThreadId := kernel32.GetCurrentThread() + windowThreadId, _ := w32.GetWindowThreadProcessId(this.hwnd) + currentThreadId := w32.GetCurrentThread() return windowThreadId != currentThreadId } diff --git a/customcontrol.go b/customcontrol.go index 79651bc..c42b79f 100644 --- a/customcontrol.go +++ b/customcontrol.go @@ -2,7 +2,6 @@ package gform import ( "github.com/AllenDang/w32" - "github.com/AllenDang/w32/user32" ) type CustomControl struct { @@ -45,5 +44,5 @@ func (this *CustomControl) WndProc(msg uint, wparam, lparam uintptr) uintptr { this.onMouseLeave.Fire(NewEventArg(sender, nil)) this.isMouseLeft = true } - return user32.DefWindowProc(this.hwnd, msg, wparam, lparam) + return w32.DefWindowProc(this.hwnd, msg, wparam, lparam) } diff --git a/dialog.go b/dialog.go index c6316d7..4938cc0 100644 --- a/dialog.go +++ b/dialog.go @@ -2,7 +2,6 @@ package gform import ( "github.com/AllenDang/w32" - "github.com/AllenDang/w32/user32" ) type Dialog struct { @@ -77,7 +76,7 @@ func (this *Dialog) ShowWithData(data interface{}) { if this.Handle() == 0 { gDialogWaiting = this - this.hwnd = user32.CreateDialog(GetAppInstance(), this.template, parentHwnd, GeneralWndprocCallBack) + this.hwnd = w32.CreateDialog(GetAppInstance(), this.template, parentHwnd, GeneralWndprocCallBack) this.Data = data if ico, err := NewIconFromResource(GetAppInstance(), 101); err == nil { this.SetIcon(0, ico) @@ -96,7 +95,7 @@ func (this *Dialog) ShowModalWithData(data interface{}) (result int) { } gDialogWaiting = this - if result = user32.DialogBox(GetAppInstance(), this.template, parentHwnd, GeneralWndprocCallBack); result == -1 { + if result = w32.DialogBox(GetAppInstance(), this.template, parentHwnd, GeneralWndprocCallBack); result == -1 { panic("Failed to create modal dialog box") } @@ -107,9 +106,9 @@ func (this *Dialog) Close(result int) { this.onClose.Fire(NewEventArg(this, nil)) if this.isModal { - user32.EndDialog(this.hwnd, uintptr(result)) + w32.EndDialog(this.hwnd, uintptr(result)) } else { - user32.DestroyWindow(this.hwnd) + w32.DestroyWindow(this.hwnd) } UnRegMsgHandler(this.hwnd) @@ -117,7 +116,7 @@ func (this *Dialog) Close(result int) { func (this *Dialog) PreTranslateMessage(msg *w32.MSG) bool { if msg.Message >= w32.WM_KEYFIRST && msg.Message <= w32.WM_KEYLAST { - if !this.isModal && user32.IsDialogMessage(this.hwnd, msg) { + if !this.isModal && w32.IsDialogMessage(this.hwnd, msg) { return true } } diff --git a/edit.go b/edit.go index 64ec1fc..a6c3b4c 100644 --- a/edit.go +++ b/edit.go @@ -2,7 +2,6 @@ package gform import ( "github.com/AllenDang/w32" - "github.com/AllenDang/w32/user32" ) type Edit struct { @@ -41,7 +40,7 @@ func (this *Edit) OnChange() *EventManager { //Public methods func (this *Edit) SetReadOnly(isReadOnly bool) { - user32.SendMessage(this.hwnd, w32.EM_SETREADONLY, uintptr(w32.BoolToBOOL(isReadOnly)), 0) + w32.SendMessage(this.hwnd, w32.EM_SETREADONLY, uintptr(w32.BoolToBOOL(isReadOnly)), 0) } func (this *Edit) AddLine(text string) { diff --git a/font.go b/font.go index 28ce174..d2b70f9 100644 --- a/font.go +++ b/font.go @@ -2,9 +2,6 @@ package gform import ( "github.com/AllenDang/w32" - "github.com/AllenDang/w32/gdi32" - "github.com/AllenDang/w32/kernel32" - "github.com/AllenDang/w32/user32" "syscall" ) @@ -32,9 +29,9 @@ func NewFont(family string, pointSize int, style byte) *Font { } //Retrive screen DPI - hDC := user32.GetDC(0) - defer user32.ReleaseDC(0, hDC) - screenDPIY := gdi32.GetDeviceCaps(hDC, w32.LOGPIXELSY) + hDC := w32.GetDC(0) + defer w32.ReleaseDC(0, hDC) + screenDPIY := w32.GetDeviceCaps(hDC, w32.LOGPIXELSY) font := Font{ family: family, @@ -53,7 +50,7 @@ func NewFont(family string, pointSize int, style byte) *Font { func (this *Font) createForDPI(dpi int) w32.HFONT { var lf w32.LOGFONT - lf.Height = -kernel32.MulDiv(this.pointSize, dpi, 72) + lf.Height = -w32.MulDiv(this.pointSize, dpi, 72) if this.style&FontBold > 0 { lf.Weight = w32.FW_BOLD } else { @@ -78,7 +75,7 @@ func (this *Font) createForDPI(dpi int) w32.HFONT { dest := lf.FaceName[:] copy(dest, src) - return gdi32.CreateFontIndirect(&lf) + return w32.CreateFontIndirect(&lf) } func (this *Font) GetHFONT() w32.HFONT { @@ -91,7 +88,7 @@ func (this *Font) Bold() bool { func (this *Font) Dispose() { if this.hfont != 0 { - gdi32.DeleteObject(w32.HGDIOBJ(this.hfont)) + w32.DeleteObject(w32.HGDIOBJ(this.hfont)) } } diff --git a/form.go b/form.go index 73f97e3..724ee24 100644 --- a/form.go +++ b/form.go @@ -2,7 +2,6 @@ package gform import ( "github.com/AllenDang/w32" - "github.com/AllenDang/w32/user32" ) type Form struct { @@ -36,8 +35,8 @@ func (this *Form) init(parent Controller) { // Public methods func (this *Form) Center() { - sWidth := user32.GetSystemMetrics(w32.SM_CXFULLSCREEN) - sHeight := user32.GetSystemMetrics(w32.SM_CYFULLSCREEN) + sWidth := w32.GetSystemMetrics(w32.SM_CXFULLSCREEN) + sHeight := w32.GetSystemMetrics(w32.SM_CYFULLSCREEN) if sWidth != 0 && sHeight != 0 { w, h := this.Size() @@ -51,7 +50,7 @@ func (this *Form) SetIcon(iconType int, icon *Icon) { panic("IconType is invalid") } - user32.SendMessage(this.hwnd, w32.WM_SETICON, uintptr(iconType), uintptr(icon.Handle())) + w32.SendMessage(this.hwnd, w32.WM_SETICON, uintptr(iconType), uintptr(icon.Handle())) } func (this *Form) EnableMaxButton(b bool) { @@ -76,21 +75,21 @@ func (this *Form) EnableTopMost(b bool) { tag = w32.HWND_TOPMOST } - user32.SetWindowPos(this.hwnd, tag, 0, 0, 0, 0, w32.SWP_NOMOVE|w32.SWP_NOSIZE) + w32.SetWindowPos(this.hwnd, tag, 0, 0, 0, 0, w32.SWP_NOMOVE|w32.SWP_NOSIZE) } func (this *Form) WndProc(msg uint, wparam, lparam uintptr) uintptr { switch msg { case w32.WM_LBUTTONDOWN: if this.isDragMove { - user32.ReleaseCapture() - user32.SendMessage(this.hwnd, w32.WM_NCLBUTTONDOWN, w32.HTCAPTION, 0) + w32.ReleaseCapture() + w32.SendMessage(this.hwnd, w32.WM_NCLBUTTONDOWN, w32.HTCAPTION, 0) } case w32.WM_CLOSE: - user32.DestroyWindow(this.hwnd) + w32.DestroyWindow(this.hwnd) case w32.WM_DESTROY: - user32.PostQuitMessage(0) + w32.PostQuitMessage(0) } - return user32.DefWindowProc(this.hwnd, msg, wparam, lparam) + return w32.DefWindowProc(this.hwnd, msg, wparam, lparam) } diff --git a/icon.go b/icon.go index aa06589..bcc0998 100644 --- a/icon.go +++ b/icon.go @@ -4,8 +4,6 @@ import ( "errors" "fmt" "github.com/AllenDang/w32" - "github.com/AllenDang/w32/shell32" - "github.com/AllenDang/w32/user32" "syscall" ) @@ -16,7 +14,7 @@ type Icon struct { func NewIconFromFile(path string) (*Icon, error) { ico := new(Icon) var err error - if ico.handle = user32.LoadIcon(0, syscall.StringToUTF16Ptr(path)); ico.handle == 0 { + if ico.handle = w32.LoadIcon(0, syscall.StringToUTF16Ptr(path)); ico.handle == 0 { err = errors.New(fmt.Sprintf("Cannot load icon from %s", path)) } @@ -27,7 +25,7 @@ func NewIconFromFile(path string) (*Icon, error) { func NewIconFromResource(instance w32.HINSTANCE, resId uint16) (*Icon, error) { ico := new(Icon) var err error - if ico.handle = user32.LoadIcon(instance, w32.MakeIntResource(resId)); ico.handle == 0 { + if ico.handle = w32.LoadIcon(instance, w32.MakeIntResource(resId)); ico.handle == 0 { err = errors.New(fmt.Sprintf("Cannot load icon from resource with id %v", resId)) } @@ -37,7 +35,7 @@ func NewIconFromResource(instance w32.HINSTANCE, resId uint16) (*Icon, error) { func ExtractIcon(fileName string, index int) (*Icon, error) { ico := new(Icon) var err error - if ico.handle = shell32.ExtractIcon(fileName, index); ico.handle == 0 || ico.handle == 1 { + if ico.handle = w32.ExtractIcon(fileName, index); ico.handle == 0 || ico.handle == 1 { err = errors.New(fmt.Sprintf("Cannot extract icon from %s at index %v", fileName, index)) } @@ -45,7 +43,7 @@ func ExtractIcon(fileName string, index int) (*Icon, error) { } func (this *Icon) Destroy() bool { - return user32.DestroyIcon(this.handle) + return w32.DestroyIcon(this.handle) } func (this *Icon) Handle() w32.HICON { diff --git a/imagelist.go b/imagelist.go index 1e61f46..5b9a7f1 100644 --- a/imagelist.go +++ b/imagelist.go @@ -2,7 +2,6 @@ package gform import ( "github.com/AllenDang/w32" - "github.com/AllenDang/w32/comctl32" ) type ImageList struct { @@ -11,7 +10,7 @@ type ImageList struct { func NewImageList(cx, cy int, flags uint, cInitial, cGrow int) *ImageList { imgl := new(ImageList) - imgl.handle = comctl32.ImageList_Create(cx, cy, flags, cInitial, cGrow) + imgl.handle = w32.ImageList_Create(cx, cy, flags, cInitial, cGrow) return imgl } @@ -21,25 +20,25 @@ func (this *ImageList) Handle() w32.HIMAGELIST { } func (this *ImageList) Destroy() bool { - return comctl32.ImageList_Destroy(this.handle) + return w32.ImageList_Destroy(this.handle) } func (this *ImageList) SetImageCount(uNewCount uint) bool { - return comctl32.ImageList_SetImageCount(this.handle, uNewCount) + return w32.ImageList_SetImageCount(this.handle, uNewCount) } func (this *ImageList) ImageCount() int { - return comctl32.ImageList_GetImageCount(this.handle) + return w32.ImageList_GetImageCount(this.handle) } func (this *ImageList) AddIcon(icon *Icon) int { - return comctl32.ImageList_AddIcon(this.handle, icon.Handle()) + return w32.ImageList_AddIcon(this.handle, icon.Handle()) } func (this *ImageList) RemoveAll() bool { - return comctl32.ImageList_RemoveAll(this.handle) + return w32.ImageList_RemoveAll(this.handle) } func (this *ImageList) Remove(i int) bool { - return comctl32.ImageList_Remove(this.handle, i) + return w32.ImageList_Remove(this.handle, i) } diff --git a/init.go b/init.go index c5e0c7b..dabe6dc 100644 --- a/init.go +++ b/init.go @@ -1,10 +1,14 @@ package gform import ( - "github.com/AllenDang/w32" + "github.com/AllenDang/w32" ) func init() { - gControllerRegistry = make(map[w32.HWND]Controller) - gRegisteredClasses = make([]string, 0) + gControllerRegistry = make(map[w32.HWND]Controller) + gRegisteredClasses = make([]string, 0) + + var si w32.GdiplusStartupInput + si.GdiplusVersion = 1 + w32.GdiplusStartup(&si, nil) } diff --git a/listview.go b/listview.go index 29d6eff..460f586 100644 --- a/listview.go +++ b/listview.go @@ -2,7 +2,6 @@ package gform import ( "github.com/AllenDang/w32" - "github.com/AllenDang/w32/user32" "syscall" "unsafe" ) @@ -30,7 +29,7 @@ func AttachListView(parent Controller, id int) *ListView { lv.attach(parent, id) RegMsgHandler(lv) - user32.SendMessage(lv.Handle(), w32.LVM_SETUNICODEFORMAT, w32.TRUE, 0) + w32.SendMessage(lv.Handle(), w32.LVM_SETUNICODEFORMAT, w32.TRUE, 0) return lv } @@ -44,7 +43,7 @@ func (this *ListView) setItemState(i int, state, mask uint) { var item w32.LVITEM item.State, item.StateMask = state, mask - user32.SendMessage(this.hwnd, w32.LVM_SETITEMSTATE, uintptr(i), uintptr(unsafe.Pointer(&item))) + w32.SendMessage(this.hwnd, w32.LVM_SETITEMSTATE, uintptr(i), uintptr(unsafe.Pointer(&item))) } func (this *ListView) EnableSingleSelect(enable bool) { @@ -65,34 +64,34 @@ func (this *ListView) EnableEditLabels(enable bool) { func (this *ListView) EnableFullRowSelect(enable bool) { if enable { - user32.SendMessage(this.hwnd, w32.LVM_SETEXTENDEDLISTVIEWSTYLE, 0, w32.LVS_EX_FULLROWSELECT) + w32.SendMessage(this.hwnd, w32.LVM_SETEXTENDEDLISTVIEWSTYLE, 0, w32.LVS_EX_FULLROWSELECT) } else { - user32.SendMessage(this.hwnd, w32.LVM_SETEXTENDEDLISTVIEWSTYLE, w32.LVS_EX_FULLROWSELECT, 0) + w32.SendMessage(this.hwnd, w32.LVM_SETEXTENDEDLISTVIEWSTYLE, w32.LVS_EX_FULLROWSELECT, 0) } } func (this *ListView) EnableDoubleBuffer(enable bool) { if enable { - user32.SendMessage(this.hwnd, w32.LVM_SETEXTENDEDLISTVIEWSTYLE, 0, w32.LVS_EX_DOUBLEBUFFER) + w32.SendMessage(this.hwnd, w32.LVM_SETEXTENDEDLISTVIEWSTYLE, 0, w32.LVS_EX_DOUBLEBUFFER) } else { - user32.SendMessage(this.hwnd, w32.LVM_SETEXTENDEDLISTVIEWSTYLE, w32.LVS_EX_DOUBLEBUFFER, 0) + w32.SendMessage(this.hwnd, w32.LVM_SETEXTENDEDLISTVIEWSTYLE, w32.LVS_EX_DOUBLEBUFFER, 0) } } func (this *ListView) EnableHotTrack(enable bool) { if enable { - user32.SendMessage(this.hwnd, w32.LVM_SETEXTENDEDLISTVIEWSTYLE, 0, w32.LVS_EX_TRACKSELECT) + w32.SendMessage(this.hwnd, w32.LVM_SETEXTENDEDLISTVIEWSTYLE, 0, w32.LVS_EX_TRACKSELECT) } else { - user32.SendMessage(this.hwnd, w32.LVM_SETEXTENDEDLISTVIEWSTYLE, w32.LVS_EX_TRACKSELECT, 0) + w32.SendMessage(this.hwnd, w32.LVM_SETEXTENDEDLISTVIEWSTYLE, w32.LVS_EX_TRACKSELECT, 0) } } func (this *ListView) SetItemCount(count int) bool { - return user32.SendMessage(this.hwnd, w32.LVM_SETITEMCOUNT, uintptr(count), 0) != 0 + return w32.SendMessage(this.hwnd, w32.LVM_SETITEMCOUNT, uintptr(count), 0) != 0 } func (this *ListView) ItemCount() int { - return int(user32.SendMessage(this.hwnd, w32.LVM_GETITEMCOUNT, 0, 0)) + return int(w32.SendMessage(this.hwnd, w32.LVM_GETITEMCOUNT, 0, 0)) } func (this *ListView) InsertColumn(caption string, width int, iCol int) { @@ -126,23 +125,23 @@ func (this *ListView) AddItem(text ...string) { } func (this *ListView) InsertLvColumn(lvColumn *w32.LVCOLUMN, iCol int) { - user32.SendMessage(this.hwnd, w32.LVM_INSERTCOLUMN, uintptr(iCol), uintptr(unsafe.Pointer(lvColumn))) + w32.SendMessage(this.hwnd, w32.LVM_INSERTCOLUMN, uintptr(iCol), uintptr(unsafe.Pointer(lvColumn))) } func (this *ListView) InsertLvItem(lvItem *w32.LVITEM) { - user32.SendMessage(this.hwnd, w32.LVM_INSERTITEM, 0, uintptr(unsafe.Pointer(lvItem))) + w32.SendMessage(this.hwnd, w32.LVM_INSERTITEM, 0, uintptr(unsafe.Pointer(lvItem))) } func (this *ListView) SetLvItem(lvItem *w32.LVITEM) { - user32.SendMessage(this.hwnd, w32.LVM_SETITEM, 0, uintptr(unsafe.Pointer(lvItem))) + w32.SendMessage(this.hwnd, w32.LVM_SETITEM, 0, uintptr(unsafe.Pointer(lvItem))) } func (this *ListView) DeleteAllItems() bool { - return user32.SendMessage(this.hwnd, w32.LVM_DELETEALLITEMS, 0, 0) == w32.TRUE + return w32.SendMessage(this.hwnd, w32.LVM_DELETEALLITEMS, 0, 0) == w32.TRUE } func (this *ListView) Item(item *w32.LVITEM) bool { - return user32.SendMessage(this.hwnd, w32.LVM_GETITEM, 0, uintptr(unsafe.Pointer(item))) == w32.TRUE + return w32.SendMessage(this.hwnd, w32.LVM_GETITEM, 0, uintptr(unsafe.Pointer(item))) == w32.TRUE } func (this *ListView) ItemAtIndex(i int) *w32.LVITEM { @@ -161,7 +160,7 @@ func (this *ListView) SelectedItems(mask uint) []*w32.LVITEM { var i int = -1 for { - if i = int(user32.SendMessage(this.hwnd, w32.LVM_GETNEXTITEM, uintptr(i), uintptr(w32.LVNI_SELECTED))); i == -1 { + if i = int(w32.SendMessage(this.hwnd, w32.LVM_GETNEXTITEM, uintptr(i), uintptr(w32.LVNI_SELECTED))); i == -1 { break } @@ -176,7 +175,7 @@ func (this *ListView) SelectedItems(mask uint) []*w32.LVITEM { } func (this *ListView) SelectedCount() uint { - return uint(user32.SendMessage(this.hwnd, w32.LVM_GETSELECTEDCOUNT, 0, 0)) + return uint(w32.SendMessage(this.hwnd, w32.LVM_GETSELECTEDCOUNT, 0, 0)) } // Set i to -1 to select all items. @@ -185,7 +184,7 @@ func (this *ListView) SetSelectedItem(i int) { } func (this *ListView) SetImageList(imageList *ImageList, imageListType int) *ImageList { - h := user32.SendMessage(this.hwnd, w32.LVM_SETIMAGELIST, uintptr(imageListType), uintptr(imageList.Handle())) + h := w32.SendMessage(this.hwnd, w32.LVM_SETIMAGELIST, uintptr(imageListType), uintptr(imageList.Handle())) if h == 0 { return nil } @@ -194,7 +193,7 @@ func (this *ListView) SetImageList(imageList *ImageList, imageListType int) *Ima } func (this *ListView) ImageList(imageListType int) *ImageList { - h := user32.SendMessage(this.hwnd, w32.LVM_GETIMAGELIST, uintptr(imageListType), 0) + h := w32.SendMessage(this.hwnd, w32.LVM_GETIMAGELIST, uintptr(imageListType), 0) if h == 0 { return nil } diff --git a/pen.go b/pen.go index 7d1f82e..5c14c76 100644 --- a/pen.go +++ b/pen.go @@ -2,7 +2,6 @@ package gform import ( "github.com/AllenDang/w32" - "github.com/AllenDang/w32/gdi32" ) type Pen struct { @@ -16,7 +15,7 @@ func NewPen(style uint, width uint, brush *Brush) *Pen { panic("Brush cannot be nil") } - hPen := gdi32.ExtCreatePen(style, width, brush.GetLOGBRUSH(), 0, nil) + hPen := w32.ExtCreatePen(style, width, brush.GetLOGBRUSH(), 0, nil) if hPen == 0 { panic("Failed to create pen") } @@ -27,7 +26,7 @@ func NewPen(style uint, width uint, brush *Brush) *Pen { func NewNullPen() *Pen { lb := w32.LOGBRUSH{LbStyle: w32.BS_NULL} - hPen := gdi32.ExtCreatePen(w32.PS_COSMETIC|w32.PS_NULL, 1, &lb, 0, nil) + hPen := w32.ExtCreatePen(w32.PS_COSMETIC|w32.PS_NULL, 1, &lb, 0, nil) if hPen == 0 { panic("failed to create null brush") } @@ -49,7 +48,7 @@ func (this *Pen) GetHPEN() w32.HPEN { func (this *Pen) Dispose() { if this.hPen != 0 { - gdi32.DeleteObject(w32.HGDIOBJ(this.hPen)) + w32.DeleteObject(w32.HGDIOBJ(this.hPen)) this.hPen = 0 } } diff --git a/progressbar.go b/progressbar.go index 2e31ba5..8d7fb3f 100644 --- a/progressbar.go +++ b/progressbar.go @@ -2,7 +2,6 @@ package gform import ( "github.com/AllenDang/w32" - "github.com/AllenDang/w32/user32" ) type ProgressBar struct { @@ -24,20 +23,20 @@ func (this *ProgressBar) init(parent Controller) { } func (this *ProgressBar) Value() uint { - ret := user32.SendMessage(this.hwnd, w32.PBM_GETPOS, 0, 0) + ret := w32.SendMessage(this.hwnd, w32.PBM_GETPOS, 0, 0) return uint(ret) } func (this *ProgressBar) SetValue(v uint) { - user32.SendMessage(this.hwnd, w32.PBM_SETPOS, uintptr(v), 0) + w32.SendMessage(this.hwnd, w32.PBM_SETPOS, uintptr(v), 0) } func (this *ProgressBar) Range() (min, max uint) { - min = uint(user32.SendMessage(this.hwnd, w32.PBM_GETRANGE, uintptr(w32.BoolToBOOL(true)), 0)) - max = uint(user32.SendMessage(this.hwnd, w32.PBM_GETRANGE, uintptr(w32.BoolToBOOL(false)), 0)) + min = uint(w32.SendMessage(this.hwnd, w32.PBM_GETRANGE, uintptr(w32.BoolToBOOL(true)), 0)) + max = uint(w32.SendMessage(this.hwnd, w32.PBM_GETRANGE, uintptr(w32.BoolToBOOL(false)), 0)) return } func (this *ProgressBar) SetRange(min, max uint) { - user32.SendMessage(this.hwnd, w32.PBM_SETRANGE32, uintptr(min), uintptr(max)) + w32.SendMessage(this.hwnd, w32.PBM_SETRANGE32, uintptr(min), uintptr(max)) } diff --git a/rect.go b/rect.go index fb6d8e3..83dd0d3 100644 --- a/rect.go +++ b/rect.go @@ -2,7 +2,6 @@ package gform import ( "github.com/AllenDang/w32" - "github.com/AllenDang/w32/user32" ) type Rect struct { @@ -11,14 +10,14 @@ type Rect struct { func NewEmptyRect() *Rect { var newRect Rect - user32.SetRectEmpty(&newRect.rect) + w32.SetRectEmpty(&newRect.rect) return &newRect } func NewRect(left, top, right, bottom int) *Rect { var newRect Rect - user32.SetRectEmpty(&newRect.rect) + w32.SetRectEmpty(&newRect.rect) newRect.Set(left, top, right, bottom) return &newRect @@ -37,37 +36,37 @@ func (this *Rect) GetW32Rect() *w32.RECT { } func (this *Rect) Set(left, top, right, bottom int) { - user32.SetRect(&this.rect, left, top, right, bottom) + w32.SetRect(&this.rect, left, top, right, bottom) } func (this *Rect) IsEqual(rect *Rect) bool { - return user32.EqualRect(&this.rect, &rect.rect) + return w32.EqualRect(&this.rect, &rect.rect) } func (this *Rect) Inflate(x, y int) { - user32.InflateRect(&this.rect, x, y) + w32.InflateRect(&this.rect, x, y) } func (this *Rect) Intersect(src *Rect) { - user32.IntersectRect(&this.rect, &this.rect, &src.rect) + w32.IntersectRect(&this.rect, &this.rect, &src.rect) } func (this *Rect) IsEmpty() bool { - return user32.IsRectEmpty(&this.rect) + return w32.IsRectEmpty(&this.rect) } func (this *Rect) Offset(x, y int) { - user32.OffsetRect(&this.rect, x, y) + w32.OffsetRect(&this.rect, x, y) } func (this *Rect) IsPointIn(x, y int) bool { - return user32.PtInRect(&this.rect, x, y) + return w32.PtInRect(&this.rect, x, y) } func (this *Rect) Substract(src *Rect) { - user32.SubtractRect(&this.rect, &this.rect, &src.rect) + w32.SubtractRect(&this.rect, &this.rect, &src.rect) } func (this *Rect) Union(src *Rect) { - user32.UnionRect(&this.rect, &this.rect, &src.rect) + w32.UnionRect(&this.rect, &this.rect, &src.rect) } diff --git a/tooltip.go b/tooltip.go index ba95f33..469f70e 100644 --- a/tooltip.go +++ b/tooltip.go @@ -2,7 +2,6 @@ package gform import ( "github.com/AllenDang/w32" - "github.com/AllenDang/w32/user32" "syscall" "unsafe" ) @@ -20,7 +19,7 @@ func NewToolTip(parent Controller) *ToolTip { func (this *ToolTip) init(parent Controller) { this.W32Control.init("tooltips_class32", parent, w32.WS_EX_TOPMOST, w32.WS_POPUP|w32.TTS_NOPREFIX|w32.TTS_ALWAYSTIP) - user32.SetWindowPos(this.Handle(), w32.HWND_TOPMOST, 0, 0, 0, 0, w32.SWP_NOMOVE|w32.SWP_NOSIZE|w32.SWP_NOACTIVATE) + w32.SetWindowPos(this.Handle(), w32.HWND_TOPMOST, 0, 0, 0, 0, w32.SWP_NOMOVE|w32.SWP_NOSIZE|w32.SWP_NOACTIVATE) } func (this *ToolTip) AddTool(tool Controller, tip string) bool { @@ -33,5 +32,5 @@ func (this *ToolTip) AddTool(tool Controller, tip string) bool { ti.UId = uintptr(tool.Handle()) ti.LpszText = syscall.StringToUTF16Ptr(tip) - return user32.SendMessage(this.Handle(), w32.TTM_ADDTOOL, 0, uintptr(unsafe.Pointer(&ti))) != w32.FALSE + return w32.SendMessage(this.Handle(), w32.TTM_ADDTOOL, 0, uintptr(unsafe.Pointer(&ti))) != w32.FALSE } diff --git a/utils.go b/utils.go index fe239c6..95110e2 100644 --- a/utils.go +++ b/utils.go @@ -3,8 +3,6 @@ package gform import ( "fmt" "github.com/AllenDang/w32" - "github.com/AllenDang/w32/comctl32" - "github.com/AllenDang/w32/user32" "syscall" "unsafe" ) @@ -16,30 +14,30 @@ func internalTrackMouseEvent(hwnd w32.HWND) { tme.HwndTrack = hwnd tme.DwHoverTime = w32.HOVER_DEFAULT - comctl32.TrackMouseEvent(&tme) + w32.TrackMouseEvent(&tme) } func ToggleStyle(hwnd w32.HWND, b bool, style int) { - originalStyle := int(user32.GetWindowLongPtr(hwnd, w32.GWL_STYLE)) + originalStyle := int(w32.GetWindowLongPtr(hwnd, w32.GWL_STYLE)) if originalStyle != 0 { if b { originalStyle |= style } else { originalStyle ^= style } - user32.SetWindowLongPtr(hwnd, w32.GWL_STYLE, uintptr(originalStyle)) + w32.SetWindowLongPtr(hwnd, w32.GWL_STYLE, uintptr(originalStyle)) } } func ToggleExStyle(hwnd w32.HWND, b bool, style int) { - originalStyle := int(user32.GetWindowLongPtr(hwnd, w32.GWL_EXSTYLE)) + originalStyle := int(w32.GetWindowLongPtr(hwnd, w32.GWL_EXSTYLE)) if originalStyle != 0 { if b { originalStyle |= style } else { originalStyle ^= style } - user32.SetWindowLongPtr(hwnd, w32.GWL_EXSTYLE, uintptr(originalStyle)) + w32.SetWindowLongPtr(hwnd, w32.GWL_EXSTYLE, uintptr(originalStyle)) } } @@ -50,7 +48,7 @@ func CreateWindow(className string, parent Controller, exStyle, style uint) w32. parentHwnd = parent.Handle() } var hwnd w32.HWND - hwnd = user32.CreateWindowEx( + hwnd = w32.CreateWindowEx( exStyle, syscall.StringToUTF16Ptr(className), nil, @@ -74,7 +72,7 @@ func CreateWindow(className string, parent Controller, exStyle, style uint) w32. func RegisterClass(className string, wndproc uintptr) { instance := GetAppInstance() - icon := user32.LoadIcon(instance, w32.MakeIntResource(w32.IDI_APPLICATION)) + icon := w32.LoadIcon(instance, w32.MakeIntResource(w32.IDI_APPLICATION)) var wc w32.WNDCLASSEX wc.Size = uint(unsafe.Sizeof(wc)) @@ -83,12 +81,12 @@ func RegisterClass(className string, wndproc uintptr) { wc.Instance = instance wc.Background = w32.COLOR_BTNFACE + 1 wc.Icon = icon - wc.Cursor = user32.LoadCursor(0, w32.MakeIntResource(w32.IDC_ARROW)) + wc.Cursor = w32.LoadCursor(0, w32.MakeIntResource(w32.IDC_ARROW)) wc.ClassName = syscall.StringToUTF16Ptr(className) wc.MenuName = nil wc.IconSm = icon - if ret := user32.RegisterClassEx(&wc); ret == 0 { + if ret := w32.RegisterClassEx(&wc); ret == 0 { panic(syscall.GetLastError()) } } @@ -111,7 +109,7 @@ func RegClassOnlyOnce(className string) { func ScreenToClientRect(hwnd w32.HWND, rect *w32.RECT) *Rect { l, t, r, b := rect.Left, rect.Top, rect.Right, rect.Bottom - l, t = user32.ScreenToClient(hwnd, l, t) - r, b = user32.ScreenToClient(hwnd, r, b) + l, t = w32.ScreenToClient(hwnd, l, t) + r, b = w32.ScreenToClient(hwnd, r, b) return NewRect(l, t, r, b) } diff --git a/w32control.go b/w32control.go index a34d749..ca0d6f5 100644 --- a/w32control.go +++ b/w32control.go @@ -2,7 +2,6 @@ package gform import ( "github.com/AllenDang/w32" - "github.com/AllenDang/w32/user32" ) type W32Control struct { @@ -18,7 +17,7 @@ func (this *W32Control) init(className string, parent Controller, exstyle, style panic("cannot create window for " + className) } this.isMouseLeft = true - this.originalWndProc = user32.SetWindowLongPtr(this.hwnd, w32.GWLP_WNDPROC, GeneralWndprocCallBack) + this.originalWndProc = w32.SetWindowLongPtr(this.hwnd, w32.GWLP_WNDPROC, GeneralWndprocCallBack) this.ControlBase.init(parent) } @@ -27,12 +26,12 @@ func (this *W32Control) attach(parent Controller, dlgItemID int) { panic("parent cannot be nil") } - if this.hwnd = user32.GetDlgItem(parent.Handle(), dlgItemID); this.hwnd == 0 { + if this.hwnd = w32.GetDlgItem(parent.Handle(), dlgItemID); this.hwnd == 0 { panic("hwnd cannot be nil") } this.isMouseLeft = true - this.originalWndProc = user32.SetWindowLongPtr(this.hwnd, w32.GWLP_WNDPROC, GeneralWndprocCallBack) + this.originalWndProc = w32.SetWindowLongPtr(this.hwnd, w32.GWLP_WNDPROC, GeneralWndprocCallBack) this.ControlBase.init(parent) } @@ -51,5 +50,5 @@ func (this *W32Control) WndProc(msg uint, wparam, lparam uintptr) uintptr { this.onMouseLeave.Fire(NewEventArg(this, nil)) this.isMouseLeft = true } - return user32.CallWindowProc(this.originalWndProc, this.hwnd, msg, wparam, lparam) + return w32.CallWindowProc(this.originalWndProc, this.hwnd, msg, wparam, lparam) } diff --git a/wndproc.go b/wndproc.go index 088a7ea..c714fe8 100644 --- a/wndproc.go +++ b/wndproc.go @@ -2,8 +2,6 @@ package gform import ( "github.com/AllenDang/w32" - "github.com/AllenDang/w32/shell32" - "github.com/AllenDang/w32/user32" "unsafe" ) @@ -20,17 +18,17 @@ func genDropFilesEventArg(wparam uintptr) *DropFilesEventData { hDrop := w32.HDROP(wparam) var data DropFilesEventData - _, fileCount := shell32.DragQueryFile(hDrop, 0xFFFFFFFF) + _, fileCount := w32.DragQueryFile(hDrop, 0xFFFFFFFF) data.Files = make([]string, fileCount) var i uint for i = 0; i < fileCount; i++ { - data.Files[i], _ = shell32.DragQueryFile(hDrop, i) + data.Files[i], _ = w32.DragQueryFile(hDrop, i) } - data.X, data.Y, _ = shell32.DragQueryPoint(hDrop) + data.X, data.Y, _ = w32.DragQueryPoint(hDrop) - shell32.DragFinish(hDrop) + w32.DragFinish(hDrop) return &data } @@ -49,7 +47,7 @@ func generalWndProc(hwnd w32.HWND, msg uint, wparam, lparam uintptr) uintptr { if controller := GetMsgHandler(nm.HwndFrom); controller != nil { ret := controller.WndProc(msg, wparam, lparam) if ret != 0 { - user32.SetWindowLong(hwnd, w32.DWL_MSGRESULT, uint32(ret)) + w32.SetWindowLong(hwnd, w32.DWL_MSGRESULT, uint32(ret)) return w32.TRUE } } @@ -59,7 +57,7 @@ func generalWndProc(hwnd w32.HWND, msg uint, wparam, lparam uintptr) uintptr { if controller := GetMsgHandler(h); controller != nil { ret := controller.WndProc(msg, wparam, lparam) if ret != 0 { - user32.SetWindowLong(hwnd, w32.DWL_MSGRESULT, uint32(ret)) + w32.SetWindowLong(hwnd, w32.DWL_MSGRESULT, uint32(ret)) return w32.TRUE } } @@ -100,5 +98,5 @@ func generalWndProc(hwnd w32.HWND, msg uint, wparam, lparam uintptr) uintptr { return ret } - return user32.DefWindowProc(hwnd, msg, wparam, lparam) + return w32.DefWindowProc(hwnd, msg, wparam, lparam) }