Click here to Skip to main content
15,914,780 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionListing hidden dir's Pin
sheetal_0611-Mar-07 20:30
sheetal_0611-Mar-07 20:30 
AnswerRe: Listing hidden dir's Pin
prasad_som11-Mar-07 21:17
prasad_som11-Mar-07 21:17 
QuestionRe: Listing hidden dir's Pin
David Crow12-Mar-07 4:34
David Crow12-Mar-07 4:34 
AnswerRe: Listing hidden dir's Pin
Hamid_RT12-Mar-07 5:37
Hamid_RT12-Mar-07 5:37 
QuestionNeed to display file open dialog in the center of the screen Pin
amitmistry_petlad 11-Mar-07 20:09
amitmistry_petlad 11-Mar-07 20:09 
AnswerRe: Need to display file open dialog in the center of the screen Pin
prasad_som11-Mar-07 20:15
prasad_som11-Mar-07 20:15 
GeneralRe: Need to display file open dialog in the center of the screen Pin
amitmistry_petlad 11-Mar-07 20:18
amitmistry_petlad 11-Mar-07 20:18 
AnswerRe: Need to display file open dialog in the center of the screen Pin
prasad_som11-Mar-07 20:35
prasad_som11-Mar-07 20:35 
Oh ! I guess, you had asked same question few days back[^]. And I'll answer same thing agains, Look, how CWnd::CenterWindow is implemented.
Code for above function I'm pasing,

/////////////////////////////////////////////////////////////////////////////
// Centering dialog support (works for any non-child window)

void CWnd::CenterWindow(CWnd* pAlternateOwner)
{
	ASSERT(::IsWindow(m_hWnd));

	// determine owner window to center against
	DWORD dwStyle = GetStyle();
	HWND hWndCenter = pAlternateOwner->GetSafeHwnd();
	if (pAlternateOwner == NULL)
	{
		if (dwStyle & WS_CHILD)
			hWndCenter = ::GetParent(m_hWnd);
		else
			hWndCenter = ::GetWindow(m_hWnd, GW_OWNER);
		if (hWndCenter != NULL)
		{
			// let parent determine alternate center window
			HWND hWndTemp =
				(HWND)::SendMessage(hWndCenter, WM_QUERYCENTERWND, 0, 0);
			if (hWndTemp != NULL)
				hWndCenter = hWndTemp;
		}
	}

	// get coordinates of the window relative to its parent
	CRect rcDlg;
	GetWindowRect(&rcDlg);
	CRect rcArea;
	CRect rcCenter;
	HWND hWndParent;
	if (!(dwStyle & WS_CHILD))
	{
		// don't center against invisible or minimized windows
		if (hWndCenter != NULL)
		{
			DWORD dwAlternateStyle = ::GetWindowLong(hWndCenter, GWL_STYLE);
			if (!(dwAlternateStyle & WS_VISIBLE) || (dwAlternateStyle & WS_MINIMIZE))
				hWndCenter = NULL;
		}

 		MONITORINFO mi;
		mi.cbSize = sizeof(mi);

		// center within appropriate monitor coordinates
		if (hWndCenter == NULL)
		{
			HWND hwDefault = AfxGetMainWnd()->GetSafeHwnd();

			GetMonitorInfo(
				MonitorFromWindow(hwDefault, MONITOR_DEFAULTTOPRIMARY), &mi);
			rcCenter = mi.rcWork;
			rcArea = mi.rcWork;
		}
		else
		{
			::GetWindowRect(hWndCenter, &rcCenter);
			GetMonitorInfo(
				MonitorFromWindow(hWndCenter, MONITOR_DEFAULTTONEAREST), &mi);
			rcArea = mi.rcWork;
		}
	}
	else
	{
		// center within parent client coordinates
		hWndParent = ::GetParent(m_hWnd);
		ASSERT(::IsWindow(hWndParent));

		::GetClientRect(hWndParent, &rcArea);
		ASSERT(::IsWindow(hWndCenter));
		::GetClientRect(hWndCenter, &rcCenter);
		::MapWindowPoints(hWndCenter, hWndParent, (POINT*)&rcCenter, 2);
	}

	// find dialog's upper left based on rcCenter
	int xLeft = (rcCenter.left + rcCenter.right) / 2 - rcDlg.Width() / 2;
	int yTop = (rcCenter.top + rcCenter.bottom) / 2 - rcDlg.Height() / 2;

	// if the dialog is outside the screen, move it inside
	if (xLeft < rcArea.left)
		xLeft = rcArea.left;
	else if (xLeft + rcDlg.Width() > rcArea.right)
		xLeft = rcArea.right - rcDlg.Width();

	if (yTop < rcArea.top)
		yTop = rcArea.top;
	else if (yTop + rcDlg.Height() > rcArea.bottom)
		yTop = rcArea.bottom - rcDlg.Height();

	// map screen coordinates to child coordinates
	SetWindowPos(NULL, xLeft, yTop, -1, -1,
		SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
}



GeneralRe: Need to display file open dialog in the center of the screen Pin
amitmistry_petlad 11-Mar-07 19:42
amitmistry_petlad 11-Mar-07 19:42 
AnswerRe: Need to display file open dialog in the center of the screen Pin
prasad_som11-Mar-07 20:57
prasad_som11-Mar-07 20:57 
GeneralRe: Need to display file open dialog in the center of the screen Pin
John R. Shaw11-Mar-07 20:57
John R. Shaw11-Mar-07 20:57 
GeneralRe: Need to display file open dialog in the center of the screen Pin
prasad_som11-Mar-07 21:02
prasad_som11-Mar-07 21:02 
GeneralRe: Need to display file open dialog in the center of the screen Pin
John R. Shaw11-Mar-07 21:50
John R. Shaw11-Mar-07 21:50 
GeneralRe: Need to display file open dialog in the center of the screen Pin
prasad_som11-Mar-07 22:56
prasad_som11-Mar-07 22:56 
GeneralRe: Need to display file open dialog in the center of the screen Pin
John R. Shaw12-Mar-07 0:08
John R. Shaw12-Mar-07 0:08 
GeneralRe: Need to display file open dialog in the center of the screen Pin
prasad_som12-Mar-07 0:20
prasad_som12-Mar-07 0:20 
GeneralRe: Need to display file open dialog in the center of the screen Pin
John R. Shaw12-Mar-07 1:36
John R. Shaw12-Mar-07 1:36 
GeneralRe: Need to display file open dialog in the center of the screen Pin
amitmistry_petlad 11-Mar-07 21:27
amitmistry_petlad 11-Mar-07 21:27 
AnswerRe: Need to display file open dialog in the center of the screen Pin
prasad_som11-Mar-07 20:40
prasad_som11-Mar-07 20:40 
GeneralRe: Need to display file open dialog in the center of the screen Pin
John R. Shaw11-Mar-07 21:32
John R. Shaw11-Mar-07 21:32 
QuestionRe: Need to display file open dialog in the center of the screen Pin
David Crow12-Mar-07 4:35
David Crow12-Mar-07 4:35 
AnswerRe: Need to display file open dialog in the center of the screen Pin
John R. Shaw11-Mar-07 20:40
John R. Shaw11-Mar-07 20:40 
Questionerror of using IID_IHTMLInputElement Pin
MyNothing11-Mar-07 18:53
MyNothing11-Mar-07 18:53 
AnswerRe: error of using IID_IHTMLInputElement Pin
Hamid_RT11-Mar-07 19:10
Hamid_RT11-Mar-07 19:10 
AnswerRe: error of using IID_IHTMLInputElement Pin
prasad_som11-Mar-07 20:13
prasad_som11-Mar-07 20:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.