Click here to Skip to main content
11,581,982 members (75,111 online)
Click here to Skip to main content
Add your own
alternative version

Temperature Convert:An XML Web service Using ATL Server and MFC Client

, 6 Mar 2007 30.9K 515 20
An XML Web Service using ATL Server and Called by MFC Client
tempconvert.zip
TempConvert
TempConvert.suo
TempConvert
TempConvert.disco
TempConvert.vcproj.ALADDINKING.Administrator.user
TempConvertClient
res
TempConvertClient.ico
temp
results.discomap
TempConvert.wsdl
TempConvertClient.aps
TempConvertClient.vcproj.ALADDINKING.Administrator.user
TempConvertService
results.discomap
TempConvert.wsdl
TempConvertIsapi
TempConvertIsapi.def
TempConvertIsapi.vcproj.ALADDINKING.Administrator.user
tempconvert_binary.zip
TempConvert_Binary
TempConvert
TempConvert.disco
TempConvert.dll
TempConvertIsapi.dll
TempConvertClient_2003
TempConvertClient.exe
TempConvertClient_2005
TempConvertClient.exe
// TempConvertClientDlg.cpp : implementation file
//

#include "stdafx.h"
#include "TempConvertClient.h"
#include "TempConvertClientDlg.h"
#include "TempConvertService.h"
using namespace TempConvertService;

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

#define MAX_TEMPRETURE 1000000.0
#define MIN_TEMPRETURE -1000000.0

// CAboutDlg dialog used for App About

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

// Dialog Data
	enum { IDD = IDD_ABOUTBOX };

	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support

// Implementation
protected:
	DECLARE_MESSAGE_MAP()
};

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

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

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
END_MESSAGE_MAP()


// CTempConvertClientDlg dialog




CTempConvertClientDlg::CTempConvertClientDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CTempConvertClientDlg::IDD, pParent)
{
	m_dTempF=0.0;
	m_dTempC=0.0;
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CTempConvertClientDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Text(pDX, IDC_FAHRENHEIT, m_dTempF);
	//DDV_MinMaxDouble(pDX, m_dTempF, MIN_TEMPRETURE, MAX_TEMPRETURE);
	DDX_Text(pDX, IDC_CELCIUS, m_dTempC);
	//DDV_MinMaxDouble(pDX, m_dTempC, MIN_TEMPRETURE, MAX_TEMPRETURE);
}

BEGIN_MESSAGE_MAP(CTempConvertClientDlg, CDialog)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	//}}AFX_MSG_MAP
	ON_BN_CLICKED(IDC_CONVERT, OnConvert)
	ON_BN_CLICKED(IDC_RADIOC2F, OnBnClickedC2F)
	ON_BN_CLICKED(IDC_RADIOF2C, OnBnClickedF2C)
END_MESSAGE_MAP()


// CTempConvertClientDlg message handlers

BOOL CTempConvertClientDlg::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

	//Initial to Set The first IDC_RADIOF2C checked
	CButton *pRadio=(CButton *)GetDlgItem(IDC_RADIOF2C);
	pRadio->SetCheck(1);

	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CTempConvertClientDlg::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 CTempConvertClientDlg::OnPaint()
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, reinterpret_cast<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 function to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CTempConvertClientDlg::OnQueryDragIcon()
{
	return static_cast<HCURSOR>(m_hIcon);
}

void CTempConvertClientDlg::OnConvert()
{
	UpdateData(TRUE);

    CoInitialize(NULL);
	HRESULT hr = S_OK;

	//Get Radio state
	UINT m_iRadio=GetCheckedRadioButton(IDC_RADIOF2C,IDC_RADIOC2F);
	GetDlgItem(IDC_CONVERT)->EnableWindow(FALSE);
    
	CTempConvertService *pTempCon=new CTempConvertService;
	switch(m_iRadio){
		case IDC_RADIOC2F:
			double dFah;
			hr=pTempCon->ConTempCel2Fah(m_dTempC,&dFah);
			if(SUCCEEDED(hr)){
				m_dTempF=dFah; 
				GetDlgItem(IDC_CONVERT)->EnableWindow();
				UpdateData(FALSE);
			}else{
				MessageBox(_T("Convert Service Failed!"),_T("Service Failed"),MB_OK | MB_ICONHAND);
			}
		case IDC_RADIOF2C:
			double dCel;
			hr=pTempCon->ConTempFah2Cel(m_dTempF,&dCel);
			if(SUCCEEDED(hr)){
				m_dTempC=dCel;
				GetDlgItem(IDC_CONVERT)->EnableWindow();
				UpdateData(FALSE);
			}else{
				MessageBox(_T("Convert Service Failed!"),_T("Service Failed"),MB_OK | MB_ICONHAND);
			}
	}

   delete pTempCon;
   CoUninitialize();
}

void CTempConvertClientDlg::OnBnClickedC2F()
{
	//Send Message to call Button IDC_CONVERT
	GetDlgItem(IDC_CONVERT)->SendMessage(BM_CLICK,0,0);
}

void CTempConvertClientDlg::OnBnClickedF2C()
{
	//Send Message to call Button IDC_CONVERT 
	GetDlgItem(IDC_CONVERT)->SendMessage(BM_CLICK,0,0);
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

James, Lu Zuheng
Web Developer
China China
I am favor to use C\C++,MFC,ATL,COM and JavaScript to program, and interesting in network security as well.In my spare time,I like playingbasketball,Climbing.I now live in Beijing,China.It is nice to go along the red walls around the Forbitten City.

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150603.1 | Last Updated 6 Mar 2007
Article Copyright 2007 by James, Lu Zuheng
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid