⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ngdialog.cpp

📁 ResOrg 图形化管理Vc项目的资源ID的工具的源代码。 ResOrg - Manage and Renumber Resource Symbol IDs Introduction The
💻 CPP
📖 第 1 页 / 共 3 页
字号:

// Context help generated by pressing F1 or using the "?" button on the title
// bar of the dialog.
BOOL CNGDialog::OnHelpInfo(HELPINFO* pHelpInfo) 
{
	if (pHelpInfo->iContextType == HELPINFO_WINDOW)
	{
		// Launch WinHelp or HtmlHelp
		// The HELP_WM_HELP flag brings up pop-up help and expects an array 
		// of DWORD pairs of the control ID and the context help ID
		UINT uCtrlID = pHelpInfo->iCtrlId;
		if ( (uCtrlID != 0) && (uCtrlID != IDC_STATIC) )
		{
			CTRLID_HELPID_PAIR dwHelpIds(	uCtrlID,
											uCtrlID + HID_BASE_CONTROL);

			::WinHelp(	(HWND)pHelpInfo->hItemHandle,
						AfxGetApp()->m_pszHelpFilePath,	
						HELP_WM_HELP,
						(DWORD)&dwHelpIds);
		}
	}
	return TRUE;
}


//	Context help generated by right clicking the control and selecting the
//	"Whats this ?" menu.
void CNGDialog::OnContextMenu(CWnd* pWnd, CPoint point) 
{
 	// The title bar has a system provided context menu which is displayed for
	// a right mouse button up
	if (HTCLIENT == OnNcHitTest(point))
	{
		//TRACE("OnContextMenu - HTCIENT\n");
		CWnd* pChildWnd;
		if (pWnd == this) //if the control on the dialog is disabled
		{
			// get the hWnd of the disabled child window
			ScreenToClient(&point);
			pChildWnd = ChildWindowFromPoint(point, CWP_ALL);
		}
		else
		{
			// for OK, Cancel and Apply (if enabled) buttons
			pChildWnd = pWnd;
		}

		// Launch WinHelp or HtmlHelp
		// The HELP_CONTEXTMENU flag brings up the "Whats this ?" menu and selecting
		// the menu in turn brings up the pop-up help. It expects an array 
		// of DWORD pairs of the control ID and the context help ID
		
		UINT uCtrlID = pChildWnd->GetDlgCtrlID();
		if ( (uCtrlID != 0) && (uCtrlID != IDC_STATIC) )
		{
			CTRLID_HELPID_PAIR dwHelpIds(	uCtrlID,
											uCtrlID + HID_BASE_CONTROL);

			::WinHelp(	(HWND)pWnd->m_hWnd,
						AfxGetApp()->m_pszHelpFilePath,
						HELP_CONTEXTMENU,
						(DWORD)&dwHelpIds);
		}
	}
}

/////////////////////////////////////////////////////////////////////////////
// CNGDialog operations

BOOL CNGDialog::SetServer(CObject* pServer)
{
	m_pServer = pServer;
	ASSERT_VALID(m_pServer);

	return (m_pServer != NULL);
}


BOOL CNGDialog::SetDocument(CDocument* pDocument)
{
	m_pDoc = pDocument;
	ASSERT_VALID(m_pDoc);

	return (m_pDoc != NULL);
}


void CNGDialog::SetModified(BOOL bChanged /*= TRUE*/)
{
	m_bModified = bChanged;
}


BOOL CNGDialog::EnableDlgControl(UINT uID, BOOL bEnable)
{
	CWnd* pWnd = GetDlgItem(uID);
    if (NULL != pWnd)
	{
		pWnd->EnableWindow(bEnable);
		return TRUE;
	}
	ASSERT(FALSE);
	return FALSE;
}

	
BOOL CNGDialog::ShowDlgControl(UINT uID, BOOL bShow)
{
	CWnd* pWnd = GetDlgItem(uID);
    if (NULL != pWnd)
	{
		pWnd->ShowWindow(bShow);
		return TRUE;
	}
	ASSERT(FALSE);
	return FALSE;
}

	
BOOL CNGDialog::SetReadOnly(UINT uID, BOOL bReadOnly /*= TRUE*/)
{
	CEdit* pCtrl = static_cast<CEdit*>( GetDlgItem(uID) );
    if (NULL != pCtrl)
	{
		pCtrl->SetReadOnly(bReadOnly);
		return TRUE;
	}
	ASSERT(FALSE);
	return FALSE;
}


BOOL CNGDialog::UpdateData(BOOL bSaveAndValidate /*= TRUE*/)
{
	if (IsWindow(m_hWnd))
	{
		return CNGDialog_BASE::UpdateData(bSaveAndValidate);
	}
	return FALSE;
}


/////////////////////////////////////////////////////////////////////////////
// CNGPropertySheet overrides

// Override to initialise data BEFORE the screen controls
BOOL CNGDialog::OnInitDialog(void)
{
	// Update initial data from the server
	OnInitData();

	BOOL bResult = CNGDialog_BASE::OnInitDialog();
	
	SetInitialPosition();
	
	return bResult;
}


void CNGDialog::OnInitData(void)
{
	if (IsWindow(m_hWnd))
	{
		UpdateData(FALSE);
	}
}


/////////////////////////////////////////////////////////////////////////////
// CNGPropertySheet message handlers

void CNGDialog::OnMove(int x, int y) 
{
	CNGDialog_BASE::OnMove(x, y);
	
	GetWindowRect(&m_rectPosition);
}


/////////////////////////////////////////////////////////////////////////////
// Implementation

void CNGDialog::SetInitialPosition(void)
{
	// If we've got a position from last time use it to position
	// our window this time
	if (!m_rectInitialPosition.IsRectEmpty())
	{
		// As the property sheet is not scaleable at the moment we need
		// to make sure we change the size of m_rectPosition to match
		// the size of the window as it is now (remember that adding or
		// deleting pages between invokations may change the size)
		m_rectInitialPosition.BottomRight() =
							CPoint(	m_rectInitialPosition.left + m_rectPosition.Width(),
									m_rectInitialPosition.top + m_rectPosition.Height() );


		MoveWindow(m_rectInitialPosition);
	}
}


/////////////////////////////////////////////////////////////////////////////
// CNGDialog message handlers



/////////////////////////////////////////////////////////////////////////////
// CNGPropertyPage property page

IMPLEMENT_DYNAMIC(CNGPropertyPage, CNGPropertyPage_BASE)


CNGPropertyPage::CNGPropertyPage(	UINT uID /*= 0*/,
									UINT uIDCaption /*= 0*/,
									UINT uTitleID /*= 0*/,
									UINT uSubtitleID /*= 0*/)
	: CNGPropertyPage_BASE(uID, uIDCaption, uTitleID, uSubtitleID)
{
	m_pDoc				= NULL;
	m_pServer			= NULL;

	m_bLockCtrlUpdates	= false;
	m_bModified			= false;

	//{{AFX_DATA_INIT(CNGPropertyPage)
	//}}AFX_DATA_INIT
}


CNGPropertyPage::CNGPropertyPage(	LPCTSTR pszCaption,
									UINT uIDCaption /*= 0*/,
									UINT uTitleID /*= 0*/,
									UINT uSubtitleID /*= 0*/)
	: CNGPropertyPage_BASE(pszCaption, uIDCaption, uTitleID, uSubtitleID)
{
	m_pDoc				= NULL;
	m_pServer			= NULL;

	m_bLockCtrlUpdates	= false;
}


CNGPropertyPage::~CNGPropertyPage(void)
{
}


void CNGPropertyPage::DoDataExchange(CDataExchange* pDX)
{
	CNGPropertyPage_BASE::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CNGPropertyPage)
	//}}AFX_DATA_MAP

	// These are out of Classwizard's grasp as it can't handle the syntax
}


BEGIN_MESSAGE_MAP(CNGPropertyPage, CNGPropertyPage_BASE)
	//{{AFX_MSG_MAP(CNGPropertyPage)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


// Override to initialise data BEFORE the screen controls
BOOL CNGPropertyPage::OnInitDialog(void)
{
	OnInitData();

	return CNGPropertyPage_BASE::OnInitDialog();
}


void CNGPropertyPage::OnInitData(void)
{
	if (IsWindow(m_hWnd))
	{
		UpdateData(FALSE);
	}
}


//	Override the default message processing to try to figure out
//	when the value of a control has changed, so that we can enable
//	the Apply button
//
//	NOTES:
//		1.	UpdateData(TRUE) is automatically called if the control value
//			could have changed, and DDV validation succeeds
//
//		2.	The detection of changed controls is not perfect, and hence the Apply
//			button could be erroneously enabled under certain circumstances.
//
BOOL CNGPropertyPage::OnCommand(WPARAM wParam, LPARAM lParam) 
{
	BOOL bResult = FALSE;

	// Crack message parameters
	// This bit was nicked from CPropertySheet::OnCommand()
	UINT uID		= LOWORD(wParam);
	HWND hWnd		= (HWND)lParam;
	int nCode		= HIWORD(wParam);

	UINT uCtrlID	= uID;						// We'll need this later

	// If the command notification was a control value change
	// which could be linked up via DDX update the DDX member
	// vars and send a WM_COMMAND notification on the affected
	// control (this allows a generic ON_COMMAND handler to be
	// used, irrespective of the type of the control)

	if (hWnd != NULL)
	{
		// Catch ENTER keypresses on a control
		// and convert to a CN_COMMAND call for that control
		// This allows the control focused when ENTER was pressed to receive
		// the change notification...
		if (uID == IDOK)
		{
			// Walk up from the focused window until we find a valid control
			HWND hWndFocusCtrl = ::GetFocus();
			while ( (hWndFocusCtrl != NULL) && (::GetParent(hWndFocusCtrl) != m_hWnd) )
			{
				hWndFocusCtrl=::GetParent(hWndFocusCtrl);
			}
			
			// If the focused control is the one we orignially received the 
			// notification from it must be the OK button itself, so
			// let it through unchanged
			if ( (hWndFocusCtrl == NULL) || (hWndFocusCtrl == hWnd) )
			{
				return CNGPropertyPage_BASE::OnCommand(wParam, lParam);
			}

			// CN_COMMAND notification fires on the focused control
			hWnd = hWndFocusCtrl;
		}	
		else if (nCode == CN_COMMAND)
		{
			uCtrlID = ::GetCtrlID(this, hWnd);
			hWnd = ::GetDlgItem(GetSafeHwnd(), uCtrlID);
			ASSERT(uCtrlID != 0);
			ASSERT(uCtrlID != 65535);

			// If the ID of the control in the message isn't the same as that
			// of the control we've identified, pass it through
			// (this can happen with radio buttons)
			if (uID != uCtrlID)
			{
				bResult = CNGPropertyPage_BASE::OnCommand(wParam, lParam);
			}
		}
		else
		{
			// All non-button controls end up here...
			bResult = CNGPropertyPage_BASE::OnCommand(wParam, lParam);
		}
		if (::IsCtrlValueChanging(this, uCtrlID, hWnd, nCode) && !m_bLockCtrlUpdates)
		{
			bResult = OnCtrlValueChanging(uCtrlID, hWnd, nCode);
		}
	}
	else
	{
		bResult = CNGPropertyPage_BASE::OnCommand(wParam, lParam);
	}
	return bResult;
}


// Called when the value of a control has been changed
BOOL CNGPropertyPage::OnCtrlValueChanging(UINT uCtrlID, HWND hWnd, int nCode)
{
	UNREFERENCED_PARAMETER(hWnd);
	UNREFERENCED_PARAMETER(nCode);

	BOOL bResult = UpdateData(TRUE);			// Try to retrieve dialog data via DoDataExchange()
	if (bResult)
	{											// Validation succeeded...
		OnCmdMsg(uCtrlID, 0, NULL, NULL);		// ...so generate a WM_COMMAND notification...
		SetModified();							// ...and mark the page as changed
	}
	return bResult;
}


BOOL CNGPropertyPage::OnApply(void)
{
	ASSERT_VALID(this);
	
	BOOL bResult = CNGPropertyPage_BASE::OnApply();

	m_bModified			= FALSE;

	return bResult;
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -