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

📄 general.cpp

📁 mini http server,可以集成嵌入到程序中,实现简单的web功能
💻 CPP
📖 第 1 页 / 共 2 页
字号:
				hWndIP = GetDlgItem( hDlg, IDC_REMOTEIP );
				hWndLocal = GetDlgItem( hDlg, IDC_LOCAL );
				hWndEdit = GetDlgItem( hDlg, IDC_HOST );
				hWndPort = GetDlgItem( hDlg, IDC_PORT );
				hWndURL = GetDlgItem( hDlg, IDC_URL );
				hWndAdmin = GetDlgItem( hDlg, IDC_ADMIN );
				hWndSsl = GetDlgItem( hDlg, IDC_SSL );
				hWndRemote = GetDlgItem( hDlg, IDC_REMOTE );
				hWndVerbose = GetDlgItem( hDlg, IDC_VERBOSE );

				assert( hWndHost && hWndIP && hWndLocal );
				assert( hWndEdit && hWndPort && hWndURL && hWndAdmin );

				assert( pA );

				::SendMessage( hWndAdmin, WM_SETTEXT, 0, (LPARAM)pA );

				::SendMessage( hWndHost, BM_SETCHECK, BST_UNCHECKED, 0 );
				::SendMessage( hWndIP, BM_SETCHECK, BST_UNCHECKED, 0 );
				::SendMessage( hWndLocal, BM_SETCHECK, BST_UNCHECKED, 0 );
				::SendMessage( hWndSsl, BM_SETCHECK, BST_UNCHECKED, 0 );
				::SendMessage( hWndRemote, BM_SETCHECK, BST_UNCHECKED, 0 );
				::SendMessage( hWndVerbose, BM_SETCHECK, BST_UNCHECKED, 0 );

				/* --- just for sanity --- */
				::SendMessage( hWndEdit, EM_SETLIMITTEXT, 256, 0 );
				::SendMessage( hWndPort, EM_SETLIMITTEXT, 256, 0 );

				::SendMessage( ::GetDlgItem( hDlg, IDC_INSTALLDIR ), WM_SETTEXT, 0,
					(LPARAM)M_LookupValue( pConfig, "General", "InstallDir" ));
				::SendMessage( ::GetDlgItem( hDlg, IDC_OS ), WM_SETTEXT, 0,
					(LPARAM)M_LookupValue( pConfig, "General", "OS" ));

				const char *pUse = M_LookupValue( pConfig, "Identity", "Use" );
				const char *pTheHost = M_LookupValue( pConfig, "General", "Host" );
				SendMessage( hWndEdit, WM_SETTEXT, 0, (LPARAM)(const char *)pTheHost );
				if ( !stricmp( pUse, "local" ) )
					{
					SendMessage( hWndLocal, BM_SETCHECK, BST_CHECKED, 0 );
					__iCurrentRadioButton = IDC_LOCAL;
					SendMessage( hWndEdit, EM_SETREADONLY, (BOOL)TRUE, 0 );
					}
				else if ( !stricmp( pUse, "remote" ) )
					{
					SendMessage( hWndHost, BM_SETCHECK, BST_CHECKED, 0 );
					__iCurrentRadioButton = IDC_REMOTEHOST;
					SendMessage( hWndEdit, EM_SETREADONLY, (BOOL)FALSE, 0 );
					}
				else if ( !stricmp( pUse, "ip" ) )
					{
					SendMessage( hWndIP, BM_SETCHECK, BST_CHECKED, 0 );
					__iCurrentRadioButton = IDC_REMOTEIP;
					SendMessage( hWndEdit, EM_SETREADONLY, (BOOL)FALSE, 0 );
					};

				const char *pTest = M_LookupValue( pConfig, "Internal", "HandlerLine" );
				if ( strstr( pTest, "TopSiteRoot" ) )
					{
					SendMessage( hWndRemote, BM_SETCHECK, BST_CHECKED, 0 );
					}

				if ( strstr( M_LookupValue( pConfig, "General", "ErrorMessages" ), "Verbose" ))
					{
					SendMessage( hWndVerbose, BM_SETCHECK, BST_CHECKED, 0 );
					}

				// Port and SSL flag are set and URL is updated
				// in PSN_SETACTIVE handler
			
				Unchanged( hDlg );
				break;
				};

		case WM_COMMAND:
			if ( GET_WM_COMMAND_CMD(wParam, lParam)==BN_CLICKED )
				{
				switch( GET_WM_COMMAND_ID( wParam, lParam) )
					{
					case IDC_REMOTEHOST:
						Internal_radioButtonChange( IDC_REMOTEHOST );	
						SendMessage( hWndEdit, EM_SETREADONLY, (BOOL)FALSE, 0 );
						break;

					case IDC_REMOTEIP:	
						Internal_radioButtonChange( IDC_REMOTEIP );	
						SendMessage( hWndEdit, EM_SETREADONLY, (BOOL)FALSE, 0 );
						break;

					case IDC_LOCAL:	
						Internal_radioButtonChange( IDC_LOCAL );	
						SendMessage( hWndEdit, EM_SETREADONLY, (BOOL)TRUE, 0 );
						break;

					case IDC_SSL:
						*szBuf = '\0';
						SendMessage( hWndPort, WM_GETTEXT, BUF_SIZE, (LPARAM)szBuf );
						if ( ::SendMessage( hWndSsl, BM_GETCHECK, 0, 0 )==BST_CHECKED )
							{
							M_ReplaceValue( pConfig, "Internal", "URLProtocol", "https://" );
							M_ReplaceValue( pConfig, "Internal", "DefaultPort", "443" );
							if (!stricmp(szBuf, "80")) {
								SendMessage( hWndPort, WM_SETTEXT, 0, (LPARAM)"443");
								};
							}
						else
							{
							M_ReplaceValue( pConfig, "Internal", "URLProtocol", "http://" );
							M_ReplaceValue( pConfig, "Internal", "DefaultPort", "80" );
							if (!stricmp(szBuf, "443")) {
								SendMessage( hWndPort, WM_SETTEXT, 0, (LPARAM)"80");
								};
							};
						Internal_updateURL( hDlg );
						break;

					case IDC_REMOTE:
					case IDC_VERBOSE:
						Changed( hDlg );
						break;

					default:;
					};
				}
			else if ( GET_WM_COMMAND_CMD(wParam, lParam)==EN_CHANGE )
				{ Internal_updateURL( hDlg ); };
			break;

		case WM_DESTROY:
			break;

			case WM_NOTIFY:
				switch( ((NMHDR *)lParam)->code )
					{
					case PSN_SETACTIVE:
						{
						int iSaveChanged = IsChanged();
						SendMessage( hWndPort, WM_SETTEXT, 0, (LPARAM)
							M_LookupValue( pConfig, "General", "Port" ) );

						const char *pTest = M_LookupValue( pConfig, "Internal", \
							"ServerIOObjectLine" );
						if ( strstr( pTest, "SSLIO" ))
							{
							SendMessage( hWndSsl, BM_SETCHECK, BST_CHECKED, 0 );
							}
						Internal_updateURL( hDlg );
						if ( !iSaveChanged ) { Unchanged( hDlg ); };
						SetWindowLong( hDlg, DWL_MSGRESULT, FALSE );
						return (TRUE);
						}

					case PSN_QUERYCANCEL:
						return SHEET->Cancel(pInterface, hDlg);
	
					case PSN_KILLACTIVE:
						if ( IsChanged() )
						{
						*szBuf = '\0';
						::SendMessage( ::GetDlgItem( hDlg, IDC_INSTALLDIR ),
							WM_GETTEXT, BUF_SIZE, (LPARAM)szBuf );
						M_ReplaceValue( pConfig, "General", "InstallDir", szBuf ); 

						*szBuf = '\0';
						::SendMessage( ::GetDlgItem( hDlg, IDC_OS ),
							WM_GETTEXT, BUF_SIZE, (LPARAM)szBuf );
						M_ReplaceValue( pConfig, "General", "OS", szBuf ); 

						*szBuf = '\0';
						SendMessage( hWndPort, WM_GETTEXT, BUF_SIZE, (LPARAM)szBuf );
						int iPort = atoi( szBuf );
						if ( iPort<0 || iPort>65535 )
							{
							/*
							** Give message and abort change
							*/
							MessageBox( hDlg, "Port must be in the range [0..65536]",
								"Port Field Error", MB_OK );
							SetFocus( hWndPort );
							SendMessage( hWndPort, EM_SETSEL, 0, -1 );
							SetWindowLong( hDlg, DWL_MSGRESULT, PSNRET_INVALID_NOCHANGEPAGE );
							return (TRUE);
							};
						M_ReplaceValue( pConfig, "General", "Port", szBuf ); 
						SendMessage( hWndAdmin, WM_GETTEXT, BUF_SIZE, (LPARAM)szBuf );
						M_ReplaceValue( pConfig, "General", "Admin", szBuf ); 
						SendMessage( hWndEdit, WM_GETTEXT, BUF_SIZE, (LPARAM)szBuf );
						M_ReplaceValue( pConfig, "General", "Host", szBuf ); 
						SendMessage( hWndURL, WM_GETTEXT, BUF_SIZE, (LPARAM)szBuf );
						M_ReplaceValue( pConfig, "Identity", "URL", szBuf );
						switch( __iCurrentRadioButton )
							{
							case IDC_LOCAL:
								M_ReplaceValue( pConfig, "Identity", "Use", "Local" );	
								break;

							case IDC_REMOTEHOST:
								M_ReplaceValue( pConfig, "Identity", "Use", "Remote" );	
								break;

							case IDC_REMOTEIP:
								M_ReplaceValue( pConfig, "Identity", "Use", "IP" );	
								break;

							default:
								assert( 0 );
							};

						if ( ::SendMessage( hWndSsl, BM_GETCHECK, 0, 0 )==BST_CHECKED )
							{
							M_ReplaceValue( pConfig, "Internal", "ServerIOObjectLine", \
								"\tIOObject SSLIOObject" );
							}
						else
							{
							M_ReplaceValue( pConfig, "Internal", "ServerIOObjectLine", \
								"\tIOObject ServerIOObject" );
							}

						if ( ::SendMessage( hWndRemote, BM_GETCHECK, 0, 0 )==BST_CHECKED )
							{
							M_ReplaceValue( pConfig, "Internal", "HandlerLine", \
								"\tHandlers TopSiteRoot" );
  							}
						else
							{
							M_ReplaceValue( pConfig, "Internal", "HandlerLine", \
								DEFAULT_HANDLERS );
							}

						if ( ::SendMessage( hWndVerbose, BM_GETCHECK, 0, 0 )==BST_CHECKED )
							{
							/*
							** Give warning message
							*/
							if ( __iCurrentRadioButton!=IDC_LOCAL )
								{
								MessageBox( hDlg, "This kind of error messages are extremely verbose. \
Don't even think about using them in an internet server.", "Verbose Errors Warning", MB_OK | MB_ICONWARNING );
								}
							M_ReplaceValue( pConfig, "General", "ErrorMessages", "Verbose" );
							}
						else
							{
							M_ReplaceValue( pConfig, "General", "ErrorMessages", "Short" );
							}
						}
						SetWindowLong( hDlg, DWL_MSGRESULT, FALSE );
						return (TRUE);
	
					case PSN_APPLY:
						return SHEET->SaveConfig(pInterface, hDlg);

					default:
						return (FALSE);
					};
				break;

            default:
                return (FALSE);
            };

        return FALSE;
        };
};

/*____________________________________________________________________________*\
 *
 Function:
 Synopsis:
 Description:
\*____________________________________________________________________________*/
static BOOL CALLBACK fnDialogProc(HWND hDlg, UINT uMsg, WPARAM wParam,
    LPARAM lParam)
{
    if ( uMsg==WM_INITDIALOG )
        {
        ::SetWindowLong( hDlg, DWL_USER, ((LPPROPSHEETPAGE)lParam)->lParam );
        };

    GeneralPage *pPage = (GeneralPage *)::GetWindowLong( hDlg, DWL_USER );
    return pPage ? pPage->DialogProc( hDlg, uMsg, wParam, lParam ) : FALSE;
}

/*____________________________________________________________________________*\
 *
 Function:
 Synopsis:
 Description:
\*____________________________________________________________________________*/
PUBLIC_PIAPI int GeneralPage_constructor( PIObject *pObj,
	int iArgc, const char *ppArgv[] )
{
	return IFaceBase_constructor( pObj, PI_NEW( GeneralPage( pObj,
		iArgc, ppArgv ) ) );
}

#if 0
/*___+++CNF_BEGIN+++___*/
	<Class>
		Name GeneralPageClass
		Type LogicExtension
		Library IntrFace
		OnClassLoad IFaceBase_onClassLoad
		Constructor GeneralPage_constructor
		CopyConstructor IFaceBase_copyConstructor
		Destructor IFaceBase_destructor
		Execute IFaceBase_execute
	</Class>

	<Object>
		Name GeneralPage
		Class GeneralPageClass
	</Object>

/*___+++CNF_END+++___*/
#endif

⌨️ 快捷键说明

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