上記プログラミングはdx,dyによって右と下はウインドウがはみ出るのことがあるで
それが嫌な人は
コード:
Function SetWindowCenter(hWnd As HWND,dx As Long,dy As Long) As Long
Dim x As Long,y As Long 'ウインドウの位置
Dim sx As Long,sy As Long 'スクリーン座標
Dim Basho As RECT 'ウインドウのrc
'ウインドウの位置を取得
GetWindowRect(hWnd,Basho)
'スクリーンの大きさ取得
sx=GetSystemMetrics(SM_CXSCREEN)
sy=GetSystemMetrics(SM_CYSCREEN)
If sx * sy = 0 Then
SetWindowCenter=0
Exit Function
End If
'中央に持っていく計算
x=(sx-Basho.right+Basho.left)/2+dx
y=(sy-Basho.bottom+Basho.top)/2+dy
If x<0 Then
x=0
Else If x>sx-Basho.right+Basho.left Then
x=sx-Basho.right+Basho.left
End If
If y<0 Then
y=0
Else If y>sy-Basho.bottom+Basho.top Then
y=sy-Basho.bottom+Basho.top
End If
'中央に持っていく
SetWindowCenter=SetWindowPos(hWnd,HWND_TOP,x,y,0,0,SWP_NOSIZE)
End Function