如何让CommonDialog1显示在窗口正中央?

whjwsy 2003-08-22 03:28:55
CommonDialog1总是在窗口的左上角,怎样才能调整到屏幕正中央?
...全文
92 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
qifanghcy 2003-08-23
  • 打赏
  • 举报
回复
自己做一个,这种控件我一般都会自己做的,呵呵....
whjwsy 2003-08-22
  • 打赏
  • 举报
回复
首先在98中应该能用,否则不能对外发布。
CommonDialog是能记忆上次拖放后的位置,只要使用者将其挪至中间就可以,
我是想让它第一次显示时就在窗口中间。
of123 2003-08-22
  • 打赏
  • 举报
回复
CommonDialog能记忆上次拖放后的位置,大概在注册表中有记录。查查看。
zqfleaf 2003-08-22
  • 打赏
  • 举报
回复
我试过了可以window2000pro sp4 +vb6.0,你单独试试
of123 2003-08-22
  • 打赏
  • 举报
回复
不支持多窗口应用程序。
自己用form做吧,省事得多,想到哪里就到哪里。
whjwsy 2003-08-22
  • 打赏
  • 举报
回复
不行,运行出错,连VB都退出了。
zqfleaf 2003-08-22
  • 打赏
  • 举报
回复
1.加到模块中

Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type

Public Declare Function UnhookWindowsHookEx Lib "user32" ( _
ByVal hHook As Long) As Long
Public Declare Function GetWindowLong Lib "user32" Alias _
"GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) _
As Long
Public Declare Function GetCurrentThreadId Lib "kernel32" () As Long
Public Declare Function SetWindowsHookEx Lib "user32" Alias _
"SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As Long, _
ByVal hmod As Long, ByVal dwThreadId As Long) As Long
Public 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
Public Declare Function GetWindowRect Lib "user32" (ByVal hwnd _
As Long, lpRect As RECT) As Long

Public Const GWL_HINSTANCE = (-6)
Public Const SWP_NOSIZE = &H1
Public Const SWP_NOZORDER = &H4
Public Const SWP_NOACTIVATE = &H10
Public Const HCBT_ACTIVATE = 5
Public Const WH_CBT = 5

Public hHook As Long

Function WinProc1(ByVal lMsg As Long, ByVal wParam As Long, _
ByVal lParam As Long) As Long

If lMsg = HCBT_ACTIVATE Then
'Show the MsgBox at a fixed location (0,0)
SetWindowPos wParam, 0, 0, 0, 0, 0, _
SWP_NOSIZE Or SWP_NOZORDER Or SWP_NOACTIVATE
'Release the CBT hook
UnhookWindowsHookEx hHook
End If
WinProc1 = False

End Function

Function WinProc2(ByVal lMsg As Long, ByVal wParam As Long, _
ByVal lParam As Long) As Long

Dim rectForm As RECT, rectMsg As RECT
Dim x As Long, y As Long

'On HCBT_ACTIVATE, show the MsgBox centered over Form1
If lMsg = HCBT_ACTIVATE Then
'Get the coordinates of the form and the message box so that
'you can determine where the center of the form is located
GetWindowRect Form1.hwnd, rectForm
GetWindowRect wParam, rectMsg
x = (rectForm.Left + (rectForm.Right - rectForm.Left) / 2) - _
(200/ 2)
y = (rectForm.Top + (rectForm.Bottom - rectForm.Top) / 2) - _
(400/ 2)
'Position the msgbox
SetWindowPos wParam, 0, x, y, 0, 0, _
SWP_NOSIZE Or SWP_NOZORDER Or SWP_NOACTIVATE
'Release the CBT hook
UnhookWindowsHookEx hHook
End If
WinProc2 = False

End Function

2.

Private Sub Command1_Click()
Dim hInst As Long
Dim Thread As Long
hInst = GetWindowLong(Me.hwnd, GWL_HINSTANCE)
Thread = GetCurrentThreadId()
hHook = SetWindowsHookEx(WH_CBT, AddressOf WinProc2, hInst, _
Thread)
commondialog1.showcolor
End Sub

1,451

社区成员

发帖
与我相关
我的任务
社区描述
VB 控件
社区管理员
  • 控件
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧