Click here to Skip to main content
15,881,248 members
Articles / Programming Languages / C#

Using the Windows 2000/XP Object Selection Dialog

Rate me:
Please Sign up or sign in to vote.
4.92/5 (29 votes)
21 Nov 2005CPOL14 min read 250.2K   4.5K   57  
This article describes how to use the "Select Users or Groups" system dialog.
/*
	$Workfile:$
	$Header:$

	Copyright � 1997-2003 Friedrich Brunzema
	All rights reserved.

	@doc
	@module DSOP_Downlevel.cpp - Source for the Downlevel Dialog |

	

	Revision History:
	$Log$ 
*/
#include "stdafx.h"
#include "SelectUsersOrGroups.h"
#include "DSOP_Downlevel.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/*
    Begin and end of the id's of the checkboxes in the dialog
    Note: these have to be consecutive and match the User Interface.
    Also: the UI has been set up to match the ObjSel.h as shown below:

	The flFilter member of a downlevel scope can contain one or more of the
	following flags:

	DSOP_DOWNLEVEL_FILTER_USERS
		Include user objects.

	DSOP_DOWNLEVEL_FILTER_LOCAL_GROUPS
		Include all local groups.

	DSOP_DOWNLEVEL_FILTER_GLOBAL_GROUPS
		Include all global groups.

	DSOP_DOWNLEVEL_FILTER_COMPUTERS
		Include computer objects

	DSOP_DOWNLEVEL_FILTER_WORLD
		Include builtin security principal World (Everyone).

	DSOP_DOWNLEVEL_FILTER_AUTHENTICATED_USER
		Include builtin security principal Authenticated User.

	DSOP_DOWNLEVEL_FILTER_ANONYMOUS
		Include builtin security principal Anonymous.

	DSOP_DOWNLEVEL_FILTER_BATCH
		Include builtin security principal Batch.

	DSOP_DOWNLEVEL_FILTER_CREATOR_OWNER
		Include builtin security principal Creator Owner.

	DSOP_DOWNLEVEL_FILTER_CREATOR_GROUP
		Include builtin security principal Creator Group.

	DSOP_DOWNLEVEL_FILTER_DIALUP
		Include builtin security principal Dialup.

	DSOP_DOWNLEVEL_FILTER_INTERACTIVE
		Include builtin security principal Interactive.

	DSOP_DOWNLEVEL_FILTER_NETWORK
		Include builtin security principal Network.

	DSOP_DOWNLEVEL_FILTER_SERVICE
		Include builtin security principal Service.

	DSOP_DOWNLEVEL_FILTER_SYSTEM
		Include builtin security principal System.

	DSOP_DOWNLEVEL_FILTER_EXCLUDE_BUILTIN_GROUPS
		Exclude local builtin groups returned by groups enumeration.

	DSOP_DOWNLEVEL_FILTER_TERMINAL_SERVER
		Include builtin security principal Terminal Server.

	DSOP_DOWNLEVEL_FILTER_LOCAL_SERVICE
		Include builtin security principal Local Service

	DSOP_DOWNLEVEL_FILTER_NETWORK_SERVICE
		Include builtin security principal Network Service

	DSOP_DOWNLEVEL_FILTER_ALL_WELLKNOWN_SIDS
		Include all builtin security principals.


	#define DSOP_DOWNLEVEL_FILTER_USERS                   0x80000001
	#define DSOP_DOWNLEVEL_FILTER_LOCAL_GROUPS            0x80000002
	#define DSOP_DOWNLEVEL_FILTER_GLOBAL_GROUPS           0x80000004
	#define DSOP_DOWNLEVEL_FILTER_COMPUTERS               0x80000008
	#define DSOP_DOWNLEVEL_FILTER_WORLD                   0x80000010
	#define DSOP_DOWNLEVEL_FILTER_AUTHENTICATED_USER      0x80000020
	#define DSOP_DOWNLEVEL_FILTER_ANONYMOUS               0x80000040
	#define DSOP_DOWNLEVEL_FILTER_BATCH                   0x80000080
	#define DSOP_DOWNLEVEL_FILTER_CREATOR_OWNER           0x80000100
	#define DSOP_DOWNLEVEL_FILTER_CREATOR_GROUP           0x80000200
	#define DSOP_DOWNLEVEL_FILTER_DIALUP                  0x80000400
	#define DSOP_DOWNLEVEL_FILTER_INTERACTIVE             0x80000800
	#define DSOP_DOWNLEVEL_FILTER_NETWORK                 0x80001000
	#define DSOP_DOWNLEVEL_FILTER_SERVICE                 0x80002000
	#define DSOP_DOWNLEVEL_FILTER_SYSTEM                  0x80004000
	#define DSOP_DOWNLEVEL_FILTER_EXCLUDE_BUILTIN_GROUPS  0x80008000
	#define DSOP_DOWNLEVEL_FILTER_TERMINAL_SERVER         0x80010000
	#define DSOP_DOWNLEVEL_FILTER_ALL_WELLKNOWN_SIDS      0x80020000
	#define DSOP_DOWNLEVEL_FILTER_LOCAL_SERVICE           0x80040000
	#define DSOP_DOWNLEVEL_FILTER_NETWORK_SERVICE         0x80080000
	#define DSOP_DOWNLEVEL_FILTER_REMOTE_LOGON            0x80100000
*/

const UINT LOW_CHECKBOX = IDC_CHECK231;		// first checkbox
const UINT HI_CHECKBOX  = IDC_CHECK251;		// last checkbox 
										

CDSOP_Downlevel::CDSOP_Downlevel(CWnd* pParent /*=NULL*/)
	: CDialog(CDSOP_Downlevel::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDSOP_Downlevel)
	//}}AFX_DATA_INIT
}


void CDSOP_Downlevel::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDSOP_Downlevel)
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDSOP_Downlevel, CDialog)
	//{{AFX_MSG_MAP(CDSOP_Downlevel)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()



/*
	Name:				CDSOP_Downlevel::OnOK
	Type:				Protected
	Override:			No
	@mfunc
	Description:
		Called when we click OK,  validates the dlg
	@rdesc				void - n/a
*/
void CDSOP_Downlevel::OnOK() 
{
	int		i;			// loop counter
	int		ct;			// bit position
	DWORD	mask;		// mask
	BOOL	fCheck;		// bit
	
	// initialize
	ct = 0;
	m_flags = 0;

	// figure out the new bit pattern according to what the checkboxes say
	for (i=LOW_CHECKBOX; i<=HI_CHECKBOX; i++)
	{
		// get the checkbox state
		fCheck = ((CButton*)GetDlgItem(i))->GetCheck();

		// if we're checked, set the corresponding bit in the m_flags
		if (fCheck)
		{
			mask = (DWORD)1 << ct;
			m_flags |= mask;
		}
		++ct; // increment bit position
	}
	
	// call EndDialog()

	if ( m_flags != 0 ) 
		m_flags |= 0x80000000; 


	CDialog::OnOK();

}



/*
	Name:				CDSOP_Downlevel::OnInitDialog
	Type:				Protected
	Override:			No
	@mfunc
	Description:
		Called before the dialog is shown
	@rdesc				BOOL - true
*/
BOOL CDSOP_Downlevel::OnInitDialog() 
{
	int		i;			// loop counter
	int		ct;			// bit position count
	DWORD	mask;		// mask

	// initialize bit position
	ct = 0;

	// required by framework
	CDialog::OnInitDialog();
	
	// loop to set our checkboxes according to bit pattern in
	// the m_flags variable
	for (i=LOW_CHECKBOX; i<=HI_CHECKBOX; i++)
	{
		// figure out what the mask is
		mask = (DWORD)1 << ct;

		// if the bit is set, set the corresponding checkbox
		if (mask & m_flags)
		{
			((CButton*)GetDlgItem(i))->SetCheck(i);
		}
		else  // otherwise reset it
		{
			((CButton*)GetDlgItem(i))->SetCheck(0);
		}

		++ct; // increment bit position
	}
	return TRUE;

}

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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) AB SCIEX
Canada Canada
I was born and grew up in Northern Germany grew up in Quebec in a French Language environment. I finished High School in Fergus, Ontario. After a 4 year training as a Pipe Organ Builder in Germany, I returned to Canada to get a B.Sc. in Computer Science. I'm currently working for a company called AB SCIEX working on Mass Spectrometer Software, am married, and have three often wonderful children. What you believe in matters - I am a follower of Jesus Christ - we attend a German-Lutheran congregation in downtown Toronto.

Comments and Discussions