home *** CD-ROM | disk | FTP | other *** search
- // UseATLstrXDlg.cpp : implementation file
-
- #include "stdafx.h"
- #include "UseATLstrX.h"
- #include "UseATLstrXDlg.h"
-
- #include <stdlib.h>
- #include <ctype.h>
-
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
-
- // CUseATLstrXDlg dialog
- CUseATLstrXDlg::CUseATLstrXDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CUseATLstrXDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CUseATLstrXDlg)
- // NOTE: the ClassWizard will add member initialization here
- //}}AFX_DATA_INIT
- m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
- }
-
- void CUseATLstrXDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CUseATLstrXDlg)
- // NOTE: the ClassWizard will add DDX and DDV calls here
- //}}AFX_DATA_MAP
- }
-
- BEGIN_MESSAGE_MAP(CUseATLstrXDlg, CDialog)
- //{{AFX_MSG_MAP(CUseATLstrXDlg)
- ON_WM_PAINT()
- ON_WM_QUERYDRAGICON()
- ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
- ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- // CUseATLstrXDlg message handlers
- BOOL CUseATLstrXDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
-
- SetIcon(m_hIcon, TRUE); // Set big icon
- SetIcon(m_hIcon, FALSE); // Set small icon
-
- // TODO: Add extra initialization here
-
- return TRUE; // return TRUE unless you set the focus to a control
- }
-
- void CUseATLstrXDlg::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();
- }
- }
-
- HCURSOR CUseATLstrXDlg::OnQueryDragIcon()
- {
- return (HCURSOR) m_hIcon;
- }
-
- void CUseATLstrXDlg::OnButton1()
- {
- // Obtain a smart pointer to the interface.
- IstrXPtr pString(CLSID_strX);
-
- CString s("HELLO WORLD");
-
- // The function in the remote server needs a pointer to a BSTR.
- // The easiest way to construct and fill a BSTR is to use a
- // CString, and then CString::AllocSysString. Finally,
- // pass the address of the BSTR.
- BSTR str = s.AllocSysString();
- HRESULT rc = pString->ATLstrlwrX(&str);
-
- // Now, because BSTR aren't intended to work with MFC
- // methods we convert the BSTR to a _bstr_t.
- if (S_OK == rc)
- {
- _bstr_t b(str, false);
- MessageBox((char *)b);
- }
- else
- MessageBox("Failure in call to ATLstrlwrX()");
-
- ::SysFreeString(str);
- }
-
- void BSTRlower(BSTR s)
- {
- wchar_t *p = (wchar_t *) s;
- while (*p)
- {
- *p = tolower(*p);
- p++;
- }
- }
-
-
- void CUseATLstrXDlg::OnButton2()
- {
- _bstr_t b("HELLO WORLD");
- BSTRlower(b);
-
- MessageBox((char *)b);
- }
-
-