@@ -549,24 +549,16 @@ MakeIconOrCursorFromResource(
549
549
* Let the OS do the real work :)
550
550
*/
551
551
552
- hIcon = (HICON ) CreateIconFromResourceEx (lpIcon -> lpBits ,
553
- lpIcon -> dwNumBytes , isIcon , 0x00030000 ,
554
- (* (LPBITMAPINFOHEADER ) lpIcon -> lpBits ).biWidth ,
555
- (* (LPBITMAPINFOHEADER ) lpIcon -> lpBits ).biHeight /2 , 0 );
552
+ hIcon = (HICON )CreateIconFromResourceEx (lpIcon -> lpBits ,
553
+ lpIcon -> dwNumBytes , isIcon , 0x00030000 , 0 , 0 , 0 );
556
554
557
555
/*
558
- * It failed, odds are good we're on NT so try the non-Ex way.
556
+ * It failed, the non-Ex way might work as a fallback .
559
557
*/
560
558
561
559
if (hIcon == NULL ) {
562
- /*
563
- * We would break on NT if we try with a 16bpp image.
564
- */
565
-
566
- if (lpIcon -> lpbi -> bmiHeader .biBitCount != 16 ) {
567
- hIcon = CreateIconFromResource (lpIcon -> lpBits , lpIcon -> dwNumBytes ,
568
- isIcon , 0x00030000 );
569
- }
560
+ hIcon = CreateIconFromResource (lpIcon -> lpBits , lpIcon -> dwNumBytes ,
561
+ isIcon , 0x00030000 );
570
562
}
571
563
return hIcon ;
572
564
}
@@ -1104,6 +1096,50 @@ ReadIconFromFile(
1104
1096
*----------------------------------------------------------------------
1105
1097
*/
1106
1098
1099
+ static BOOL
1100
+ SetSizeAndColorFromHICON ( /* Helper for AdjustIconImagePointers */
1101
+ HICON hicon ,
1102
+ LPICONIMAGE lpImage )
1103
+ {
1104
+ ICONINFO info ;
1105
+ BOOL bRes ;
1106
+ BITMAP bmp ;
1107
+
1108
+ memset (& info , 0 , sizeof (info ));
1109
+
1110
+ bRes = GetIconInfo (hicon , & info );
1111
+ if (!bRes ) {
1112
+ return FALSE;
1113
+ }
1114
+
1115
+ if (info .hbmColor ) {
1116
+ const int nWrittenBytes = GetObject (info .hbmColor , sizeof (bmp ), & bmp );
1117
+
1118
+ if (nWrittenBytes > 0 ) {
1119
+ lpImage -> Width = bmp .bmWidth ;
1120
+ lpImage -> Height = bmp .bmHeight ;
1121
+ lpImage -> Colors = bmp .bmBitsPixel ;
1122
+ }
1123
+ } else if (info .hbmMask ) {
1124
+ // Icon has no color plane, image data stored in mask
1125
+ const int nWrittenBytes = GetObject (info .hbmMask , sizeof (bmp ), & bmp );
1126
+
1127
+ if (nWrittenBytes > 0 ) {
1128
+ lpImage -> Width = bmp .bmWidth ;
1129
+ lpImage -> Height = bmp .bmHeight / 2 ;
1130
+ lpImage -> Colors = 1 ;
1131
+ }
1132
+ }
1133
+
1134
+ if (info .hbmColor ) {
1135
+ DeleteObject (info .hbmColor );
1136
+ }
1137
+ if (info .hbmMask ) {
1138
+ DeleteObject (info .hbmMask );
1139
+ }
1140
+ return TRUE;
1141
+ }
1142
+
1107
1143
static BOOL
1108
1144
AdjustIconImagePointers (
1109
1145
LPICONIMAGE lpImage )
@@ -1123,24 +1159,10 @@ AdjustIconImagePointers(
1123
1159
lpImage -> lpbi = (LPBITMAPINFO ) lpImage -> lpBits ;
1124
1160
1125
1161
/*
1126
- * Width - simple enough.
1127
- */
1128
-
1129
- lpImage -> Width = lpImage -> lpbi -> bmiHeader .biWidth ;
1130
-
1131
- /*
1132
- * Icons are stored in funky format where height is doubled so account for
1133
- * that.
1162
+ * Width, height, and number of colors.
1134
1163
*/
1135
1164
1136
- lpImage -> Height = (lpImage -> lpbi -> bmiHeader .biHeight )/2 ;
1137
-
1138
- /*
1139
- * How many colors?
1140
- */
1141
-
1142
- lpImage -> Colors = lpImage -> lpbi -> bmiHeader .biPlanes
1143
- * lpImage -> lpbi -> bmiHeader .biBitCount ;
1165
+ SetSizeAndColorFromHICON (lpImage -> hIcon , lpImage );
1144
1166
1145
1167
/*
1146
1168
* XOR bits follow the header and color table.
@@ -1153,7 +1175,7 @@ AdjustIconImagePointers(
1153
1175
*/
1154
1176
1155
1177
lpImage -> lpAND = lpImage -> lpXOR +
1156
- lpImage -> Height * BytesPerLine ((LPBITMAPINFOHEADER ) lpImage -> lpbi );
1178
+ lpImage -> Height * BytesPerLine ((LPBITMAPINFOHEADER ) lpImage -> lpbi );
1157
1179
return TRUE;
1158
1180
}
1159
1181
@@ -1533,17 +1555,17 @@ ReadIconOrCursorFromFile(
1533
1555
}
1534
1556
1535
1557
/*
1536
- * Set the internal pointers appropriately.
1558
+ * Create the icon from the resource, and set the internal pointers appropriately.
1537
1559
*/
1538
1560
1561
+ lpIR -> IconImages [i ].hIcon =
1562
+ MakeIconOrCursorFromResource (& lpIR -> IconImages [i ], isIcon );
1539
1563
if (!AdjustIconImagePointers (& lpIR -> IconImages [i ])) {
1540
1564
Tcl_SetObjResult (interp , Tcl_NewStringObj (
1541
1565
"Error converting to internal format" , TCL_INDEX_NONE ));
1542
1566
Tcl_SetErrorCode (interp , "TK" , "WM" , "ICON" , "FORMAT" , NULL );
1543
1567
goto readError ;
1544
1568
}
1545
- lpIR -> IconImages [i ].hIcon =
1546
- MakeIconOrCursorFromResource (& lpIR -> IconImages [i ], isIcon );
1547
1569
}
1548
1570
1549
1571
/*
0 commit comments