Exemplo n.º 1
0
BOOL COXMonthCalPopup::Pick(CRect rect, CRect rectParent, COleDateTime dtInitialDate, COleDateTime& dtPickedDate)
{
	AdjustDisplayRectangle(rect, rectParent);

	SetCurSel(dtInitialDate);

	MoveWindow(rect);
	ShowWindow(SW_SHOW);
	SetCapture();

	// init message loop
	bool bBreak = false;
	BOOL bValidDatePicked = FALSE;
	while (!bBreak)
	{
		MSG msg;
		VERIFY(::GetMessage(&msg, NULL, 0, 0));


		if (msg.message == WM_LBUTTONDOWN)
		{
			DispatchMessage(&msg);
			SetCapture();
		}
		else if (msg.message == WM_LBUTTONUP)
		{
			DispatchMessage(&msg);

			MCHITTESTINFO hti;
			::memset(&hti, 0, sizeof(hti));
			hti.pt.x = GET_X_LPARAM(msg.lParam);
			hti.pt.y = GET_Y_LPARAM(msg.lParam);
			hti.cbSize = sizeof(hti);
			HitTest(&hti);
			DWORD dwResult = HitTest(&hti);
			if (dwResult == MCHT_CALENDARDATE)
			{
				// The user clicked on a date, so save and close
				SYSTEMTIME stOut;
				GetCurSel(&stOut);
				stOut.wHour = 0;
				stOut.wMinute = 0;
				stOut.wSecond = 0;
				stOut.wMilliseconds = 0;
		
				dtPickedDate = COleDateTime(stOut);
				bValidDatePicked = TRUE;
				bBreak = true;
			}
			else if (dwResult == MCHT_NOWHERE)
			{
				// The user clicked outside
				bBreak = true;
			}

			SetCapture();
		}
		else if (msg.message == WM_KEYDOWN)
		{
			// Handle ESCAPE and ENTER
			if (msg.wParam == VK_ESCAPE)
				bBreak = true;
			else if (msg.wParam == VK_RETURN)
			{
				DispatchMessage(&msg);

				SYSTEMTIME stOut;
				GetCurSel(&stOut);
				stOut.wHour = 0;
				stOut.wMinute = 0;
				stOut.wSecond = 0;
				stOut.wMilliseconds = 0;
		
				dtPickedDate = COleDateTime(stOut);
				bValidDatePicked = TRUE;
				bBreak = true;
			}
			else
				DispatchMessage(&msg);
		}
		else
		{
			DispatchMessage(&msg);
		}
	}

	ReleaseCapture();
	ShowWindow(SW_HIDE);

	return bValidDatePicked;
}
Exemplo n.º 2
0
int COXListPopup::Pick(CRect rect, CRect rectParent)
{
	AdjustDisplayRectangle(rect, rectParent);

	MoveWindow(rect);
	ShowWindow(SW_SHOWNA);
	SetCapture();

	// init message loop
	bool bBreak = false;
	int iReturnItemIdx = -1;
	while (!bBreak)
	{
		MSG msg;
		VERIFY(::GetMessage(&msg, NULL, 0, 0));
		if (msg.message == WM_LBUTTONUP)
		{
			// Get the item under the mouse cursor
			int xPos = GET_X_LPARAM(msg.lParam); 
			int yPos = GET_Y_LPARAM(msg.lParam);

			BOOL bOutside;
			UINT nIndex = ItemFromPoint(CPoint(xPos, yPos), bOutside);
			if (!bOutside)
				iReturnItemIdx = (int) nIndex;
			bBreak = true;
		}
		else if (msg.message == WM_KEYDOWN)
		{
			// Handle ESCAPE, UP, DOWN and ENTER
			if (msg.wParam == VK_ESCAPE)
				bBreak = true;
			else if (msg.wParam == VK_UP)
			{
				int iSel = GetCurSel();
				if (iSel == -1 || iSel == 0)
					SetCurSel(0);
				else
					SetCurSel(iSel - 1);
			}
			else if (msg.wParam == VK_DOWN)
			{
				// Move the selection 1 item down
				int iSel = GetCurSel();
				if (iSel == -1)
					SetCurSel(0);
				else if (iSel == GetCount() - 1)
				{
					// Do nothing
				}
				else
					SetCurSel(iSel + 1);
			}
			else if (msg.wParam == VK_RETURN)
			{
				iReturnItemIdx = GetCurSel();
				bBreak = true;
			}
		}
		else if (msg.message == WM_LBUTTONDOWN)
		{
			// Do nothing				
		}
		else if (msg.message == WM_MOUSEMOVE)
		{
			// Select the item under the mouse cursor
			int xPos = GET_X_LPARAM(msg.lParam); 
			int yPos = GET_Y_LPARAM(msg.lParam);

			BOOL bOutside;
			UINT nIndex = ItemFromPoint(CPoint(xPos, yPos), bOutside);
			if (!bOutside)
				SetCurSel((int) nIndex);
		}
		else
		{
			DispatchMessage(&msg);
		}
	}

	ReleaseCapture();
	ShowWindow(SW_HIDE);

	return iReturnItemIdx;
}