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

📄 index.c

📁 EVC4 编程CEDB数据库操作
💻 C
📖 第 1 页 / 共 2 页
字号:
	TCHAR				szProperty[50];
	DWORD			*	pProp;
	LONG				lResult, l;

    switch(message)
    {
	case WM_INITDIALOG:
		{
		//On Pocket PC devices you normally create all Dialog's as fullscreen dialog's
		// with an OK button in the upper corner. You should get/set any program settings
		// during each modal dialog creation and destruction
		SHINITDLGINFO shidi;
		// Create a Done button and size it.
		shidi.dwMask = SHIDIM_FLAGS;
		shidi.dwFlags = SHIDIF_DONEBUTTON | SHIDIF_SIPDOWN | SHIDIF_SIZEDLGFULLSCREEN;
		shidi.hDlg = hDlg;
		//initialzes the dialog based on the dwFlags parameter
		SHInitDialog(&shidi);

		pModIndex = (MODSORT *) lParam;
		if ( pModIndex )
		{
			GetIndexesProps(pModIndex);
			pProp = (DWORD *) pModIndex->RemainingProps;
			for ( i = 0 ; i < pModIndex->RemainProps; i++)
			{
				switch(TypeFromPropID(pProp[i]))
				{
					case CEVT_I2:
						wsprintf(szProperty, TEXT("%#X: (Short)"), pProp[i]);
						break;
					case CEVT_UI2:
						wsprintf(szProperty, TEXT("%#X: (UShort)"), pProp[i]);
						break;
					case CEVT_I4:
						wsprintf(szProperty, TEXT("%#X: (Long)"), pProp[i]);
						break;
					case CEVT_UI4:
						wsprintf(szProperty, TEXT("%#X: (ULong)"), pProp[i]);
						break;
					case CEVT_FILETIME:
						wsprintf(szProperty, TEXT("%#X: (FileTime)"), pProp[i]);
						break;
					case CEVT_LPWSTR:
						wsprintf(szProperty, TEXT("%#X: (String)"), pProp[i]);
						break;
					case CEVT_BLOB:
						wsprintf(szProperty, TEXT("%#X: (Blob)"), pProp[i]);
						break;
					default:
						wsprintf(szProperty, TEXT("%#X: (Unknown)"), pProp[i]);
						break;
				}	
				if( (lResult=SendDlgItemMessage(hDlg,IDC_AVAILABLE,LB_ADDSTRING,0,(LPARAM) (LPCTSTR) szProperty)) != LB_ERR)
					SendDlgItemMessage(hDlg,IDC_AVAILABLE,LB_SETITEMDATA ,(WPARAM) lResult,(LPARAM) pProp[i]);

			
			}

			for ( i = 0 ; i < pModIndex->PropsIndexed; i++)
			{
				wsprintf(szProperty, TEXT("%#lX "), pModIndex->SortOrderIn[i].propid);
				if ( pModIndex->SortOrderIn[i].dwFlags & CEDB_SORT_DESCENDING)
					lstrcat(szProperty, TEXT("DESC "));

				if ( pModIndex->SortOrderIn[i].dwFlags & CEDB_SORT_CASEINSENSITIVE )
					lstrcat(szProperty, TEXT("CASE "));
				
				if ( pModIndex->SortOrderIn[i].dwFlags & CEDB_SORT_UNKNOWNFIRST )
					lstrcat(szProperty, TEXT("UNKNOWN "));

				if( (lResult=SendDlgItemMessage(hDlg,IDC_CURRENT,LB_ADDSTRING,0,(LPARAM) (LPCTSTR) szProperty)) != LB_ERR)
					SendDlgItemMessage(hDlg,IDC_CURRENT,LB_SETITEMDATA ,(WPARAM) lResult,(LPARAM) pModIndex->SortOrderIn[i].propid);
			}
		}
		
	    return (TRUE);
		}

	case WM_COMMAND:
	    switch (LOWORD(wParam))
	    {
			case IDOK:

				// get the number of listbox entries
				if ((lResult=SendDlgItemMessage(hDlg, IDC_CURRENT, LB_GETCOUNT, (WPARAM)0 , (LPARAM)0)) != LB_ERR )
				{
					pModIndex->PropsIndexed = (WORD) lResult;
					for ( l = 0 ; l < lResult; l++ )
					{
						pModIndex->SortOrderOut[l].propid = (CEPROPID) SendDlgItemMessage(hDlg,IDC_CURRENT,LB_GETITEMDATA ,(WPARAM) l,(LPARAM) 0);						
						pModIndex->SortOrderOut[l].dwFlags = 0;
					}
				}

				if ( pModIndex && pModIndex->RemainingProps)
					LocalFree(pModIndex->RemainingProps);

				EndDialog(hDlg, IDOK);
				break;
			case IDCANCEL:
				if ( pModIndex && pModIndex->RemainingProps)
					LocalFree(pModIndex->RemainingProps);

				EndDialog(hDlg, IDCANCEL);
				break;

			case IDC_ADDINDEX:
			{
				if ((lResult=SendDlgItemMessage(hDlg, IDC_CURRENT, LB_GETCOUNT, (WPARAM)0 , (LPARAM)0)) != LB_ERR )
				{
					if ( lResult < 4 )
					{
						if ((lResult=SendDlgItemMessage(hDlg, IDC_AVAILABLE, LB_GETCURSEL, (WPARAM)0 , (LPARAM)0)) != LB_ERR )
						{
							if ( LB_ERR != SendDlgItemMessage( hDlg, IDC_AVAILABLE, LB_GETTEXT,
								(WPARAM) lResult, (LPARAM) (LPCTSTR) szProperty) )
							{
								LRESULT	lItemData;
                                long lPropType;

								lItemData = SendDlgItemMessage(hDlg,IDC_AVAILABLE,LB_GETITEMDATA ,(WPARAM) lResult,(LPARAM) 0);
								lPropType = TypeFromPropID(lItemData);
                                if(lPropType == CEVT_BLOB)
                                {
                                    MessageBox(hDlg, TEXT("Binary Fields can not be indexed."),TEXT("Invalid index type"),MB_OK|MB_ICONINFORMATION);
                                }
                                else
                                {
                                    SendDlgItemMessage( hDlg, IDC_AVAILABLE, LB_DELETESTRING, (WPARAM) lResult, (LPARAM) 0);
								
								    lResult = SendDlgItemMessage( hDlg, IDC_CURRENT, LB_ADDSTRING,(WPARAM) 0, (LPARAM) (LPCTSTR) szProperty);
								    SendDlgItemMessage(hDlg,IDC_CURRENT,LB_SETITEMDATA ,(WPARAM) lResult,(LPARAM) lItemData);						
								    EnableWindow(GetDlgItem(hDlg,IDC_ADDINDEX),	FALSE);
                                }
							}
						
						}
					}
					else
						MessageBox(hDlg, TEXT("A Windows CE database only supports 4 indexes!"), TEXT("Index Limit"), MB_OK|MB_ICONINFORMATION);
				}
				break;
			}
			case IDC_REMINDEX:
			{
				if ((lResult=SendDlgItemMessage(hDlg, IDC_CURRENT, LB_GETCURSEL, (WPARAM)0 , (LPARAM)0)) != LB_ERR )
				{
					if ( LB_ERR != SendDlgItemMessage( hDlg, IDC_CURRENT, LB_GETTEXT,
						(WPARAM) lResult, (LPARAM) (LPCTSTR) szProperty) )
					{
						LRESULT	lItemData;

						lItemData = SendDlgItemMessage(hDlg,IDC_CURRENT,LB_GETITEMDATA ,(WPARAM) lResult,(LPARAM) 0);
						SendDlgItemMessage( hDlg, IDC_CURRENT, LB_DELETESTRING, (WPARAM) lResult, (LPARAM) 0);
						lResult = SendDlgItemMessage( hDlg, IDC_AVAILABLE, LB_ADDSTRING,(WPARAM) 0, (LPARAM) (LPCTSTR) szProperty);
						SendDlgItemMessage(hDlg,IDC_AVAILABLE,LB_SETITEMDATA ,(WPARAM) lResult,(LPARAM) lItemData);
						EnableWindow(GetDlgItem(hDlg,IDC_REMINDEX),	FALSE);

					}
				
				}
				break;
			}

			case IDC_AVAILABLE:
				switch ( HIWORD(wParam) )
				{
					case LBN_SELCHANGE:
					{
						EnableWindow(GetDlgItem(hDlg,IDC_ADDINDEX),	TRUE);
						break;
					}
				}
				break;
				



			case IDC_CURRENT:
				switch ( HIWORD(wParam) )
				{
					case LBN_SELCHANGE:
					{
						EnableWindow(GetDlgItem(hDlg,IDC_REMINDEX),	TRUE);
						break;
					}

				}

				break;
	    }
	    return (TRUE);
    }
    return (FALSE);
}


void WINAPI GetIndexesProps( MODSORT * pModIndex)
{
	TCHAR           szBuf[200];
	TCHAR           szSort[100] = {0};
	CEOID          CeOID = 0;
    CEOIDINFO		CeObject;
	HANDLE          hOpenDB;
	int             i, j;
	WORD			cPropID;
	LPBYTE 			bData = NULL;
	DWORD			cbData;
	DWORD	*		pdwNextProp = NULL;
	PCEPROPVAL		pPropIds;

	hOpenDB = CeOpenDatabase(&CeOID, pModIndex->pszDBName, 0, 0, NULL);
	if ( hOpenDB == INVALID_HANDLE_VALUE)
	{
		wsprintf(szBuf, TEXT("ERROR: CeOpenDatabase failed to open database.(Error: %ld)\r\n"), GetLastError());
		MessageBox(NULL, szBuf, TEXT("ERROR"), MB_OK);
		OutputDebugString(szBuf);
	}
	else
	{
		if ( !CeOidGetInfo(CeOID, &CeObject) )
		{
			wsprintf(szBuf, TEXT("ERROR: CeOidGetInfo failed with error (%ld)\r\n"), GetLastError());
			MessageBox(NULL, szBuf, TEXT("ERROR"), MB_OK);
			OutputDebugString(szBuf);
		}
		else
		{
			if ( CeObject.infDatabase.dwFlags &  CEDB_VALIDSORTSPEC ) // is valid sort struct
			{
				pModIndex->PropsIndexed = CeObject.infDatabase.wNumSortOrder;
				for ( i = 0 ; i < CeObject.infDatabase.wNumSortOrder ; i++)
				{
					if( !(CeObject.infDatabase.rgSortSpecs[i].dwFlags & CEDB_SORT_GENERICORDER ) )
						memcpy(&pModIndex->SortOrderIn[i], &CeObject.infDatabase.rgSortSpecs[i], sizeof(SORTORDERSPEC));
					else
						--pModIndex->PropsIndexed;

				}
			}
		}
		pModIndex->MaxProps = 0;
		pModIndex->RemainProps = 0;

		// get a list of properties
		if( !CeReadRecordProps(hOpenDB, CEDB_ALLOWREALLOC, &cPropID,NULL,&bData,&cbData) )
		{
			DWORD dwError;

			if ( (dwError = GetLastError()) != ERROR_NO_MORE_ITEMS)
			{
				wsprintf(szBuf, TEXT("ERROR: CeReadRecordProps failed to read database.(Error: %ld)\r\n"), dwError);
				MessageBox(NULL, szBuf, TEXT("ERROR"), MB_OK);
				OutputDebugString(szBuf);
			}
		}
		else
		{
			pModIndex->MaxProps = cPropID;

			pModIndex->RemainProps = 0;

			if ( cPropID )
				pModIndex->RemainingProps = (BYTE * )LocalAlloc(LPTR, sizeof(CEPROPID)* cPropID);

			if ( pModIndex->RemainingProps )
			{
				pdwNextProp = (DWORD *) pModIndex->RemainingProps;
				pPropIds = (PCEPROPVAL) bData;
				for ( i = 0 ; i < cPropID; i++ )
				{
					for ( j = 0 ; j < pModIndex->PropsIndexed ; j++)
					{
						if ( pModIndex->SortOrderIn[j].propid == (DWORD)pPropIds[i].propid )
							break;
					}
					if ( j == pModIndex->PropsIndexed )
					{
						pdwNextProp[pModIndex->RemainProps] = (DWORD)pPropIds[i].propid;
						++(pModIndex->RemainProps);
					}

				}

			}
			LocalFree(bData);
		}
		CloseHandle(hOpenDB);
	}
}

⌨️ 快捷键说明

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