Een pictogram te gebruiken, moet uw toepassing een handvat om het pictogram te krijgen. In het volgende voorbeeld laat zien hoe twee verschillende pictogram handgrepen maken: één voor het pictogram standaard uitroepteken en één voor een aangepaste pictogram inbegrepen als resource in resource-definitie bestand van de toepassing.
HICON hIcon1; / / pictogram behandelen HICON hIcon2; / / pictogram verwerken / / maken van een standaard vraag pictogram.
hIcon1 = LoadIcon (NULL, IDI_QUESTION);
/ / Maak een aangepast pictogram op basis van een resource.
hIcon2 = LoadIcon (hinst, MAKEINTRESOURCE(460));
/ / Maak een aangepast pictogram tijdens runtime
Een toepassing aangepaste pictogrammen als middelen ten uitvoer moeten leggen en moeten gebruiken de LoadIcon of LoadImage functioneren, in plaats van de pictogrammen maken tijdens runtime. Deze aanpak vermijdt apparaat afhankelijkheid, vereenvoudigt de lokalisatie en kan toepassingen delen pictogram bitmaps. In het volgende voorbeeld wordt echter CreateIcon bij het maken van een aangepast pictogram tijdens runtime, op basis van bitmap bitmaskers; het is opgenomen om te illustreren hoe het systeem interpreteert pictogram bitmap bitmaskers.
HICON hIcon3; // icon handle
// Yang icon AND bitmask
BYTE ANDmaskIcon[] = {0xFF, 0xFF, 0xFF, 0xFF, // line 1
0xFF, 0xFF, 0xC3, 0xFF, // line 2
0xFF, 0xFF, 0x00, 0xFF, // line 3
0xFF, 0xFE, 0x00, 0x7F, // line 4
0xFF, 0xFC, 0x00, 0x1F, // line 5
0xFF, 0xF8, 0x00, 0x0F, // line 6
0xFF, 0xF8, 0x00, 0x0F, // line 7
0xFF, 0xF0, 0x00, 0x07, // line 8
0xFF, 0xF0, 0x00, 0x03, // line 9
0xFF, 0xE0, 0x00, 0x03, // line 10
0xFF, 0xE0, 0x00, 0x01, // line 11
0xFF, 0xE0, 0x00, 0x01, // line 12
0xFF, 0xF0, 0x00, 0x01, // line 13
0xFF, 0xF0, 0x00, 0x00, // line 14
0xFF, 0xF8, 0x00, 0x00, // line 15
0xFF, 0xFC, 0x00, 0x00, // line 16
0xFF, 0xFF, 0x00, 0x00, // line 17
0xFF, 0xFF, 0x80, 0x00, // line 18
0xFF, 0xFF, 0xE0, 0x00, // line 19
0xFF, 0xFF, 0xE0, 0x01, // line 20
0xFF, 0xFF, 0xF0, 0x01, // line 21
0xFF, 0xFF, 0xF0, 0x01, // line 22
0xFF, 0xFF, 0xF0, 0x03, // line 23
0xFF, 0xFF, 0xE0, 0x03, // line 24
0xFF, 0xFF, 0xE0, 0x07, // line 25
0xFF, 0xFF, 0xC0, 0x0F, // line 26
0xFF, 0xFF, 0xC0, 0x0F, // line 27
0xFF, 0xFF, 0x80, 0x1F, // line 28
0xFF, 0xFF, 0x00, 0x7F, // line 29
0xFF, 0xFC, 0x00, 0xFF, // line 30
0xFF, 0xF8, 0x03, 0xFF, // line 31
0xFF, 0xFC, 0x3F, 0xFF}; // line 32
// Yang icon XOR bitmask
BYTE XORmaskIcon[] = {0x00, 0x00, 0x00, 0x00, // line 1
0x00, 0x00, 0x00, 0x00, // line 2
0x00, 0x00, 0x00, 0x00, // line 3
0x00, 0x00, 0x00, 0x00, // line 4
0x00, 0x00, 0x00, 0x00, // line 5
0x00, 0x00, 0x00, 0x00, // line 6
0x00, 0x00, 0x00, 0x00, // line 7
0x00, 0x00, 0x38, 0x00, // line 8
0x00, 0x00, 0x7C, 0x00, // line 9
0x00, 0x00, 0x7C, 0x00, // line 10
0x00, 0x00, 0x7C, 0x00, // line 11
0x00, 0x00, 0x38, 0x00, // line 12
0x00, 0x00, 0x00, 0x00, // line 13
0x00, 0x00, 0x00, 0x00, // line 14
0x00, 0x00, 0x00, 0x00, // line 15
0x00, 0x00, 0x00, 0x00, // line 16
0x00, 0x00, 0x00, 0x00, // line 17
0x00, 0x00, 0x00, 0x00, // line 18
0x00, 0x00, 0x00, 0x00, // line 19
0x00, 0x00, 0x00, 0x00, // line 20
0x00, 0x00, 0x00, 0x00, // line 21
0x00, 0x00, 0x00, 0x00, // line 22
0x00, 0x00, 0x00, 0x00, // line 23
0x00, 0x00, 0x00, 0x00, // line 24
0x00, 0x00, 0x00, 0x00, // line 25
0x00, 0x00, 0x00, 0x00, // line 26
0x00, 0x00, 0x00, 0x00, // line 27
0x00, 0x00, 0x00, 0x00, // line 28
0x00, 0x00, 0x00, 0x00, // line 29
0x00, 0x00, 0x00, 0x00, // line 30
0x00, 0x00, 0x00, 0x00, // line 31
0x00, 0x00, 0x00, 0x00}; // line 32
hIcon3 = CreateIcon(hinst, // application instance
32, // icon width
32, // icon height
1, // number of XOR planes
1, // number of bits per pixel
ANDmaskIcon, // AND bitmask
XORmaskIcon); // XOR bitmask
CreateIcon wordt het pictogram maken, de volgende waarheid tabel toegepast op de en en XOR bitmaskers.
| EN bitmasker | XOR bitmasker | Weergave |
|---|---|---|
| 0 | 0 | Black |
| 0 | 1 | White |
| 1 | 0 | Scherm |
| 1 | 1 | Omgekeerde scherm |
Alvorens te sluiten, moet uw toepassing DestroyIcon gebruiken om te vernietigen elke pictogram die het gemaakt met CreateIconIndirect. Het is niet nodig te vernietigen pictogrammen gemaakt door andere functies.