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

📄 setdialog.cpp

📁 超强的图形界面聊天软件.rar
💻 CPP
字号:
// SetDialog.cpp : implementation file
//

#include "stdafx.h"
#include "pictalk.h"
#include "SetDialog.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CSetDialog dialog


CSetDialog::CSetDialog(CWnd* pParent /*=NULL*/)
	: CDialog(CSetDialog::IDD, pParent)
{
	//{{AFX_DATA_INIT(CSetDialog)
	m_PortAddress = 700;
	m_bShowWeb = FALSE;
	m_strSelSer = _T("");
	m_RoomName = _T("");
	m_IP = _T("");
	//}}AFX_DATA_INIT
}


void CSetDialog::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CSetDialog)
	DDX_Control(pDX, IDC_COMBO1, m_ComSer);
	DDX_Text(pDX, IDC_PORT, m_PortAddress);
	DDX_Check(pDX, IDC_SHOW_WEB, m_bShowWeb);
	DDX_CBString(pDX, IDC_COMBO1, m_strSelSer);
	DDX_Text(pDX, IDC_ROOM_NAME, m_RoomName);
	DDX_Text(pDX, IDC_STATIC_IP, m_IP);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CSetDialog, CDialog)
	//{{AFX_MSG_MAP(CSetDialog)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

CCriticalSection g_csStatus;
CString g_strFile="show.asp?";
CString g_strServerName="www.devie.com";
CString g_strServerIP="";
volatile UINT g_nPort = 80;
CString g_strShowInfo;
int roomid;

UINT ShowWinInetThreadProc(LPVOID pParam)
{
	CInternetSession session;
	CHttpConnection* pConnection = NULL;
	CHttpFile* pFile1 = NULL;
	char* buffer = new char[2];
	UINT nBytesRead = 0;
	DWORD dwStatus;
	CString g_str;
	try {
		// username/password doesn't work yet
		if(!g_strServerName.IsEmpty()) {
			pConnection = session.GetHttpConnection(g_strServerName,
					(INTERNET_PORT) g_nPort);
		}
		else {
			pConnection = session.GetHttpConnection(g_strServerIP,
					(INTERNET_PORT) g_nPort);
		}
		pFile1 = pConnection->OpenRequest(1, g_strFile+g_strShowInfo, NULL, 1, NULL, NULL, // GET request
				INTERNET_FLAG_KEEP_CONNECTION |INTERNET_FLAG_RELOAD); // needed for NT Challenge/Response authentication
				// INTERNET_FLAG_RELOAD forces reload from the server (bypasses client's cache)
		pFile1->SendRequest();
		pFile1->QueryInfoStatusCode(dwStatus);
		TRACE("QueryInfoStatusCode = %d\n", dwStatus);
		
		pFile1->ReadString(g_str);
		g_str="";
		while(1){
			nBytesRead = pFile1->Read(buffer, 1);
			buffer[nBytesRead] = '\0';
			if(buffer[0]==13)
				break;
			g_str+=buffer[0];
		}
		if(g_str!=CString("headtou")){
			AfxMessageBox("主服务器不可用",MB_OK);
		}
		
		g_str="";
		while(1){
			nBytesRead = pFile1->Read(buffer, 1);
			buffer[nBytesRead] = '\0';
			if(buffer[0]==13)
				break;
			g_str+=buffer[0];
		}
		sscanf(g_str,"%d",&roomid);

		g_str="";
		while(1){
			nBytesRead = pFile1->Read(buffer, 1);
			buffer[nBytesRead] = '\0';
			if(buffer[0]==13)
				break;
			g_str+=buffer[0];
		}
		if(g_str!=CString("tailwei")){
			roomid=0;
			AfxMessageBox("主服务器不可用",MB_OK);
		}
		// could use existing pFile1 to SendRequest again if we wanted to
	}
	catch(CInternetException* e) {
//		LogInternetException(pParam, e);
		e->Delete();
	}
	// could call OpenRequest again on same connection if we wanted to 
	if(pFile1) delete pFile1; // does the close -- prints a warning
	if(pConnection) delete pConnection; // why does it print a warning?
	delete [] buffer;
	return 0;
}

/////////////////////////////////////////////////////////////////////////////
// CSetDialog message handlers

BOOL CSetDialog::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	CString filename="web.txt";
	CStdioFile file;
	if(file.Open(filename,CFile::modeRead)==0){
		AfxMessageBox("读取文件失败",MB_OK);
	}
	CString str;
	while(1){
		WebServer web;
		file.ReadString(web.m_Webname);
		if(web.m_Webname=="")
			break;
		file.ReadString(web.m_Web);
		file.ReadString(web.m_show);
		file.ReadString(web.m_get);
		m_WebList.Add(web);
	}
	file.Close();

	int i;
	for(i=0;i<m_WebList.GetSize();i++)
		m_ComSer.AddString(m_WebList[i].m_Webname);
	m_ComSer.SetCurSel(0);
	CString ip;
{
      WORD wversionrequested;
      WSADATA wsadata;
      char name[255];
      
      PHOSTENT hostinfo;
      wversionrequested = MAKEWORD( 2, 0 );

      if ( WSAStartup( wversionrequested, &wsadata ) == 0 )
      {

            if( gethostname ( name, sizeof(name)) == 0)
            {
                  if((hostinfo = gethostbyname(name)) != NULL)
                  {
                        ip = inet_ntoa (*(struct in_addr *)*hostinfo->h_addr_list);
                  }
            }
            
            WSACleanup( );
      } 
}
	CStatic * pIP=(CStatic *)GetDlgItem(IDC_STATIC_IP);
	pIP->SetWindowText(ip);
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CSetDialog::OnOK() 
{
	// TODO: Add extra validation here
	UpdateData(TRUE);
	g_strServerName=m_WebList[m_ComSer.GetCurSel()].m_Web;
	g_strFile=m_WebList[m_ComSer.GetCurSel()].m_show;
	CDialog::OnOK();
}

⌨️ 快捷键说明

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