Click here to Skip to main content
15,879,535 members
Articles / Desktop Programming / ATL

"Select Computer" Dialog

Rate me:
Please Sign up or sign in to vote.
5.00/5 (3 votes)
16 Apr 20013 min read 202.4K   4.4K   36  
The ATL and MFC versions of the class that implements a dialog for selecting users(computers) within the Windows Network.
// SelectComputerNetwork.h: interface for the CSelectComputerNetwork class.
//
//////////////////////////////////////////////////////////////////////
#include <winnetwk.h>
#include <vector>
#include <string>

using namespace std;

class CSelectComputerNetwork  
{
public:
    CSelectComputerNetwork();
    virtual ~CSelectComputerNetwork();

public: 
    static bool GetDomains(vector<basic_string<TCHAR> >& vecstrDomains);
    static bool GetServers(const basic_string<TCHAR>& strDomain, vector<basic_string<TCHAR> >& vecstrServers);

private:
//NETRESOURCE structure wrapper used to save text data that freed by WNetEnumClose(_);
    class CNETRESOURCE 
    {
    public:
        CNETRESOURCE(const NETRESOURCE& nr):
        m_nr(nr)
        {
			m_strLocalName = nr.lpLocalName ? nr.lpLocalName : _T("");
			m_strRemoteName = nr.lpRemoteName ? nr.lpRemoteName : _T("");
			m_strComment = nr.lpComment ? nr.lpComment : _T("");
			m_strProvider = nr.lpProvider ? nr.lpProvider : _T("");

            m_nr.lpLocalName = new TCHAR [m_strLocalName.size() + 1];
            _tcscpy(m_nr.lpLocalName, m_strLocalName.c_str());

            m_nr.lpRemoteName = new TCHAR [m_strRemoteName.size() + 1];
            _tcscpy(m_nr.lpRemoteName, m_strRemoteName.c_str());

            m_nr.lpComment = new TCHAR [m_strComment.size() + 1];
            _tcscpy(m_nr.lpComment, m_strComment.c_str());

            m_nr.lpProvider = new TCHAR [m_strProvider.size() + 1];
            _tcscpy(m_nr.lpProvider, m_strProvider.c_str());

        }

        CNETRESOURCE(const CNETRESOURCE& rhs):
        m_nr(rhs.m_nr),
        m_strLocalName(rhs.m_strLocalName), 
        m_strRemoteName(rhs.m_strRemoteName), 
        m_strComment(rhs.m_strComment), 
        m_strProvider(rhs.m_strProvider) 
        {
            m_nr.lpLocalName = new TCHAR [m_strLocalName.size() + 1];
            _tcscpy(m_nr.lpLocalName, m_strLocalName.c_str());

            m_nr.lpRemoteName = new TCHAR [m_strRemoteName.size() + 1];
            _tcscpy(m_nr.lpRemoteName, m_strRemoteName.c_str());

            m_nr.lpComment = new TCHAR [m_strComment.size() + 1];
            _tcscpy(m_nr.lpComment, m_strComment.c_str());

            m_nr.lpProvider = new TCHAR [m_strProvider.size() + 1];
            _tcscpy(m_nr.lpProvider, m_strProvider.c_str());
        }
        
        ~CNETRESOURCE()
        {
            delete [] m_nr.lpLocalName;
            delete [] m_nr.lpRemoteName;
            delete [] m_nr.lpComment;
            delete [] m_nr.lpProvider;
        }

    public:
        NETRESOURCE* operator &() 
        {
            return &m_nr;
        }

        operator NETRESOURCE() const
        {
            return m_nr;
        }
    
        void CorrectRemoteName()
        {
            m_strRemoteName = m_strRemoteName.substr(2);//skip 2 leading slashes

            delete [] m_nr.lpRemoteName;
            
            m_nr.lpRemoteName = new TCHAR [m_strRemoteName.size() + 1];
            _tcscpy(m_nr.lpRemoteName, m_strRemoteName.c_str());
        }

        basic_string<TCHAR> GetRemoteName() const
        {
            return m_strRemoteName;
        }
            
        
    
    private:
        NETRESOURCE m_nr;

    private:
        basic_string<TCHAR>     m_strLocalName; 
        basic_string<TCHAR>     m_strRemoteName; 
        basic_string<TCHAR>     m_strComment; 
        basic_string<TCHAR>     m_strProvider; 

    };
//NETRESOURCE structure wrapper

private:
    static bool EnumDomains(NETRESOURCE* pnr, vector<CNETRESOURCE>& vecnrDomains);
    static bool EnumServers(NETRESOURCE* pnr, vector<CNETRESOURCE>& vecnrServers);
};

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


Written By
Other
Australia Australia
Igor Sukhov is %a someone who can take your project from user requirements to successfull completion% residing in Sydney, NSW, Australia.

Igor has been working on design, development and maintenance (surprise!) of many large-scale business-critical enterprise applications.

Igor holds MS degree in Computer Science/Applied Mathematics from Kazan State University.

MCAD .NET

Tag cloud:

.NET 2.0

C#

Business applications

Design

Enterprise applications

Development

Sydney


Comments and Discussions