- '
- '窗口操作(SmWinCtrl)
- '
- Option Explicit
- Private Const HWND_TOP = 0
- Private Const HWND_BOTTOM = 1
- Private Const HWND_TOPMOST = -1
- Private Const HWND_NOTOPMOST = -2
- Private Const SWP_NOSIZE =
- Private Const SWP_NOMOVE =
- Private Const SWP_NOZORDER =
- Private Const SWP_NOREDRAW =
- '/*以下常數在 ShowWindow中應用*
- Private Const SW_SHOWMAXIMIZED = 3
- Private Const SW_HIDE = 0
- Private Const SW_MINIMIZE = 6
- Private Const SW_RESTORE = 9
- Private Const SW_SHOW = 5
- Private Const SW_SHOWMINIMIZED = 2
- Private Const SW_SHOWMINNOACTIVE = 7
- Private Const SW_SHOWNA = 8
- Private Const SW_SHOWNOACTIVATE = 4
- Private Const SW_SHOWNORMAL = 1
- '/====================================
- '/隱藏窗口,活動狀態給令一個窗口
- '/ SW_HIDE
- '/ 最小化窗口,活動狀態給令一個窗口
- '/ SW_MINIMIZE
- '/ 用原來的大小和位置顯示一個窗口,同時令其進入活動狀態
- '/ SW_RESTORE
- '/用當前的大小和位置顯示一個窗口,同時令其進入活動狀態
- '/ SW_SHOW
- '/ 最大化窗口,並將其激活
- '/ SW_SHOWMAXIMIZED
- '/ 最小化窗口,並將其激活
- '/ SW_SHOWMINIMIZED
- '/ 最小化一個窗口,同時不改變活動窗口
- '/ SW_SHOWMINNOACTIVE
- '/ 用當前的大小和位置顯示一個窗口,不改變活動窗口
- '/ SW_SHOWNA
- '/ 用最近的大小和位置顯示一個窗口,同時不改變活動窗口
- '/ SW_SHOWNOACTIVATE
- '/ 與SW_RESTORE相同
- '/SW_SHOWNORMAL
- Private Const xMenuID = 10
- Private Const WM_NCACTIVATE =
- '/********************************************
- '/MENU ID
- Private Const SC_RESTORE = &HF120& '還原
- Private Const SC_MOVE = &HF010& '移動
- Private Const SC_SIZE = &HF000& '大小
- Private Const SC_MINIMIZE = &HF020& '縮到最小
- Private Const SC_MAXIMIZE = &HF030& '放到最大
- Private Const SC_CLOSE = &HF060& '關閉
- '/********************************************
- Private Const MIIM_STATE = &H1
- Private Const MIIM_ID = &H2
- Private Const MFS_GRAYED = &H3
- Private Const MFS_CHECKED = &H8
- Private Type MENUITEMINFO
- cbSize As Long
- fMask As Long
- fType As Long
- fState As Long
- Wid As Long
- hSubMenu As Long
- hbmpChecked As Long
- hbmpUnchecked As Long
- dwItemData As Long
- dwTypeData As String
- cch As Long
- End Type
- Private Declare Function GetSystemMenu Lib "user32" (ByVal hWnd As Long, ByVal bRevert As Long) As Long
- Private Declare Function GetMenuItemInfo Lib "user32" Alias "GetMenuItemInfoA" (ByVal hMenu As Long, ByVal un As Long, ByVal B As Boolean, lpMenuItemInfo As MENUITEMINFO) As Long
- Private Declare Function SetMenuItemInfo Lib "user32" Alias "SetMenuItemInfoA" (ByVal hMenu As Long, ByVal un As Long, ByVal bool As Boolean, lpcMenuItemInfo As MENUITEMINFO) As Long
- '/--------------------------------------------------
- '/爲窗口指定一個新位置和狀態
- Private Declare Function SetWindowPos Lib "user32" (ByVal hWnd As Long, _
- ByVal hWndInsertAfter As Long, _
- ByVal X As Long, ByVal Y As Long, _
- ByVal cx As Long, ByVal cy As Long, _
- ByVal wFlags As Long) As Long
- '/控制窗口的可見性
- Private Declare Function ShowWindow Lib "user32" _
- (ByVal hWnd As Long, _
- ByVal nCmdShow As Long) As Long
- '/恢復一個最小化的程序,並將其激活
- Private Declare Function OpenIcon Lib "user32" (ByVal hWnd As Long) As Long
- '/將輸入焦點移到指定的窗體(必須與調用者同一線程)
- Private Declare Function SetFocus Lib "user32" (ByVal hWnd As Long) As Long
- '/激活指定窗口(必須與調用者同一線程)
- Private Declare Function SetActiveWindow Lib "user32" (ByVal hWnd As Long) As Long
- '/獲取前臺窗口或者聚焦窗口的句柄
- Private Declare Function GetForegroundWindow Lib "user32" () As Long
- '/===============================================================================
- '/取窗口標題
- Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" _
- (ByVal hWnd As Long, _
- ByVal lpString As String, _
- ByVal cch As Long) As Long
- '/設置窗口標題
- Private Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" _
- (ByVal hWnd As Long, _
- ByVal lpString As String) As Long
- '/將窗口放在前臺
- Private Declare Function SetForegroundWindow Lib "user32" (ByVal hWnd As Long) As Long
- '/向窗口發送消息
- Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
- (ByVal hWnd As Long, ByVal wMsg As Long, _
- ByVal wParam As Long, lParam As Any) As Long
- '/----------------------------------------------------------------------
- '/關閉一個窗口
- '/HWND 要關閉的窗口的句柄
- '/返回值 如果非零,則成功,否則失敗
- Private Declare Function DestroyWindow Lib "user32" (ByVal hWnd As Long) As Long
- '/爲窗體指定一個新父
- '/自身的HWND,新父的HWND.
- Private Declare Function SetParent Lib "user32" (ByVal HwndChild As Long, ByVal HWndNewParent As Long) As Long
- '
- '設置窗口爲最頂層
- '函數:SetTopWindow
- '參數:Winwnd 要設置爲最頂層窗口的HWND
- '返回值:
- '例子:
- Public Function SetTopWindow(WinWnd As Long)
- SetWindowPos WinWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE Or SWP_NOMOVE
- End Function
- Public Function MoveWindow(WinHwnd As Long, X As Long, Y As Long)
- SetWindowPos WinHwnd, HWND_NOTOPMOST, X, Y, 0, 0, SWP_NOSIZE Or SWP_NOMOVE
- End Function
- '
- '將窗口位於Z軸方向的最前.
- '函數:SetTopWindowZ
- '參數:MWinwnd 要設置爲Z軸最前窗口的HWND
- '返回值:
- '例子:
- Public Function SetTopWindowZ(MWinWnd As Long)
- Dim WinHwnd As Long
- WinHwnd = GetForegroundWindow()
- If WinHwnd <> MWinWnd And WinHwnd <> 0 Then
- SetWindowPos WinHwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE Or SWP_NOMOVE
- End If
- End Function
- '
- '將最頂層窗口恢復爲正常
- '函數:NoTopWindow
- '參數:Winwnd 要恢復窗口的HWND
- '返回值:
- '例子:
- Public Function NoTopWindow(WinWnd As Long)
- SetWindowPos WinWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE Or SWP_NOMOVE
- End Function
- '
- '將焦點移到指定的窗體上
- '函數:SetWinFocus
- '參數:hWnd 操作窗口HWND
- '返回值:
- '例子:
- Public Sub SetWinFocus(hWnd As Long)
- Call SetFocus(hWnd)
- End Sub
- '
- '無關閉按鈕.
- '函數:NoClose
- '參數:FHwnd 操作窗口HWND
- '返回值:
- '例子:
- Public Function NoClose(FHwnd As Long)
- Dim hMenu As Long, MII As MENUITEMINFO
- hMenu = GetSystemMenu(FHwnd, 0)
- MII.cbSize = Len(MII)
- MII.dwTypeData = String(80, 0)
- MII.cch = Len(MII.dwTypeData)
- MII.fMask = MIIM_STATE
- MII.Wid = SC_CLOSE
- GetMenuItemInfo hMenu, SC_CLOSE, False, MII
- MII.Wid = xMenuID
- MII.fMask = MIIM_ID
- SetMenuItemInfo hMenu, SC_CLOSE, False, MII
- MII.fState = MII.fState Or MFS_GRAYED
- MII.fMask = MIIM_STATE
- SetMenuItemInfo hMenu, MII.Wid, False, MII
- SendMessage FHwnd, WM_NCACTIVATE, True, ByVal 0
- End Function
- '
- '無最小化按鈕
- '函數:NoMin
- '參數:FHwnd 操作窗口HWND
- '返回值:
- '例子:
- Public Function NoMin(FHwnd As Long)
- Dim hMenu As Long, MII As MENUITEMINFO
- hMenu = GetSystemMenu(FHwnd, 0)
- MII.cbSize = Len(MII)
- MII.dwTypeData = String(80, 0)
- MII.cch = Len(MII.dwTypeData)
- MII.fMask = MIIM_STATE
- MII.Wid = SC_MINIMIZE
- GetMenuItemInfo hMenu, SC_MINIMIZE, False, MII
- MII.Wid = xMenuID
- MII.fMask = MIIM_ID
- SetMenuItemInfo hMenu, SC_MINIMIZE, False, MII
- MII.fState = MII.fState Or MFS_GRAYED
- MII.fMask = MIIM_STATE
- SetMenuItemInfo hMenu, MII.Wid, False, MII
- SendMessage FHwnd, WM_NCACTIVATE, True, ByVal 0
- End Function
- '
- '無最大化按鈕.
- '函數:NoMax
- '參數:FHwnd 操作窗口HWND
- '返回值:
- '例子:
- Public Function NoMax(FHwnd As Long)
- Dim hMenu As Long, MII As MENUITEMINFO
- hMenu = GetSystemMenu(FHwnd, 0)
- MII.cbSize = Len(MII)
- MII.dwTypeData = String(80, 0)
- MII.cch = Len(MII.dwTypeData)
- MII.fMask = MIIM_STATE
- MII.Wid = SC_RESTORE
- GetMenuItemInfo hMenu, SC_RESTORE, False, MII
- MII.Wid = xMenuID
- MII.fMask = MIIM_ID
- SetMenuItemInfo hMenu, SC_RESTORE, False, MII
- MII.fState = MII.fState Or MFS_GRAYED
- MII.fMask = MIIM_STATE
- SetMenuItemInfo hMenu, MII.Wid, False, MII
- SendMessage FHwnd, WM_NCACTIVATE, True, ByVal 0
- End Function
- '
- '爲窗口指定一個新父窗口
- '函數:SetNewParent
- '參數:HwndChild 操作窗口的句柄,HWndNewParent 新父窗口的句柄.
- '返回值:
- '例子:
- Public Function SetNewParent(HwndChild As Long, HWndNewParent As Long)
- SetParent HwndChild, HWndNewParent
- End Function
- '
- '取焦點窗口句柄
- '函數:GetTopWinHwnd
- '參數:
- '返回值:窗口句柄.
- '例子:
- Public Function GetTopWinHwnd() As Long
- GetTopWinHwnd = GetForegroundWindow()
- End Function
- '
- '激活指定窗口
- '函數:GetTopWinHwnd
- '參數:WinHwnd 操作窗口句柄.
- '返回值:
- '例子:
- Public Function SetActWin(WinHwnd As Long)
- SetFocus WinHwnd
- End Function
- '
- '返回窗口標題
- '函數:GetWinLab
- '參數:WinHwnd 操作窗口句柄.
- '返回值:String,窗口標題.
- '例子:
- Public Function GetWinLab(WinHwnd As Long) As String
- Dim MyStr As String
- MyStr = String(255, Chr$(0))
- GetWindowText WinHwnd, MyStr, 255
- MyStr = Left$(MyStr, InStr(MyStr, Chr$(0)) - 1)
- GetWinLab = MyStr
- End Function
- '
- '關閉一個窗口
- '函數:CloseWin
- '參數:WinHwnd 操作窗口句柄.
- '返回值:
- '例子:
- Public Function CloseWin(WinHwnd As Long)
- DestroyWindow WinHwnd
- End Function
- Private Sub Class_Initialize()
- Dim T As New ClsRev
- Call T.GetIniVal
- Set T = Nothing
- End Sub
VB中窗體操作.
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.