Set window always on top and Make center in MFC

Add following code at the end of function OnInitDialog(). This will make window always on top and center on screen.

	GetWindowRect( rect );
	int screenWidth = GetSystemMetrics(SM_CXSCREEN);
	int screenHeight = GetSystemMetrics(SM_CYSCREEN);
	// now change the size, position, and Z order of the window.
	::SetWindowPos(m_hWnd ,       // handle to window
				HWND_TOPMOST,  // placement-order handle
				(screenWidth - rect.Width())/2,
				(screenHeight - rect.Height())/2,     // vertical position
				rect.Width(),  // width
				rect.Height(), // height
				SWP_SHOWWINDOW // window-positioning options
				);


Advertisements
Posted in Uncategorized. Leave a Comment »

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: