984 * Method: setNativeIcon 985 * Signature: (I[B[IIIII)V 986 */ 987 JNIEXPORT void JNICALL 988 Java_sun_awt_windows_WTrayIconPeer_setNativeIcon(JNIEnv *env, jobject self, 989 jintArray intRasterData, jbyteArray andMask, 990 jint nSS, jint nW, jint nH) 991 { 992 TRY; 993 994 int length = env->GetArrayLength(andMask); 995 jbyte *andMaskPtr = new jbyte[length]; 996 997 env->GetByteArrayRegion(andMask, 0, length, andMaskPtr); 998 999 HBITMAP hMask = ::CreateBitmap(nW, nH, 1, 1, (BYTE *)andMaskPtr); 1000 // ::GdiFlush(); 1001 1002 delete[] andMaskPtr; 1003 1004 jint *intRasterDataPtr = NULL; 1005 HBITMAP hColor = NULL; 1006 try { 1007 intRasterDataPtr = (jint *)env->GetPrimitiveArrayCritical(intRasterData, 0); 1008 if (intRasterDataPtr == NULL) { 1009 ::DeleteObject(hMask); 1010 return; 1011 } 1012 hColor = AwtTrayIcon::CreateBMP(NULL, (int *)intRasterDataPtr, nSS, nW, nH); 1013 } catch (...) { 1014 if (intRasterDataPtr != NULL) { 1015 env->ReleasePrimitiveArrayCritical(intRasterData, intRasterDataPtr, 0); 1016 } 1017 ::DeleteObject(hMask); 1018 throw; 1019 } 1020 1021 env->ReleasePrimitiveArrayCritical(intRasterData, intRasterDataPtr, 0); 1022 intRasterDataPtr = NULL; 1023 1024 HICON hIcon = NULL; 1025 1026 if (hMask && hColor) { 1027 ICONINFO icnInfo; 1028 memset(&icnInfo, 0, sizeof(ICONINFO)); 1029 icnInfo.hbmMask = hMask; 1030 icnInfo.hbmColor = hColor; 1031 icnInfo.fIcon = TRUE; 1032 icnInfo.xHotspot = TRAY_ICON_X_HOTSPOT; 1033 icnInfo.yHotspot = TRAY_ICON_Y_HOTSPOT; 1034 1035 hIcon = ::CreateIconIndirect(&icnInfo); 1036 } 1037 ::DeleteObject(hColor); 1038 ::DeleteObject(hMask); 1039 1040 ////////////////////////////////////////// 1041 1042 SetIconStruct *sis = new SetIconStruct; | 984 * Method: setNativeIcon 985 * Signature: (I[B[IIIII)V 986 */ 987 JNIEXPORT void JNICALL 988 Java_sun_awt_windows_WTrayIconPeer_setNativeIcon(JNIEnv *env, jobject self, 989 jintArray intRasterData, jbyteArray andMask, 990 jint nSS, jint nW, jint nH) 991 { 992 TRY; 993 994 int length = env->GetArrayLength(andMask); 995 jbyte *andMaskPtr = new jbyte[length]; 996 997 env->GetByteArrayRegion(andMask, 0, length, andMaskPtr); 998 999 HBITMAP hMask = ::CreateBitmap(nW, nH, 1, 1, (BYTE *)andMaskPtr); 1000 // ::GdiFlush(); 1001 1002 delete[] andMaskPtr; 1003 1004 /* Copy the raster data because GDI may fail on some Java heap 1005 * allocated memory. 1006 */ 1007 length = env->GetArrayLength(intRasterData); 1008 jint *intRasterDataPtr = new jint[length]; 1009 HBITMAP hColor = NULL; 1010 try { 1011 env->GetIntArrayRegion(intRasterData, 0, length, intRasterDataPtr); 1012 hColor = AwtTrayIcon::CreateBMP(NULL, (int *)intRasterDataPtr, nSS, nW, nH); 1013 } catch (...) { 1014 delete[] intRasterDataPtr; 1015 ::DeleteObject(hMask); 1016 throw; 1017 } 1018 delete[] intRasterDataPtr; 1019 1020 HICON hIcon = NULL; 1021 1022 if (hMask && hColor) { 1023 ICONINFO icnInfo; 1024 memset(&icnInfo, 0, sizeof(ICONINFO)); 1025 icnInfo.hbmMask = hMask; 1026 icnInfo.hbmColor = hColor; 1027 icnInfo.fIcon = TRUE; 1028 icnInfo.xHotspot = TRAY_ICON_X_HOTSPOT; 1029 icnInfo.yHotspot = TRAY_ICON_Y_HOTSPOT; 1030 1031 hIcon = ::CreateIconIndirect(&icnInfo); 1032 } 1033 ::DeleteObject(hColor); 1034 ::DeleteObject(hMask); 1035 1036 ////////////////////////////////////////// 1037 1038 SetIconStruct *sis = new SetIconStruct; |