[Dialog] 대화상자를 부모 윈도우 정 중앙에 위치시키기
대화상자를 부모의 정 중앙에 위치시키는 메소드입니다.
- 윈도우API 정복(개정판) 2060 페이지에서 가져왔습니다.
void MoveToParentCenter( HWND hWnd )
{
RECT sttParentRect, sttClientRect;
HWND hParent;
hParent = ::GetParent( hWnd );
if( hParent == NULL ) return;
if( ::IsIconic( hWnd ) )
{
::ShowWindow( hParent, SW_RESTORE );
}
::GetWindowRect( hParent, &sttParentRect );
::GetWindowRect( hWnd, &sttClientRect );
::SetWindowPos( hWnd, NULL
, sttParentRect.left + ( sttParentRect.right - sttParentRect.left ) / 2 - ( sttClientRect.right - sttClientRect.left ) / 2
, sttParentRect.top + ( sttParentRect.bottom - sttParentRect.top ) / 2 - ( sttClientRect.bottom - sttClientRect.top ) / 2
, 0
, 0
, SWP_NOSIZE | SWP_NOZORDER );
}