Exemple #1
0
///Button clicked.
void XTailForm::buttonClicked(int id)
{
	swprintf_s(tbuffer, L"XTailForm button clicked: %i\n", id);
	logger->debug(tbuffer);

	if (id == 99)
	{
		if (chunkCount < 1)
			return;
		current = -1;
		id = BTN_NEXT;
	}
	if (id == 98)
	{
		if (chunkCount < 1)
			return;
		current = chunkCount-1;
		id = BTN_NEXT;
	}

	if (id == BTN_PREV || id == BTN_NEXT)
	{
		if (id == BTN_PREV)
		{
			current -= 1;
			if (current < 0)
				current = 0L;
		}
		if (id == BTN_NEXT)
		{
			current += 1;
			if (current > chunkCount)
				current = chunkCount;
		}

		//Set the start/end chunks.
		__int64 len = getXTail()->len;

		__int64 startXX = (len/chunkCount) * current;
		__int64 endXX = startXX + MAX_FILE_BUFFER;
		if (startXX > len)
			startXX = len;
		if (endXX > len)
			endXX = len;

		swprintf_s(tbuffer, L"Current: %I64i, Start: %I64i, End: %I64i\n", current, startXX, endXX);
		logger->debug(tbuffer);

		swprintf_s(tbuffer, L"%I64i", startXX);
		SendMessageW(getHWND(TXT_BYTE_START), WM_SETTEXT, 2048, (LPARAM) tbuffer);

		swprintf_s(tbuffer, L"%I64i", endXX);
		SendMessageW(getHWND(TXT_BYTE_END), WM_SETTEXT, 2048, (LPARAM) tbuffer);

		id = BTN_LOAD;

	}


	if (id == BTN_LOAD)
	{
		chunkCount = 0l;


		ZeroMemory(tmp, sizeof(wchar_t) * 2048);
		getText(TXT_FILENAME, tmp, 2048);
		swprintf_s(tbuffer, L"Attempting to load file: %s\n", tmp);
		logger->debug(tbuffer);

		wchar_t fileName[2048];
		wcscpy_s(fileName, tmp);

		if (wcslen(tmp) < 1)
		{
			MessageBoxExW(hwnd, L"Please enter a valid filename.", L"Invalid Input", MB_OK, NULL);
			return;
		}

		ZeroMemory(tmp, sizeof(wchar_t) * 2048);
		getText(TXT_BYTE_START, tmp, 2048);
		swprintf_s(tbuffer, L"Start Pos: %s\n", tmp);
		logger->debug(tbuffer);
		if (wcslen(tmp) < 1)
		{
			MessageBoxExW(hwnd, L"Please enter a valid file start position.", L"Invalid Input", MB_OK, NULL);
			return;
		}

		wchar_t *tmpX;

		__int64 start = _wcstoi64(tmp, &tmpX, 10);
		swprintf_s(tbuffer, L"Got the start pos: %I64i\n", start);
		logger->debug(tbuffer);

		ZeroMemory(tmp, sizeof(wchar_t) * 2048);
		getText(TXT_BYTE_END, tmp, 2048);
		swprintf_s(tbuffer, L"End Pos: %s\n", tmp);
		logger->debug(tbuffer);
		if (wcslen(tmp) < 1)
		{
			MessageBoxExW(hwnd, L"Please enter a valid file end position.", L"Invalid Input", MB_OK, NULL);
			return;
		}

		__int64 end = _wcstoi64(tmp, &tmpX, 10);
		
		swprintf_s(tbuffer, L"Got the end pos: %I64i\n", end);
		logger->debug(tbuffer);

		if (start < 0 || end < 1 || (end < start))
		{
			swprintf_s(tbuffer, L"Invalid start(%I64i) and end(%I64i) pos", start, end);
			MessageBoxExW(hwnd, tbuffer, L"Invalid Input", MB_OK, NULL);
			return;
		}


		//Get the file/length.
		__int64 fileLength = getXTail()->getFileLength(fileName);
		swprintf_s(tbuffer, L"Got the file length: %I64i\n", fileLength);
		logger->debug(tbuffer);

		if (fileLength < 1)
		{
			swprintf_s(tbuffer, L"File (%s) is not valid.", fileName);
			MessageBoxExW(hwnd, tbuffer, L"Invalid Input", MB_OK, NULL);
			return;
		}

		if (start > fileLength)
		{
			swprintf_s(tbuffer, L"Start(%I64i) is > file length", start);
			MessageBoxExW(hwnd, tbuffer, L"Invalid Input", MB_OK, NULL);
			return;
		}

		if (end > fileLength)
			end = fileLength;

		//Update window caption.
		char fileNamea[2048];
		SendMessageA(getHWND(TXT_FILENAME), WM_GETTEXT, 2048, (LPARAM) fileNamea);

		wchar_t fmtFileLength[128];
		formatBytes(fileLength, fmtFileLength, 128);

		chunkCount = (fileLength / MAX_FILE_BUFFER);

		swprintf_s(tbuffer, L"Len(%s) - 63Kb Chunks(%I64i), Current: %I64i", fmtFileLength, chunkCount, current);
		logger->debug(tbuffer);

		SendMessageW(getHWND(LBL_CHUNKS), WM_SETTEXT, 2048, (LPARAM) tbuffer);

		//Attempt to load and display file.
		ZeroMemory(file_buffer, sizeof(wchar_t) * MAX_FILE_BUFFER);

		swprintf_s(tbuffer, L"going to call readChunk Start: %I64i, End: %I64i\n", start, end);
		logger->debug(tbuffer);

		if (!getXTail()->readChunk(start, end, file_buffer, MAX_FILE_BUFFER))
			return;
		setText(TXT_OUTPUT, file_buffer, MAX_FILE_BUFFER);
	}

}
INT_PTR CALLBACK TrackingUIProc(HWND hwndTrk, UINT message, WPARAM wParam, LPARAM lParam)
{ 	
	switch (message)
	{ 
    case WM_INITDIALOG:
		{
			g_hWndTrack = hwndTrk;
		
			LVCOLUMN column;
			column.mask = LVCF_TEXT | LVCF_SUBITEM | LVCF_WIDTH;
			column.cx = 50;
			column.iSubItem = 0;
			column.pszText = L"ID";
			ListView_InsertColumn(GetControl(IDC_MODELS), 0, &column);
			column.cx = 400;
			column.iSubItem = 1;
			column.pszText = L"File";
			ListView_InsertColumn(GetControl(IDC_MODELS), 1, &column);
				
			HIMAGELIST imgList = ImageList_Create(16, 16, 0, 2, 0);
		
			HBITMAP trackingBmp	   = LoadBitmap(g_hInst, MAKEINTRESOURCE(IDB_TRACKING_OK));
			HBITMAP notTrackingBmp = LoadBitmap(g_hInst, MAKEINTRESOURCE(IDB_NOT_TRACKING));
				
			ImageList_Add(imgList, notTrackingBmp, NULL);
			ImageList_Add(imgList, trackingBmp, NULL);

			TreeView_SetImageList(GetControl(IDC_MODELS), imgList, TVSIL_NORMAL);

			DeleteObject(trackingBmp);
			DeleteObject(notTrackingBmp);
		
			// Initialize combo tracking box	
			ComboBox_AddString(GetControl(IDC_TRACKINGTYPE), L"3D Tracking");
			ComboBox_SetItemData(GetControl(IDC_TRACKINGTYPE), 0, TRACKING_3D);
			ComboBox_AddString(GetControl(IDC_TRACKINGTYPE), L"2D Tracking");
			ComboBox_SetItemData(GetControl(IDC_TRACKINGTYPE), 1, TRACKING_2D);
			ComboBox_AddString(GetControl(IDC_TRACKINGTYPE), L"3D Instant");
			ComboBox_SetItemData(GetControl(IDC_TRACKINGTYPE), 2, TRACKING_INSTANT);
			ComboBox_SetCurSel(GetControl(IDC_TRACKINGTYPE), 0);
		
			return TRUE; 
		}

	case WM_COMMAND:
        switch (LOWORD(wParam))
		{		
		case IDC_LOADMODEL:
			AddTargetFile();
			return TRUE;
		case IDC_CLEARMODELS:
			ClearModelTree();
			return TRUE;
        }
		
		if (HIWORD(wParam) == CBN_SELCHANGE)
		{
			HWND comboBox = (HWND) lParam;
			int selIndex = ComboBox_GetCurSel(comboBox);
			TrackingType type = (TrackingType) ComboBox_GetItemData(comboBox, selIndex);

			switch (type)
			{
			case TRACKING_2D:
				Button_Enable(GetControl(IDC_START), false);
				Button_Enable(GetControl(IDC_LOADMODEL), true);
				Button_Enable(GetControl(IDC_CLEARMODELS), false);
				Button_Enable(GetControl(IDC_ROI), false);
				Button_SetCheck(GetControl(IDC_ROI), false);
				ClearModelTree();
				return TRUE;		
			case TRACKING_3D:				
				Button_Enable(GetControl(IDC_START), false);
				Button_Enable(GetControl(IDC_LOADMODEL), true);
				Button_Enable(GetControl(IDC_CLEARMODELS), false);
				Button_Enable(GetControl(IDC_ROI), false);
				Button_SetCheck(GetControl(IDC_ROI), false);
				ClearModelTree();			
				return TRUE;
			case TRACKING_INSTANT:				
				ClearModelTree();
				Button_Enable(GetControl(IDC_START),true);
				Button_Enable(GetControl(IDC_LOADMODEL),false);
				Button_Enable(GetControl(IDC_CLEARMODELS), false);
				Button_Enable(GetControl(IDC_ROI), true);
				Button_SetCheck(GetControl(IDC_ROI), false);

				if (!showedMessage)
				{
					showedMessage = true;
					MessageBoxExW(GetParent(hwndTrk), L"Please be aware that instant tracking needs special scene/background setup. Refer to the reference manual for details.", L"Note", MB_OK | MB_ICONINFORMATION, 0);
				}
				return TRUE;
			}
		}
		break;
	case WM_NOTIFY:		
		switch ( ((LPNMHDR) lParam)->code)
		{
			case TVN_GETDISPINFO:
			{
				NMTVDISPINFO *dispInfo = (NMTVDISPINFO*) lParam;			
		
				if (dispInfo->item.mask & LVIF_IMAGE)
				{				
					int targetIndex = dispInfo->item.lParam & 0xFF;
					int cosIDIndex  = (dispInfo->item.lParam & 0xFF00) >> 8;

					if (g_targets[targetIndex].cosIDs[cosIDIndex].isTracking)
					{
						dispInfo->item.iImage = 1;
					}
					else
					{
						dispInfo->item.iImage = 0;
					}				
				}
				return TRUE;
			}			
		}
		break;	
    }