Click here to Skip to main content
15,851,453 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I want to create in MFC App a combobox void CSecondDlg::ComboExistUser() that adds users and groups from any folder -> properties -> security -> edit -> add -> advanced -> search now -> search Results. If some user or group is added previously, don't add additionally.

What I have tried:

I've tried to search tutorials in YT, but I didn't find any. Also, I wrote my message in AI, but it doesn't give me a good code that I wanted.
Posted
Updated 13-Sep-23 5:51am
v2

Your time would be better spent studying the documentation for the CComboBox Class | Microsoft Learn[^]. It is a simple matter to use one of the Findxxx methods to checlk if an entry already exists before adding it to the list.
 
Share this answer
 
I guess this is asking for a way to list users and rights groups via the Win32 API. One possibility would be this:
Enumerating Users: Enumerating Users - Win32 apps | Microsoft Learn[^]
 
Share this answer
 
The previous solutions have given information with useful references. I will point out a very, very handy method of the CComboBox class. That is SetItemDataPtr. If this were my problem, I would first assemble the collection of users, and then I would load the combo box. This method, SetItemDataPtr, lets you associate a pointer with an item in a combo box. There is another method, SetItemData, that lets you associate an integer with an item. These are used to make it easy to obtain a pointer to the data represented by the UI. That is done with the methods GetItemDataPtr and GetItemData. I highly recommend that you become familiar with these methods because they make it really easy to handle data in dialog classes. They are also available with the CListBox and CListCtrl classes so the same techniques can be used with all of these controls. The remarks about SetItemDataPtr in the docs linked previously explain why these methods are so useful :
Quote:
This pointer remains valid for the life of the combo box, even though the item's relative position within the combo box might change as items are added or removed. Hence, the item's index within the box can change, but the pointer remains reliable.
 
Share this answer
 
You should use a more structural approach and use some data model for your combobox. Like an array of strings or suitable objects. This model can you than search or modify and than make a complete reload.
Learning about the guts of the MFC is also a must do. So read the documentation to understand it.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900