Changeset 855 for trunk/src/shell32/new/shell.cpp
- Timestamp:
- Sep 7, 1999, 1:13:19 PM (26 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/shell32/new/shell.cpp
r815 r855 19 19 //#include "wine/shell16.h" 20 20 #include "winerror.h" 21 #include "file.h"21 //#include "file.h" 22 22 #include "heap.h" 23 23 #include "ldt.h" … … 30 30 #include "debugtools.h" 31 31 #include "winreg.h" 32 #include "syslevel.h"32 //#include "syslevel.h" 33 33 #include "imagelist.h" 34 34 … … 147 147 148 148 /************************************************************************* 149 * DragAcceptFiles16 [SHELL.9]150 */151 void WINAPI DragAcceptFiles16(HWND16 hWnd, BOOL16 b)152 {153 DragAcceptFiles(hWnd, b);154 }155 156 /*************************************************************************157 149 * SHELL_DragQueryFile [internal] 158 150 * … … 242 234 return i; 243 235 } 244 /*************************************************************************245 * DragQueryFile16 [SHELL.11]246 */247 UINT16 WINAPI DragQueryFile16(HDROP16 hDrop, WORD wFile, LPSTR lpszFile,248 WORD wLength)249 { /* hDrop is a global memory block allocated with GMEM_SHARE250 * with DROPFILESTRUCT as a header and filenames following251 * it, zero length filename is in the end */252 253 LPDROPFILESTRUCT16 lpDropFileStruct;254 LPSTR lpCurrent;255 WORD i;256 257 TRACE_(shell)("(%04x, %x, %p, %u)\n", hDrop,wFile,lpszFile,wLength);258 259 lpDropFileStruct = (LPDROPFILESTRUCT16) GlobalLock16(hDrop);260 if(!lpDropFileStruct)261 return 0;262 263 lpCurrent = (LPSTR) lpDropFileStruct + lpDropFileStruct->wSize;264 265 i = (WORD)SHELL_DragQueryFile(lpCurrent, NULL, wFile==0xffff?0xffffffff:wFile,266 lpszFile, NULL, wLength);267 GlobalUnlock16(hDrop);268 return i;269 }270 271 236 272 237 … … 410 375 411 376 /* Check registry */ 412 if (RegQueryValue 16( HKEY_CLASSES_ROOT, tmpext, filetype,377 if (RegQueryValueA( HKEY_CLASSES_ROOT, tmpext, filetype, 413 378 &filetypelen ) == ERROR_SUCCESS ) 414 379 { … … 421 386 strcat( filetype, "\\command" ); 422 387 423 if (RegQueryValue 16( HKEY_CLASSES_ROOT, filetype, command,388 if (RegQueryValueA( HKEY_CLASSES_ROOT, filetype, command, 424 389 &commandlen ) == ERROR_SUCCESS ) 425 390 { … … 471 436 } 472 437 473 /*************************************************************************474 * ShellExecute16 [SHELL.20]475 */476 HINSTANCE16 WINAPI ShellExecute16( HWND16 hWnd, LPCSTR lpOperation,477 LPCSTR lpFile, LPCSTR lpParameters,478 LPCSTR lpDirectory, INT16 iShowCmd )479 { HINSTANCE16 retval=31;480 char old_dir[1024];481 char cmd[256];482 483 TRACE_(shell)("(%04x,'%s','%s','%s','%s',%x)\n",484 hWnd, lpOperation ? lpOperation:"<null>", lpFile ? lpFile:"<null>",485 lpParameters ? lpParameters : "<null>",486 lpDirectory ? lpDirectory : "<null>", iShowCmd);487 488 if (lpFile==NULL) return 0; /* should not happen */489 if (lpOperation==NULL) /* default is open */490 lpOperation="open";491 492 if (lpDirectory)493 { GetCurrentDirectoryA( sizeof(old_dir), old_dir );494 SetCurrentDirectoryA( lpDirectory );495 }496 497 retval = SHELL_FindExecutable( lpFile, lpOperation, cmd );498 499 if (retval > 32) /* Found */500 {501 if (lpParameters)502 {503 strcat(cmd," ");504 strcat(cmd,lpParameters);505 }506 507 TRACE_(shell)("starting %s\n",cmd);508 SYSLEVEL_ReleaseWin16Lock();509 retval = WinExec( cmd, iShowCmd );510 SYSLEVEL_RestoreWin16Lock();511 }512 if (lpDirectory)513 SetCurrentDirectoryA( old_dir );514 return retval;515 }516 517 /*************************************************************************518 * FindExecutable16 (SHELL.21)519 */520 HINSTANCE16 WINAPI FindExecutable16( LPCSTR lpFile, LPCSTR lpDirectory,521 LPSTR lpResult )522 { return (HINSTANCE16)FindExecutableA( lpFile, lpDirectory, lpResult );523 }524 525 526 /*************************************************************************527 * AboutDlgProc16 (SHELL.33)528 */529 BOOL16 WINAPI AboutDlgProc16( HWND16 hWnd, UINT16 msg, WPARAM16 wParam,530 LPARAM lParam )531 { return AboutDlgProc( hWnd, msg, wParam, lParam );532 }533 534 535 /*************************************************************************536 * ShellAbout16 (SHELL.22)537 */538 BOOL16 WINAPI ShellAbout16( HWND16 hWnd, LPCSTR szApp, LPCSTR szOtherStuff,539 HICON16 hIcon )540 { return ShellAboutA( hWnd, szApp, szOtherStuff, hIcon );541 }542 438 543 439 /************************************************************************* … … 585 481 size = ne_header.rname_tab_offset - ne_header.resource_tab_offset; 586 482 483 //@@@PH no NE support 484 #if 0 587 485 if( size > sizeof(NE_TYPEINFO) ) 588 486 { pTypeInfo = (BYTE*)HeapAlloc( GetProcessHeap(), 0, size); … … 595 493 } 596 494 } 495 #endif 496 597 497 *retptr = pTypeInfo; 598 498 return IMAGE_OS2_SIGNATURE; … … 601 501 } 602 502 603 /*************************************************************************604 * SHELL_LoadResource605 */606 static HGLOBAL16 SHELL_LoadResource(HINSTANCE16 hInst, HFILE hFile, NE_NAMEINFO* pNInfo, WORD sizeShift)607 { BYTE* ptr;608 HGLOBAL16 handle = DirectResAlloc16( hInst, 0x10, (DWORD)pNInfo->length << sizeShift);609 610 TRACE_(shell)("\n");611 612 if( (ptr = (BYTE*)GlobalLock16( handle )) )613 { _llseek( hFile, (DWORD)pNInfo->offset << sizeShift, SEEK_SET);614 _lread( hFile, (char*)ptr, pNInfo->length << sizeShift);615 return handle;616 }617 return 0;618 }619 620 /*************************************************************************621 * ICO_LoadIcon622 */623 static HGLOBAL16 ICO_LoadIcon(HINSTANCE16 hInst, HFILE hFile, LPicoICONDIRENTRY lpiIDE)624 { BYTE* ptr;625 HGLOBAL16 handle = DirectResAlloc16( hInst, 0x10, lpiIDE->dwBytesInRes);626 TRACE_(shell)("\n");627 if( (ptr = (BYTE*)GlobalLock16( handle )) )628 { _llseek( hFile, lpiIDE->dwImageOffset, SEEK_SET);629 _lread( hFile, (char*)ptr, lpiIDE->dwBytesInRes);630 return handle;631 }632 return 0;633 }634 635 /*************************************************************************636 * ICO_GetIconDirectory637 *638 * Read .ico file and build phony ICONDIR struct for GetIconID639 */640 static HGLOBAL16 ICO_GetIconDirectory(HINSTANCE16 hInst, HFILE hFile, LPicoICONDIR* lplpiID )641 { WORD id[3]; /* idReserved, idType, idCount */642 LPicoICONDIR lpiID;643 int i;644 645 TRACE_(shell)("\n");646 _llseek( hFile, 0, SEEK_SET );647 if( _lread(hFile,(char*)id,sizeof(id)) != sizeof(id) ) return 0;648 649 /* check .ICO header650 *651 * - see http://www.microsoft.com/win32dev/ui/icons.htm652 */653 654 if( id[0] || id[1] != 1 || !id[2] ) return 0;655 656 i = id[2]*sizeof(icoICONDIRENTRY) ;657 658 lpiID = (LPicoICONDIR)HeapAlloc( GetProcessHeap(), 0, i + sizeof(id));659 660 if( _lread(hFile,(char*)lpiID->idEntries,i) == i )661 { HGLOBAL16 handle = DirectResAlloc16( hInst, 0x10,662 id[2]*sizeof(CURSORICONDIRENTRY) + sizeof(id) );663 if( handle )664 { CURSORICONDIR* lpID = (CURSORICONDIR*)GlobalLock16( handle );665 lpID->idReserved = lpiID->idReserved = id[0];666 lpID->idType = lpiID->idType = id[1];667 lpID->idCount = lpiID->idCount = id[2];668 for( i=0; i < lpiID->idCount; i++ )669 { memcpy((void*)(lpID->idEntries + i),670 (void*)(lpiID->idEntries + i), sizeof(CURSORICONDIRENTRY) - 2);671 lpID->idEntries[i].wResId = i;672 }673 *lplpiID = lpiID;674 return handle;675 }676 }677 /* fail */678 679 HeapFree( GetProcessHeap(), 0, lpiID);680 return 0;681 }682 683 /*************************************************************************684 * InternalExtractIcon [SHELL.39]685 *686 * This abortion is called directly by Progman687 */688 HGLOBAL16 WINAPI InternalExtractIcon16(HINSTANCE16 hInstance,689 LPCSTR lpszExeFileName, UINT16 nIconIndex, WORD n )690 { HGLOBAL16 hRet = 0;691 HGLOBAL16* RetPtr = NULL;692 LPBYTE pData;693 OFSTRUCT ofs;694 DWORD sig;695 HFILE hFile = OpenFile( lpszExeFileName, &ofs, OF_READ );696 UINT16 iconDirCount = 0,iconCount = 0;697 LPBYTE peimage;698 HANDLE fmapping;699 700 TRACE_(shell)("(%04x,file %s,start %d,extract %d\n",701 hInstance, lpszExeFileName, nIconIndex, n);702 703 if( hFile == HFILE_ERROR || !n )704 return 0;705 706 hRet = GlobalAlloc16( GMEM_FIXED | GMEM_ZEROINIT, sizeof(HICON16)*n);707 RetPtr = (HICON16*)GlobalLock16(hRet);708 709 *RetPtr = (n == 0xFFFF)? 0: 1; /* error return values */710 711 sig = SHELL_GetResourceTable(hFile,&pData);712 713 if( sig==IMAGE_OS2_SIGNATURE || sig==1 ) /* .ICO file */714 { HICON16 hIcon = 0;715 NE_TYPEINFO* pTInfo = (NE_TYPEINFO*)(pData + 2);716 NE_NAMEINFO* pIconStorage = NULL;717 NE_NAMEINFO* pIconDir = NULL;718 LPicoICONDIR lpiID = NULL;719 720 if( pData == (BYTE*)-1 )721 { hIcon = ICO_GetIconDirectory(hInstance, hFile, &lpiID); /* check for .ICO file */722 if( hIcon )723 { iconDirCount = 1; iconCount = lpiID->idCount;724 }725 }726 else while( pTInfo->type_id && !(pIconStorage && pIconDir) )727 { if( pTInfo->type_id == NE_RSCTYPE_GROUP_ICON ) /* find icon directory and icon repository */728 { iconDirCount = pTInfo->count;729 pIconDir = ((NE_NAMEINFO*)(pTInfo + 1));730 TRACE_(shell)("\tfound directory - %i icon families\n", iconDirCount);731 }732 if( pTInfo->type_id == NE_RSCTYPE_ICON )733 { iconCount = pTInfo->count;734 pIconStorage = ((NE_NAMEINFO*)(pTInfo + 1));735 TRACE_(shell)("\ttotal icons - %i\n", iconCount);736 }737 pTInfo = (NE_TYPEINFO *)((char*)(pTInfo+1)+pTInfo->count*sizeof(NE_NAMEINFO));738 }739 740 /* load resources and create icons */741 742 if( (pIconStorage && pIconDir) || lpiID )743 { if( nIconIndex == (UINT16)-1 )744 { RetPtr[0] = iconDirCount;745 }746 else if( nIconIndex < iconDirCount )747 { UINT16 i, icon;748 if( n > iconDirCount - nIconIndex )749 n = iconDirCount - nIconIndex;750 751 for( i = nIconIndex; i < nIconIndex + n; i++ )752 { /* .ICO files have only one icon directory */753 754 if( lpiID == NULL )755 hIcon = SHELL_LoadResource( hInstance, hFile, pIconDir + i, *(WORD*)pData );756 RetPtr[i-nIconIndex] = GetIconID16( hIcon, 3 );757 GlobalFree16(hIcon);758 }759 760 for( icon = nIconIndex; icon < nIconIndex + n; icon++ )761 { hIcon = 0;762 if( lpiID )763 { hIcon = ICO_LoadIcon( hInstance, hFile, lpiID->idEntries + RetPtr[icon-nIconIndex]);764 }765 else766 { for( i = 0; i < iconCount; i++ )767 { if( pIconStorage[i].id == (RetPtr[icon-nIconIndex] | 0x8000) )768 { hIcon = SHELL_LoadResource( hInstance, hFile, pIconStorage + i,*(WORD*)pData );769 }770 }771 }772 if( hIcon )773 { RetPtr[icon-nIconIndex] = LoadIconHandler16( hIcon, TRUE );774 FarSetOwner16( RetPtr[icon-nIconIndex], GetExePtr(hInstance) );775 }776 else777 { RetPtr[icon-nIconIndex] = 0;778 }779 }780 }781 }782 if( lpiID )783 HeapFree( GetProcessHeap(), 0, lpiID);784 else785 HeapFree( GetProcessHeap(), 0, pData);786 }787 788 if( sig == IMAGE_NT_SIGNATURE)789 { LPBYTE idata,igdata;790 PIMAGE_DOS_HEADER dheader;791 PIMAGE_NT_HEADERS pe_header;792 PIMAGE_SECTION_HEADER pe_sections;793 PIMAGE_RESOURCE_DIRECTORY rootresdir,iconresdir,icongroupresdir;794 PIMAGE_RESOURCE_DATA_ENTRY idataent,igdataent;795 int i,j;796 PIMAGE_RESOURCE_DIRECTORY_ENTRY xresent;797 CURSORICONDIR **cids;798 799 fmapping = CreateFileMappingA(hFile,NULL,PAGE_READONLY|SEC_COMMIT,0,0,NULL);800 if (fmapping == 0)801 { /* FIXME, INVALID_HANDLE_VALUE? */802 WARN_(shell)("failed to create filemap.\n");803 hRet = 0;804 goto end_2; /* failure */805 }806 peimage = MapViewOfFile(fmapping,FILE_MAP_READ,0,0,0);807 if (!peimage)808 { WARN_(shell)("failed to mmap filemap.\n");809 hRet = 0;810 goto end_2; /* failure */811 }812 dheader = (PIMAGE_DOS_HEADER)peimage;813 814 /* it is a pe header, SHELL_GetResourceTable checked that */815 pe_header = (PIMAGE_NT_HEADERS)(peimage+dheader->e_lfanew);816 817 /* probably makes problems with short PE headers... but I haven't seen818 * one yet...819 */820 pe_sections = (PIMAGE_SECTION_HEADER)(((char*)pe_header)+sizeof(*pe_header));821 rootresdir = NULL;822 823 for (i=0;i<pe_header->FileHeader.NumberOfSections;i++)824 { if (pe_sections[i].Characteristics & IMAGE_SCN_CNT_UNINITIALIZED_DATA)825 continue;826 /* FIXME: doesn't work when the resources are not in a seperate section */827 if (pe_sections[i].VirtualAddress == pe_header->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_RESOURCE].VirtualAddress)828 { rootresdir = (PIMAGE_RESOURCE_DIRECTORY)((char*)peimage+pe_sections[i].PointerToRawData);829 break;830 }831 }832 833 if (!rootresdir)834 { WARN_(shell)("haven't found section for resource directory.\n");835 goto end_4; /* failure */836 }837 838 icongroupresdir = GetResDirEntryW(rootresdir,RT_GROUP_ICONW, (DWORD)rootresdir,FALSE);839 840 if (!icongroupresdir)841 { WARN_(shell)("No Icongroupresourcedirectory!\n");842 goto end_4; /* failure */843 }844 845 iconDirCount = icongroupresdir->NumberOfNamedEntries+icongroupresdir->NumberOfIdEntries;846 847 if( nIconIndex == (UINT16)-1 )848 { RetPtr[0] = iconDirCount;849 goto end_3; /* success */850 }851 852 if (nIconIndex >= iconDirCount)853 { WARN_(shell)("nIconIndex %d is larger than iconDirCount %d\n",nIconIndex,iconDirCount);854 GlobalFree16(hRet);855 goto end_4; /* failure */856 }857 858 cids = (CURSORICONDIR**)HeapAlloc(GetProcessHeap(),0,n*sizeof(CURSORICONDIR*));859 860 /* caller just wanted the number of entries */861 xresent = (PIMAGE_RESOURCE_DIRECTORY_ENTRY)(icongroupresdir+1);862 863 /* assure we don't get too much ... */864 if( n > iconDirCount - nIconIndex )865 { n = iconDirCount - nIconIndex;866 }867 868 /* starting from specified index ... */869 xresent = xresent+nIconIndex;870 871 for (i=0;i<n;i++,xresent++)872 { CURSORICONDIR *cid;873 PIMAGE_RESOURCE_DIRECTORY resdir;874 875 /* go down this resource entry, name */876 resdir = (PIMAGE_RESOURCE_DIRECTORY)((DWORD)rootresdir+(xresent->u2.s.OffsetToDirectory));877 878 /* default language (0) */879 resdir = GetResDirEntryW(resdir,(LPWSTR)0,(DWORD)rootresdir,TRUE);880 igdataent = (PIMAGE_RESOURCE_DATA_ENTRY)resdir;881 882 /* lookup address in mapped image for virtual address */883 igdata = NULL;884 885 for (j=0;j<pe_header->FileHeader.NumberOfSections;j++)886 { if (igdataent->OffsetToData < pe_sections[j].VirtualAddress)887 continue;888 if (igdataent->OffsetToData+igdataent->Size > pe_sections[j].VirtualAddress+pe_sections[j].SizeOfRawData)889 continue;890 igdata = peimage+(igdataent->OffsetToData-pe_sections[j].VirtualAddress+pe_sections[j].PointerToRawData);891 }892 893 if (!igdata)894 { WARN_(shell)("no matching real address for icongroup!\n");895 goto end_4; /* failure */896 }897 /* found */898 cid = (CURSORICONDIR*)igdata;899 cids[i] = cid;900 RetPtr[i] = LookupIconIdFromDirectoryEx(igdata,TRUE,GetSystemMetrics(SM_CXICON),GetSystemMetrics(SM_CYICON),0);901 }902 903 iconresdir=GetResDirEntryW(rootresdir,RT_ICONW,(DWORD)rootresdir,FALSE);904 905 if (!iconresdir)906 { WARN_(shell)("No Iconresourcedirectory!\n");907 goto end_4; /* failure */908 }909 910 for (i=0;i<n;i++)911 { PIMAGE_RESOURCE_DIRECTORY xresdir;912 xresdir = GetResDirEntryW(iconresdir,(LPWSTR)(DWORD)RetPtr[i],(DWORD)rootresdir,FALSE);913 xresdir = GetResDirEntryW(xresdir,(LPWSTR)0,(DWORD)rootresdir,TRUE);914 idataent = (PIMAGE_RESOURCE_DATA_ENTRY)xresdir;915 idata = NULL;916 917 /* map virtual to address in image */918 for (j=0;j<pe_header->FileHeader.NumberOfSections;j++)919 { if (idataent->OffsetToData < pe_sections[j].VirtualAddress)920 continue;921 if (idataent->OffsetToData+idataent->Size > pe_sections[j].VirtualAddress+pe_sections[j].SizeOfRawData)922 continue;923 idata = peimage+(idataent->OffsetToData-pe_sections[j].VirtualAddress+pe_sections[j].PointerToRawData);924 }925 if (!idata)926 { WARN_(shell)("no matching real address found for icondata!\n");927 RetPtr[i]=0;928 continue;929 }930 RetPtr[i] = CreateIconFromResourceEx(idata,idataent->Size,TRUE,0x00030000,GetSystemMetrics(SM_CXICON),GetSystemMetrics(SM_CYICON),0);931 }932 goto end_3; /* sucess */933 }934 goto end_1; /* return array with icon handles */935 936 /* cleaning up (try & catch would be nicer) */937 end_4: hRet = 0; /* failure */938 end_3: UnmapViewOfFile(peimage); /* success */939 end_2: CloseHandle(fmapping);940 end_1: _lclose( hFile);941 return hRet;942 }943 944 /*************************************************************************945 * ExtractIcon16 (SHELL.34)946 */947 HICON16 WINAPI ExtractIcon16( HINSTANCE16 hInstance, LPCSTR lpszExeFileName,948 UINT16 nIconIndex )949 { TRACE_(shell)("\n");950 return ExtractIconA( hInstance, lpszExeFileName, nIconIndex );951 }952 953 /*************************************************************************954 * ExtractIconEx16 (SHELL.40)955 */956 HICON16 WINAPI ExtractIconEx16(957 LPCSTR lpszFile, INT16 nIconIndex, HICON16 *phiconLarge,958 HICON16 *phiconSmall, UINT16 nIcons959 ) {960 HICON *ilarge,*ismall;961 UINT16 ret;962 int i;963 964 if (phiconLarge)965 ilarge = (HICON*)HeapAlloc(GetProcessHeap(),0,nIcons*sizeof(HICON));966 else967 ilarge = NULL;968 if (phiconSmall)969 ismall = (HICON*)HeapAlloc(GetProcessHeap(),0,nIcons*sizeof(HICON));970 else971 ismall = NULL;972 ret = ExtractIconExA(lpszFile,nIconIndex,ilarge,ismall,nIcons);973 if (ilarge) {974 for (i=0;i<nIcons;i++)975 phiconLarge[i]=ilarge[i];976 HeapFree(GetProcessHeap(),0,ilarge);977 }978 if (ismall) {979 for (i=0;i<nIcons;i++)980 phiconSmall[i]=ismall[i];981 HeapFree(GetProcessHeap(),0,ismall);982 }983 return ret;984 }985 503 986 504 /************************************************************************* … … 992 510 HICON WINAPI ExtractAssociatedIconA(HINSTANCE hInst, LPSTR lpIconPath, LPWORD lpiIcon) 993 511 { TRACE_(shell)("\n"); 994 return ExtractAssociatedIcon16(hInst,lpIconPath,lpiIcon); 995 } 996 997 HICON16 WINAPI ExtractAssociatedIcon16(HINSTANCE16 hInst, LPSTR lpIconPath, LPWORD lpiIcon) 998 { HICON16 hIcon; 999 1000 TRACE_(shell)("\n"); 1001 1002 hIcon = ExtractIcon16(hInst, lpIconPath, *lpiIcon); 512 HICON hIcon; 513 514 hIcon = ExtractIconA(hInst, lpIconPath, *lpiIcon); 1003 515 1004 516 if( hIcon < 2 ) 1005 517 { if( hIcon == 1 ) /* no icons found in given file */ 1006 { char tempPath[0x 80];1007 UINT16 uRet = FindExecutable 16(lpIconPath,NULL,tempPath);518 { char tempPath[0x104]; 519 UINT16 uRet = FindExecutableA(lpIconPath,NULL,tempPath); 1008 520 1009 521 if( uRet > 32 && tempPath[0] ) 1010 522 { strcpy(lpIconPath,tempPath); 1011 hIcon = ExtractIcon 16(hInst, lpIconPath, *lpiIcon);523 hIcon = ExtractIconA(hInst, lpIconPath, *lpiIcon); 1012 524 if( hIcon > 2 ) 1013 525 return hIcon; … … 1021 533 *lpiIcon = 6; /* generic icon - found nothing */ 1022 534 1023 GetModuleFileName 16(hInst, lpIconPath, 0x80);1024 hIcon = LoadIcon 16( hInst, MAKEINTRESOURCE16(*lpiIcon));535 GetModuleFileNameA(hInst, lpIconPath, 0x80); 536 hIcon = LoadIconA( hInst, (LPCSTR)*lpiIcon); 1025 537 } 1026 538 return hIcon; 1027 539 } 1028 1029 /*************************************************************************1030 * FindEnvironmentString [SHELL.38]1031 *1032 * Returns a pointer into the DOS environment... Ugh.1033 */1034 LPSTR SHELL_FindString(LPSTR lpEnv, LPCSTR entry)1035 { UINT16 l;1036 1037 TRACE_(shell)("\n");1038 1039 l = strlen(entry);1040 for( ; *lpEnv ; lpEnv+=strlen(lpEnv)+1 )1041 { if( lstrncmpiA(lpEnv, entry, l) )1042 continue;1043 if( !*(lpEnv+l) )1044 return (lpEnv + l); /* empty entry */1045 else if ( *(lpEnv+l)== '=' )1046 return (lpEnv + l + 1);1047 }1048 return NULL;1049 }1050 1051 SEGPTR WINAPI FindEnvironmentString16(LPSTR str)1052 { SEGPTR spEnv;1053 LPSTR lpEnv,lpString;1054 TRACE_(shell)("\n");1055 1056 spEnv = GetDOSEnvironment16();1057 1058 lpEnv = (LPSTR)PTR_SEG_TO_LIN(spEnv);1059 lpString = (spEnv)?SHELL_FindString(lpEnv, str):NULL;1060 1061 if( lpString ) /* offset should be small enough */1062 return spEnv + (lpString - lpEnv);1063 return (SEGPTR)NULL;1064 }1065 1066 /*************************************************************************1067 * DoEnvironmentSubst [SHELL.37]1068 *1069 * Replace %KEYWORD% in the str with the value of variable KEYWORD1070 * from "DOS" environment.1071 */1072 DWORD WINAPI DoEnvironmentSubst16(LPSTR str,WORD length)1073 {1074 LPSTR lpEnv = (LPSTR)PTR_SEG_TO_LIN(GetDOSEnvironment16());1075 LPSTR lpBuffer = (LPSTR)HeapAlloc( GetProcessHeap(), 0, length);1076 LPSTR lpstr = str;1077 LPSTR lpbstr = lpBuffer;1078 1079 CharToOemA(str,str);1080 1081 TRACE_(shell)("accept %s\n", str);1082 1083 while( *lpstr && lpbstr - lpBuffer < length )1084 {1085 LPSTR lpend = lpstr;1086 1087 if( *lpstr == '%' )1088 {1089 do { lpend++; } while( *lpend && *lpend != '%' );1090 if( *lpend == '%' && lpend - lpstr > 1 ) /* found key */1091 {1092 LPSTR lpKey;1093 *lpend = '\0';1094 lpKey = SHELL_FindString(lpEnv, lpstr+1);1095 if( lpKey ) /* found key value */1096 {1097 int l = strlen(lpKey);1098 1099 if( l > length - (lpbstr - lpBuffer) - 1 )1100 {1101 WARN_(shell)("-- Env subst aborted - string too short\n");1102 *lpend = '%';1103 break;1104 }1105 strcpy(lpbstr, lpKey);1106 lpbstr += l;1107 }1108 else break;1109 *lpend = '%';1110 lpstr = lpend + 1;1111 }1112 else break; /* back off and whine */1113 1114 continue;1115 }1116 1117 *lpbstr++ = *lpstr++;1118 }1119 1120 *lpbstr = '\0';1121 if( lpstr - str == strlen(str) )1122 {1123 strncpy(str, lpBuffer, length);1124 length = 1;1125 }1126 else1127 length = 0;1128 1129 TRACE_(shell)("-- return %s\n", str);1130 1131 OemToCharA(str,str);1132 HeapFree( GetProcessHeap(), 0, lpBuffer);1133 1134 /* Return str length in the LOWORD1135 * and 1 in HIWORD if subst was successful.1136 */1137 return (DWORD)MAKELONG(strlen(str), length);1138 }1139 1140 /*************************************************************************1141 * ShellHookProc [SHELL.103]1142 * System-wide WH_SHELL hook.1143 */1144 LRESULT WINAPI ShellHookProc16(INT16 code, WPARAM16 wParam, LPARAM lParam)1145 {1146 TRACE_(shell)("%i, %04x, %08x\n", code, wParam,1147 (unsigned)lParam );1148 if( SHELL_hHook && SHELL_hWnd )1149 {1150 UINT16 uMsg = 0;1151 switch( code )1152 {1153 case HSHELL_WINDOWCREATED: uMsg = uMsgWndCreated; break;1154 case HSHELL_WINDOWDESTROYED: uMsg = uMsgWndDestroyed; break;1155 case HSHELL_ACTIVATESHELLWINDOW: uMsg = uMsgShellActivate;1156 }1157 PostMessage16( SHELL_hWnd, uMsg, wParam, 0 );1158 }1159 return CallNextHookEx16( WH_SHELL, code, wParam, lParam );1160 }1161 1162 /*************************************************************************1163 * RegisterShellHook [SHELL.102]1164 */1165 BOOL WINAPI RegisterShellHook16(HWND16 hWnd, UINT16 uAction)1166 { TRACE_(shell)("%04x [%u]\n", hWnd, uAction );1167 1168 switch( uAction )1169 { case 2: /* register hWnd as a shell window */1170 if( !SHELL_hHook )1171 { HMODULE16 hShell = GetModuleHandle16( "SHELL" );1172 SHELL_hHook = SetWindowsHookEx16( WH_SHELL, ShellHookProc16, hShell, 0 );1173 if( SHELL_hHook )1174 { uMsgWndCreated = RegisterWindowMessageA( lpstrMsgWndCreated );1175 uMsgWndDestroyed = RegisterWindowMessageA( lpstrMsgWndDestroyed );1176 uMsgShellActivate = RegisterWindowMessageA( lpstrMsgShellActivate );1177 }1178 else1179 WARN_(shell)("-- unable to install ShellHookProc()!\n");1180 }1181 1182 if( SHELL_hHook )1183 return ((SHELL_hWnd = hWnd) != 0);1184 break;1185 1186 default:1187 WARN_(shell)("-- unknown code %i\n", uAction );1188 /* just in case */1189 SHELL_hWnd = 0;1190 }1191 return FALSE;1192 }
Note:
See TracChangeset
for help on using the changeset viewer.