Weet iemand toevallig hoe je een HICON kan opslaan naar een ico of bmp file? Of gewoon bij de pixeldata kan komen?
ik heb een beetje zitten zoeken in de msdn, maar volgens mij is er geen functie voor
wat je natuurlijk wel kan doen, hoewel het erg omslachtig is, is een memory device context maken (met CreateCompatibleDC), dan je icon erop tekenen met DrawIcon, en dan de bits opvragen met GetDIBits
wat je natuurlijk wel kan doen, hoewel het erg omslachtig is, is een memory device context maken (met CreateCompatibleDC), dan je icon erop tekenen met DrawIcon, en dan de bits opvragen met GetDIBits
Give a man a game and he'll have fun for a day. Teach a man to make games and he'll never have fun again.
Das een beetje een omweg, waarschijnelijk wel de enige manier. MS heeft wel functies voor het laden van icons and bitmaps, maar andersom nietOp woensdag 09 januari 2002 21:42 schreef OiSyN het volgende:
ik heb een beetje zitten zoeken in de msdn, maar volgens mij is er geen functie voor
wat je natuurlijk wel kan doen, hoewel het erg omslachtig is, is een memory device context maken (met CreateCompatibleDC), dan je icon erop tekenen met DrawIcon, en dan de bits opvragen met GetDIBits
Uh in VCL kun je wel een TIcon assignen aan een TBitmap en daarin dan de pixeldata verneuken. Ik gok zo dat dat intern exact doet wat je nu zegt. En de omslachtigheid valt best mee, CreateCompatibleDC en GetDIBits zijn verneukend snel.Op woensdag 09 januari 2002 21:42 schreef OiSyN het volgende:
wat je natuurlijk wel kan doen, hoewel het erg omslachtig is, is een memory device context maken (met CreateCompatibleDC), dan je icon erop tekenen met DrawIcon, en dan de bits opvragen met GetDIBits
Ik zal ook eens ff zoeken want het lijkt me toch sterk dat er geen simpele manier is om direct een icon te verklooien.
Verwijderd
http://codeguru.earthweb.com/cgi-bin/bbs/wt/showpost.pl?Board=vc&Number=323891&page=9&view=collapsed&sb=5
Kort en bondig is de code niet, maar als het werkt....
Kort en bondig is de code niet, maar als het werkt....
Gezocht en gevonden in de API: 
GetIconInfo
The GetIconInfo function retrieves information about the specified icon or cursor.
fIcon : Specifies whether this structure defines an icon or a cursor. A value of TRUE specifies an icon; FALSE specifies a cursor.
hbmMask : Specifies the icon bitmask bitmap. If this structure defines a black and white icon, this bitmask is formatted so that the upper half is the icon AND bitmask and the lower half is the icon XOR bitmask. Under this condition, the height should be an even multiple of two. If this structure defines a color icon, this mask only defines the AND bitmask of the icon.
hbmColor : Handle to the icon color bitmap. This member can be optional if this structure defines a black and white icon. The AND bitmask of hbmMask is applied with the SRCAND flag to the destination; subsequently, the color bitmap is applied (using XOR) to the destination by using the SRCINVERT flag.
GetIconInfo
The GetIconInfo function retrieves information about the specified icon or cursor.
code:
1
2
3
4
5
6
7
8
9
10
11
12
| BOOL GetIconInfo(
HICON hIcon, // icon handle
PICONINFO piconinfo // icon structure
);
typedef struct _ICONINFO {
BOOL fIcon;
DWORD xHotspot;
DWORD yHotspot;
HBITMAP hbmMask;
HBITMAP hbmColor;
} ICONINFO; |
fIcon : Specifies whether this structure defines an icon or a cursor. A value of TRUE specifies an icon; FALSE specifies a cursor.
hbmMask : Specifies the icon bitmask bitmap. If this structure defines a black and white icon, this bitmask is formatted so that the upper half is the icon AND bitmask and the lower half is the icon XOR bitmask. Under this condition, the height should be an even multiple of two. If this structure defines a color icon, this mask only defines the AND bitmask of the icon.
hbmColor : Handle to the icon color bitmap. This member can be optional if this structure defines a black and white icon. The AND bitmask of hbmMask is applied with the SRCAND flag to the destination; subsequently, the color bitmap is applied (using XOR) to the destination by using the SRCINVERT flag.
ik ging daar voorbij en dacht bij mezelf: nee, dat zal het niet zijn
Give a man a game and he'll have fun for a day. Teach a man to make games and he'll never have fun again.
Ah.... en dan met GetDIBits de bitjes uit de HBITMAP peuteren....... In FOX (www.fox-toolkit.org) gaat het toch allemaal wat makkelijkerOp woensdag 09 januari 2002 23:36 schreef curry684 het volgende:
Gezocht en gevonden in de API:
GetIconInfo
The GetIconInfo function retrieves information about the specified icon or cursor.
code:
1 2 3 4 5 6 7 8 9 10 11 12BOOL GetIconInfo( HICON hIcon, // icon handle PICONINFO piconinfo // icon structure ); typedef struct _ICONINFO { BOOL fIcon; DWORD xHotspot; DWORD yHotspot; HBITMAP hbmMask; HBITMAP hbmColor; } ICONINFO;
fIcon : Specifies whether this structure defines an icon or a cursor. A value of TRUE specifies an icon; FALSE specifies a cursor.
hbmMask : Specifies the icon bitmask bitmap. If this structure defines a black and white icon, this bitmask is formatted so that the upper half is the icon AND bitmask and the lower half is the icon XOR bitmask. Under this condition, the height should be an even multiple of two. If this structure defines a color icon, this mask only defines the AND bitmask of the icon.
hbmColor : Handle to the icon color bitmap. This member can be optional if this structure defines a black and white icon. The AND bitmask of hbmMask is applied with the SRCAND flag to the destination; subsequently, the color bitmap is applied (using XOR) to the destination by using the SRCINVERT flag.
VCL:Op donderdag 10 januari 2002 01:22 schreef vicz het volgende:
Ah.... en dan met GetDIBits de bitjes uit de HBITMAP peuteren....... In FOX (www.fox-toolkit.org) gaat het toch allemaal wat makkelijker
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
| TIcon* l_Icon = new TIcon;
TBitmap* l_Bitmap = new TBitmap;
l_Icon->LoadFromFile("MyFirstIcon.ico");
l_Bitmap->Assign(l_Icon);
l_Bitmap->Canvas->Pen->Color = clBlack;
l_Bitmap->Canvas->MoveTo(2, 2);
l_Bitmap->Canvas->LineTo(14, 14);
l_Bitmap->SaveToFile("MyBitmap.bmp");
l_Icon->Assign(l_Bitmap);
l_Icon->SaveToFile("MyIcon.ico"); |
Wel langzamer dan API choppen... het is maar waar je voor kiest
Ik moet bekennen dat ik ook eerst de ICONINFO struct vond en daarna pas de bijbehorende functieOp woensdag 09 januari 2002 23:58 schreef OiSyN het volgende:
ik ging daar voorbij en dacht bij mezelf: nee, dat zal het niet zijn
Ja... icon loaden was geen probleem.... Daar heeft FOX ook mooie functies voor. Het probleem zat in hem, dat ik ExtractIconEx gebruik om icons uit dll/exe los te peuteren...dan krijg je een HICON voorgeschoteld...Op donderdag 10 januari 2002 03:03 schreef curry684 het volgende:
[..]
VCL:
code:
1 2 3 4 5 6 7 8 9 10 11 12 13TIcon* l_Icon = new TIcon; TBitmap* l_Bitmap = new TBitmap; l_Icon->LoadFromFile("MyFirstIcon.ico"); l_Bitmap->Assign(l_Icon); l_Bitmap->Canvas->Pen->Color = clBlack; l_Bitmap->Canvas->MoveTo(2, 2); l_Bitmap->Canvas->LineTo(14, 14); l_Bitmap->SaveToFile("MyBitmap.bmp"); l_Icon->Assign(l_Bitmap); l_Icon->SaveToFile("MyIcon.ico");
Wel langzamer dan API choppen... het is maar waar je voor kiest
Op donderdag 10 januari 2002 15:31 schreef vicz het volgende:
[..]
Ja... icon loaden was geen probleem.... Daar heeft FOX ook mooie functies voor. Het probleem zat in hem, dat ik ExtractIconEx gebruik om icons uit dll/exe los te peuteren...dan krijg je een HICON voorgeschoteld...
code:
1
2
3
| TIcon* l_MyIcon = new TIcon; l_MyIcon->Handle = ExtractIconExe(...); |
Klaar
In een platform onafhankelijke toolkit worden er geen OS dependent handles gebruikt...Op zaterdag 12 januari 2002 11:40 schreef curry684 het volgende:
[..]
code:
1 2 3 TIcon* l_MyIcon = new TIcon; l_MyIcon->Handle = ExtractIconExe(...);
Klaar
In een goed geschreven platform onafhankelijke toolkit zou een OS-specifieke functie een vriendelijke exception gooien met als tekst 'This function is not available on this operating system' als het op een ander OS wordt uitgevoerd.Op zaterdag 12 januari 2002 14:08 schreef vicz het volgende:
In een platform onafhankelijke toolkit worden er geen OS dependent handles gebruikt...
#ifdef Win32 en zo doen het zonodig ook goed
Sowieso als een open framework de mogelijkheid tot direct hacken dichtmetselt is het wat mij betreft al troep. Je kunt nooit alles encapsuleren wat de gebruiker mogelijkerwijs zou willen...
Wat een onzin, je wilt zo juist min mogelijk met OS afhankelijke functies te maken hebben. Wat heb je nou aan 'This function is not available on this operating system'. Als gebruiker heb je er niks aan en als programmeur ook niet sinds je op alle platformen het programma het zelfde wil laten werken.Op zaterdag 12 januari 2002 16:03 schreef curry684 het volgende:
[..]
In een goed geschreven platform onafhankelijke toolkit zou een OS-specifieke functie een vriendelijke exception gooien met als tekst 'This function is not available on this operating system' als het op een ander OS wordt uitgevoerd.
#ifdef Win32 en zo doen het zonodig ook goed
Als je advanced features wil gebruiken wordt je code vrij per definitie platformafhankelijk. Moet je maar een #ifdef gebruiken die in je programma die bonus-optie uitschakelt, of er op een andere manier omheen werken.Op zaterdag 12 januari 2002 16:23 schreef vicz het volgende:
Wat een onzin, je wilt zo juist min mogelijk met OS afhankelijke functies te maken hebben. Wat heb je nou aan 'This function is not available on this operating system'. Als gebruiker heb je er niks aan en als programmeur ook niet sinds je op alle platformen het programma het zelfde wil laten werken.
Platformonafhankelijkheid zonder #ifdef's is een illusie.
Pagina: 1