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

📄 dirindex.cpp

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

 Copyright (c) 1997-2003 John Roy, Holger Zimmermann. All rights reserved.

 These sources, libraries and applications are
 FREE FOR COMMERCIAL AND NON-COMMERCIAL USE
 as long as the following conditions are adhered to.

 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions
 are met:

 1. Redistributions of source code must retain the above copyright
    notice, this list of conditions and the following disclaimer. 

 2. Redistributions in binary form must reproduce the above copyright
    notice, this list of conditions and the following disclaimer in
    the documentation and/or other materials provided with the
    distribution.

 3. The name of the author may not be used to endorse or promote products
    derived from this software without specific prior written permission.

 THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 IN NO EVENT SHALL THE AUTHORS OR ITS CONTRIBUTORS BE LIABLE FOR ANY
 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 OF THE POSSIBILITY OF SUCH DAMAGE.

 *____________________________________________________________________________*|
 *
 * $Source: /cvsroot/pi3web/Pi3Web_200/Source/EnhPi3/DirIndex.cpp,v $
 * $Date: 2003/05/13 18:41:57 $
 *
 Description:

\*____________________________________________________________________________*/
/* $SourceTop:$ */

#include <windows.h>
#include <windowsx.h>
#include <commctrl.h>
#include <assert.h>
#include <stdio.h>

#include "PICompat.h"
#include "PIString.h"

#include "resrc1.h"
#include "Common.h"

/*____________________________________________________________________________*\
 *
 Description:
	Definitions and global values
\*____________________________________________________________________________*/
#define COLUMNCOUNT		6
#define FMT_DECIMAL		"Size"
#define FMT_ABBREV		"AbbrevSize"
#define FMT_FORMAT		"FormatSize"

static HWND hWndSortCol = 0;
static HWND hWndColumns = 0;
static HWND hWndHyperlink = 0;
static HWND hWndICase = 0;
static HWND hWndDescending = 0;
static HWND hWndTag = 0;
static HWND hWndTruncate = 0;
static HWND hWndHeader = 0;
static HWND hWndFooter = 0;
static HWND hWndDescription = 0;
static int __iCurrentLayout = 0;
static const char *__pCurrentSizeFmt = FMT_ABBREV;

/*____________________________________________________________________________*\
 *
 Function:
 Synopsis:
 Description:
\*____________________________________________________________________________*/
static void Internal_SortColumnChanged( HWND hDlg )
{
	if ( __iCurrentLayout == 6 ) return;

	enum { BUF_SIZE=1023 };
	char szBuf[BUF_SIZE+1];

	int iIdx = ::SendMessage( hWndSortCol, CB_GETCURSEL, 0, 0 );
	*szBuf = 0;
	if (iIdx != CB_ERR )
		{ ::SendMessage( hWndSortCol, CB_GETLBTEXT, iIdx, (LPARAM)szBuf); };
	if (!*szBuf ) { return; };
	if ( !strcmp(szBuf, "(none)" ))
		{
		::EnableWindow( hWndHyperlink, FALSE );
		::EnableWindow( hWndICase, FALSE );
		::EnableWindow( hWndDescending, FALSE );
		}
	else
		{
		::EnableWindow( hWndHyperlink, TRUE );
		::EnableWindow( hWndICase, TRUE );
		::EnableWindow( hWndDescending, TRUE );
		}
}

/*____________________________________________________________________________*\
 *
 Function:
 Synopsis:
 Description:
\*____________________________________________________________________________*/
static void Internal_ColumnsChanged( HWND hDlg )
{
	int iItems[COLUMNCOUNT];
	ZeroMemory( &iItems, sizeof(iItems) );
	int i = ::SendMessage( hWndColumns, LB_GETSELITEMS,
		COLUMNCOUNT, (LPARAM)&iItems );

	// Column 'Size' = index 3
	for (;i>0;i--) {
		if ( iItems[i-1] == 3 ) { break; }
	}

	if ( __iCurrentLayout == 6 ) i = 0;

	EnableWindow( GetDlgItem( hDlg, IDC_DECIMAL ), i );
	EnableWindow( GetDlgItem( hDlg, IDC_ABBREV ), i );
	EnableWindow( GetDlgItem( hDlg, IDC_FORMAT ), i );
}

/*____________________________________________________________________________*\
 *
 Function:
 Synopsis:
 Description:
\*____________________________________________________________________________*/
static void Internal_LayoutChanged( HWND hDlg, int iNewLayout )
{
	int iIdx = ::SendMessage( hWndSortCol, CB_GETCURSEL, 0, 0 );

	if ( iNewLayout == __iCurrentLayout ) return;

	if ( iNewLayout != 6 )
		{
		EnableWindow( hWndSortCol, TRUE );
		EnableWindow( hWndColumns, TRUE );
		EnableWindow( hWndTag, TRUE );
		EnableWindow( hWndTruncate, TRUE );
		EnableWindow( hWndHeader, TRUE );
		EnableWindow( hWndFooter, TRUE );
		EnableWindow( hWndDescription, TRUE );
		// the rest will be done dynamically
		}

	switch (iNewLayout)
		{
		/*
		** HTML table index 
		*/
		case 1:
			// Column 'Type' = index 0
			::SendMessage( hWndColumns, LB_SETSEL, TRUE, 0 );

			// Column 'Name' = index 1
			::SendMessage( hWndColumns, LB_SETSEL, TRUE, 1 );

			// 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 '(Type)' = index 1
			::SendMessage( hWndSortCol, CB_SETCURSEL, 1, 0 );

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

			// Options
			if ( ::SendMessage( hWndTag, WM_GETTEXTLENGTH, 0, 0 ) == 0 )
				{ ::SendMessage( hWndTag, WM_SETTEXT, 0, (LPARAM)"10" ); }

			if ( ::SendMessage( hWndTruncate, WM_GETTEXTLENGTH, 0, 0 ) == 0 )
				{ ::SendMessage( hWndTruncate, WM_SETTEXT, 0, (LPARAM)"20" ); }

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

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

		/*
		** HTML index with fixed font
		*/
		case 2:
			// Column 'Type' = index 0
			::SendMessage( hWndColumns, LB_SETSEL, TRUE, 0 );

			// Column 'Name' = index 1
			::SendMessage( hWndColumns, LB_SETSEL, TRUE, 1 );

			// 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 '(Type)' = index 1
			::SendMessage( hWndSortCol, CB_SETCURSEL, 1, 0 );

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

			// Options
			if ( ::SendMessage( hWndTag, WM_GETTEXTLENGTH, 0, 0 ) == 0 )
				{ ::SendMessage( hWndTag, WM_SETTEXT, 0, (LPARAM)"10" ); }

			if ( ::SendMessage( hWndTruncate, WM_GETTEXTLENGTH, 0, 0 ) == 0 )
				{ ::SendMessage( hWndTruncate, WM_SETTEXT, 0, (LPARAM)"20" ); }

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

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

		/*
		** Generic HTML index
		*/
		case 3:
			// Column 'Type' = index 0
			::SendMessage( hWndColumns, LB_SETSEL, FALSE, 0 );

			// Column 'Name' = index 1
			::SendMessage( hWndColumns, LB_SETSEL, TRUE, 1 );

			// 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 '(Type)' = index 1
			::SendMessage( hWndSortCol,CB_SETCURSEL, 1, 0 );

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

			// Options
			if ( ::SendMessage( hWndTag, WM_GETTEXTLENGTH, 0, 0 ) == 0 )
				{ ::SendMessage( hWndTag, WM_SETTEXT, 0, (LPARAM)"10" ); }

			if ( ::SendMessage( hWndTruncate, WM_GETTEXTLENGTH, 0, 0 ) == 0 )
				{ ::SendMessage( hWndTruncate, WM_SETTEXT, 0, (LPARAM)"20" ); }

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

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

		/*
		** DOS style HTML index
		*/
		case 4:
			// Column 'Type' = index 0
			::SendMessage( hWndColumns, LB_SETSEL, FALSE, 0 );

			// Column 'Name' = index 1
			::SendMessage( hWndColumns, LB_SETSEL, TRUE, 1 );

			// Column 'AltName' = index 2
			::SendMessage( hWndColumns, LB_SETSEL, TRUE, 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, FALSE, 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_UNCHECKED, 0 );
			SendMessage( GetDlgItem( hDlg, IDC_ABBREV ), BM_SETCHECK, BST_UNCHECKED, 0 );
			SendMessage( GetDlgItem( hDlg, IDC_FORMAT ), BM_SETCHECK, BST_CHECKED, 0 );
			break;

		/*
		** 'Text with Tabs' index
		*/
		case 5:
			// Column 'Type' = index 0
			::SendMessage( hWndColumns, LB_SETSEL, FALSE, 0 );

			// Column 'Name' = index 1
			::SendMessage( hWndColumns, LB_SETSEL, TRUE, 1 );

⌨️ 快捷键说明

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