Встроенный ресурс в C++

Вот мой взгляд на эту проблему. :) Я только начал изучать Python, поэтому я называю это:

Решение «Понятно для начинающих».

#Code without comments.

list1 = {'george':16,'amber':19, 'Garry':19}
search_age = raw_input("Provide age: ")
print
search_age = int(search_age)

listByAge = {}

for name, age in list1.items():
    if age == search_age:
        age = str(age)
        results = name + " " +age
        print results

        age2 = int(age)
        listByAge[name] = listByAge.get(name,0)+age2

print
print listByAge

.

#Code with comments.
#I've added another name with the same age to the list.
list1 = {'george':16,'amber':19, 'Garry':19}
#Original code.
search_age = raw_input("Provide age: ")
print
#Because raw_input gives a string, we need to convert it to int,
#so we can search the dictionary list with it.
search_age = int(search_age)

#Here we define another empty dictionary, to store the results in a more 
#permanent way.
listByAge = {}

#We use double variable iteration, so we get both the name and age 
#on each run of the loop.
for name, age in list1.items():
    #Here we check if the User Defined age = the age parameter 
    #for this run of the loop.
    if age == search_age:
        #Here we convert Age back to string, because we will concatenate it 
        #with the person's name. 
        age = str(age)
        #Here we concatenate.
        results = name + " " +age
        #If you want just the names and ages displayed you can delete
        #the code after "print results". If you want them stored, don't...
        print results

        #Here we create a second variable that uses the value of
        #the age for the current person in the list.
        #For example if "Anna" is "10", age2 = 10,
        #integer value which we can use in addition.
        age2 = int(age)
        #Here we use the method that checks or creates values in dictionaries.
        #We create a new entry for each name that matches the User Defined Age
        #with default value of 0, and then we add the value from age2.
        listByAge[name] = listByAge.get(name,0)+age2

#Here we print the new dictionary with the users with User Defined Age.
print
print listByAge

.

#Results
Running: *\test.py (Thu Jun 06 05:10:02 2013)

Provide age: 19

amber 19
Garry 19

{'amber': 19, 'Garry': 19}

Execution Successful!
7
задан Ismael 23 March 2016 в 17:42
поделиться

2 ответа

Я делаю описанный ранее @Sharptooth и использую следующий код для получения ресурса

HRSRC hResInfo = FindResource(hInstance, MAKEINTRESOURCE(resourceId), type);
HGLOBAL hRes = LoadResource(hInstance, hResInfo);
LPVOID memRes = LockResource(hRes);
DWORD sizeRes = SizeofResource(hInstance, hResInfo);

Здесь вам нужно изменить resourceId и тип .

Например, для файла .png я использую FindResource (hInstance, MAKEINTRESOURCE (bitmapId), _T («PNG»)); (строка «PNG» - это тип, который вы использовали при добавлении пользовательского ресурс).

9
ответ дан 6 December 2019 в 19:40
поделиться

Добавьте в проект файл ресурсов (.rc), поместите туда описание ресурса. При сборке проекта компилятор ресурсов скомпилирует файл ресурсов, а компоновщик свяжет скомпилированный файл ресурсов с результирующим исполняемым модулем.

Во время выполнения вызовите FindResource (), затем LoadResource () функции WinAPI.

4
ответ дан 6 December 2019 в 19:40
поделиться
Другие вопросы по тегам:

Похожие вопросы: