⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 module_对话框居中.bas

📁 日本富士仪表PXR的MODBUS通信测试
💻 BAS
字号:
Attribute VB_Name = "Module_对话框居中"
Option Explicit

Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Const WM_INITDIALOG = &H110
Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Declare Function MoveWindow Lib "user32" (ByVal hwnd As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal bRepaint As Long) As Long

Public Function GetProcAddress(ByVal Addr As Long) As Long
GetProcAddress = Addr
End Function

Public Function OpenSaveHookProc(ByVal hwnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
On Error Resume Next

Select Case uMsg
Case WM_INITDIALOG
'temporary vars for demo
Dim rc As RECT
Dim hwndParent As Long, newLeft As Long, newTop As Long, dlgWidth As Long, dlgHeight As Long, scrWidth As Long, scrHeight As Long

'obtain the handle to the parent dialog
hwndParent = GetParent(hwnd)

If hwndParent <> 0 Then
'Just to prove the handle was obtained,
'change the dialog's caption.
'Call SetWindowText(hwndParent, "I'm Hooked on Hooked Dialogs!")

'Position the dialog in the centre of
'the screen. First get the current dialog size.
Call GetWindowRect(hwndParent, rc)

'(To show the calculations involved, I've
'used variables instead of creating a
'one-line MoveWindow call.)
dlgWidth = rc.Right - rc.Left
dlgHeight = rc.Bottom - rc.Top

scrWidth = Screen.Width \ Screen.TwipsPerPixelX
scrHeight = Screen.Height \ Screen.TwipsPerPixelY

newLeft = (scrWidth - dlgWidth) \ 2
newTop = (scrHeight - dlgHeight) \ 2

'..and set the new dialog position to centre.
Call MoveWindow(hwndParent, newLeft, newTop, dlgWidth, dlgHeight, True)

End If
OpenSaveHookProc = 1

' Case WM_COMMAND
' ……
' Case WM_NOTIFY
' ……
End Select
End Function




⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -