#ifndef __WINDOWSHANDLE_SBP__ #define __WINDOWSHANDLE_SBP__ #ifdef _WIN64 Declare Function _System_GetWindowLongPtr Lib "user32" Alias "GetWindowLongPtrA" (hWnd As HWND, nIndex As Long) As LONG_PTR Declare Function _System_SetWindowLongPtr Lib "user32" Alias "SetWindowLongPtrA" (hWnd As HWND, nIndex As Long, l As LONG_PTR) As LONG_PTR #else Declare Function _System_GetWindowLongPtr Lib "user32" Alias "GetWindowLongA" (hWnd As HWND, nIndex As Long) As LONG_PTR Declare Function _System_SetWindowLongPtr Lib "user32" Alias "SetWindowLongA" (hWnd As HWND, nIndex As Long, l As LONG_PTR) As LONG_PTR #endif Declare Function _System_GetParent Lib "user32" Alias "GetParent" (hWnd As HWND) As HWND Declare Function _System_SetParent Lib "user32" Alias "SetParent" (hWnd As HWND) As HWND Declare Function _System_GetMenu Lib "user32" Alias "GetMenu" (hWnd As HWND) As HMENU Declare Function _System_SetMenu Lib "user32" Alias "SetMenu" (hWnd As HWND) As HMENU Declare Function _System_InvalidateRect Lib "user32" Alias "InvalidateRect" (hWnd As HWND, ByRef Rect As RECT, bErase As BOOL) As BOOL Declare Function _System_InvalidateRgn Lib "user32" Alias "InvalidateRgn" (hWnd As HWND, hRgn As HRGN, bErase As BOOL) As BOOL Declare Function _System_ValidateRect Lib "user32" Alias "ValidateRect" (hWnd As HWND, ByRef Rect As RECT) As BOOL Declare Function _System_ValidateRgn Lib "user32" Alias "ValidateRgn" (hWnd As HWND, hRgn As HRGN) As BOOL Declare Function _System_BeginPaint Lib "user32" Alias "BeginPaint" (hWnd As HWND, ByRef ps As PAINTSTRUCT) As HDC Declare Function _System_EndPaint Lib "user32" Alias "EndPaint" (hWnd As HWND, ByRef lpPaint As PAINTSTRUCT) As HDC Declare Function _System_ClientToScreen Lib "user32" Alias "ClientToScreen" (hWnd As HWND, ByRef lpPoint As POINTAPI) As BOOL Declare Function _System_ScreenToClient Lib "user32" Alias "ScreenToClient" (hWnd As HWND, ByRef lpPoint As POINTAPI) As BOOL Declare Function _System_CreateCaret Lib "user32" Alias "CreateCaret" (hWnd As HWND, hBitmap As HBITMAP, nWidth As Long, nHeight As Long) As BOOL Declare Function _System_HideCaret Lib "user32" Alias "HideCaret" (hWnd As HWND) As BOOL Declare Function _System_ShowCaret Lib "user32" Alias "ShowCaret" (hWnd As HWND) As BOOL Declare Function _System_DrawMenuBar Lib "user32" Alias "DrawMenuBar" (hwnd As HWND) As BOOL Declare Function _System_GetWindowRect Lib "user32" Alias "DrawMenuBar" (hWnd As HWND, ByRef Rect As RECT) As BOOL Declare Function _System_IsWindow Lib "user32" Alias "IsWindow" (hWnd As HWND) As BOOL Declare Function _System_Isiconic Lib "user32" Alias "Isiconic" (hWnd As HWND) As BOOL Declare Function _System_GetClientRect Lib "user32" Alias "GetClientRect" (hWnd As HWND, ByRef lpRect As RECT) As BOOL 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 Const Function HWnd() As HWND Return hwnd End Function Const Function Operator() As HWND Return hwnd End Function Function BringToTop() As BOOL Return BringWindowToTop(hwnd) End Function Function BeginPaint(ByRef ps As PAINTSTRUCT) As HDC Return _System_BeginPaint(hwnd, ps) End Function Const Function ChildFromPoint(x As Long, y As Long) As HWND Return ChildWindowFromPoint(hwnd, x, y) End Function Const Function ChildFromPointEx(x As Long, y As Long, flags As DWord) As HWND Return ChildWindowFromPointEx(hwnd, x, y, flags) End Function Const Function ClientToScreen(ByRef pt As POINTAPI) As BOOL Return _System_ClientToScreen(hwnd, pt) End Function Function Close() As BOOL Return CloseWindow(hwnd) End Function Function CreateCaret(hbmp As HBITMAP, width As Long, height As Long) As BOOL Return _System_CreateCaret(hwnd, hbmp, width, hegiht) End Function Function Destroy() As BOOL Return DestroyWindow(hwnd) End Function Function DrawMenuBar() As BOOL Return _System_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 _System_EndPaint(hwnd, ps) End Function Const 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 Const Function GetClassLongPtr(index As Long) As LONG_PTR Return GetClassLongPtr(hwnd, index) End Function Const Function GetClassName(className As PSTR, maxCount As Long) As Long Return GetClassName(className, maxCount) End Function Const Function GetClientRect(ByRef rc As RECT) As BOOL Return _System_GetClientRect(hwnd, rc) End Function Const Function GetContextHelpId() As DWord Return GetWindowContextHelpId(hwnd) 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 Const Function GetDlgCtrlID() As Long Return GetDlgCtrlID(hwnd) End Function Const Function GetDlgItem(idDlgItem As Long) As WindowHandle Return GetDlgItem(hwnd, idDlgItem) End Function Const Function GetDlgItemText(idDlgItem As Long, ps As PSTR, maxCount As Long) As Long Return GetDlgItemText(hwnd, idDlgItem, ps, maxCount) End Function Const Function GetMenu() As HMENU Return _System_GetMenu(hwnd) End Function Const Function GetParent() As WindowHandle Dim w As WindowHandle(_System_GetParent(hwnd)) Return w End Function Const Function GetProp(psz As PCSTR) As HANDLE Return GetProp(hwnd, psz) End Function Const Function GetProp(atom As ATOM) As HANDLE Return GetProp(hwnd, atom As ULONG_PTR As PCSTR) End Function Const Function GetScrollInfo(fnBar As Long, ByRef si As SCROLLINFO) As BOOL Return GetScrollInfo(hwnd, fnBar, si) End Function Const Function GetSystemMenu(revert As BOOL) As HMENU Return GetSystemMenu(hwnd, revert) End Function Const Function GetUpdateRect(ByRef rc As RECT, erase As BOOL) As BOOL Return GetUpdateRact(hwnd, rc, erase) End Function Const Function GetUpdateRgn(hrgn As HRGN, erase As BOOL) As BOOL Return GetUpdateRgn(hwnd, hrgn, erase) End Function Const Function GetWindow(cmd As DWord) As WindowHandle Return GetWindow(hwnd, cmd) End Function Function GetWindowDC() As HDC Return GetWindowDC(hwnd) End Function Const Function GetWindowLongPtr(index As Long) As LONG_PTR Return _System_GetWindowLongPtr(hwnd, index) End Function Const Function GetWindowPlasement(ByRef wndpl As WINDOWPLACEMENT) As BOOL Return GetWindowPlasement(hwnd, wndpl) End Function Const Function GetWindowRect(ByRef rc As RECT) As BOOL Return _System_GetWindowRect(rc) End Function Const Function GetText(ps As PSTR, maxCount As Long) As BOOL Return GetWindowText(ps, maxCount) End Function Const Function GetTextLength() As Long Return GetWindowTextLength(hwnd) End Function Const Function GetWindowThreadId() As DWord Return GetWindowProcessThreadId(hwnd, 0) End Function Const Function GetWindowProcessThreadId(ByRef processId As DWord) As DWord Return GetWindowProcessThreadId(hwnd, processId) End Function Function HideCaret() As BOOL Return _System_HideCaret(hwnd) End Function Function InvalidateRect(ByRef rc As RECT, erace As BOOL) As BOOL Return _System_InvalidateRect(hwnd, rc, erace) End Function Function InvalidateRect(ByRef rc As RECT) As BOOL Return _System_InvalidateRect(hwnd, rc, TRUE) End Function Function InvalidateRgn(hrgn As HRGN, erace As BOOL) As BOOL Return _System_InvalidateRgn(hwnd, hrgn, erace) End Function Function InvalidateRgn(hrgn As HRGN) As BOOL Return _System_InvalidateRgn(hwnd, hrgn, TRUE) End Function Function Invalidate(erace As BOOL) As BOOL Return _System_InvalidateRect(hwnd, ByVal 0, erace) End Function Function Invalidate() As BOOL Return _System_InvalidateRect(hwnd, ByVal 0, TRUE) End Function Const Function IsChild(hwnd As HWND) As BOOL Return IsChild(This.hwnd, hwnd) End Function Const Function IsDialogMessage(ByRef msg As MSG) As BOOL Return IsDialogMessage(hwnd, msg) End Function Const Function IsIconic() As BOOL Return _System_IsIconic(hwnd) End Function Const Function IsWindow() As BOOL Return _System_IsWindow(hwnd) End Function Const Function IsEnabled() As BOOL Return IsWindowEnabled(hwnd) End Function Const Function IsUnicode() As BOOL Return IsWindowUnicode(hwnd) End Function Const Function IsVisible() As BOOL Return IsWindowVisible(hwnd) End Function Const 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 Const Function MessageBox(text As PCSTR, caption As PCSTR, uType As DWord) As Long Return MessageBox(hwnd, text, caption, uType) End Function Const Function MessageBox(text As PCSTR, caption As PCSTR) As Long Return MessageBox(hwnd, text, caption, MB_OK) End Function Const Function MessageBox(text As PCSTR) As Long Return MessageBox(hwnd, text, 0, MB_OK) End Function Function Move(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 Move(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 Move(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 Move(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 Const Function ScreenToClient(ByRef pt As POINTAPI) As BOOL Return _System_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 _System_SetMenu(hwnd, hmenu) End Function Function SetParent(hwndNewParent As HWND) As HWND Return _System_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 _System_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 ShowCaret() As BOOL Return _System_ShowCaret(hwnd) 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 _System_ValidateRect(hwnd, rc) End Function Function ValidateRgn(hrgn As HRGN) As BOOL Return _System_ValidateRgn(hwnd, hrgn) End Function Function Validate() As BOOL Return _System_ValidateRect(hwnd, ByVal 0) End Function ' Get/SetWindowLongPtr Wrappers Const Function GetExStyle() As DWord Return _System_GetWindowLongPtr(hwnd, GWL_EXSTYLE) As DWord End Function Const Function GetStyle() As DWord Return _System_GetWindowLongPtr(hwnd, GWL_STYLE) As DWord End Function Const Function GetWndProc() As WNDPROC Return _System_GetWindowLongPtr(hwnd, GWLP_HINSTANCE) As WNDPROC End Function Const Function GetInstance() As HINSTANCE Return _System_GetWindowLongPtr(hwnd, GWLP_HINSTANCE) As HINSTANCE End Function Const Function GetUserData() As LONG_PTR Return _System_GetWindowLongPtr(hwnd, GWLP_USERDATA) End Function Function SetExStyle(style As DWord) As DWord Return _System_SetWindowLongPtr(hwnd, GWL_EXSTYLE, style) As DWord End Function Function SetStyle(style As DWord) As DWord Return _System_SetWindowLongPtr(hwnd, GWL_STYLE, style) As DWord End Function Function SetWndProc(wndProc As WNDPROC) As WNDPROC Return _System_SetWindowLongPtR(hwnd, GWLP_WNDPROC, wndProc As WNDPROC) As WNDPROC End Function Function SetUserData(value As LONG_PTR) As LONG_PTR Return _System_SetWindowLongPtr(value As LONG_PTR) End Function ' Propaties Const Function ClientRect() As RECT Dim rc As RECT _System_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 Const Function WindowRect() As RECT Dim rc As RECT _System_GetWindowRect(hwnd, rc) Return rc End Function Sub WindowRect(ByRef rc As RECT) MoveWindow(rc) End Sub Const Function ContextHelpID() As DWord Return GetContextHelpId(hwnd) End Function Sub ContextHelpID(newID As DWord) _System_SetContextHelpId(hwnd, newId) End Sub Const Function DlgCtrlID() As Long Return GetDlgCtrlID(hwnd) End Function Sub DlgCtrlId(newId As Long) _System_SetWindowLongPtr(hwnd, GWLP_ID, newId) End Sub Function DlgItem(idDlgItem As Long) As WindowHandle Dim w As WindowHandle(GetDlgItem(hwnd, idDlgItem)) Return w End Function Const Function ExStyle() As DWord Return _System_GetWindowLongPtr(hwnd, GWL_EXSTYLE) As DWord End Function Sub ExStyle(newExStyle As DWord) _System_SetWindowLongPtr(hwnd, GWLP_EXSTYLE, newExStyle) End Sub Const Function Style() As DWord Return _System_GetWindowLongPtr(hwnd, GWL_STYLE) As DWord End Function Sub Style(newStyle As DWord) DWord _System_SetWindowLongPtr(hwnd, GWLP_STYLE, newStyle) End Sub Const Function Enabled() As BOOL Return IsWindowEnabled(hwnd) End Function Sub Enabled(enable As BOOL) EnableWindow(hwnd, enable) End Sub Const 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 Const 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 Const 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 Const Function Instance() As HINSTANCE Return _System_GetWindowLongPtr(hwnd, GWLP_HINSTANCE) As HINSTANCE End Function ' IsWindow, IsUnicodeはメソッドと同じ。 Const Function Parent() As WindowHandle Return _System_GetParent(hwnd) End Function Sub Parent(hwndNewParent As HWND) _System_SetParent(hwnd, hwndNewParent) End Sub Const Function ProcessID() As DWord GetWindowProcessThreadId(ProcessID) End Function Const Function ThreadID() As DWord Return GetWindowProcessThreadId(ByVal 0) End Function Const Function Menu() As HMENU Return _System_GetMenu(hwnd) End Function Sub Menu(hmenuNew As HMENU) _System_SetMenu(hwnd, hmenuNew) End Sub Const 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 Const Function TextLength() As Long Return GetWindowTextLength(hwnd) End Function Const Function UserData() As LONG_PTR Return _System_GetWindowLongPtr(hwnd, GWLP_USERDATA) End Function Sub UserData(newValue As LONG_PTR) _System_SetWindowLongPtr(hwnd, GWLP_USERDATA, newValue) End Sub Const 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 Const Function WindowPlacement() As WINDOWPLACEMENT WindowPlacement.length = Len(WindowPlacement) GetWindowPlacement(hwnd, WindowPlacement) End Function Sub WindowPlacement(ByRef wndpl As WINDOWPLACEMENT) SetWindowPlacement(wndpl) End Sub Const Function WndProc() As WNDPROC Return _System_GetWindowLongPtr(hwnd, GWLP_HINSTANCE) As WNDPROC End Function Sub WndProc(newWndProc As WNDPROC) _System_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__