#ifndef __WINDOWSHANDLE_SBP__ #define __WINDOWSHANDLE_SBP__ Class WindowHandle hwnd As HWND Public Sub WindowHandle() hwnd = 0 End Sub Sub WindowHandle(hwndNew As HWND) hwnd = hwndNew End Sub Sub WindowHandle(ByRef wnd As WindowHandle) hwnd = wnd.hwnd End Sub Sub Operator =(hwndNew As HWND) hwnd = hwndNew End Sub Function HWnd() As HWND Return hwnd End Function Function Operator() As HWND Return hwnd End Function Function BeginPaint(ByRef ps As PAINTSTRUCT) As HDC Return BeginPaint(hwnd, ps) End Function Function ChildFromPoint(x As Long, y As Long) As HWND Return ChildWindowFromPoint(hwnd, x, y) End Function Function ChildFromPointEx(x As Long, y As Long, flags As DWord) As HWND Return ChildWindowFromPointEx(hwnd, x, y, flags) End Function Function ClientToScreen(ByRef pt As POINTAPI) As BOOL Return ClientToScreen(pt) End Function Function Close() As BOOL Return CloseWindow() End Function Function CreateCaret(hbmp As HBITMAP, width As Long, height As Long) As BOOL Return CreateCaret(hwnd, hbmp, width, hegiht) End Function Function Destroy() As BOOL Return DestroyWindow(hwnd) End Function Function DrawMenuBar() As BOOL Return DrawMenuBar(hwnd) End Function Function EnableScrollBar(SBFlags As DWord, arrows As DWord) As BOOL Return EnableScrollBar(hwnd, SBFlags, arrows) End Function Function Enable(enable As BOOL) As BOOL Return EnableWindow(hwnd, enable) End Function Function EndPaint(ByRef ps As PAINTSTRUCT) As BOOL Return EndPaint(hwnd, ps) End Function Function EnumChilds(enumFunc As WNDENUMPROC, lp As LPARAM) As BOOL Return EnumChildWindows(hwnd, enumFunc, lp) End Function Function Flash(invert As BOOL) As BOOL Return FlashWindow(hwnd, invert) End Function Function GetClassLongPtr(index As Long) As LONG_PTR Return GetClassLongPtr(hwnd, index) End Function Function GetClassName(className As PSTR, maxCount As Long) As Long Return GetClassName(className, maxCount) End Function Function GetClientRect(ByRef rc As RECT) As BOOL Return GetClientRect(hwnd, rc) End Function Function GetDC() As HDC Return GetDC(hwnd) End Function Function GetDCEx(hrgnClip As HRGN, flags As DWord) As HDC Return GetDCEx(hwnd, hrgnClip, flags) End Function Function GetDlgCtrlID() As Long Return GetDlgCtrlID(hwnd) End Function Function GetDlgItem(idDlgItem As Long) As WindowHandle Return GetDlgItem(hwnd, idDlgItem) End Function Function GetDlgItemText(idDlgItem As Long, ps As PSTR, maxCount As Long) As Long Return GetDlgItemText(hwnd, idDlgItem, ps, maxCount) End Function Function GetMenu() As HMENU Return GetMenu(hwnd) End Function Function GetParent() As WindowHandle Return GetParent(hwnd) End Function Function GetProp(psz As PCSTR) As HANDLE Return GetProp(hwnd, psz) End Function Function GetProp(atom As ATOM) As HANDLE Return GetProp(hwnd, atom As ULONG_PTR As PCSTR) End Function Function GetScrollInfo(fnBar As Long, ByRef si As SCROLLINFO) As BOOL Return GetScrollInfo(hwnd, fnBar, si) End Function Function GetSystemMenu(revert As BOOL) As HMENU Return GetSystemMenu(hwnd, revert) End Function Function GetUpdateRect(ByRef rc As RECT, erase As BOOL) As BOOL Return GetUpdateRact(hwnd, rc, erase) End Function Function GetUpdateRgn(hrgn As HRGN, erase As BOOL) As BOOL Return GetUpdateRgn(hwnd, hrgn, erase) End Function Function GetWindow(cmd As DWord) As WindowHandle Return GetWindow(hwnd, cmd) End Function Function GetWindowPlacement(ByRef wndpl As WINDOWPLACEMENT) As BOOL Return GetWindowPlacement(hwnd, wndpl) End Function Function GetContextHelpId() As DWord Return GetWindowContextHelpId(hwnd) End Function Function GetWindowDC() As HDC Return GetWindowDC(hwnd) End Function Function GetWindowLongPtr(index As Long) As LONG_PTR Return GetWindowLongPtr(hwnd, index) End Function Function GetWindowPlasement(ByRef wndpl As WINDOWPLACEMENT) As BOOL Return GetWindowPlasement(hwnd, wndpl) End Function Function GetWindowRect(ByRef rc As RECT) As BOOL Return GetWindowRect(rc) End Function Function GetText(ps As PSTR, maxCount As Long) As BOOL Return GetWindowText(ps, maxCount) End Function Function GetTextLength() As Long Return GetWindowTextLength(hwnd) End Function Function GetWindowThreadId() As DWord Return GetWindowProcessThreadId(hwnd, 0) End Function Function GetWindowProcessThreadId(ByRef processId As DWord) As DWord Return GetWindowProcessThreadId(hwnd, processId) End Function Function HideCaret() As BOOL Return HideCaret(hwnd) End Function Function InvalidateRect(ByRef rc As RECT, erace As BOOL) As BOOL Return InvalidateRect(hwnd, rc, erace) End Function Function InvalidateRect(ByRef rc As RECT) As BOOL Return InvalidateRect(hwnd, rc, TRUE) End Function Function InvalidateRgn(hrgn As HRGN, erace As BOOL) As BOOL Return InvalidateRgn(hwnd, hrgn, erace) End Function Function InvalidateRgn(hrgn As HRGN) As BOOL Return InvalidateRgn(hwnd, hrgn, TRUE) End Function Function Invalidate(erace As BOOL) As BOOL Return InvalidateRect(hwnd, ByVal 0, erace) End Function Function Invalidate() As BOOL Return InvalidateRect(hwnd, ByVal 0, TRUE) End Function Function IsChild(hwnd As HWND) As BOOL Return IsChild(This.hwnd, hwnd) End Function Function IsDialogMessage(ByRef msg As MSG) As BOOL Return IsDialogMessage(hwnd, msg) End Function Function IsIconic() As BOOL Return IsIconic(hwnd) End Function Function IsWindow() As BOOL Return IsWindow(hwnd) End Function Function IsEnabled() As BOOL Return IsWindowEnabled(hwnd) End Function Function IsUnicode() As BOOL Return IsWindowUnicode(hwnd) End Function Function IsVisible() As BOOL Return IsWindowVisible(hwnd) End Function Function IsZoomed() As BOOL Return IsZoomed(hwnd) End Function Function KillTimer(idEvent As ULONG_PTR) As BOOL Return KillTimer(idEvent) End Function Function LockUpdate() As BOOL Return LockWindowUpdate(hwnd) End Function Function MapPoints(hwndTo As HWND, pPoints As *POINTAPI, cPoints As DWord) As Long Return MapWindowPoints(hwnd, hwndTo, pPoints, cPoints) End Function Function MapPoints(hwndTo As HWND, ByRef rc As RECT) As Long Return MapWindowPoints(hwnd, hwndTo, VarPtr(rc) As *POINTAPI, 2) End Function Function MessageBox(text As PCSTR, caption As PCSTR, uType As DWord) As Long Return MessageBox(hwnd, text, caption, uType) End Function Function MessageBox(text As PCSTR, caption As PCSTR) As Long Return MessageBox(hwnd, text, caption, MB_OK) End Function Function MessageBox(text As PCSTR) As Long Return MessageBox(hwnd, text, 0, MB_OK) End Function Function MoveWindow(x As Long, y As Long, width As Long, height As Long, repaint As BOOL) As BOOL Return MoveWindow(hwnd, x, y, width, height, repaint) End Function Function MoveWindow(x As Long, y As Long, width As Long, height As Long) As BOOL Return MoveWindow(hwnd, x, y, width, height, TRUE) End Function Function MoveWindow(ByRef rc As RECT, repeaint As BOOL) As BOOL With rc Return MoveWindow(hwnd, .left, .top, .right - .left, .bottom - .top, repaint) End With End Function Function MoveWindow(ByRef rc As RECT) As BOOL With rc Return MoveWindow(hwnd, .left, .top, .right - .left, .bottom - .top, TRUE) End With End Function Function OpenClipboard() As BOOL Return OpenClipboard(hwnd) End Function Function OpenIcon() As BOOL Return OpenIcon(hwnd) End Function Function PostMessage(msg As DWord, wp As WPARAM, lp As LPARAM) As BOOL Return PostMessage(hwnd, msg, wp, lp) End Function Function PostMessage(msg As DWord) As BOOL Return PostMessage(hwnd, msg, 0, 0) End Function Function RedrawWindow(ByRef rcUpdate As RECT, hrgnUpdate As HRGN, flags As DWord) As BOOL Return RedrawWindow(hwnd, rcUpdatre, hrgnUpdate, flags) End Function Function ReleaseDC(hdc As HDC) As BOOL Return ReleaseDC(hwnd, hdc) End Function Function RemoveProp(psz As PCSTR) As HANDLE Return RemoveProp(hwnd, psz) End Function Function RemoveProp(atom As ATOM) As HANDLE Return RemoveProp(hwnd, atom As ULONG_PTR As PCSTR) End Function Function ScreenToClient(ByRef pt As POINTAPI) As BOOL Return ScreenToClient(hwnd, pt) End Function Function Scroll(dx As Long, dy As Long, ByRef rcScroll As RECT, ByRef rcClip As RECT, hrgnUpdate As HRGN, ByRef rcUpdate As RECT, flags As DWord) As BOOL Return ScrollWindowEx(hwnd, dx, dy, rcScroll, rcClip, hrgnUpdate, rcUpdate, flags) End Function Function SendDlgItemMessage(idDlgItem As Long, msg As DWord, wp As WPARAM, lp As LPARAM) As LRESULT Return SendDlgItemMessage(hwnd, idDlgItem, wp, lp) End Function Function SendDlgItemMessage(idDlgItem As Long, msg As DWord) As LRESULT Return SendDlgItemMessage(hwnd, idDlgItem, 0, 0) End Function Function SendMessage(msg As DWord, wp As WPARAM, lp As LPARAM) As LRESULT Return SendMessage(hwnd, msg, wp, lp) End Function Function SendMessage(msg As DWord) As LRESULT Return SendMessage(hwnd, msg, 0, 0) End Function Function SetActiveWindow() As HWND Return SetActiveWindow(hwnd) End Function Function SetDlgItemText(idDlgItem As Long, psz As PCSTR) As BOOL Return SetDlgItemText(hwnd, idDlgItem, psz) End Function Function SetCapture() As HWND Return SetCapture(hwnd) As HWND End Function Function SetClassLongPtr(index As Long, newLong As LONG_PTR) As LONG_PTR Return SetClassLongPtr(hwnd, index, newLong) End Function Function SetFocus() As HWND Return SetFocus(hwnd) End Function Function SetForeground() As BOOL Return SetForegroundWindow(hwnd) End Function Function SetMenu(hmenu As HMENU) As BOOL Return SetMenu(hwnd, hmenu) End Function Function SetParent(hwndNewParent As HWND) As HWND Return SetParent(hwnd, hwndNewParent) End Function Function SetProp(psz As PCSTR, hData As HANDLE) As BOOL Return SetProp(hwnd, psz, hData) End Function Function SetProp(atom As ATOM, hData As HANDLE) As BOOL Return SetProp(atom As ULONG_PTR As PCSTR, hData) End Function Function SetScrollInfo(fnBar As Long, ByRef si As SCROLLINFO, redraw As BOOL) As BOOL Return SetScrollInfo(hwnd, fnBar, si, redraw) End Function Function SetScrollInfo(fnBar As Long, ByRef si As SCROLLINFO) As BOOL Return SetScrollInfo(hwnd, fnBar, si, TRUE) End Function Function SetTimer(idEvent As ULONG_PTR, elapse As DWord, timerFunc As TIMERPROC) As ULONG_PTR Return SetTmer(hwnd, idEvent, elapse, timerFunc) End Function Function SetTimer(idEvent As ULONG_PTR, elapse As DWord) As ULONG_PTR Return SetTmer(hwnd, idEvent, elapse, 0) End Function Function SetContextHelpId(contextHelpId As DWord) As BOOL Return SetContextHelpId(hwnd, contextHelpId) End Function Function SetWindowLongPtr(index As Long, newLong As LONG_PTR) As LONG_PTR Return SetWindowLongPtr(hwnd, index, newLong) End Function Function SetWindowPlacement(ByRef wndpl As WINDOWPLACEMENT) As BOOL Return SetWindowPlacement(hwnd, wndpl) End Function Function SetPos(hwndInsertAfter As HWND, x As Long, y As Long, cx As Long, cy As Long, flags As DWord) As BOOL Return SetWindowPos(hwnd, hwndInsertAfter, x, y, cx, cy, flags) End Function Function SetPos(hwndInsertAfter As HWND, ByRef rc As RECT, flags As DWord) As BOOL With rc Return SetWindowPos(hwnd, hwndInsertAfter, .left, .top, .right - .left, .bottom - .top, flags) End With End Function Function SetRgn(hrgn As HRGN, redraw As BOOL) As BOOL Return SetWindowRgn(hwnd, hrgn, redraw) End Function Function SetRgn(hrgn As HRGN) As BOOL Return SetWindowRgn(hwnd, hrgn, TRUE) End Function Function SetText(psz As PCSTR) As BOOL Return SetWindowText(hwnd, psz) End Function Function ShowScrollBar(bar As DWord, show As BOOL) As BOOL Return ShowScrollBar(hwnd, bar, show) End Function Function ShowScrollBar(bar As DWord) As BOOL Return ShowScrollBar(hwnd, bar, TRUE) End Function Function Show(cmdShow As DWord) As BOOL Return ShowWindow(hwnd, cmdShow) End Function Function ShowAsync(cmdShow As DWord) As BOOL Return ShowWindowAsync(hwnd, cmdShow) End Function Function Update() As BOOL Return UpdateWindow(hwnd) End Function Function ValidateRect(ByRef rc As RECT) As BOOL Return ValidateRect(hwnd, rc) End Function Function ValidateRgn(hrgn As HRGN) As BOOL Return ValidateRgn(hwnd, hrgn) End Function Function Validate() As BOOL Return ValidateRect(hwnd, ByVal 0) End Function ' Get/SetWindowLongPtr Wrappers Function GetExStyle() As DWord Return GetWindowLongPtr(hwnd, GWL_EXSTYLE) As DWord End Function Function GetStyle() As DWord Return GetWindowLongPtr(hwnd, GWL_STYLE) As DWord End Function Function GetWndProc() As WNDPROC Return GetWindowLongPtr(hwnd, GWLP_HINSTANCE) As WNDPROC End Function Function GetInstance() As HINSTANCE Return GetWindowLongPtr(hwnd, GWLP_HINSTANCE) As HINSTANCE End Function Function GetUserData() As LONG_PTR Return GetWindowLongPtr(hwnd, GWLP_USERDATA) End Function Function SetExStyle(style As DWord) As DWord Return SetWindowLongPtr(hwnd, GWL_EXSTYLE, style) As DWord End Function Function SetStyle(style As DWord) As DWord Return SetWindowLongPtr(hwnd, GWL_STYLE, style) As DWord End Function Function SetWndProc(wndProc As WNDPROC) As WNDPROC Return SetWindowLongPtR(hwnd, GWLP_WNDPROC, wndProc As WNDPROC) As WNDPROC End Function Function SetUserData(value As LONG_PTR) As LONG_PTR Return SetWindowLongPtr(value As LONG_PTR) End Function ' Propaties Function ClientRect() As RECT Dim rc As RECT GetClientRect(hwnd, rc) Return rc End Function Sub ClientRect(ByRef rc As RECT) Dim hasMenu As BOOL If IsChild() = FALSE And IsMenu() <> FALSE Then hasMenu = TRUE Else hasMenu = FALSE EndIf AdjustWindowRectEx(rc, GetStyle(), hasMenu, GetExStyle()) MoveWindow(rc) ' WindowRect = rc End Sub Function WindowRect() As RECT Dim rc As RECT GetWindowRect(hwnd, rc) Return rc End Function Sub WindowRect(ByRef rc As RECT) MoveWindow(rc) End Sub Function ContextHelpID() As DWord Return GetContextHelpId(hwnd) End Function Sub ContextHelpID(newID As DWord) SetContextHelpId(hwnd, newId) End Sub Function DlgCtrlID() As Long Return GetDlgCtrlID(hwnd) End Function Sub DlgCtrlId(newId As Long) SetWindowLongPtr(hwnd, GWLP_ID, newId) End Sub Function DlgItem(idDlgItem As Long) As WindowHandle Return GetDlgItem(hwnd, idDlgItem) End Function Function ExStyle() As DWord Return GetWindowLongPtr(hwnd, GWL_EXSTYLE) As DWord End Function Sub ExStyle(newExStyle As DWord) SetWindowLongPtr(hwnd, GWL_EXSTYLE, newExStyle) End Sub Function Style() As DWord Return GetWindowLongPtr(hwnd, GWL_STYLE) As DWord End Function Sub Style(newStyle As DWord) DWord SetWindowLongPtr(hwnd, GWL_STYLE, newStyle) End Sub Function Enabled() As BOOL Return IsWindowEnabled(hwnd) End Function Sub Enabled(enable As BOOL) EnableWindow(hwnd, enable) End Sub Function Font() As HFONT Return SendMessage(hwnd, WM_GETFONT, 0, 0) As HFONT End Function Sub Font(hfntNew As HFONT) SendMessage(hwnd, WM_SETFONT, hfntNew As WPARAM, TRUE) End Sub Function Maximized() As BOOL Return IsIconic(hwnd) End Function Sub Maximized(maximized As BOOL) If maximized <> FALSE Then ShowWindow(hwnd, SW_SHOWMAXIMIZED) Else ShowWindow(hwnd, SW_RESTORE) End If End Sub Function Minimized() As BOOL Return IsIconic(hwnd) End Function Sub Minimized(minimized As BOOL) If minimized <> FALSE Then CloseWindow(hwnd) Else OpenIcon(hwnd) End If End Sub Function Instance() As HINSTANCE Return GetWindowLongPtr(hwnd, GWLP_HINSTANCE) As HINSTANCE End Function ' IsWindow, IsUnicodeはメソッドと同じ。 Function Parent() As WindowHandle Return GetParent(hwnd) End Function Sub Parent(hwndNewParent As HWND) SetParent(hwnd, hwndNewParent) End Sub Function ProcessID() As DWord GetWindowProcessThreadId(ProcessID) End Function Function ThreadID() As DWord Return GetWindowProcessThreadId(ByVal 0) End Function Function Menu() As HMENU Return GetMenu(hwnd) End Function Sub Menu(hmenuNew As HMENU) SetMenu(hwnd, hmenuNew) End Sub Function Text() As String With Text .ReSize(GetWindowTextLength(hwnd)) .ReSize(GetWindowText(hwnd, .Chars, .Length + 1)) End With End Function Sub Text(newText As PCSTR) SetWindowText(hwnd, newText) End Sub Function TextLength() As Long Return GetWindowTextLength(hwnd) End Function Function UserData() As LONG_PTR Return GetWindowLongPtr(hwnd, GWLP_USERDATA) End Function Sub UserData(newValue As LONG_PTR) SetWindowLongPtr(hwnd, GWLP_USERDATA, newValue) End Sub Function Visible() As BOOL Return IsVisible(hwnd) End Function Sub Visible(visible As BOOL) If visible <> FALSE Then ShowWindow(hwnd, SW_SHOW) Else ShowWindow(hwnd, SW_HIDE) EndIf End Sub Function WindowPlacement() As WINDOWPLACEMENT WindowPlacement.length = Len(WindowPlacement) GetWindowPlacement(hwnd, WindowPlacement) End Function Sub WindowPlacement(ByRef wndpl As WINDOWPLACEMENT) SetWindowPlacement(wndpl) End Sub Function WndProc() As WNDPROC Return GetWindowLongPtr(hwnd, GWLP_HINSTANCE) As WNDPROC End Function Sub WndProc(newWndProc As WNDPROC) SetWindowLongPtr(hwnd, GWLP_WNDPROC, newWndProc As LONG_PTR) End Sub Protected Sub SetHWnd(hwndNew As HWND) hwnd = hwndNew End Sub End Class #endif '__WINDOWSHANDLE_SBP__