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

📄 dirindex.cpp

📁 mini http server,可以集成嵌入到程序中,实现简单的web功能
💻 CPP
📖 第 1 页 / 共 2 页
字号:

			// Column 'AltName' = index 2
			::SendMessage( hWndColumns, LB_SETSEL, FALSE, 2 );

			// Column 'Size' = index 3
			::SendMessage( hWndColumns, LB_SETSEL, TRUE, 3 );

			// Column 'Date' = index 4
			::SendMessage( hWndColumns, LB_SETSEL, TRUE, 4 );

			// Column 'Description' = index 5
			::SendMessage( hWndColumns,LB_SETSEL, TRUE, 5 );

			// SortColumn '(none)' = index 0
			::SendMessage( hWndSortCol, CB_SETCURSEL, 0, 0 );

			// Sort Flags
			::SendMessage( hWndHyperlink, BM_SETCHECK, FALSE, 0 );
			::SendMessage( hWndICase, BM_SETCHECK, FALSE, 0 );
			::SendMessage( hWndDescending, BM_SETCHECK, FALSE, 0 );

			// Options
			::SendMessage( hWndTag, WM_SETTEXT, 0, (LPARAM)"" );
			::SendMessage( hWndTruncate, WM_SETTEXT, 0, (LPARAM)"" );

			// Axiliary Files
			::SendMessage( hWndHeader, BM_SETCHECK, FALSE, 0 );
			::SendMessage( hWndFooter, BM_SETCHECK, FALSE, 0 );
			::SendMessage( hWndDescription, BM_SETCHECK, FALSE, 0 );

			// SizeFormat
			SendMessage( GetDlgItem( hDlg, IDC_DECIMAL ), BM_SETCHECK, BST_CHECKED, 0 );
			SendMessage( GetDlgItem( hDlg, IDC_ABBREV ), BM_SETCHECK, BST_UNCHECKED, 0 );
			SendMessage( GetDlgItem( hDlg, IDC_FORMAT ), BM_SETCHECK, BST_UNCHECKED, 0 );
			break;

		/*
		** Custom index, this isn't handled here
		*/
		case 6:
			EnableWindow( hWndSortCol, FALSE );
			EnableWindow( hWndColumns, FALSE );
			EnableWindow( hWndHyperlink, FALSE );
			EnableWindow( hWndICase, FALSE );
			EnableWindow( hWndDescending, FALSE );
			EnableWindow( hWndTag, FALSE );
			EnableWindow( hWndTruncate, FALSE );
			EnableWindow( hWndHeader, FALSE );
			EnableWindow( hWndFooter, FALSE );
			EnableWindow( hWndDescription, FALSE );
			EnableWindow( GetDlgItem( hDlg, IDC_DECIMAL ), FALSE );
			EnableWindow( GetDlgItem( hDlg, IDC_ABBREV ), FALSE );
			EnableWindow( GetDlgItem( hDlg, IDC_FORMAT ), FALSE );
			break;

		default:
			assert(0);
		}

	__iCurrentLayout = iNewLayout;
	Internal_ColumnsChanged( hDlg );
	Internal_SortColumnChanged( hDlg );
}

/*____________________________________________________________________________*\
 *
 Function:
 Synopsis:
 Description:
\*____________________________________________________________________________*/

#define SET_LAYOUT( Idx ) SendMessage( GetDlgItem( hDlg, IDC_INDEX##Idx ), \
	BM_SETCHECK, BST_CHECKED, 0 ); __iCurrentLayout = Idx

#define SET_FORMAT( Fmt ) SendMessage( GetDlgItem( hDlg, IDC_##Fmt ), \
	BM_SETCHECK, BST_CHECKED, 0 ); __pCurrentSizeFmt = FMT_##Fmt

static BOOL CALLBACK DialogProc(HWND hDlg, UINT uMsg, WPARAM wParam,
	LPARAM lParam)
{
	enum { BUF_SIZE=1023 };
	char szBuf[BUF_SIZE+1];

	switch (uMsg)
		{
		case WM_INITDIALOG:
			{
			const char *pA = AD_lookupValue( __pConfig, "General", "Admin" );
			hWndColumns = GetDlgItem( hDlg, IDC_COLUMNS );;
			hWndSortCol = GetDlgItem( hDlg, IDC_SORTCOL );
			hWndHyperlink = GetDlgItem( hDlg, IDC_HLINK );
			hWndICase = GetDlgItem( hDlg, IDC_ICASE );
			hWndDescending = GetDlgItem( hDlg, IDC_DESCEND );
			hWndTag = GetDlgItem( hDlg, IDC_TAG );
			hWndTruncate = GetDlgItem( hDlg, IDC_TRUNCATE );
			hWndHeader = GetDlgItem( hDlg, IDC_HEAD );
			hWndFooter = GetDlgItem( hDlg, IDC_FOOT );
			hWndDescription = GetDlgItem( hDlg, IDC_DESCR );

			assert( hWndColumns );
			assert( hWndSortCol && hWndHyperlink );
			assert( hWndICase && hWndDescending );
			assert( hWndTag && hWndTruncate );
			assert( hWndHeader && hWndFooter && hWndDescription );
			assert( pA );

			/* --- just for sanity --- */
			::SendMessage( hWndTag, EM_SETLIMITTEXT, 256, 0 );
			::SendMessage( hWndTruncate, EM_SETLIMITTEXT, 256, 0 );

			/* --- Layout --- */
			switch (atoi(AD_lookupValue(__pConfig,"DirIndex","Layout")))
				{
				case 1:
					SET_LAYOUT( 1 ); break;
				case 2:
					SET_LAYOUT( 2 ); break;
				case 3:
					SET_LAYOUT( 3 ); break;
				case 4:
					SET_LAYOUT( 4 ); break;
				case 5:
					SET_LAYOUT( 5 ); break;
				case 6:
					SET_LAYOUT( 6 );
					EnableWindow( hWndSortCol, FALSE );
					EnableWindow( hWndColumns, FALSE );
					EnableWindow( hWndHyperlink, FALSE );
					EnableWindow( hWndICase, FALSE );
					EnableWindow( hWndDescending, FALSE );
					EnableWindow( hWndTag, FALSE );
					EnableWindow( hWndTruncate, FALSE );
					EnableWindow( hWndHeader, FALSE );
					EnableWindow( hWndFooter, FALSE );
					EnableWindow( hWndDescription, FALSE );
					EnableWindow( GetDlgItem( hDlg, IDC_DECIMAL ), FALSE );
					EnableWindow( GetDlgItem( hDlg, IDC_ABBREV ), FALSE );
					EnableWindow( GetDlgItem( hDlg, IDC_FORMAT ), FALSE );
					break;
				default:
					return (FALSE);
				}

			/* --- Columns --- */
			::SendMessage( hWndColumns, LB_ADDSTRING, 0, (LPARAM)"Type" );
			::SendMessage( hWndColumns, LB_ADDSTRING, 0, (LPARAM)"Name" );
			::SendMessage( hWndColumns, LB_ADDSTRING, 0, (LPARAM)"AltName" );
			::SendMessage( hWndColumns, LB_ADDSTRING, 0, (LPARAM)"Size" );
			::SendMessage( hWndColumns, LB_ADDSTRING, 0, (LPARAM)"Date" );
			::SendMessage( hWndColumns, LB_ADDSTRING, 0, (LPARAM)"Description" );

			int iColumns = atoi( AD_lookupValue( __pConfig, "DirIndex", "Columns" ));
			int i = 0;
			for (;i<COLUMNCOUNT;i++) {
				if ( iColumns & (1 << i) )
					{ ::SendMessage( hWndColumns, LB_SETSEL, TRUE, i ); };
				}
			Internal_ColumnsChanged( hDlg );

			/* --- Sort-Column --- */
			::SendMessage( hWndSortCol, CB_ADDSTRING, 0, (LPARAM)"(none)" );
			::SendMessage( hWndSortCol, CB_ADDSTRING, 0, (LPARAM)"Type" );
			::SendMessage( hWndSortCol, CB_ADDSTRING, 0, (LPARAM)"Name" );
			::SendMessage( hWndSortCol, CB_ADDSTRING, 0, (LPARAM)"Size" );
			::SendMessage( hWndSortCol, CB_ADDSTRING, 0, (LPARAM)"Date" );
			::SendMessage( hWndSortCol, CB_ADDSTRING, 0, (LPARAM)"Description" );

			const char *pVal = AD_lookupValue( __pConfig, "DirIndex", "SortColumn" );
			if ( ::SendMessage(hWndSortCol,CB_SELECTSTRING,0,(LPARAM)pVal)==CB_ERR )
				{ ::SendMessage( hWndSortCol, CB_SETCURSEL, 0, 0 ); };

			Internal_SortColumnChanged( hDlg );

			/* --- Sorting-Flags --- */
			i = atoi(AD_lookupValue( __pConfig, "DirIndex", "SortFlags" ));
			::SendMessage( hWndHyperlink, BM_SETCHECK, (WPARAM)(i & 1), 0 );
			::SendMessage( hWndICase, BM_SETCHECK, (WPARAM)(i & 2), 0 );
			::SendMessage( hWndDescending, BM_SETCHECK, (WPARAM)(i & 4), 0 );

			/* --- Options --- */
			pVal = AD_lookupValue( __pConfig, "DirIndex", "TagNew" );
			::SendMessage( hWndTag, WM_SETTEXT, 0, (LPARAM)pVal );
			pVal = AD_lookupValue( __pConfig, "DirIndex", "Truncate" );
			::SendMessage( hWndTruncate, WM_SETTEXT, 0, (LPARAM)pVal );

			/* --- File Flags --- */
			i = atoi(AD_lookupValue( __pConfig, "DirIndex", "FileFlags" ));
			::SendMessage( hWndHeader, BM_SETCHECK, (WPARAM)(i & 1), 0 );
			::SendMessage( hWndFooter, BM_SETCHECK, (WPARAM)(i & 2), 0 );
			::SendMessage( hWndDescription, BM_SETCHECK, (WPARAM)(i & 4), 0 );

			/* --- Size-Format --- */
			pVal = AD_lookupValue( __pConfig, "DirIndex", "SizeFormat" );
			if ( pVal && !strcmp( pVal, FMT_DECIMAL ))
				{ SET_FORMAT( DECIMAL ); }
			else if ( pVal && !strcmp( pVal, FMT_ABBREV ))
				{ SET_FORMAT( ABBREV ); }
			else if ( pVal && !strcmp( pVal, FMT_FORMAT ))
				{ SET_FORMAT( FORMAT ); }
			else
				{ return (FALSE); }

			AD_UnChanged( hDlg );
			};
			break;

		case WM_COMMAND:
			if ( GET_WM_COMMAND_CMD(wParam, lParam)==BN_CLICKED )
				{
				switch( GET_WM_COMMAND_ID( wParam, lParam) )
					{
					case IDC_INDEX1:
						Internal_LayoutChanged( hDlg, 1 ); break;
					case IDC_INDEX2:
						Internal_LayoutChanged( hDlg, 2 ); break;
					case IDC_INDEX3:
						Internal_LayoutChanged( hDlg, 3 ); break;
					case IDC_INDEX4:
						Internal_LayoutChanged( hDlg, 4 ); break;
					case IDC_INDEX5:
						Internal_LayoutChanged( hDlg, 5 ); break;
					case IDC_INDEX6:
						Internal_LayoutChanged( hDlg, 6 ); break;
					case IDC_DECIMAL:
						__pCurrentSizeFmt = FMT_DECIMAL; break;
					case IDC_ABBREV:
						__pCurrentSizeFmt = FMT_ABBREV; break;
					case IDC_FORMAT:
						__pCurrentSizeFmt = FMT_FORMAT; break;
					default:;
					};
				/* --- mark property sheet as modified --- */
				AD_Changed( hDlg );
				}
			if ( GET_WM_COMMAND_CMD(wParam, lParam) == CBN_SELCHANGE )
				{
				if ( GET_WM_COMMAND_ID( wParam, lParam) == IDC_SORTCOL )
					{
					Internal_SortColumnChanged( hDlg );
					/* --- mark property sheet as modified --- */
					AD_Changed( hDlg );
					}
				}
			if ( GET_WM_COMMAND_CMD(wParam, lParam) == LBN_SELCHANGE )
				{
				if ( GET_WM_COMMAND_ID( wParam, lParam) == IDC_COLUMNS )
					{
					Internal_ColumnsChanged( hDlg );
					/* --- mark property sheet as modified --- */
					AD_Changed( hDlg );
					}
				}
			if ( GET_WM_COMMAND_CMD(wParam, lParam)==EN_CHANGE )
				{
				/* --- mark property sheet as modified --- */
				AD_Changed( hDlg );
				}
			break;

		case WM_DESTROY:
			break;

		case WM_NOTIFY:
			switch( ((NMHDR *)lParam)->code )
				{
				case PSN_QUERYCANCEL:
					return AD_cancel( hDlg );
				
				case PSN_KILLACTIVE:
					if ( AD_IsChanged() )
					{
					/* --- Layout --- */
					AD_replaceValue( __pConfig, "DirIndex", "Layout",
						itoa( __iCurrentLayout, szBuf, 10 ));

					/* --- Columns --- */
					int iColumns = 0;
					int iItems[COLUMNCOUNT];
					ZeroMemory( &iItems, sizeof(iItems) );
					int i = ::SendMessage( hWndColumns, LB_GETSELITEMS,
						COLUMNCOUNT, (LPARAM)&iItems );

					for (;i>0;i--)
						{ iColumns += 1 << iItems[i-1]; }
					AD_replaceValue( __pConfig, "DirIndex", "Columns",
						itoa( iColumns,szBuf,10 ));	

					/* --- Sort-Column --- */
					*szBuf = 0;
					int iIdx = ::SendMessage( hWndSortCol,	CB_GETCURSEL, 0, 0 );
					::SendMessage( hWndSortCol, CB_GETLBTEXT, iIdx , (LPARAM)&szBuf );
					if ( szBuf && !strcmp(szBuf, "(none)" )) { *szBuf = 0; };
					AD_replaceValue( __pConfig, "DirIndex", "SortColumn", szBuf );

					/* --- Sorting-Flags --- */
					iIdx = 0;
					if ( ::SendMessage( hWndHyperlink, BM_GETCHECK, 0, 0 ))
						{ iIdx += 1; };
					if ( ::SendMessage( hWndICase, BM_GETCHECK, 0, 0 ))
						{ iIdx += 2; };
					if ( ::SendMessage( hWndDescending, BM_GETCHECK, 0, 0 ))
						{ iIdx += 4; };
					AD_replaceValue( __pConfig, "DirIndex", "SortFlags",
						itoa( iIdx,szBuf,10 ));

					/* --- Options --- */
					*szBuf = 0;
					::SendMessage( hWndTag, WM_GETTEXT, BUF_SIZE, (LPARAM)szBuf );
					AD_replaceValue( __pConfig, "DirIndex", "TagNew", szBuf );
					*szBuf = 0;
					::SendMessage( hWndTruncate, WM_GETTEXT, BUF_SIZE, (LPARAM)szBuf );
					AD_replaceValue( __pConfig, "DirIndex", "Truncate", szBuf );

					/* --- Size-Format --- */
					AD_replaceValue( __pConfig, "DirIndex", "SizeFormat",
						__pCurrentSizeFmt );

					/* --- File Flags --- */
					iIdx = 0;
					if ( ::SendMessage( hWndHeader, BM_GETCHECK, 0, 0 ))
						{ iIdx += 1; };
					if ( ::SendMessage( hWndFooter, BM_GETCHECK, 0, 0 ))
						{ iIdx += 2; };
					if ( ::SendMessage( hWndDescription, BM_GETCHECK, 0, 0 ))
						{ iIdx += 4; };
					AD_replaceValue( __pConfig, "DirIndex", "FileFlags",
						itoa( iIdx,szBuf,10 ));
					}
					SetWindowLong( hDlg, DWL_MSGRESULT, FALSE );
					return (TRUE);

				case PSN_APPLY:
					if ( !AD_apply( hDlg ))
						{
						SetWindowLong( hDlg, DWL_MSGRESULT, PSNRET_INVALID );
						return (TRUE);
						};
					
					if( ((PSHNOTIFY *)lParam)->lParam == TRUE )
						{
						return AD_cancel( hDlg );
						};
					break;
				};
			break;

		default:
				return (FALSE);
		};

	return (TRUE);
}

/*____________________________________________________________________________*\
 *
 Description:
	Definitions and global values
\*____________________________________________________________________________*/
DLGPROC fnDirIndex = (DLGPROC)DialogProc;

⌨️ 快捷键说明

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