Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

右键打开托盘菜单,遇到野指针错误 #140

Closed
qq82850696 opened this issue Oct 31, 2021 · 1 comment
Closed

右键打开托盘菜单,遇到野指针错误 #140

qq82850696 opened this issue Oct 31, 2021 · 1 comment

Comments

@qq82850696
Copy link

断点堆栈:
void CMenuWnd::ResizeMenu()
{
CControlUI* pRoot = m_pm.GetRoot();

#if defined(WIN32) && !defined(UNDER_CE)
MONITORINFO oMonitor = {};
oMonitor.cbSize = sizeof(oMonitor);
::GetMonitorInfo(::MonitorFromWindow(*this, MONITOR_DEFAULTTOPRIMARY), &oMonitor);
CDuiRect rcWork = oMonitor.rcWork;
#else
CDuiRect rcWork;
GetWindowRect(m_pOwner->GetManager()->GetPaintWindow(), &rcWork);
#endif
SIZE szAvailable = { rcWork.right - rcWork.left, rcWork.bottom - rcWork.top };
szAvailable = pRoot->EstimateSize(szAvailable);
m_pm.SetInitSize(szAvailable.cx, szAvailable.cy);

	//必须是Menu标签作为xml的根节点
	CMenuUI *pMenuRoot = static_cast<CMenuUI*>(pRoot);
	ASSERT(pMenuRoot);

	SIZE szInit = m_pm.GetInitSize();
	CDuiRect rc;
	CDuiPoint point = m_BasedPoint;
	rc.left = point.x;
	rc.top = point.y;
	rc.right = rc.left + szInit.cx;
	rc.bottom = rc.top + szInit.cy;

	int nWidth = rc.GetWidth();
	int nHeight = rc.GetHeight();

	if (m_dwAlignment & eMenuAlignment_Right)
	{
		rc.right = point.x;
		rc.left = rc.right - nWidth;
	}

	if (m_dwAlignment & eMenuAlignment_Bottom)
	{
		rc.bottom = point.y;
		rc.top = rc.bottom - nHeight;
	}
	m_wndSize.cx = rc.GetWidth();
	m_wndSize.cy = rc.GetHeight() + pMenuRoot->GetInset().bottom + pMenuRoot->GetInset().top;

	SetForegroundWindow(m_hWnd);  //运行到这句遇到野指针,不是每次都有,偶尔有碰到
	MoveWindow(m_hWnd, rc.left, rc.top, rc.GetWidth(), rc.GetHeight(), FALSE);
	SetWindowPos(m_hWnd, HWND_TOPMOST, rc.left, rc.top, rc.GetWidth(), m_wndSize.cy, SWP_SHOWWINDOW);

}

LRESULT CALLBACK CShadowUI::ParentProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
....
#pragma warning(disable: 4312) // temporrarily disable the type_cast warning in Win32
// Call the default(original) window procedure for other messages or messages processed but not returned
return ((WNDPROC)pThis->m_OriParentProc)(hwnd, uMsg, wParam, lParam); //断在这一句,变量 m_OriParentProc=0,uUmsg=70
#pragma warning(default: 4312)
}

@qdtroy
Copy link
Owner

qdtroy commented Jan 5, 2022

测试未发现此问题

@qdtroy qdtroy closed this as completed Jan 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants