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

📄 mythreaddlg.cpp

📁 电信短信应用smgp1.3协议网关,中兴开发包
💻 CPP
字号:
// MyThreadDlg.cpp : implementation file
//

#include "stdafx.h"
#include "MyThread.h"
#include "MyThreadDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMyThreadDlg dialog

CMyThreadDlg::CMyThreadDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CMyThreadDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CMyThreadDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CMyThreadDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CMyThreadDlg)
	DDX_Control(pDX, IDC_BUTTON_STOP, m_stop);
	DDX_Control(pDX, IDC_BUTTON_START, m_start);
	DDX_Control(pDX, IDC_LIST1, m_List1);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CMyThreadDlg, CDialog)
	//{{AFX_MSG_MAP(CMyThreadDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON_START, OnButtonStart)
	ON_BN_CLICKED(IDC_BUTTON_STOP, OnButtonStop)
	//ON_COMMAND(IDC_REG, OnReg)
	ON_COMMAND(IDC_REG,OnAbout1)
	ON_COMMAND(IDC_ABOUT1, OnAbout1)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMyThreadDlg message handlers

BOOL CMyThreadDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
	m_stop.EnableWindow(false);
	AfxOleInit();
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CMyThreadDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CMyThreadDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CMyThreadDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CMyThreadDlg::OnButtonStart() 
{
	//HRESULT hr;	
	char 		g_cConfigFileDir[200];
	char 		m_buffer[50];
	memset(g_cConfigFileDir,0,200); 
	GetCurrentDirectory(200,g_cConfigFileDir);
	#ifdef _WIN32 
	strcat(g_cConfigFileDir,"\\");
	#else
	strcat(g_cConfigFileDir,"/");
	#endif
	strcat(g_cConfigFileDir,"smgpc.ini");
	send_speed=GetPrivateProfileInt("Option" ,"SendSpeed",0,g_cConfigFileDir);

	memset(m_buffer,0,50); 
	GetPrivateProfileString("Option","DbUser","default",m_buffer,10,g_cConfigFileDir);
	db_user=m_buffer;
	memset(m_buffer,0,50); 
	GetPrivateProfileString("Option","DbPassword","default",m_buffer,10,g_cConfigFileDir);
	db_password=m_buffer;
	memset(m_buffer,0,50); 
	GetPrivateProfileString("Option","DbServer","default",m_buffer,10,g_cConfigFileDir);
	db_server=m_buffer;
	memset(g_cConfigFileDir,0,200); 
	memset(m_buffer,0,50); 
	if(send_speed<1||send_speed>3){AfxMessageBox("速度错误");return;}
	m_active=false;
	db_active=false;
	m_start.EnableWindow(false);
	m_stop.EnableWindow(true);
	if(!ConnectDB())
	{
	m_start.EnableWindow(true);
	m_stop.EnableWindow(false);
	return;
	}
	m_thread3=(Thread3*)AfxBeginThread(RUNTIME_CLASS(Thread3),THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED,NULL);	
	send_thread1=(SendThread1*)AfxBeginThread(RUNTIME_CLASS(SendThread1),THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED,NULL);	
	m_thread1=(Thread1*)AfxBeginThread(RUNTIME_CLASS(Thread1),THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED,NULL);	
	m_thread2=(Thread2*)AfxBeginThread(RUNTIME_CLASS(Thread2),THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED,NULL);
	m_thread2->GetOwner(this,m_thread3,m_thread1);
	m_thread3->GetOwner(this);
	m_thread1->GetOwner(this,m_thread3);
	send_thread1->GetOwner(this,m_thread3);
	m_thread2->ResumeThread();
	m_thread3->ResumeThread();	
	m_thread1->ResumeThread();
	send_thread1->ResumeThread();
	// TODO: Add your control notification handler code here
	
}

BOOL CMyThreadDlg::AddString(char *s1)
{
	CTime t  = CTime::GetCurrentTime();
    CString str;      
	str.Format("%d-%d",t.GetMonth(),t.GetDay());
    str+= t.Format(" %H-%M-%S :");
	str+=s1;
	g_cs.Lock();
	m_List1.AddString(str);
	g_cs.Unlock();
	return true;
}
BOOL CMyThreadDlg::ConnectDB()
{
	//db_active=false;
 	try
 	{
		hr=m_connection.CreateInstance("ADODB.Connection");
 		if(SUCCEEDED(hr))
 		{
 			hr=m_connection->Open(db_server.GetBuffer(0),db_user.GetBuffer(0),db_password.GetBuffer(0),adModeUnknown);
			//m_connection->Execute("set rowcount 60",&RecordsAffected,adCmdText);
			AddString("连接数据库成功");
		}
 		else
 		{
 			AddString("连接数据库失败!link");
 		}
	}
	catch(_com_error e)
 	{
		AddString("连接数据库失败err!");
 		return false;
 	}
	return true;
}
void CMyThreadDlg::OnButtonStop() 
{
	send_thread1->m_stop_state=true;
	m_thread1->m_stop_state=true;
	m_thread2->m_stop_state=true;
	m_thread3->m_stop_state=true;
//	g_cs.Unlock();
//	m_Operate.cs_send.Unlock();
	m_thread3->ResumeThread();
	//m_thread3->TerminateThread();
	m_start.EnableWindow(true);
	m_stop.EnableWindow(false);
	//CoUninitialize();
}



void CMyThreadDlg::OnReg() 
{
	reg.DoModal();	
}

void CMyThreadDlg::OnAbout1() 
{
	// TODO: Add your command handler code here
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
}

⌨️ 快捷键说明

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