- Timestamp:
- Nov 18, 2000, 3:08:54 PM (25 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/user32/winicon.cpp
r4584 r4612 1 /* $Id: winicon.cpp,v 1.1 3 2000-11-10 10:14:50sandervl Exp $ */1 /* $Id: winicon.cpp,v 1.14 2000-11-18 14:08:54 sandervl Exp $ */ 2 2 /* 3 3 * Win32 Icon Code for OS/2 … … 33 33 static WORD ICON_HOTSPOT = 0x4242; 34 34 35 static HGLOBAL CURSORICON_CreateFromResource( HINSTANCE hInstance, HGLOBAL hObj, LPBYTE bits, 36 UINT cbSize, BOOL bIcon, DWORD dwVersion, 37 INT width, INT height, UINT loadflags ); 38 static HGLOBAL CURSORICON_Copy( HINSTANCE hInstance, HGLOBAL handle ); 35 static HGLOBAL CURSORICON_CreateFromResource( HINSTANCE hInstance, DWORD dwResGroupId, HGLOBAL hObj, LPBYTE bits, 36 UINT cbSize, BOOL bIcon, DWORD dwVersion, INT width, INT height, UINT loadflags ); 37 static HGLOBAL CURSORICON_Copy( HGLOBAL handle ); 39 38 static CURSORICONDIRENTRY *CURSORICON_FindBestIcon( CURSORICONDIR *dir, int width, 40 39 int height, int colors ); … … 62 61 info.bPlanes = bPlanes; 63 62 info.bBitsPerPixel = bBitsPixel; 64 63 info.hInstance = hInstance; 64 info.dwResGroupId = -1; 65 65 return CreateCursorIconIndirect(0, &info, lpANDbits, lpXORbits); 66 66 } … … 81 81 { 82 82 dprintf(("USER32: CreateIconFromResourceEx %X %d %d %X %d %d %X,", bits, cbSize, bIcon, dwVersion, width, height, cFlag)); 83 return CURSORICON_CreateFromResource(0, 0, bits, cbSize, bIcon, dwVersion, width, height, cFlag );83 return CURSORICON_CreateFromResource(0, -1, 0, bits, cbSize, bIcon, dwVersion, width, height, cFlag ); 84 84 } 85 85 /********************************************************************** … … 124 124 info->bPlanes = bmpXor.bmPlanes; 125 125 info->bBitsPerPixel = bmpXor.bmBitsPixel; 126 126 info->hInstance = -1; 127 info->dwResGroupId = -1; 127 128 /* Transfer the bitmap bits to the CURSORICONINFO structure */ 128 129 GetBitmapBits( iconinfo->hbmMask ,sizeAnd,(char*)(info + 1) ); … … 147 148 { 148 149 dprintf(("USER32: CopyIcon %x", hIcon)); 149 return CURSORICON_Copy( 0,hIcon );150 return CURSORICON_Copy( hIcon ); 150 151 } 151 152 /********************************************************************** … … 285 286 dirEntry = (CURSORICONDIRENTRY *)CURSORICON_FindBestIcon(dir, width, height, colors); 286 287 bits = ptr[dirEntry->wResId-1]; 287 h = CURSORICON_CreateFromResource( 0, 0, bits, dirEntry->dwBytesInRes,288 h = CURSORICON_CreateFromResource( 0, -1, 0, bits, dirEntry->dwBytesInRes, 288 289 !fCursor, 0x00030000, width, height, loadflags); 289 290 HeapFree( GetProcessHeap(), 0, dir ); … … 340 341 if (!(handle = LoadResource( hInstance, hRsrc ))) return 0; 341 342 bits = (LPBYTE)LockResource( handle ); 342 h = CURSORICON_CreateFromResource( 0, 0, bits, dwBytesInRes,343 h = CURSORICON_CreateFromResource( hInstance, (DWORD)name, 0, bits, dwBytesInRes, 343 344 !fCursor, 0x00030000, width, height, loadflags); 344 345 FreeResource( handle ); … … 459 460 * with cbSize parameter as well. 460 461 */ 461 static HGLOBAL CURSORICON_CreateFromResource( HINSTANCE hInstance, HGLOBAL hObj, LPBYTE bits,462 static HGLOBAL CURSORICON_CreateFromResource( HINSTANCE hInstance, DWORD dwResGroupId, HGLOBAL hObj, LPBYTE bits, 462 463 UINT cbSize, BOOL bIcon, DWORD dwVersion, 463 464 INT width, INT height, UINT loadflags ) … … 474 475 hotspot.x = ICON_HOTSPOT; 475 476 hotspot.y = ICON_HOTSPOT; 477 478 //testestest 479 dprintf(("CURSORICON_CreateFromResource %x %x %x %x %d", hInstance, dwResGroupId, hObj, bits, cbSize)); 476 480 477 481 if (dwVersion == 0x00020000) … … 696 700 info->bBitsPerPixel = bmpXor.bmBitsPixel; 697 701 info->hColorBmp = hXorBits; 702 info->hInstance = hInstance; 703 info->dwResGroupId = dwResGroupId; 698 704 699 705 /* Transfer the bitmap bits to the CURSORICONINFO structure */ … … 774 780 * Make a copy of a cursor or icon. 775 781 */ 776 static HGLOBAL CURSORICON_Copy( HINSTANCE hInstance, HGLOBAL handle)782 static HGLOBAL CURSORICON_Copy(HGLOBAL handle) 777 783 { 778 784 char *ptrOld, *ptrNew; … … 813 819 * 814 820 */ 815 816 821 HGLOBAL CURSORICON_ExtCopy(HGLOBAL Handle, UINT nType, 817 INT iDesiredCX, INT iDesiredCY,818 UINT nFlags)822 INT iDesiredCX, INT iDesiredCY, 823 UINT nFlags) 819 824 { 820 825 HGLOBAL hNew=0; … … 822 827 if(Handle == 0) 823 828 { 824 return 0; 825 } 826 827 hNew = CURSORICON_Copy(0, Handle); 829 return 0; 830 } 831 /* Best Fit or Monochrome */ 832 if( (nFlags & LR_COPYFROMRESOURCE 833 && (iDesiredCX > 0 || iDesiredCY > 0)) 834 || nFlags & LR_MONOCHROME) 835 { 836 int iTargetCY = iDesiredCY, iTargetCX = iDesiredCX; 837 LPBYTE pBits; 838 HANDLE hMem; 839 HRSRC hRsrc; 840 DWORD dwBytesInRes; 841 WORD wResId; 842 DWORD dwResGroupId; 843 HINSTANCE hInstance; 844 CURSORICONINFO *iconinfo; 845 CURSORICONDIR *pDir; 846 CURSORICONDIRENTRY *pDirEntry; 847 BOOL bIsIcon = (nType == IMAGE_ICON); 848 849 iconinfo = (CURSORICONINFO *)GlobalLock( Handle ); 850 if(iconinfo == NULL) { 851 dprintf(("ERROR: CURSORICON_ExtCopy invalid icon!")); 852 } 853 hInstance = iconinfo->hInstance; 854 dwResGroupId = iconinfo->dwResGroupId; 855 GlobalUnlock( Handle ); 856 if(dwResGroupId == -1) { 857 dprintf(("WARNING: no resource associated with icon/cursor -> copy without scaling!")); 858 hNew = CURSORICON_Copy(Handle); 859 } 860 861 /* Completing iDesiredCX CY for Monochrome Bitmaps if needed 862 */ 863 if(((nFlags & LR_MONOCHROME) && !(nFlags & LR_COPYFROMRESOURCE)) 864 || (iDesiredCX == 0 && iDesiredCY == 0)) 865 { 866 iDesiredCY = GetSystemMetrics(bIsIcon ? SM_CYICON : SM_CYCURSOR); 867 iDesiredCX = GetSystemMetrics(bIsIcon ? SM_CXICON : SM_CXCURSOR); 868 } 869 870 /* Retreive the CURSORICONDIRENTRY 871 */ 872 hRsrc = FindResourceW(hInstance, (LPWSTR)dwResGroupId, bIsIcon ? RT_GROUP_ICONW : RT_GROUP_CURSORW); 873 if(!hRsrc) return 0; 874 875 if (!(hMem = LoadResource( hInstance, hRsrc))) 876 { 877 return 0; 878 } 879 if (!(pDir = (CURSORICONDIR*)LockResource( hMem ))) 880 { 881 return 0; 882 } 883 884 /* Find Best Fit 885 */ 886 if(bIsIcon) 887 { 888 pDirEntry = (CURSORICONDIRENTRY *)CURSORICON_FindBestIcon( 889 pDir, iDesiredCX, iDesiredCY, 256); 890 } 891 else 892 { 893 pDirEntry = (CURSORICONDIRENTRY *)CURSORICON_FindBestCursor( 894 pDir, iDesiredCX, iDesiredCY, 1); 895 } 896 897 wResId = pDirEntry->wResId; 898 dwBytesInRes = pDirEntry->dwBytesInRes; 899 FreeResource(hMem); 900 901 /* Get the Best Fit 902 */ 903 if (!(hRsrc = FindResourceW(hInstance , 904 MAKEINTRESOURCEW(wResId), bIsIcon ? RT_ICONW : RT_CURSORW))) 905 { 906 return 0; 907 } 908 if (!(hMem = LoadResource( hInstance, hRsrc ))) 909 { 910 return 0; 911 } 912 913 pBits = (LPBYTE)LockResource( hMem ); 914 915 if(nFlags & LR_DEFAULTSIZE) 916 { 917 iTargetCY = GetSystemMetrics(SM_CYICON); 918 iTargetCX = GetSystemMetrics(SM_CXICON); 919 } 920 921 /* Create a New Icon with the proper dimension 922 */ 923 hNew = CURSORICON_CreateFromResource( hInstance, dwResGroupId, 0, pBits, dwBytesInRes, 924 bIsIcon, 0x00030000, iTargetCX, iTargetCY, nFlags); 925 FreeResource(hMem); 926 } 927 else 928 { 929 hNew = CURSORICON_Copy(Handle); 930 } 828 931 return hNew; 829 932 } … … 879 982 } 880 983 } 881 984 ////testestest 985 dprintf(("CURSORICON_FindBestIcon (%d,%d) %d -> %d", width, height, colors, (bestEntry) ? bestEntry->wResId : 0)); 882 986 return bestEntry; 883 987 }
Note:
See TracChangeset
for help on using the changeset viewer.