Click here to Skip to main content
15,392,679 members
Articles / Desktop Programming / ATL
Posted 1 Apr 2001


36 bookmarked

"Select Computer" Dialog

Rate me:
Please Sign up or sign in to vote.
5.00/5 (3 votes)
16 Apr 20013 min read
The ATL and MFC versions of the class that implements a dialog for selecting users(computers) within the Windows Network.

"Select Computer" Dialog. Why do you need it ?

The "Select Computer" Dialog is very handy if you need something like the "Select Computer/User/Groups" dialog you've seen while playing with the user management or network configuration tools in Windows.

Just take a look at the picture below and you'll see what I'm talking about:

 [Select Computer Dialog - 10K]

This "Select Computer" dialog allow you to select computers ("servers" in terms of the WNetEnumResource() function) within any domain of your Windows Network environment. I tried to make this dialog to behave as closely to the original Microsoft dialog as possible. And I think I did it. So - it's resizable, supports both multiply and single selection and, ... hmm ... it works.

For your convenience I'm presenting both ATL and MFC versions of this dialog (and as you've already noticed - both versions of demo project). BTW, the ATL version works perfectly in WTL environment.

Usage - Step by Step

Add these files to your project: SelectComputerDialog.h, SelectComputerDialog.cpp, SELECT_COMPUTER_USER.ico, SELECT_COMPUTER_USERS.ico, SelectComputerDialog.rc, SelectComputerResource.h, SelectComputerNetwork.h, SelectComputerNetwork.cpp, Sizer.h, Sizer.cpp

Include the SelectComputerDialog.rc file to your project resource script file:

Choose (from Visual C++ 6 main menu) "View" -> "Resource Includes" and type "#include "SelectComputerDialog.rc" in "Compile-time directives" edit field:

 [Resource includes - 8K]

Include "SelectComputerDialog.h" in the file where you'd like to use the dialog.

#include "SelectComputerDialog.h" 

ATL sample code :

//here is the non-static method of CDialogImpl<T>-derived class 
//(actually it's a BN_CLICKED notification handler)
    CSelectComputerDialog dlg;

    //change dialog settings according to the check boxes state 
                            == BST_UNCHECKED);

    //show dialog
    if (dlg.DoModal() == IDOK)
        typedef basic_string<TCHAR> tstring;
        tstring str;
        typedef pair<tstring, tstring> tstringpair;

        //filling string with names of selected computers
        vector<tstringpair>::const_iterator ci = dlg.GetComputerNames().begin();
        for (; ci != dlg.GetComputerNames().end(); ++ci)
            str += (ci->first + _T(" / ") +  ci->second);
            str += _T("\r\n");
        SetDlgItemText(IDC_EDIT_COMPUTERNAME, str.c_str());

MFC sample code :

//here is the non-static method of CDialog-derived class 
//(actually it's a BN_CLICKED notification handler)
    CSelectComputerDialog dlg;

    //change dialog settings according to the check boxes state 

    m_strComputerName = _T("");
    //show dialog
    if (dlg.DoModal() == IDOK)
        //get computer names
        typedef pair<CString, CString> CStringPair;

        vector<CStringPair>::const_iterator ci = dlg.GetComputerNames().begin()
        for (; ci != dlg.GetComputerNames().end(); ++ci)
            m_strComputerName += (ci->first + _T(" / ") +  ci->second);
            m_strComputerName += _T("\r\n");

I think that sample is quite simple - but I'd like to explain it a bit:

A SingleSelection(bool) method is used to set a selection mode for the dialog. If the argument is true, then only one computer name can be selected at time, otherwise multiple selection is possible.

If the single selection mode is chosen use the GetComputerName() to get a name of the selected computer, otherwise you have to use the GetComputerNames() method that returns a STL vector of names. Actually, both methods returns computer name as the STL pair value that consists of both computer name and domain name.

Here is the prototypes for these methods:

for the ATL version:

const pair<basic_string<TCHAR>, basic_string<TCHAR> > & GetComputerName() const
const vector<pair<basic_string<TCHAR>, basic_string<TCHAR> > > & GetComputerNames() const

and for the MFC version:

const pair<CString, CString> & GetComputerName() const
const vector<pair<CString, CString> >& GetComputerNames() const

A NoALLDomain(bool) method is used to set a mode for the dialog that lets it show and select computers from different domains at one time. If argument is false the (ALL DOMAINS) item will be added to the combobox. If you'll select this "domain," all computers of all domains will be shown in the list control.

 [Select Computer Dialog - 10K]

At this time you know all that you need to know to use this class in your project. But for those of you who want a bit more, I wrote the next "chapter".

Dialog Internals

There are little descriptions of the classes I used to implement this dialog:

  • CSelectComputerDialog

    This class provides the UI and an interface to data where names of the selected computers are stored. It is derived directly from CDialogImpl<CSelectComputerDialog> in ATL version, and from CDialog in the MFC version.

  • CSizer

    This class provides the ability to resize the dialog, with consequent rearrangement of child controls, and you can control the minimum and maximum size allowed.

  • CSelectComputerNetwork

    This one does all the network-related jobs - enumeration of computers and domains. Actually I'm using the WNetEnumResource() function to enumerate network resources.
    If an enumerated resource is identified as RESOURCEDISPLAYTYPE_DOMAIN object I display it as a domain, and if it's identified as RESOURCEDISPLAYTYPE_SERVER object I show it as a computer.
    The name of computer and domain are read from the lpRemoteName member of the NETRESOURCE structure.


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


About the Author

Igor Sukhov
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.


Tag cloud:

.NET 2.0


Business applications


Enterprise applications



Comments and Discussions

GeneralASSERT Pin
XHungChung22-Oct-06 22:12
MemberXHungChung22-Oct-06 22:12 
GeneralGreat Work Pin
Shail_Srivastav23-Oct-04 8:38
MemberShail_Srivastav23-Oct-04 8:38 
GeneralWNetEnumResource doesn't works correctly with ME Pin
Dmitry Chkov8-Aug-02 7:13
sussDmitry Chkov8-Aug-02 7:13 
GeneralFit a dialog into a View of a Window Pin
17-Apr-02 8:31
suss17-Apr-02 8:31 
GeneralIDsObjectPicker Pin
Daniel B.19-Feb-02 2:27
MemberDaniel B.19-Feb-02 2:27 
GeneralMillions and billions of warnings Pin
Christian Skovdal Andersen18-Feb-02 1:09
MemberChristian Skovdal Andersen18-Feb-02 1:09 
GeneralVC7 Compiler Error... Pin
Mario M.1-Jan-02 23:34
MemberMario M.1-Jan-02 23:34 
GeneralRe: VC7 Compiler Error... Pin
Igor Sukhov4-Feb-02 10:11
MemberIgor Sukhov4-Feb-02 10:11 
GeneralRe: VC7 Compiler Error... Pin
norsd6-Jun-04 1:37
Membernorsd6-Jun-04 1:37 
GeneralRe: VC7 Compiler Error... Pin
Igor Sukhov6-Jun-04 2:38
MemberIgor Sukhov6-Jun-04 2:38 
GeneralCommon Window Dialog Resizing Pin
13-Sep-01 22:43
suss13-Sep-01 22:43 
GeneralOne missing function. Pin
Steve Kemp27-Aug-01 22:06
MemberSteve Kemp27-Aug-01 22:06 
GeneralRe: One missing function. Pin
Igor Sukhov5-Sep-01 9:53
MemberIgor Sukhov5-Sep-01 9:53 
QuestionWhat about users? Pin
Gennady Oster12-Jun-01 20:26
MemberGennady Oster12-Jun-01 20:26 
AnswerRe: What about users? Pin
Igor Sukhov13-Jun-01 2:31
MemberIgor Sukhov13-Jun-01 2:31 
AnswerRe: What about users? Pin
Adam Frost30-Jul-02 10:18
sussAdam Frost30-Jul-02 10:18 
GeneralRe: What about users? Pin
Gennady Oster30-Jul-02 20:12
MemberGennady Oster30-Jul-02 20:12 
GeneralRe: What about users? Pin
Anonymous6-Aug-02 17:02
MemberAnonymous6-Aug-02 17:02 
QuestionWhat's New? Pin
Mario M.16-Apr-01 13:23
MemberMario M.16-Apr-01 13:23 
AnswerRe: What's New? Pin
Igor Sukhov16-Apr-01 20:40
MemberIgor Sukhov16-Apr-01 20:40 
GeneralRe: What's New? Pin
18-Apr-01 2:22
suss18-Apr-01 2:22 
GeneralRe: What's New? Pin
Igor Sukhov18-Apr-01 4:46
MemberIgor Sukhov18-Apr-01 4:46 
GeneralNice, but... Pin
2-Apr-01 13:30
suss2-Apr-01 13:30 
GeneralRe: Nice, but... Pin
Igor Sukhov3-Apr-01 5:32
MemberIgor Sukhov3-Apr-01 5:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.