Exemplo n.º 1
0
// This function starts (and displays) the clock loading all the necessary bitmaps
// and creating the worker thread.
//
// Parameters:
//		[IN]	nPaneID
//				ID number of the bitmap resource of the whole clock.
//		[IN]	nBigID
//				ID number of the bitmap resource of the big digits.
//		[IN]	nSmallID
//				ID number of the bitmap resource of the small digits.
//		[IN]	bAlternateDateFormat
//				TRUE to display date in mm-dd-yyyy format, else
//				FALSE to display date in dd-mm-yyyy format.
//
// Return value:
//		CLOCKST_OK
//			Function executed successfully.
//		CLOCKST_INVALIDRESOURCE
//			Some error loading bitmaps.
//		CLOCKST_THREADKO
//			Failed creating worker thread.
//
DWORD CClockST::Start(int nPaneID, int nBigID, int nSmallID, BOOL bAlternateDateFormat)
{
	BOOL	bFailed = FALSE;

	// If already started
	if (m_thrParam.hThrHandle) return FALSE;

	// Detach previous resources
	Clean();

	// Load bitmaps & palette
	if (GetBitmapAndPalette(nSmallID, m_bmSmall, m_palPalette) == FALSE)	bFailed = TRUE;
	m_palPalette.DeleteObject();
	if (GetBitmapAndPalette(nBigID, m_bmBig, m_palPalette) == FALSE)		bFailed = TRUE;
	m_palPalette.DeleteObject();
	// Get palette of the whole clock
	if (GetBitmapAndPalette(nPaneID, m_bmClock, m_palPalette) == FALSE)	bFailed = TRUE;

	// If failed loading bitmaps
	if (bFailed)
	{
		Clean();
		return CLOCKST_INVALIDRESOURCE;
	} // if

	// Get dimension of the whole clock
	m_bmClock.GetObject(sizeof(m_bmInfoClock), &m_bmInfoClock);

	// Modify control rect to fit clock
	CRect rect;
	GetWindowRect(rect);

	rect.right = rect.left + m_bmInfoClock.bmWidth;
	rect.bottom = rect.top + m_bmInfoClock.bmHeight;

	SetWindowPos(NULL, 0, 0, rect.Width(), rect.Height(), SWP_NOZORDER | SWP_NOMOVE);

	// Date format to use
	m_bAlternateDateFormat = bAlternateDateFormat;

	// Create thread
	::ZeroMemory(&m_thrParam, sizeof(m_thrParam));
	m_thrParam.pParent = this;
	m_thrParam.bRun = TRUE;

    CWinThread* cw = AfxBeginThread( &thrClock, (LPVOID)&m_thrParam );
	if (cw == NULL)
	{
		Clean();
		return CLOCKST_THREADKO;
	} // if

	m_thrParam.hThrHandle = cw->m_hThread;
	m_thrParam.dwThrId = cw->m_nThreadID;

	return CLOCKST_OK;
} // End of Start
Exemplo n.º 2
0
BOOL CProgressST::SetBitmap(UINT nBitmapId, BOOL bRepaint)
{
	BITMAP bm;
	BOOL bRet;

	// Detach any previuos bitmap
	m_bmPattern.Detach();

	// Default return value
	bRet = TRUE;

	// Load new bitmap
	if (nBitmapId != NULL)
	{
		bRet = GetBitmapAndPalette(nBitmapId, m_bmPattern, m_Palette);
		// If all ok
		if (bRet == TRUE)
		{
			// Get dimension
			m_bmPattern.GetBitmap(&bm);
			// Width of the bitmap
			m_nWidth = bm.bmWidth;
			// Height of the bitmap
			m_nHeight = bm.bmHeight;
		}
	}

	// Repaint control
	if (bRepaint == TRUE) Invalidate();

	return bRet;
} // End of SetBitmap
Exemplo n.º 3
0
BOOL CBackgroundUtil::SetBitmap(UINT uResourceID)
{
	BITMAP bm;
	BOOL bRet;

	// Detach previous resources
	m_BmpPattern.Detach();  
	m_BmpPalette.Detach();  

	// Default return value
	bRet = TRUE;

	// Load new bitmap
	if (uResourceID != 0)
	{
		bRet = GetBitmapAndPalette(uResourceID, m_BmpPattern, m_BmpPalette);
		// If all ok
		if (bRet == TRUE)
		{
			// Get dimension
			m_BmpPattern.GetBitmap(&bm);
			// Width of the bitmap
			m_nBmpWidth = bm.bmWidth;
			// Height of the bitmap
			m_nBmpHeight = bm.bmHeight;
		}
	}

	return bRet;
} // End of SetBitmap