0% found this document useful (0 votes)
3 views

Select computer dialog

The document describes the 'Select Computer' dialog, a tool for selecting computers within a Windows Network, implemented in both ATL and MFC versions. It provides detailed instructions on how to integrate the dialog into projects, including code samples for usage and customization options. The dialog mimics the functionality of the original Microsoft dialog, allowing single or multiple selections and supporting domain filtering.

Uploaded by

kate.moss
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Select computer dialog

The document describes the 'Select Computer' dialog, a tool for selecting computers within a Windows Network, implemented in both ATL and MFC versions. It provides detailed instructions on how to integrate the dialog into projects, including code samples for usage and customization options. The dialog mimics the functionality of the original Microsoft dialog, allowing single or multiple selections and supporting domain filtering.

Uploaded by

kate.moss
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

https://www.codeproject.

com/Articles/1038/quot-Select-Computer-quot-Dialog

"Select Computer" Dialog

Igor Sukhov

0.00/5 (No votes)

16 Apr 2001 1
The ATL and MFC versions of the class that implements a dialog for selecting users(computers) within the
Windows Network.
Download demo project (ATL version) - 22 Kb
Download demo project (MFC version) - 22 Kb
Download source (ATL version) - 10 Kb
Download source (MFC version) - 10 Kb

"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:

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

1
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:

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

#include "SelectComputerDialog.h"

ATL sample code :

Shrink ▲
//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

dlg.SingleSelection(IsDlgButtonChecked(IDC_CHECK_ALLOW_MULTIPLY_SELECTION)\
== BST_UNCHECKED);
dlg.NoALLDomain(IsDlgButtonChecked(IDC_CHECK_ALLOW_ALL_DOMAINS) == BST_UNCHECKED);

//show dialog

if (dlg.DoModal() == IDOK)
{
typedef basic_string<TCHAR> tstring;
tstring str;

2
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 :

Shrink ▲
//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

dlg.SingleSelection(!m_bAllowMultiplySelection);
dlg.NoALLDomain(!m_bAllowAllDomains);

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");
}

UpdateData(FALSE);
}

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.

3
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.

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.

4
 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.

You might also like