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

📄 mappings.cpp

📁 mini http server,可以集成嵌入到程序中,实现简单的web功能
💻 CPP
📖 第 1 页 / 共 3 页
字号:
	
    void Internal_saveValues( HWND hDlg )
        {
		enum { BUF_SIZE=1023 };
		char pszBuf[BUF_SIZE+1];
	
		for(;;)
			{
			int iCount = ::SendMessage( hWndList, LB_GETCOUNT, 0, 0 );
	
			if ( !iCount )
				{ return; };
	
			int iBiggest = -1;
			int iBiggestIndex = -1;
	
			for( int j=0; j<iCount; j++ )	
				{
				/*
				** Get string
				*/
				if (::SendMessage( hWndList, LB_GETTEXTLEN, j, 0 ) >= BUF_SIZE)
					{
					::MessageBox( hDlg, "Mapping line too long",
                        "Internal Error", MB_OK );
					return;
					};
				::SendMessage( hWndList, LB_GETTEXT, j, (LPARAM)pszBuf );
				
				/*
				** Get number of components in path
				*/
				int iNumComponents = 0;
				int i=0;
				for( ; pszBuf[i] && pszBuf[i]!='\t'; i++ );
				for( ; pszBuf[i] && isspace(pszBuf[i]); i++ );
				for( ; pszBuf[i] && !isspace(pszBuf[i]); i++ )
					{
					if ( pszBuf[i]=='/' )
						{
						iNumComponents++;
						i++; 
						if ( !pszBuf[i] || isspace(pszBuf[i]) )
							{ break; };
						};
					};
	
				if ( iNumComponents>iBiggest )
					{
					iBiggestIndex = j;
					iBiggest = iNumComponents;
					};
				};
	
			/*
			** Add biggest line to list and remove it from
			** listbox
			*/
			SendMessage( hWndList, LB_GETTEXT, iBiggestIndex, (LPARAM)pszBuf );
			SendMessage( hWndList, LB_DELETESTRING, iBiggestIndex, 0 );
			M_AddValue( pConfig, "Mappings", "Mapping", pszBuf );
			};
        };
		
	void Internal_addLine( const char *pLine )
	    {
		assert( pLine );
		assert( lTypes.Size()==lFroms.Size() );
		assert( lFroms.Size()==lTos.Size() );
	
		int i = 0;
		/* --- scan to tab --- */
		for( ; pLine[i] && pLine[i]!='\t'; i++ );
		lTypes.Append( (DblList::type)PI_NEW( PIString( pLine, i ) ) );
	
		/* --- scan over whitespace to start of from --- */
		for( ; pLine[i] && isspace(pLine[i]); i++ );
		pLine = &( pLine[i] );	
		i=0;
		/* --- scan to tab --- */
		for( ; pLine[i] && pLine[i]!='\t'; i++ );
		lFroms.Append( (DblList::type)PI_NEW( PIString( pLine, i ) ) );	
	
		/* --- scan over whitespace to start of to --- */
		for( ; pLine[i] && isspace(pLine[i]); i++ );
		pLine = &( pLine[i] );	
		i=0;
		/* --- scan to tab --- */
		for( ; pLine[i] && pLine[i]!='\t'; i++ );
		lTos.Append( (DblList::type)PI_NEW( PIString( pLine, i ) ) );	
	
		/* --- scan over whitespace to start of realm --- */
		for( ; pLine[i] && isspace(pLine[i]); i++ );
		pLine = &( pLine[i] );	
		i=0;
		/* --- scan to tab --- */
		for( ; pLine[i] && pLine[i]!='\t'; i++ );
		if ( i )
			{ lRealms.Append( (DblList::type)PI_NEW( PIString( pLine, i ) ) ); }
		else
			{ lRealms.Append( (DblList::type)PI_NEW( PIString( "(none)" ) ) ); }
	
		assert( lTypes.Size()==lFroms.Size() );
		assert( lFroms.Size()==lTos.Size() );
	    };
	
    void Internal_updateButtons( WPARAM wParam, LPARAM lParam, 
		const char *pFrom )
	    {
		int iCBSel = SendMessage( hWndType, CB_GETCURSEL, 0, 0 );
		const char *pType = 0;
		if ( iCBSel>-1 )
			{
			pType = M_LookupValueEx( pConfig, "Internal", 
				"MappingTypes", iCBSel );
			assert( pType );
			};
	
		/*
		** If the 'from' changed check is it an existing one.
		*/
		int iExistingIndex = -1;
		assert( pFrom );
		int iIndex = 0;
		if ( *pFrom )
			{
			for( DblListIterator i( lFroms ); !i.BadIndex(); i++, iIndex++ )
				{
				PIString *pString = (PIString *)i.Current();
				assert( pString );
				if ( (*pString)==pFrom )
					{
					iExistingIndex = iIndex;
					break;
					};
				};
			};
	
		/*
		** Remove listbox selection or scroll to correct line
		** as appropriate 
		*/
		SendMessage( hWndList, LB_SETCURSEL, iExistingIndex, 0 );
	
		/*
		** Set buttons
		*/
		if ( iCBSel<0 || SendMessage( hWndType, CB_GETLBTEXTLEN, iCBSel, 0 )
                ==0 ||
				SendMessage( hWndFrom, EM_LINELENGTH, 0, 0 )==0 ||
				SendMessage( hWndTo, EM_LINELENGTH, 0, 0 )==0 )
			{
			if ( IsWindowEnabled( hWndAdd ) )
                ::EnableWindow( hWndAdd, FALSE );
			if ( IsWindowEnabled( hWndReplace ) )
                ::EnableWindow( hWndReplace, FALSE );
			}
		else
			{
			if ( iExistingIndex>-1 )/* --- disable add, enable replace --- */
				{
				if ( IsWindowEnabled( hWndAdd ) )
                    ::EnableWindow( hWndAdd, FALSE );
				if ( !IsWindowEnabled( hWndReplace ) )
                    ::EnableWindow( hWndReplace, TRUE );
				}
			else					/* --- disable replace, enable add --- */
				{
				if ( !IsWindowEnabled( hWndAdd ) )
                    ::EnableWindow( hWndAdd, TRUE );
				if ( IsWindowEnabled( hWndReplace ) )
                    ::EnableWindow( hWndReplace, FALSE );
				};
			};
	
		/*
		** If there is a selected item in the listbox then
		** enable delete, otherwise disable delete	
		*/
		if ( SendMessage( hWndList, LB_GETCURSEL, 0, 0 )==LB_ERR )
			{ EnableWindow( hWndDelete, FALSE ); }
		else
			{ EnableWindow( hWndDelete, TRUE ); };
	    };
	
    int Win32Create( Interface &tWindow )
        {
        /* --- property sheet pages should not be created --- */
        return PIAPI_ABORT;
		};

    BOOL CALLBACK DialogProc(HWND hDlg, UINT uMsg, WPARAM wParam,
		LPARAM lParam)
	    {
		enum { BUF_SIZE=1023 };
		char szBuf[BUF_SIZE+1];
		int aTabstop[4];
	
		switch (uMsg)
			{
			case WM_INITDIALOG:
				HourglassOn();
				{
				const char *pTmp;
				int iTmp;
				hWndList = GetDlgItem( hDlg, IDC_LIST );
				hWndType = GetDlgItem( hDlg, IDC_TYPE );
				hWndFrom = GetDlgItem( hDlg, IDC_FROM );
				hWndTo = GetDlgItem( hDlg, IDC_TO );
				hWndRealm = GetDlgItem( hDlg, IDC_REALM );
				hWndAdd = GetDlgItem( hDlg, IDC_ADD );
				hWndReplace = GetDlgItem( hDlg, IDC_REPLACE );
				hWndDelete= GetDlgItem( hDlg, IDC_DELETE );
	
				assert( hWndList && hWndType && hWndFrom && hWndTo );
				assert( hWndAdd && hWndReplace && hWndDelete && hWndRealm );
	
				EnableWindow( hWndAdd, FALSE );
				EnableWindow( hWndReplace, FALSE );
				EnableWindow( hWndDelete, FALSE );
	
				/*
				** Add options to 'Types' combo-box
				*/
				iTmp = 0;
				for(;; iTmp++ )
					{
					pTmp = M_LookupValueEx( pConfig, "Internal", 
						"MappingTypes", iTmp );
					if ( !pTmp )
						{ break; };
	
					::SendMessage( hWndType, CB_ADDSTRING, 0, 
						(LPARAM)pTmp ); 
					};
	
				/*
				** Limit edit field lengths, really just a sanity thing
				*/
				SendMessage( hWndFrom, EM_SETLIMITTEXT, 256, 0 );
				SendMessage( hWndTo, EM_SETLIMITTEXT, 256, 0 );
	
				/*
				** Setup tabstops
				*/
				aTabstop[0] = 0;
				aTabstop[1] = 53;
				aTabstop[2] = 107;
				aTabstop[3] = 161;
				SendMessage( hWndList, LB_SETTABSTOPS, 4, (LPARAM)&aTabstop );
	
				/*
				** Load all mappings
				*/
				iTmp = 0;
				for(;; iTmp++ )
					{
					pTmp = M_LookupValueEx( pConfig, "Mappings", 
						"Mapping", iTmp );
					if ( !pTmp )
						{ break; };
	
					if ( ::SendMessage( hWndList, LB_ADDSTRING, 0,
                        (LPARAM)pTmp )>=0 )
						{
						Internal_addLine( pTmp );
						}
					else
						{ break; /* error */; };
					};
				}
	
				HourglassOff();
				break;
	
			case WM_DESTROY:
				{
				/*
				** Delete values
				*/
				DblListIterator x( lTypes );
				DblListIterator y( lFroms );
				DblListIterator z( lTos );
				DblListIterator w( lRealms );
				for( ; !x.BadIndex(); x++, y++, z++, w++ )
					{
					assert( !x.BadIndex() && !y.BadIndex() && !z.BadIndex() 
						&& !w.BadIndex() );
					PI_DELETE( (PIString *)x.Current() );
					PI_DELETE( (PIString *)y.Current() );
					PI_DELETE( (PIString *)z.Current() );
					PI_DELETE( (PIString *)w.Current() );
					};
				lTypes.Clear();
				lFroms.Clear();
				lTos.Clear();
				lRealms.Clear();
				};
				break;
	
			case WM_COMMAND:
				switch (GET_WM_COMMAND_ID(wParam, lParam))
					{
					case IDC_ADD:
						{
						/*
						** Verify fields are valid
						*/
						if ( !Internal_verifyFields( hDlg, szBuf, BUF_SIZE ) )
							{ break; };
	
						int i, j;
						*szBuf = '\0';
	
						SendMessage( hWndType, WM_GETTEXT, BUF_SIZE,
                            (LPARAM)szBuf );
						for( i=0; i<BUF_SIZE && szBuf[i]!='\t' && szBuf[i];
                            i++ );
						if ( szBuf[i] ) { szBuf[i] = '\0'; };
						lTypes.Append( (DblList::type)PI_NEW(
                            PIString( szBuf ) ) );
						szBuf[i++] = '\t';
	
						SendMessage( hWndFrom, WM_GETTEXT, BUF_SIZE-i,
                            (LPARAM)&(szBuf[i]) );
						for( j=i; i<BUF_SIZE && szBuf[i] && szBuf[i]!='\t';
                            i++ );
						if ( szBuf[i] ) { szBuf[i] = '\0'; };
						lFroms.Append( (DblList::type)PI_NEW( PIString(
                            &(szBuf[j]) ) ) );
						szBuf[i++] = '\t';
	
						SendMessage( hWndTo, WM_GETTEXT, BUF_SIZE-i,
                            (LPARAM)&(szBuf[i]) );
						for( j=i; i<BUF_SIZE && szBuf[i] && szBuf[i]!='\t';
                            i++ );
						if ( szBuf[i] ) { szBuf[i] = '\0'; };
						lTos.Append( (DblList::type)PI_NEW( PIString(
                            &(szBuf[j]) ) ) );
						szBuf[i++] = '\t';
	
						szBuf[i] = '\0';
						SendMessage( hWndRealm, WM_GETTEXT, BUF_SIZE-i,
                            (LPARAM)&(szBuf[i]) );
						if ( szBuf[i]=='\0' )
							{ strncpy( &(szBuf[i]), "(none)", BUF_SIZE-i ); };
						lRealms.Append( (DblList::type)PI_NEW( PIString(
                            &(szBuf[i]) ) ) );
		
						SendMessage( hWndList, LB_ADDSTRING, 0, (LPARAM)szBuf );
	
						/*
						** Clear edit fields, focus to list
						*/
						SendMessage( hWndType, CB_SETCURSEL, (WPARAM)-1, 0 );
						SendMessage( hWndFrom, WM_SETTEXT, 0, (LPARAM)"" );
						SendMessage( hWndTo, WM_SETTEXT, 0, (LPARAM)"" );
						SendMessage( hWndRealm, CB_SETCURSEL, (WPARAM)-1, 0 );
						SetFocus( hWndList );
						Changed( hDlg );
						};

⌨️ 快捷键说明

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