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

📄 cdxcdynamicwnd.cpp

📁 电力监控系统。 使用VC实现
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	catch(...)
	{
		delete pli;
		throw;
	}

	delete pli;
}

//////////////////////////////////////////////////////////////////////
// message work
//////////////////////////////////////////////////////////////////////

/*
 * DoMoveCtrl()
 * ------------
 * This virtual function is used to calculate a child window's new position
 * based on the some data (from the cdxCDynamicLayoutInfo object).
 * This standard routine is made to implement the algorithm as known from
 * the cdxCDynamicControlsManager.
 * You can implement your own code if you are not satisfied with the
 * following function.
 * If you need global data, overwrite DoCreateLayoutInfo() which will
 * be called by Layout() and which you can use to collect these data
 * once for the entire layout process.
 *
 * PARAMETERS:
 *
 *		hwnd			-	handle of the child control
 *		id				-	its id
 *		rectNewPos	-	write the new position here in.
 *							initially contains the current position
 *		li				-	Some information on the parent window.
 *							You can provide extra information here
 *							by overwriting DoCreateLayoutInfo().
 *
 * RETURN CODES:
 *
 * return false if you don't want to move the control
 * return true if you updated the control's position and stored it into "rectNewPos"
 * If you don't change it, the control will not be moved.
 *
 * #### don't move the control by yourself. Layout() will do for you to ensure
 *      that as little flickering as possible will occur.
 */

bool cdxCDynamicWnd::DoMoveCtrl(HWND hwnd, UINT id, CRect & rectNewPos, const cdxCDynamicLayoutInfo & li)
{
	Position	pos;

	if(!GetControlPosition(hwnd,pos))
		return false;

	pos.Apply(hwnd,rectNewPos,li);
	return true;
}	

/*
 * DoDestroyCtrl()
 * ---------------
 * Called when a child window is about being destroyed.
 * We use it to remove our "Position" data from our database.
 */
 
void cdxCDynamicWnd::DoDestroyCtrl(HWND hwnd)
{
	m_Map.RemoveKey(hwnd);
}

//////////////////////////////////////////////////////////////////////
// initialization & clean-uo
//////////////////////////////////////////////////////////////////////

/*
 * DoInitWindow()
 * --------------
 * This function sets up the window pointer.
 * It is recommended that "rWnd" points to an existing CWnd.
 * However, it doesn't need to exist as long as you
 * 1) provide a non-zero "szInitial" object.
 * 2) don't want a size icon.
 *
 *	PARAMETERS:
 *
 *		rWnd			-	reference to your window ("*this")
 *							the window must exist (::IsWindow(rWnd.m_hWnd) must be true)
 *		fd				-	Freedom (in which direction(s) your window shall be sizable BY THE USER):
 *							Possible values: fdAll, fdHorz, fdVert and fdNone.
 *							This is only applied to user-actions; resizing + layout may work
 *							even if the freedom parameter is fdNone (in that case user cannot resize
 *							your window, but you can).
 *		flags			-	several flags:
 *								flSizeIcon		-	creates a size icon
 *								flAntiFlicker	-	activates anti-flickering stuff
 *		[szInitial	-	initial client size]
 */

void cdxCDynamicWnd::DoInitWindow(CWnd & rWnd)
{
	ASSERT(::IsWindow(rWnd.m_hWnd));	// ensure the window exists ...

	m_pWnd		=	&rWnd;
	DoInitWindow(rWnd,GetCurrentClientSize());
}

void cdxCDynamicWnd::DoInitWindow(CWnd & rWnd, const CSize & szInitial)
{
	ASSERT(::IsWindow(rWnd.m_hWnd) && szInitial.cx && szInitial.cy);	// ensure the window exists ...

	m_pWnd		=	&rWnd;
	m_szInitial	=	szInitial;
	m_szMin		=	szInitial;

	/*
	 * this window will flicker somewhat deadly if you do not have the
	 * WS_CLIPCHILDREN style set for you window.
	 * You may like to use the following line anywhere
	 * to apply it:
	 
		  CWnd::ModifyStyle(0,WS_CLIPCHILDREN);

    */

#ifdef _DEBUG
	if(!(rWnd.GetStyle() & WS_CLIPCHILDREN) && !(m_nFlags & flSWPCopyBits))
	{
		TRACE(_T("***\n"
					"*** cdxCDynamicWnd class note: If your window flickers too much, add the WS_CLIPCHILDREN style to it\n"
					"***                            or try to set the flSWPCopyBits flags !!!\n"
					"***\n"));
	}
#endif

	//
	// now, if a DYNAMIC MAP is been defined,
	// we start working with it
	//

	const __dynEntry	*pEntry,*pLast	=	NULL;
	UINT					nInitCnt	=	GetCtrlCount();

	if(pLast = __getDynMap(pLast))
	{
		HWND		hwnd;
		SBYTES	bytes;

		for(pEntry = pLast; pEntry->type != __end; ++pEntry)
		{
			if((pEntry->id != DYNAMIC_MAP_DEFAULT_ID)
				&& !( hwnd = ::GetDlgItem(m_pWnd->m_hWnd,pEntry->id) ))
			{
				TRACE(_T("*** NOTE[cdxCDynamicWnd::DoInitWindow()]: Dynamic map initialization: There's no control with the id 0x%lx !\n"),pEntry->id);
				continue;
			}

			switch(pEntry->type)
			{
				case	__bytes:

					bytes[X1]	=	pEntry->b1;
					bytes[Y1]	=	pEntry->b2;
					bytes[X2]	=	pEntry->b3;
					bytes[Y2]	=	pEntry->b4;
					break;

				case	__modes:
					
					_translate((Mode)pEntry->b1,bytes[X1],bytes[X2]);
					_translate((Mode)pEntry->b2,bytes[Y1],bytes[Y2]);
					break;

				default:

					ASSERT(false);		// never come here !!!!!
					break;
			}

			if(pEntry->id == DYNAMIC_MAP_DEFAULT_ID)
				AllControls(bytes,false,false);
			else
				AddSzControl(hwnd,bytes,M_szNull,false);
		}
	}

	//
	// handle creation flags
	//

	if(m_nFlags & flSizeIcon)
	{
		m_pSizeIcon	=	new cdxCSizeIconCtrl;
		VERIFY( m_pSizeIcon->Create(m_pWnd) );

		AddSzControl(m_pSizeIcon->m_hWnd,BotRight,M_szNull,false);
		m_pSizeIcon->ShowWindow(SW_SHOW);
	}

	m_bIsAntiFlickering	=	false;
	m_nMyTimerID			=	DEFAULT_TIMER_ID;
	m_dwClassStyle			=	::GetClassLong(*m_pWnd,GCL_STYLE) & (CS_VREDRAW|CS_HREDRAW);

	OnInitialized();

	if(nInitCnt < GetCtrlCount())
		Layout();
}


/*
 * DoDestroyWindow()
 * -----------------
 * Clean up.
 */

void cdxCDynamicWnd::DoOnDestroy()
{
	if(IsWindow())
		OnDestroying();

	m_iDisabled		=	1;
	m_pWnd			=	NULL;
	m_Map.RemoveAll();

	if(m_pSizeIcon)
	{
		m_pSizeIcon->DestroyWindow();
		delete m_pSizeIcon;

		m_pSizeIcon	=	NULL;
	}
}

//////////////////////////////////////////////////////////////////////
// message work
//////////////////////////////////////////////////////////////////////

/*
 * DoOnSize()
 * ----------
 * Calls Layout() if necessary.
 */

void cdxCDynamicWnd::DoOnSize(UINT nType, int cx, int cy)
{
	if(!IsDisabled() &&
		IsWindow() &&
		(nType != SIZE_MINIMIZED))
	{
		Layout();
	}
}

/*
 * DoOnSizing()
 * ------------
 * This is my turbo-new-super-duper anti-flickering function
 * StartAntiFlickering() is called by the following handler.
 */

void cdxCDynamicWnd::DoOnSizing(UINT fwSide, LPRECT pRect)
{
	if(m_nMyTimerID && !IsDisabled() && IsWindow() && (m_nFlags & flAntiFlicker))
		StartAntiFlickering(	(fwSide == WMSZ_BOTTOM) ||
									(fwSide == WMSZ_BOTTOMRIGHT) ||
									(fwSide == WMSZ_RIGHT));
}

/*
 * StartAntiFlickering()
 * ---------------------
 * This routine modifies the CS_VREDRAW and CS_HREDRAW CLASS style
 * flags.
 * If you don't like this, set "m_nMyTimerID" to 0.
 *		bIsBotRight	-	true if the window is sized in right, bottom or bot/right direction.
 */

void cdxCDynamicWnd::StartAntiFlickering(bool bIsBotRight)
{
	if(IsWindow() && m_nMyTimerID)
	{
		DWORD	dw	=	m_dwClassStyle;
		if(bIsBotRight)
			dw	&=	~(CS_VREDRAW|CS_HREDRAW);
		else
			dw	|=	CS_VREDRAW|CS_HREDRAW;

		m_pWnd->KillTimer(m_nMyTimerID);
		m_pWnd->SetTimer(m_nMyTimerID,120,NULL);

		if(!m_bIsAntiFlickering)
		{
			::SetClassLong(*m_pWnd,GCL_STYLE,dw);
			m_bIsAntiFlickering	=	true;
		}
	}
}

/*
 * DoOnTimer()
 * -----------
 * Processes the timer associated to my DoOnSizing() routine.
 * Changes back the class style.
 */

void cdxCDynamicWnd::DoOnTimer(UINT nIDEvent) 
{
	if(IsWindow() && (nIDEvent == m_nMyTimerID))
	{
		m_pWnd->KillTimer(m_nMyTimerID);
		if(m_bIsAntiFlickering)
		{
			::SetClassLong(*m_pWnd,GCL_STYLE,m_dwClassStyle);
			m_bIsAntiFlickering	=	false;
		}
	}
}

//////////////////////////////////////////////////////////////////////

/*
 * DoOnGetMinMaxInfo()
 * -------------------
 * fill in MINMAXINFO as requested
 * Call your CWnd's OnGetMinMaxInfo first !
 * [changed due to a bug reported by Michel Wassink <mww@mitutoyo.nl>]
 */

void cdxCDynamicWnd::DoOnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)
{
	if(IsWindow() && !IsDisabled())
	{
		CSize	szDelta	=	GetBorderSize();

		lpMMI->ptMinTrackSize.x	=	m_szMin.cx + szDelta.cx;
		lpMMI->ptMinTrackSize.y	=	m_szMin.cy + szDelta.cy;

		if(m_Freedom & fdHoriz)
		{
			if(m_szMax.cx > 0)
				lpMMI->ptMaxTrackSize.x	=	m_szMax.cx + szDelta.cx;
		}
		else
			lpMMI->ptMaxTrackSize.x	=	lpMMI->ptMinTrackSize.x;

		if(m_Freedom & fdVert)
		{
			if(m_szMax.cy > 0)
				lpMMI->ptMaxTrackSize.y	=	m_szMax.cy + szDelta.cy;
		}
		else
			lpMMI->ptMaxTrackSize.y	=	lpMMI->ptMinTrackSize.y;
	}
}

//////////////////////////////////////////////////////////////////////

/*
 * DoOnParentNotify()
 * ------------------
 * When a child window is been destroyed, we remove the appropiate
 * HWND entries.
 */

void cdxCDynamicWnd::DoOnParentNotify(UINT message, LPARAM lParam) 
{
	if(!lParam || (message != WM_DESTROY))
		return;

	DoDestroyCtrl((HWND)lParam);
}



⌨️ 快捷键说明

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