Alexandre Julliard | 5819953 | 1994-04-21 01:20:00 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Shell Library Functions |
Alexandre Julliard | ebfc0fe | 1998-06-28 18:40:26 +0000 | [diff] [blame] | 3 | * |
Alexandre Julliard | 642d313 | 1998-07-12 19:29:36 +0000 | [diff] [blame] | 4 | * 1998 Marcus Meissner |
Alexandre Julliard | 5819953 | 1994-04-21 01:20:00 +0000 | [diff] [blame] | 5 | */ |
Alexandre Julliard | e658d82 | 1997-11-30 17:45:40 +0000 | [diff] [blame] | 6 | #include <assert.h> |
Alexandre Julliard | 5819953 | 1994-04-21 01:20:00 +0000 | [diff] [blame] | 7 | #include <stdlib.h> |
Alexandre Julliard | 5819953 | 1994-04-21 01:20:00 +0000 | [diff] [blame] | 8 | #include <string.h> |
| 9 | #include <unistd.h> |
Alexandre Julliard | 808cb04 | 1995-08-17 17:11:36 +0000 | [diff] [blame] | 10 | #include <ctype.h> |
Michael Veksler | ca1bc86 | 1999-01-01 18:57:33 +0000 | [diff] [blame] | 11 | #include "wine/winuser16.h" |
Marcus Meissner | 317af32 | 1999-02-17 13:51:06 +0000 | [diff] [blame] | 12 | #include "wine/winbase16.h" |
| 13 | #include "wine/shell16.h" |
Alexandre Julliard | 44ed71f | 1997-12-21 19:17:50 +0000 | [diff] [blame] | 14 | #include "winerror.h" |
Alexandre Julliard | 2ace16a | 1996-04-28 15:09:19 +0000 | [diff] [blame] | 15 | #include "file.h" |
Alexandre Julliard | 7ebe1a4 | 1996-12-22 18:27:48 +0000 | [diff] [blame] | 16 | #include "heap.h" |
Alexandre Julliard | c981d0b | 1996-03-31 16:40:13 +0000 | [diff] [blame] | 17 | #include "module.h" |
Alexandre Julliard | 7cbe657 | 1995-01-09 18:21:16 +0000 | [diff] [blame] | 18 | #include "neexe.h" |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 19 | #include "dlgs.h" |
Alexandre Julliard | af0bae5 | 1995-10-03 17:06:08 +0000 | [diff] [blame] | 20 | #include "win.h" |
Alexandre Julliard | 1e37a18 | 1996-08-18 16:21:52 +0000 | [diff] [blame] | 21 | #include "cursoricon.h" |
Alexandre Julliard | e658d82 | 1997-11-30 17:45:40 +0000 | [diff] [blame] | 22 | #include "sysmetrics.h" |
Marcus Meissner | 317af32 | 1999-02-17 13:51:06 +0000 | [diff] [blame] | 23 | #include "shellapi.h" |
Alexandre Julliard | e658d82 | 1997-11-30 17:45:40 +0000 | [diff] [blame] | 24 | #include "shlobj.h" |
Alexandre Julliard | 3a405ba | 1994-10-30 16:25:19 +0000 | [diff] [blame] | 25 | #include "debug.h" |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 26 | #include "winreg.h" |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 27 | #include "imagelist.h" |
Alexandre Julliard | 5819953 | 1994-04-21 01:20:00 +0000 | [diff] [blame] | 28 | |
Alexandre Julliard | 1e37a18 | 1996-08-18 16:21:52 +0000 | [diff] [blame] | 29 | /* .ICO file ICONDIR definitions */ |
| 30 | |
| 31 | #pragma pack(1) |
| 32 | |
| 33 | typedef struct |
| 34 | { |
| 35 | BYTE bWidth; /* Width, in pixels, of the image */ |
| 36 | BYTE bHeight; /* Height, in pixels, of the image */ |
| 37 | BYTE bColorCount; /* Number of colors in image (0 if >=8bpp) */ |
| 38 | BYTE bReserved; /* Reserved ( must be 0) */ |
| 39 | WORD wPlanes; /* Color Planes */ |
| 40 | WORD wBitCount; /* Bits per pixel */ |
| 41 | DWORD dwBytesInRes; /* How many bytes in this resource? */ |
| 42 | DWORD dwImageOffset; /* Where in the file is this image? */ |
| 43 | } icoICONDIRENTRY, *LPicoICONDIRENTRY; |
| 44 | |
| 45 | typedef struct |
| 46 | { |
| 47 | WORD idReserved; /* Reserved (must be 0) */ |
| 48 | WORD idType; /* Resource Type (1 for icons) */ |
| 49 | WORD idCount; /* How many images? */ |
| 50 | icoICONDIRENTRY idEntries[1]; /* An entry for each image (idCount of 'em) */ |
| 51 | } icoICONDIR, *LPicoICONDIR; |
| 52 | |
| 53 | #pragma pack(4) |
| 54 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 55 | static const char* lpstrMsgWndCreated = "OTHERWINDOWCREATED"; |
| 56 | static const char* lpstrMsgWndDestroyed = "OTHERWINDOWDESTROYED"; |
| 57 | static const char* lpstrMsgShellActivate = "ACTIVATESHELLWINDOW"; |
| 58 | |
| 59 | static HWND16 SHELL_hWnd = 0; |
| 60 | static HHOOK SHELL_hHook = 0; |
| 61 | static UINT16 uMsgWndCreated = 0; |
| 62 | static UINT16 uMsgWndDestroyed = 0; |
| 63 | static UINT16 uMsgShellActivate = 0; |
Alexandre Julliard | 2ace16a | 1996-04-28 15:09:19 +0000 | [diff] [blame] | 64 | |
Alexandre Julliard | d18872d | 1994-05-11 12:18:19 +0000 | [diff] [blame] | 65 | /************************************************************************* |
Kai Morich | 0913cdf | 1998-10-24 12:02:54 +0000 | [diff] [blame] | 66 | * DragAcceptFiles32 [SHELL32.54] |
Alexandre Julliard | d18872d | 1994-05-11 12:18:19 +0000 | [diff] [blame] | 67 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame^] | 68 | void WINAPI DragAcceptFiles(HWND hWnd, BOOL b) |
Kai Morich | 0913cdf | 1998-10-24 12:02:54 +0000 | [diff] [blame] | 69 | { |
| 70 | WND* wnd = WIN_FindWndPtr(hWnd); |
| 71 | |
| 72 | if( wnd ) |
| 73 | wnd->dwExStyle = b? wnd->dwExStyle | WS_EX_ACCEPTFILES |
| 74 | : wnd->dwExStyle & ~WS_EX_ACCEPTFILES; |
Alexandre Julliard | d18872d | 1994-05-11 12:18:19 +0000 | [diff] [blame] | 75 | } |
| 76 | |
Kai Morich | 0913cdf | 1998-10-24 12:02:54 +0000 | [diff] [blame] | 77 | /************************************************************************* |
| 78 | * DragAcceptFiles16 [SHELL.9] |
| 79 | */ |
| 80 | void WINAPI DragAcceptFiles16(HWND16 hWnd, BOOL16 b) |
| 81 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame^] | 82 | DragAcceptFiles(hWnd, b); |
Kai Morich | 0913cdf | 1998-10-24 12:02:54 +0000 | [diff] [blame] | 83 | } |
Alexandre Julliard | d18872d | 1994-05-11 12:18:19 +0000 | [diff] [blame] | 84 | |
| 85 | /************************************************************************* |
Kai Morich | 0913cdf | 1998-10-24 12:02:54 +0000 | [diff] [blame] | 86 | * SHELL_DragQueryFile [internal] |
| 87 | * |
Alexandre Julliard | d18872d | 1994-05-11 12:18:19 +0000 | [diff] [blame] | 88 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame^] | 89 | static UINT SHELL_DragQueryFile(LPSTR lpDrop, LPWSTR lpwDrop, UINT lFile, |
| 90 | LPSTR lpszFile, LPWSTR lpszwFile, UINT lLength) |
Kai Morich | 0913cdf | 1998-10-24 12:02:54 +0000 | [diff] [blame] | 91 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame^] | 92 | UINT i; |
Kai Morich | 0913cdf | 1998-10-24 12:02:54 +0000 | [diff] [blame] | 93 | |
| 94 | i = 0; |
| 95 | if (lpDrop) { |
| 96 | while (i++ < lFile) { |
| 97 | while (*lpDrop++); /* skip filename */ |
| 98 | if (!*lpDrop) |
| 99 | return (lFile == 0xFFFFFFFF) ? i : 0; |
| 100 | } |
| 101 | } |
| 102 | if (lpwDrop) { |
| 103 | while (i++ < lFile) { |
| 104 | while (*lpwDrop++); /* skip filename */ |
| 105 | if (!*lpwDrop) |
| 106 | return (lFile == 0xFFFFFFFF) ? i : 0; |
| 107 | } |
| 108 | } |
| 109 | |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame^] | 110 | if (lpDrop) i = lstrlenA(lpDrop); |
| 111 | if (lpwDrop) i = lstrlenW(lpwDrop); |
Kai Morich | 0913cdf | 1998-10-24 12:02:54 +0000 | [diff] [blame] | 112 | i++; |
| 113 | if (!lpszFile && !lpszwFile) { |
| 114 | return i; /* needed buffer size */ |
| 115 | } |
| 116 | i = (lLength > i) ? i : lLength; |
| 117 | if (lpszFile) { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame^] | 118 | if (lpDrop) lstrcpynA (lpszFile, lpDrop, i); |
Kai Morich | 0913cdf | 1998-10-24 12:02:54 +0000 | [diff] [blame] | 119 | else lstrcpynWtoA(lpszFile, lpwDrop, i); |
| 120 | } else { |
| 121 | if (lpDrop) lstrcpynAtoW(lpszwFile, lpDrop, i); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame^] | 122 | else lstrcpynW (lpszwFile, lpwDrop, i); |
Kai Morich | 0913cdf | 1998-10-24 12:02:54 +0000 | [diff] [blame] | 123 | } |
| 124 | return i; |
| 125 | } |
| 126 | |
| 127 | /************************************************************************* |
| 128 | * DragQueryFile32A [SHELL32.81] [shell32.82] |
| 129 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame^] | 130 | UINT WINAPI DragQueryFileA(HDROP hDrop, UINT lFile, LPSTR lpszFile, |
| 131 | UINT lLength) |
Kai Morich | 0913cdf | 1998-10-24 12:02:54 +0000 | [diff] [blame] | 132 | { /* hDrop is a global memory block allocated with GMEM_SHARE |
| 133 | * with DROPFILESTRUCT as a header and filenames following |
| 134 | * it, zero length filename is in the end */ |
| 135 | |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame^] | 136 | LPDROPFILESTRUCT lpDropFileStruct; |
Kai Morich | 0913cdf | 1998-10-24 12:02:54 +0000 | [diff] [blame] | 137 | LPSTR lpCurrent; |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame^] | 138 | UINT i; |
Kai Morich | 0913cdf | 1998-10-24 12:02:54 +0000 | [diff] [blame] | 139 | |
| 140 | TRACE(shell,"(%08x, %x, %p, %u)\n", hDrop,lFile,lpszFile,lLength); |
| 141 | |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame^] | 142 | lpDropFileStruct = (LPDROPFILESTRUCT) GlobalLock(hDrop); |
Kai Morich | 0913cdf | 1998-10-24 12:02:54 +0000 | [diff] [blame] | 143 | if(!lpDropFileStruct) |
| 144 | return 0; |
| 145 | |
| 146 | lpCurrent = (LPSTR) lpDropFileStruct + lpDropFileStruct->lSize; |
| 147 | i = SHELL_DragQueryFile(lpCurrent, NULL, lFile, lpszFile, NULL, lLength); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame^] | 148 | GlobalUnlock(hDrop); |
Kai Morich | 0913cdf | 1998-10-24 12:02:54 +0000 | [diff] [blame] | 149 | return i; |
| 150 | } |
| 151 | |
| 152 | /************************************************************************* |
| 153 | * DragQueryFile32W [shell32.133] |
| 154 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame^] | 155 | UINT WINAPI DragQueryFileW(HDROP hDrop, UINT lFile, LPWSTR lpszwFile, |
| 156 | UINT lLength) |
Kai Morich | 0913cdf | 1998-10-24 12:02:54 +0000 | [diff] [blame] | 157 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame^] | 158 | LPDROPFILESTRUCT lpDropFileStruct; |
Kai Morich | 0913cdf | 1998-10-24 12:02:54 +0000 | [diff] [blame] | 159 | LPWSTR lpwCurrent; |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame^] | 160 | UINT i; |
Kai Morich | 0913cdf | 1998-10-24 12:02:54 +0000 | [diff] [blame] | 161 | |
| 162 | TRACE(shell,"(%08x, %x, %p, %u)\n", hDrop,lFile,lpszwFile,lLength); |
| 163 | |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame^] | 164 | lpDropFileStruct = (LPDROPFILESTRUCT) GlobalLock(hDrop); |
Kai Morich | 0913cdf | 1998-10-24 12:02:54 +0000 | [diff] [blame] | 165 | if(!lpDropFileStruct) |
| 166 | return 0; |
| 167 | |
| 168 | lpwCurrent = (LPWSTR) lpDropFileStruct + lpDropFileStruct->lSize; |
| 169 | i = SHELL_DragQueryFile(NULL, lpwCurrent, lFile, NULL, lpszwFile,lLength); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame^] | 170 | GlobalUnlock(hDrop); |
Kai Morich | 0913cdf | 1998-10-24 12:02:54 +0000 | [diff] [blame] | 171 | return i; |
| 172 | } |
| 173 | /************************************************************************* |
| 174 | * DragQueryFile16 [SHELL.11] |
| 175 | */ |
| 176 | UINT16 WINAPI DragQueryFile16(HDROP16 hDrop, WORD wFile, LPSTR lpszFile, |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 177 | WORD wLength) |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 178 | { /* hDrop is a global memory block allocated with GMEM_SHARE |
Alexandre Julliard | d471965 | 1995-12-12 18:49:11 +0000 | [diff] [blame] | 179 | * with DROPFILESTRUCT as a header and filenames following |
| 180 | * it, zero length filename is in the end */ |
| 181 | |
Kai Morich | 0913cdf | 1998-10-24 12:02:54 +0000 | [diff] [blame] | 182 | LPDROPFILESTRUCT16 lpDropFileStruct; |
Alexandre Julliard | d471965 | 1995-12-12 18:49:11 +0000 | [diff] [blame] | 183 | LPSTR lpCurrent; |
| 184 | WORD i; |
| 185 | |
Kai Morich | 0913cdf | 1998-10-24 12:02:54 +0000 | [diff] [blame] | 186 | TRACE(shell,"(%04x, %x, %p, %u)\n", hDrop,wFile,lpszFile,wLength); |
Alexandre Julliard | d471965 | 1995-12-12 18:49:11 +0000 | [diff] [blame] | 187 | |
Kai Morich | 0913cdf | 1998-10-24 12:02:54 +0000 | [diff] [blame] | 188 | lpDropFileStruct = (LPDROPFILESTRUCT16) GlobalLock16(hDrop); |
| 189 | if(!lpDropFileStruct) |
| 190 | return 0; |
| 191 | |
Alexandre Julliard | d471965 | 1995-12-12 18:49:11 +0000 | [diff] [blame] | 192 | lpCurrent = (LPSTR) lpDropFileStruct + lpDropFileStruct->wSize; |
Alexandre Julliard | 75d86e1 | 1996-11-17 18:59:11 +0000 | [diff] [blame] | 193 | |
Kai Morich | 0913cdf | 1998-10-24 12:02:54 +0000 | [diff] [blame] | 194 | i = (WORD)SHELL_DragQueryFile(lpCurrent, NULL, wFile==0xffff?0xffffffff:wFile, |
| 195 | lpszFile, NULL, wLength); |
Alexandre Julliard | 1285c2f | 1996-05-06 16:06:24 +0000 | [diff] [blame] | 196 | GlobalUnlock16(hDrop); |
Alexandre Julliard | d471965 | 1995-12-12 18:49:11 +0000 | [diff] [blame] | 197 | return i; |
Alexandre Julliard | d18872d | 1994-05-11 12:18:19 +0000 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | |
Kai Morich | 0913cdf | 1998-10-24 12:02:54 +0000 | [diff] [blame] | 201 | |
Alexandre Julliard | d18872d | 1994-05-11 12:18:19 +0000 | [diff] [blame] | 202 | /************************************************************************* |
Kai Morich | 0913cdf | 1998-10-24 12:02:54 +0000 | [diff] [blame] | 203 | * DragFinish32 [SHELL32.80] |
Alexandre Julliard | d18872d | 1994-05-11 12:18:19 +0000 | [diff] [blame] | 204 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame^] | 205 | void WINAPI DragFinish(HDROP h) |
Kai Morich | 0913cdf | 1998-10-24 12:02:54 +0000 | [diff] [blame] | 206 | { TRACE(shell,"\n"); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame^] | 207 | GlobalFree((HGLOBAL)h); |
Kai Morich | 0913cdf | 1998-10-24 12:02:54 +0000 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | /************************************************************************* |
| 211 | * DragFinish16 [SHELL.12] |
| 212 | */ |
| 213 | void WINAPI DragFinish16(HDROP16 h) |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 214 | { TRACE(shell,"\n"); |
Alexandre Julliard | 1285c2f | 1996-05-06 16:06:24 +0000 | [diff] [blame] | 215 | GlobalFree16((HGLOBAL16)h); |
Alexandre Julliard | d18872d | 1994-05-11 12:18:19 +0000 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | |
| 219 | /************************************************************************* |
Kai Morich | 0913cdf | 1998-10-24 12:02:54 +0000 | [diff] [blame] | 220 | * DragQueryPoint32 [SHELL32.135] |
Alexandre Julliard | d18872d | 1994-05-11 12:18:19 +0000 | [diff] [blame] | 221 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame^] | 222 | BOOL WINAPI DragQueryPoint(HDROP hDrop, POINT *p) |
Kai Morich | 0913cdf | 1998-10-24 12:02:54 +0000 | [diff] [blame] | 223 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame^] | 224 | LPDROPFILESTRUCT lpDropFileStruct; |
| 225 | BOOL bRet; |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 226 | TRACE(shell,"\n"); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame^] | 227 | lpDropFileStruct = (LPDROPFILESTRUCT) GlobalLock(hDrop); |
Kai Morich | 0913cdf | 1998-10-24 12:02:54 +0000 | [diff] [blame] | 228 | |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame^] | 229 | memcpy(p,&lpDropFileStruct->ptMousePos,sizeof(POINT)); |
Kai Morich | 0913cdf | 1998-10-24 12:02:54 +0000 | [diff] [blame] | 230 | bRet = lpDropFileStruct->fInNonClientArea; |
| 231 | |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame^] | 232 | GlobalUnlock(hDrop); |
Kai Morich | 0913cdf | 1998-10-24 12:02:54 +0000 | [diff] [blame] | 233 | return bRet; |
| 234 | } |
Alexandre Julliard | af0bae5 | 1995-10-03 17:06:08 +0000 | [diff] [blame] | 235 | |
Kai Morich | 0913cdf | 1998-10-24 12:02:54 +0000 | [diff] [blame] | 236 | /************************************************************************* |
| 237 | * DragQueryPoint16 [SHELL.13] |
| 238 | */ |
| 239 | BOOL16 WINAPI DragQueryPoint16(HDROP16 hDrop, POINT16 *p) |
| 240 | { |
| 241 | LPDROPFILESTRUCT16 lpDropFileStruct; |
| 242 | BOOL16 bRet; |
| 243 | TRACE(shell,"\n"); |
| 244 | lpDropFileStruct = (LPDROPFILESTRUCT16) GlobalLock16(hDrop); |
| 245 | |
| 246 | memcpy(p,&lpDropFileStruct->ptMousePos,sizeof(POINT16)); |
| 247 | bRet = lpDropFileStruct->fInNonClientArea; |
| 248 | |
| 249 | GlobalUnlock16(hDrop); |
| 250 | return bRet; |
Alexandre Julliard | 5819953 | 1994-04-21 01:20:00 +0000 | [diff] [blame] | 251 | } |
| 252 | |
Alexandre Julliard | 5819953 | 1994-04-21 01:20:00 +0000 | [diff] [blame] | 253 | /************************************************************************* |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 254 | * SHELL_FindExecutable [Internal] |
| 255 | * |
Alexandre Julliard | ef702d8 | 1996-05-28 18:54:58 +0000 | [diff] [blame] | 256 | * Utility for code sharing between FindExecutable and ShellExecute |
Alexandre Julliard | 5819953 | 1994-04-21 01:20:00 +0000 | [diff] [blame] | 257 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame^] | 258 | HINSTANCE SHELL_FindExecutable( LPCSTR lpFile, |
Alexandre Julliard | bf9130a | 1996-10-13 17:45:47 +0000 | [diff] [blame] | 259 | LPCSTR lpOperation, |
| 260 | LPSTR lpResult) |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 261 | { char *extension = NULL; /* pointer to file extension */ |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 262 | char tmpext[5]; /* local copy to mung as we please */ |
| 263 | char filetype[256]; /* registry name for this filetype */ |
| 264 | LONG filetypelen=256; /* length of above */ |
| 265 | char command[256]; /* command from registry */ |
| 266 | LONG commandlen=256; /* This is the most DOS can handle :) */ |
| 267 | char buffer[256]; /* Used to GetProfileString */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame^] | 268 | HINSTANCE retval=31; /* default - 'No association was found' */ |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 269 | char *tok; /* token pointer */ |
| 270 | int i; /* random counter */ |
Alexandre Julliard | 1e37a18 | 1996-08-18 16:21:52 +0000 | [diff] [blame] | 271 | char xlpFile[256]; /* result of SearchPath */ |
Alexandre Julliard | 2ace16a | 1996-04-28 15:09:19 +0000 | [diff] [blame] | 272 | |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 273 | TRACE(shell, "%s\n", (lpFile != NULL?lpFile:"-") ); |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 274 | |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 275 | lpResult[0]='\0'; /* Start off with an empty return string */ |
| 276 | |
| 277 | /* trap NULL parameters on entry */ |
Alexandre Julliard | 8cc3a5e | 1996-08-11 15:49:51 +0000 | [diff] [blame] | 278 | if (( lpFile == NULL ) || ( lpResult == NULL ) || ( lpOperation == NULL )) |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 279 | { WARN(exec, "(lpFile=%s,lpResult=%s,lpOperation=%s): NULL parameter\n", |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 280 | lpFile, lpOperation, lpResult); |
| 281 | return 2; /* File not found. Close enough, I guess. */ |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 282 | } |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 283 | |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame^] | 284 | if (SearchPathA( NULL, lpFile,".exe",sizeof(xlpFile),xlpFile,NULL)) |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 285 | { TRACE(shell, "SearchPath32A returned non-zero\n"); |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 286 | lpFile = xlpFile; |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 287 | } |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 288 | |
| 289 | /* First thing we need is the file's extension */ |
Alexandre Julliard | 8cc3a5e | 1996-08-11 15:49:51 +0000 | [diff] [blame] | 290 | extension = strrchr( xlpFile, '.' ); /* Assume last "." is the one; */ |
Alexandre Julliard | ca22b33 | 1996-07-12 19:02:39 +0000 | [diff] [blame] | 291 | /* File->Run in progman uses */ |
| 292 | /* .\FILE.EXE :( */ |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 293 | TRACE(shell, "xlpFile=%s,extension=%s\n", xlpFile, extension); |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 294 | |
Alexandre Julliard | 8cc3a5e | 1996-08-11 15:49:51 +0000 | [diff] [blame] | 295 | if ((extension == NULL) || (extension == &xlpFile[strlen(xlpFile)])) |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 296 | { WARN(shell, "Returning 31 - No association\n"); |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 297 | return 31; /* no association */ |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 298 | } |
| 299 | |
| 300 | /* Make local copy & lowercase it for reg & 'programs=' lookup */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame^] | 301 | lstrcpynA( tmpext, extension, 5 ); |
| 302 | CharLowerA( tmpext ); |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 303 | TRACE(shell, "%s file\n", tmpext); |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 304 | |
| 305 | /* Three places to check: */ |
| 306 | /* 1. win.ini, [windows], programs (NB no leading '.') */ |
| 307 | /* 2. Registry, HKEY_CLASS_ROOT\<filetype>\shell\open\command */ |
| 308 | /* 3. win.ini, [extensions], extension (NB no leading '.' */ |
| 309 | /* All I know of the order is that registry is checked before */ |
| 310 | /* extensions; however, it'd make sense to check the programs */ |
| 311 | /* section first, so that's what happens here. */ |
| 312 | |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 313 | /* See if it's a program - if GetProfileString fails, we skip this |
| 314 | * section. Actually, if GetProfileString fails, we've probably |
| 315 | * got a lot more to worry about than running a program... */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame^] | 316 | if ( GetProfileStringA("windows", "programs", "exe pif bat com", |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 317 | buffer, sizeof(buffer)) > 0 ) |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 318 | { for (i=0;i<strlen(buffer); i++) buffer[i]=tolower(buffer[i]); |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 319 | |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 320 | tok = strtok(buffer, " \t"); /* ? */ |
| 321 | while( tok!= NULL) |
| 322 | { |
| 323 | if (strcmp(tok, &tmpext[1])==0) /* have to skip the leading "." */ |
| 324 | { |
| 325 | strcpy(lpResult, xlpFile); |
| 326 | /* Need to perhaps check that the file has a path |
| 327 | * attached */ |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 328 | TRACE(shell, "found %s\n", lpResult); |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 329 | return 33; |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 330 | |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 331 | /* Greater than 32 to indicate success FIXME According to the |
| 332 | * docs, I should be returning a handle for the |
| 333 | * executable. Does this mean I'm supposed to open the |
| 334 | * executable file or something? More RTFM, I guess... */ |
| 335 | } |
| 336 | tok=strtok(NULL, " \t"); |
| 337 | } |
| 338 | } |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 339 | |
| 340 | /* Check registry */ |
Alexandre Julliard | f90efa9 | 1998-06-14 15:24:15 +0000 | [diff] [blame] | 341 | if (RegQueryValue16( HKEY_CLASSES_ROOT, tmpext, filetype, |
| 342 | &filetypelen ) == ERROR_SUCCESS ) |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 343 | { |
| 344 | filetype[filetypelen]='\0'; |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 345 | TRACE(shell, "File type: %s\n", filetype); |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 346 | |
Alexandre Julliard | ef702d8 | 1996-05-28 18:54:58 +0000 | [diff] [blame] | 347 | /* Looking for ...buffer\shell\lpOperation\command */ |
| 348 | strcat( filetype, "\\shell\\" ); |
| 349 | strcat( filetype, lpOperation ); |
| 350 | strcat( filetype, "\\command" ); |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 351 | |
Alexandre Julliard | f90efa9 | 1998-06-14 15:24:15 +0000 | [diff] [blame] | 352 | if (RegQueryValue16( HKEY_CLASSES_ROOT, filetype, command, |
| 353 | &commandlen ) == ERROR_SUCCESS ) |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 354 | { |
| 355 | /* Is there a replace() function anywhere? */ |
| 356 | command[commandlen]='\0'; |
| 357 | strcpy( lpResult, command ); |
| 358 | tok=strstr( lpResult, "%1" ); |
| 359 | if (tok != NULL) |
| 360 | { |
| 361 | tok[0]='\0'; /* truncate string at the percent */ |
Alexandre Julliard | 8cc3a5e | 1996-08-11 15:49:51 +0000 | [diff] [blame] | 362 | strcat( lpResult, xlpFile ); /* what if no dir in xlpFile? */ |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 363 | tok=strstr( command, "%1" ); |
| 364 | if ((tok!=NULL) && (strlen(tok)>2)) |
| 365 | { |
| 366 | strcat( lpResult, &tok[2] ); |
| 367 | } |
| 368 | } |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 369 | retval=33; /* FIXME see above */ |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 370 | } |
| 371 | } |
| 372 | else /* Check win.ini */ |
| 373 | { |
| 374 | /* Toss the leading dot */ |
| 375 | extension++; |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame^] | 376 | if ( GetProfileStringA( "extensions", extension, "", command, |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 377 | sizeof(command)) > 0) |
| 378 | { |
| 379 | if (strlen(command)!=0) |
| 380 | { |
| 381 | strcpy( lpResult, command ); |
| 382 | tok=strstr( lpResult, "^" ); /* should be ^.extension? */ |
| 383 | if (tok != NULL) |
| 384 | { |
| 385 | tok[0]='\0'; |
| 386 | strcat( lpResult, xlpFile ); /* what if no dir in xlpFile? */ |
| 387 | tok=strstr( command, "^" ); /* see above */ |
| 388 | if ((tok != NULL) && (strlen(tok)>5)) |
| 389 | { |
| 390 | strcat( lpResult, &tok[5]); |
| 391 | } |
| 392 | } |
| 393 | retval=33; /* FIXME - see above */ |
| 394 | } |
| 395 | } |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 396 | } |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 397 | |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 398 | TRACE(shell, "returning %s\n", lpResult); |
Alexandre Julliard | ef702d8 | 1996-05-28 18:54:58 +0000 | [diff] [blame] | 399 | return retval; |
| 400 | } |
| 401 | |
| 402 | /************************************************************************* |
Alexandre Julliard | 2197901 | 1997-03-05 08:22:35 +0000 | [diff] [blame] | 403 | * ShellExecute16 [SHELL.20] |
Alexandre Julliard | ef702d8 | 1996-05-28 18:54:58 +0000 | [diff] [blame] | 404 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 405 | HINSTANCE16 WINAPI ShellExecute16( HWND16 hWnd, LPCSTR lpOperation, |
| 406 | LPCSTR lpFile, LPCSTR lpParameters, |
| 407 | LPCSTR lpDirectory, INT16 iShowCmd ) |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 408 | { HINSTANCE16 retval=31; |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 409 | char old_dir[1024]; |
Alexandre Julliard | ef702d8 | 1996-05-28 18:54:58 +0000 | [diff] [blame] | 410 | char cmd[256]; |
| 411 | |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 412 | TRACE(shell, "(%04x,'%s','%s','%s','%s',%x)\n", |
Alexandre Julliard | ef702d8 | 1996-05-28 18:54:58 +0000 | [diff] [blame] | 413 | hWnd, lpOperation ? lpOperation:"<null>", lpFile ? lpFile:"<null>", |
| 414 | lpParameters ? lpParameters : "<null>", |
| 415 | lpDirectory ? lpDirectory : "<null>", iShowCmd); |
| 416 | |
| 417 | if (lpFile==NULL) return 0; /* should not happen */ |
| 418 | if (lpOperation==NULL) /* default is open */ |
| 419 | lpOperation="open"; |
| 420 | |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 421 | if (lpDirectory) |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame^] | 422 | { GetCurrentDirectoryA( sizeof(old_dir), old_dir ); |
| 423 | SetCurrentDirectoryA( lpDirectory ); |
Alexandre Julliard | ef702d8 | 1996-05-28 18:54:58 +0000 | [diff] [blame] | 424 | } |
| 425 | |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 426 | retval = SHELL_FindExecutable( lpFile, lpOperation, cmd ); |
Alexandre Julliard | ef702d8 | 1996-05-28 18:54:58 +0000 | [diff] [blame] | 427 | |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 428 | if (retval > 32) /* Found */ |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 429 | { if (lpParameters) |
| 430 | { strcat(cmd," "); |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 431 | strcat(cmd,lpParameters); |
| 432 | } |
| 433 | |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 434 | TRACE(shell,"starting %s\n",cmd); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame^] | 435 | retval = WinExec( cmd, iShowCmd ); |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 436 | } |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 437 | if (lpDirectory) |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame^] | 438 | SetCurrentDirectoryA( old_dir ); |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 439 | return retval; |
Alexandre Julliard | ef702d8 | 1996-05-28 18:54:58 +0000 | [diff] [blame] | 440 | } |
| 441 | |
Alexandre Julliard | 2197901 | 1997-03-05 08:22:35 +0000 | [diff] [blame] | 442 | /************************************************************************* |
| 443 | * FindExecutable16 (SHELL.21) |
| 444 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 445 | HINSTANCE16 WINAPI FindExecutable16( LPCSTR lpFile, LPCSTR lpDirectory, |
| 446 | LPSTR lpResult ) |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame^] | 447 | { return (HINSTANCE16)FindExecutableA( lpFile, lpDirectory, lpResult ); |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 448 | } |
| 449 | |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 450 | |
| 451 | /************************************************************************* |
| 452 | * AboutDlgProc16 (SHELL.33) |
| 453 | */ |
Juergen Schmied | ba28ba1 | 1999-01-23 14:12:48 +0000 | [diff] [blame] | 454 | BOOL16 WINAPI AboutDlgProc16( HWND16 hWnd, UINT16 msg, WPARAM16 wParam, |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 455 | LPARAM lParam ) |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame^] | 456 | { return AboutDlgProc( hWnd, msg, wParam, lParam ); |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 457 | } |
| 458 | |
| 459 | |
| 460 | /************************************************************************* |
| 461 | * ShellAbout16 (SHELL.22) |
| 462 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 463 | BOOL16 WINAPI ShellAbout16( HWND16 hWnd, LPCSTR szApp, LPCSTR szOtherStuff, |
| 464 | HICON16 hIcon ) |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame^] | 465 | { return ShellAboutA( hWnd, szApp, szOtherStuff, hIcon ); |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 466 | } |
Alexandre Julliard | 73450d6 | 1994-05-18 18:29:32 +0000 | [diff] [blame] | 467 | |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 468 | /************************************************************************* |
Alexandre Julliard | 2ace16a | 1996-04-28 15:09:19 +0000 | [diff] [blame] | 469 | * SHELL_GetResourceTable |
Alexandre Julliard | d18872d | 1994-05-11 12:18:19 +0000 | [diff] [blame] | 470 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame^] | 471 | static DWORD SHELL_GetResourceTable(HFILE hFile,LPBYTE *retptr) |
Juergen Schmied | 72b76d1 | 1998-11-15 13:28:00 +0000 | [diff] [blame] | 472 | { IMAGE_DOS_HEADER mz_header; |
| 473 | char magic[4]; |
| 474 | int size; |
| 475 | |
| 476 | TRACE(shell,"\n"); |
| 477 | |
| 478 | *retptr = NULL; |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame^] | 479 | _llseek( hFile, 0, SEEK_SET ); |
| 480 | if ((_lread(hFile,&mz_header,sizeof(mz_header)) != sizeof(mz_header)) || (mz_header.e_magic != IMAGE_DOS_SIGNATURE)) |
Juergen Schmied | 72b76d1 | 1998-11-15 13:28:00 +0000 | [diff] [blame] | 481 | { /* .ICO file ? */ |
| 482 | if (mz_header.e_cblp == 1) |
| 483 | { /* ICONHEADER.idType, must be 1 */ |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 484 | *retptr = (LPBYTE)-1; |
| 485 | return 1; |
Juergen Schmied | 72b76d1 | 1998-11-15 13:28:00 +0000 | [diff] [blame] | 486 | } |
| 487 | else |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 488 | return 0; /* failed */ |
Alexandre Julliard | e658d82 | 1997-11-30 17:45:40 +0000 | [diff] [blame] | 489 | } |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame^] | 490 | _llseek( hFile, mz_header.e_lfanew, SEEK_SET ); |
Juergen Schmied | 72b76d1 | 1998-11-15 13:28:00 +0000 | [diff] [blame] | 491 | |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame^] | 492 | if (_lread( hFile, magic, sizeof(magic) ) != sizeof(magic)) |
Juergen Schmied | 72b76d1 | 1998-11-15 13:28:00 +0000 | [diff] [blame] | 493 | return 0; |
| 494 | |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame^] | 495 | _llseek( hFile, mz_header.e_lfanew, SEEK_SET); |
Juergen Schmied | 72b76d1 | 1998-11-15 13:28:00 +0000 | [diff] [blame] | 496 | |
| 497 | if (*(DWORD*)magic == IMAGE_NT_SIGNATURE) |
| 498 | return IMAGE_NT_SIGNATURE; |
| 499 | |
| 500 | if (*(WORD*)magic == IMAGE_OS2_SIGNATURE) |
| 501 | { IMAGE_OS2_HEADER ne_header; |
| 502 | LPBYTE pTypeInfo = (LPBYTE)-1; |
| 503 | |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame^] | 504 | if (_lread(hFile,&ne_header,sizeof(ne_header))!=sizeof(ne_header)) |
Juergen Schmied | 72b76d1 | 1998-11-15 13:28:00 +0000 | [diff] [blame] | 505 | return 0; |
| 506 | |
| 507 | if (ne_header.ne_magic != IMAGE_OS2_SIGNATURE) |
| 508 | return 0; |
| 509 | |
| 510 | size = ne_header.rname_tab_offset - ne_header.resource_tab_offset; |
| 511 | |
| 512 | if( size > sizeof(NE_TYPEINFO) ) |
| 513 | { pTypeInfo = (BYTE*)HeapAlloc( GetProcessHeap(), 0, size); |
| 514 | if( pTypeInfo ) |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame^] | 515 | { _llseek(hFile, mz_header.e_lfanew+ne_header.resource_tab_offset, SEEK_SET); |
| 516 | if( _lread( hFile, (char*)pTypeInfo, size) != size ) |
Juergen Schmied | 72b76d1 | 1998-11-15 13:28:00 +0000 | [diff] [blame] | 517 | { HeapFree( GetProcessHeap(), 0, pTypeInfo); |
| 518 | pTypeInfo = NULL; |
| 519 | } |
| 520 | } |
| 521 | } |
| 522 | *retptr = pTypeInfo; |
| 523 | return IMAGE_OS2_SIGNATURE; |
| 524 | } |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 525 | return 0; /* failed */ |
Alexandre Julliard | d18872d | 1994-05-11 12:18:19 +0000 | [diff] [blame] | 526 | } |
| 527 | |
Alexandre Julliard | 2ace16a | 1996-04-28 15:09:19 +0000 | [diff] [blame] | 528 | /************************************************************************* |
| 529 | * SHELL_LoadResource |
| 530 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame^] | 531 | static HGLOBAL16 SHELL_LoadResource(HINSTANCE16 hInst, HFILE hFile, NE_NAMEINFO* pNInfo, WORD sizeShift) |
Juergen Schmied | 72b76d1 | 1998-11-15 13:28:00 +0000 | [diff] [blame] | 532 | { BYTE* ptr; |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame^] | 533 | HGLOBAL16 handle = DirectResAlloc16( hInst, 0x10, (DWORD)pNInfo->length << sizeShift); |
Juergen Schmied | 72b76d1 | 1998-11-15 13:28:00 +0000 | [diff] [blame] | 534 | |
| 535 | TRACE(shell,"\n"); |
| 536 | |
| 537 | if( (ptr = (BYTE*)GlobalLock16( handle )) ) |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame^] | 538 | { _llseek( hFile, (DWORD)pNInfo->offset << sizeShift, SEEK_SET); |
| 539 | _lread( hFile, (char*)ptr, pNInfo->length << sizeShift); |
Juergen Schmied | 72b76d1 | 1998-11-15 13:28:00 +0000 | [diff] [blame] | 540 | return handle; |
| 541 | } |
| 542 | return 0; |
Alexandre Julliard | 2ace16a | 1996-04-28 15:09:19 +0000 | [diff] [blame] | 543 | } |
| 544 | |
| 545 | /************************************************************************* |
Alexandre Julliard | 1e37a18 | 1996-08-18 16:21:52 +0000 | [diff] [blame] | 546 | * ICO_LoadIcon |
| 547 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame^] | 548 | static HGLOBAL16 ICO_LoadIcon(HINSTANCE16 hInst, HFILE hFile, LPicoICONDIRENTRY lpiIDE) |
Juergen Schmied | 72b76d1 | 1998-11-15 13:28:00 +0000 | [diff] [blame] | 549 | { BYTE* ptr; |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame^] | 550 | HGLOBAL16 handle = DirectResAlloc16( hInst, 0x10, lpiIDE->dwBytesInRes); |
Juergen Schmied | 72b76d1 | 1998-11-15 13:28:00 +0000 | [diff] [blame] | 551 | TRACE(shell,"\n"); |
| 552 | if( (ptr = (BYTE*)GlobalLock16( handle )) ) |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame^] | 553 | { _llseek( hFile, lpiIDE->dwImageOffset, SEEK_SET); |
| 554 | _lread( hFile, (char*)ptr, lpiIDE->dwBytesInRes); |
Juergen Schmied | 72b76d1 | 1998-11-15 13:28:00 +0000 | [diff] [blame] | 555 | return handle; |
| 556 | } |
| 557 | return 0; |
Alexandre Julliard | 1e37a18 | 1996-08-18 16:21:52 +0000 | [diff] [blame] | 558 | } |
| 559 | |
| 560 | /************************************************************************* |
| 561 | * ICO_GetIconDirectory |
| 562 | * |
| 563 | * Read .ico file and build phony ICONDIR struct for GetIconID |
| 564 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame^] | 565 | static HGLOBAL16 ICO_GetIconDirectory(HINSTANCE16 hInst, HFILE hFile, LPicoICONDIR* lplpiID ) |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 566 | { WORD id[3]; /* idReserved, idType, idCount */ |
Alexandre Julliard | 1e37a18 | 1996-08-18 16:21:52 +0000 | [diff] [blame] | 567 | LPicoICONDIR lpiID; |
| 568 | int i; |
| 569 | |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 570 | TRACE(shell,"\n"); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame^] | 571 | _llseek( hFile, 0, SEEK_SET ); |
| 572 | if( _lread(hFile,(char*)id,sizeof(id)) != sizeof(id) ) return 0; |
Alexandre Julliard | 1e37a18 | 1996-08-18 16:21:52 +0000 | [diff] [blame] | 573 | |
| 574 | /* check .ICO header |
| 575 | * |
| 576 | * - see http://www.microsoft.com/win32dev/ui/icons.htm |
| 577 | */ |
| 578 | |
| 579 | if( id[0] || id[1] != 1 || !id[2] ) return 0; |
| 580 | |
| 581 | i = id[2]*sizeof(icoICONDIRENTRY) + sizeof(id); |
| 582 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 583 | lpiID = (LPicoICONDIR)HeapAlloc( GetProcessHeap(), 0, i); |
Alexandre Julliard | 1e37a18 | 1996-08-18 16:21:52 +0000 | [diff] [blame] | 584 | |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame^] | 585 | if( _lread(hFile,(char*)lpiID->idEntries,i) == i ) |
| 586 | { HGLOBAL16 handle = DirectResAlloc16( hInst, 0x10, |
Alexandre Julliard | bf9130a | 1996-10-13 17:45:47 +0000 | [diff] [blame] | 587 | id[2]*sizeof(ICONDIRENTRY) + sizeof(id) ); |
Alexandre Julliard | 1e37a18 | 1996-08-18 16:21:52 +0000 | [diff] [blame] | 588 | if( handle ) |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 589 | { CURSORICONDIR* lpID = (CURSORICONDIR*)GlobalLock16( handle ); |
Alexandre Julliard | 1e37a18 | 1996-08-18 16:21:52 +0000 | [diff] [blame] | 590 | lpID->idReserved = lpiID->idReserved = id[0]; |
| 591 | lpID->idType = lpiID->idType = id[1]; |
| 592 | lpID->idCount = lpiID->idCount = id[2]; |
| 593 | for( i=0; i < lpiID->idCount; i++ ) |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 594 | { memcpy((void*)(lpID->idEntries + i), |
Alexandre Julliard | 1e37a18 | 1996-08-18 16:21:52 +0000 | [diff] [blame] | 595 | (void*)(lpiID->idEntries + i), sizeof(ICONDIRENTRY) - 2); |
| 596 | lpID->idEntries[i].icon.wResId = i; |
| 597 | } |
| 598 | *lplpiID = lpiID; |
| 599 | return handle; |
| 600 | } |
| 601 | } |
| 602 | /* fail */ |
| 603 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 604 | HeapFree( GetProcessHeap(), 0, lpiID); |
Alexandre Julliard | 1e37a18 | 1996-08-18 16:21:52 +0000 | [diff] [blame] | 605 | return 0; |
| 606 | } |
| 607 | |
| 608 | /************************************************************************* |
Alexandre Julliard | 2ace16a | 1996-04-28 15:09:19 +0000 | [diff] [blame] | 609 | * InternalExtractIcon [SHELL.39] |
| 610 | * |
| 611 | * This abortion is called directly by Progman |
| 612 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame^] | 613 | HGLOBAL16 WINAPI InternalExtractIcon16(HINSTANCE16 hInstance, |
Juergen Schmied | 72b76d1 | 1998-11-15 13:28:00 +0000 | [diff] [blame] | 614 | LPCSTR lpszExeFileName, UINT16 nIconIndex, WORD n ) |
| 615 | { HGLOBAL16 hRet = 0; |
| 616 | HGLOBAL16* RetPtr = NULL; |
| 617 | LPBYTE pData; |
| 618 | OFSTRUCT ofs; |
| 619 | DWORD sig; |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame^] | 620 | HFILE hFile = OpenFile( lpszExeFileName, &ofs, OF_READ ); |
Juergen Schmied | 72b76d1 | 1998-11-15 13:28:00 +0000 | [diff] [blame] | 621 | UINT16 iconDirCount = 0,iconCount = 0; |
| 622 | LPBYTE peimage; |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame^] | 623 | HANDLE fmapping; |
Juergen Schmied | 72b76d1 | 1998-11-15 13:28:00 +0000 | [diff] [blame] | 624 | |
| 625 | TRACE(shell,"(%04x,file %s,start %d,extract %d\n", |
Alexandre Julliard | 2ace16a | 1996-04-28 15:09:19 +0000 | [diff] [blame] | 626 | hInstance, lpszExeFileName, nIconIndex, n); |
| 627 | |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame^] | 628 | if( hFile == HFILE_ERROR || !n ) |
Juergen Schmied | 72b76d1 | 1998-11-15 13:28:00 +0000 | [diff] [blame] | 629 | return 0; |
Alexandre Julliard | 2ace16a | 1996-04-28 15:09:19 +0000 | [diff] [blame] | 630 | |
Juergen Schmied | 72b76d1 | 1998-11-15 13:28:00 +0000 | [diff] [blame] | 631 | hRet = GlobalAlloc16( GMEM_FIXED | GMEM_ZEROINIT, sizeof(HICON16)*n); |
| 632 | RetPtr = (HICON16*)GlobalLock16(hRet); |
Alexandre Julliard | 2ace16a | 1996-04-28 15:09:19 +0000 | [diff] [blame] | 633 | |
Juergen Schmied | 72b76d1 | 1998-11-15 13:28:00 +0000 | [diff] [blame] | 634 | *RetPtr = (n == 0xFFFF)? 0: 1; /* error return values */ |
Alexandre Julliard | 2ace16a | 1996-04-28 15:09:19 +0000 | [diff] [blame] | 635 | |
Juergen Schmied | 72b76d1 | 1998-11-15 13:28:00 +0000 | [diff] [blame] | 636 | sig = SHELL_GetResourceTable(hFile,&pData); |
Alexandre Julliard | e658d82 | 1997-11-30 17:45:40 +0000 | [diff] [blame] | 637 | |
Juergen Schmied | 72b76d1 | 1998-11-15 13:28:00 +0000 | [diff] [blame] | 638 | if( sig==IMAGE_OS2_SIGNATURE || sig==1 ) /* .ICO file */ |
| 639 | { HICON16 hIcon = 0; |
| 640 | NE_TYPEINFO* pTInfo = (NE_TYPEINFO*)(pData + 2); |
| 641 | NE_NAMEINFO* pIconStorage = NULL; |
| 642 | NE_NAMEINFO* pIconDir = NULL; |
| 643 | LPicoICONDIR lpiID = NULL; |
Alexandre Julliard | 1e37a18 | 1996-08-18 16:21:52 +0000 | [diff] [blame] | 644 | |
Juergen Schmied | 72b76d1 | 1998-11-15 13:28:00 +0000 | [diff] [blame] | 645 | if( pData == (BYTE*)-1 ) |
| 646 | { hIcon = ICO_GetIconDirectory(hInstance, hFile, &lpiID); /* check for .ICO file */ |
| 647 | if( hIcon ) |
| 648 | { iconDirCount = 1; iconCount = lpiID->idCount; |
Alexandre Julliard | e658d82 | 1997-11-30 17:45:40 +0000 | [diff] [blame] | 649 | } |
Juergen Schmied | 72b76d1 | 1998-11-15 13:28:00 +0000 | [diff] [blame] | 650 | } |
| 651 | else while( pTInfo->type_id && !(pIconStorage && pIconDir) ) |
| 652 | { if( pTInfo->type_id == NE_RSCTYPE_GROUP_ICON ) /* find icon directory and icon repository */ |
| 653 | { iconDirCount = pTInfo->count; |
| 654 | pIconDir = ((NE_NAMEINFO*)(pTInfo + 1)); |
| 655 | TRACE(shell,"\tfound directory - %i icon families\n", iconDirCount); |
| 656 | } |
| 657 | if( pTInfo->type_id == NE_RSCTYPE_ICON ) |
| 658 | { iconCount = pTInfo->count; |
| 659 | pIconStorage = ((NE_NAMEINFO*)(pTInfo + 1)); |
| 660 | TRACE(shell,"\ttotal icons - %i\n", iconCount); |
| 661 | } |
| 662 | pTInfo = (NE_TYPEINFO *)((char*)(pTInfo+1)+pTInfo->count*sizeof(NE_NAMEINFO)); |
| 663 | } |
| 664 | |
| 665 | /* load resources and create icons */ |
| 666 | |
| 667 | if( (pIconStorage && pIconDir) || lpiID ) |
| 668 | { if( nIconIndex == (UINT16)-1 ) |
| 669 | { RetPtr[0] = iconDirCount; |
| 670 | } |
| 671 | else if( nIconIndex < iconDirCount ) |
| 672 | { UINT16 i, icon; |
| 673 | if( n > iconDirCount - nIconIndex ) |
| 674 | n = iconDirCount - nIconIndex; |
| 675 | |
| 676 | for( i = nIconIndex; i < nIconIndex + n; i++ ) |
| 677 | { /* .ICO files have only one icon directory */ |
| 678 | |
| 679 | if( lpiID == NULL ) |
| 680 | hIcon = SHELL_LoadResource( hInstance, hFile, pIconDir + i, *(WORD*)pData ); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame^] | 681 | RetPtr[i-nIconIndex] = GetIconID16( hIcon, 3 ); |
Juergen Schmied | 72b76d1 | 1998-11-15 13:28:00 +0000 | [diff] [blame] | 682 | GlobalFree16(hIcon); |
| 683 | } |
| 684 | |
| 685 | for( icon = nIconIndex; icon < nIconIndex + n; icon++ ) |
| 686 | { hIcon = 0; |
| 687 | if( lpiID ) |
| 688 | { hIcon = ICO_LoadIcon( hInstance, hFile, lpiID->idEntries + RetPtr[icon-nIconIndex]); |
| 689 | } |
| 690 | else |
| 691 | { for( i = 0; i < iconCount; i++ ) |
| 692 | { if( pIconStorage[i].id == (RetPtr[icon-nIconIndex] | 0x8000) ) |
| 693 | { hIcon = SHELL_LoadResource( hInstance, hFile, pIconStorage + i,*(WORD*)pData ); |
| 694 | } |
| 695 | } |
| 696 | } |
| 697 | if( hIcon ) |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame^] | 698 | { RetPtr[icon-nIconIndex] = LoadIconHandler16( hIcon, TRUE ); |
| 699 | FarSetOwner16( RetPtr[icon-nIconIndex], GetExePtr(hInstance) ); |
Juergen Schmied | 72b76d1 | 1998-11-15 13:28:00 +0000 | [diff] [blame] | 700 | } |
| 701 | else |
| 702 | { RetPtr[icon-nIconIndex] = 0; |
| 703 | } |
| 704 | } |
| 705 | } |
| 706 | } |
| 707 | if( lpiID ) |
| 708 | HeapFree( GetProcessHeap(), 0, lpiID); |
| 709 | else |
| 710 | HeapFree( GetProcessHeap(), 0, pData); |
| 711 | } |
| 712 | |
| 713 | if( sig == IMAGE_NT_SIGNATURE) |
| 714 | { LPBYTE idata,igdata; |
| 715 | PIMAGE_DOS_HEADER dheader; |
| 716 | PIMAGE_NT_HEADERS pe_header; |
| 717 | PIMAGE_SECTION_HEADER pe_sections; |
| 718 | PIMAGE_RESOURCE_DIRECTORY rootresdir,iconresdir,icongroupresdir; |
| 719 | PIMAGE_RESOURCE_DATA_ENTRY idataent,igdataent; |
| 720 | int i,j; |
| 721 | PIMAGE_RESOURCE_DIRECTORY_ENTRY xresent; |
| 722 | CURSORICONDIR **cids; |
| 723 | |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame^] | 724 | fmapping = CreateFileMappingA(hFile,NULL,PAGE_READONLY|SEC_COMMIT,0,0,NULL); |
Juergen Schmied | 72b76d1 | 1998-11-15 13:28:00 +0000 | [diff] [blame] | 725 | if (fmapping == 0) |
| 726 | { /* FIXME, INVALID_HANDLE_VALUE? */ |
| 727 | WARN(shell,"failed to create filemap.\n"); |
| 728 | hRet = 0; |
| 729 | goto end_2; /* failure */ |
| 730 | } |
| 731 | peimage = MapViewOfFile(fmapping,FILE_MAP_READ,0,0,0); |
| 732 | if (!peimage) |
| 733 | { WARN(shell,"failed to mmap filemap.\n"); |
| 734 | hRet = 0; |
| 735 | goto end_2; /* failure */ |
| 736 | } |
| 737 | dheader = (PIMAGE_DOS_HEADER)peimage; |
| 738 | |
| 739 | /* it is a pe header, SHELL_GetResourceTable checked that */ |
| 740 | pe_header = (PIMAGE_NT_HEADERS)(peimage+dheader->e_lfanew); |
| 741 | |
| 742 | /* probably makes problems with short PE headers... but I haven't seen |
| 743 | * one yet... |
| 744 | */ |
| 745 | pe_sections = (PIMAGE_SECTION_HEADER)(((char*)pe_header)+sizeof(*pe_header)); |
| 746 | rootresdir = NULL; |
| 747 | |
| 748 | for (i=0;i<pe_header->FileHeader.NumberOfSections;i++) |
| 749 | { if (pe_sections[i].Characteristics & IMAGE_SCN_CNT_UNINITIALIZED_DATA) |
| 750 | continue; |
| 751 | /* FIXME: doesn't work when the resources are not in a seperate section */ |
| 752 | if (pe_sections[i].VirtualAddress == pe_header->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_RESOURCE].VirtualAddress) |
| 753 | { rootresdir = (PIMAGE_RESOURCE_DIRECTORY)((char*)peimage+pe_sections[i].PointerToRawData); |
| 754 | break; |
| 755 | } |
| 756 | } |
| 757 | |
| 758 | if (!rootresdir) |
| 759 | { WARN(shell,"haven't found section for resource directory.\n"); |
| 760 | goto end_4; /* failure */ |
| 761 | } |
| 762 | |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame^] | 763 | icongroupresdir = GetResDirEntryW(rootresdir,RT_GROUP_ICONW, (DWORD)rootresdir,FALSE); |
Juergen Schmied | 72b76d1 | 1998-11-15 13:28:00 +0000 | [diff] [blame] | 764 | |
| 765 | if (!icongroupresdir) |
| 766 | { WARN(shell,"No Icongroupresourcedirectory!\n"); |
| 767 | goto end_4; /* failure */ |
| 768 | } |
| 769 | |
| 770 | iconDirCount = icongroupresdir->NumberOfNamedEntries+icongroupresdir->NumberOfIdEntries; |
| 771 | |
| 772 | if( nIconIndex == (UINT16)-1 ) |
| 773 | { RetPtr[0] = iconDirCount; |
| 774 | goto end_3; /* success */ |
| 775 | } |
| 776 | |
| 777 | if (nIconIndex >= iconDirCount) |
| 778 | { WARN(shell,"nIconIndex %d is larger than iconDirCount %d\n",nIconIndex,iconDirCount); |
| 779 | GlobalFree16(hRet); |
| 780 | goto end_4; /* failure */ |
| 781 | } |
| 782 | |
| 783 | cids = (CURSORICONDIR**)HeapAlloc(GetProcessHeap(),0,n*sizeof(CURSORICONDIR*)); |
| 784 | |
| 785 | /* caller just wanted the number of entries */ |
| 786 | xresent = (PIMAGE_RESOURCE_DIRECTORY_ENTRY)(icongroupresdir+1); |
| 787 | |
| 788 | /* assure we don't get too much ... */ |
| 789 | if( n > iconDirCount - nIconIndex ) |
| 790 | { n = iconDirCount - nIconIndex; |
| 791 | } |
| 792 | |
| 793 | /* starting from specified index ... */ |
| 794 | xresent = xresent+nIconIndex; |
| 795 | |
| 796 | for (i=0;i<n;i++,xresent++) |
| 797 | { CURSORICONDIR *cid; |
| 798 | PIMAGE_RESOURCE_DIRECTORY resdir; |
| 799 | |
| 800 | /* go down this resource entry, name */ |
| 801 | resdir = (PIMAGE_RESOURCE_DIRECTORY)((DWORD)rootresdir+(xresent->u2.s.OffsetToDirectory)); |
| 802 | |
| 803 | /* default language (0) */ |
| 804 | resdir = GetResDirEntryW(resdir,(LPWSTR)0,(DWORD)rootresdir,TRUE); |
| 805 | igdataent = (PIMAGE_RESOURCE_DATA_ENTRY)resdir; |
| 806 | |
| 807 | /* lookup address in mapped image for virtual address */ |
| 808 | igdata = NULL; |
| 809 | |
| 810 | for (j=0;j<pe_header->FileHeader.NumberOfSections;j++) |
| 811 | { if (igdataent->OffsetToData < pe_sections[j].VirtualAddress) |
| 812 | continue; |
| 813 | if (igdataent->OffsetToData+igdataent->Size > pe_sections[j].VirtualAddress+pe_sections[j].SizeOfRawData) |
Alexandre Julliard | e658d82 | 1997-11-30 17:45:40 +0000 | [diff] [blame] | 814 | continue; |
Juergen Schmied | 72b76d1 | 1998-11-15 13:28:00 +0000 | [diff] [blame] | 815 | igdata = peimage+(igdataent->OffsetToData-pe_sections[j].VirtualAddress+pe_sections[j].PointerToRawData); |
| 816 | } |
| 817 | |
| 818 | if (!igdata) |
| 819 | { WARN(shell,"no matching real address for icongroup!\n"); |
| 820 | goto end_4; /* failure */ |
| 821 | } |
| 822 | /* found */ |
| 823 | cid = (CURSORICONDIR*)igdata; |
| 824 | cids[i] = cid; |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame^] | 825 | RetPtr[i] = LookupIconIdFromDirectoryEx(igdata,TRUE,SYSMETRICS_CXICON,SYSMETRICS_CYICON,0); |
Juergen Schmied | 72b76d1 | 1998-11-15 13:28:00 +0000 | [diff] [blame] | 826 | } |
| 827 | |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame^] | 828 | iconresdir=GetResDirEntryW(rootresdir,RT_ICONW,(DWORD)rootresdir,FALSE); |
Juergen Schmied | 72b76d1 | 1998-11-15 13:28:00 +0000 | [diff] [blame] | 829 | |
| 830 | if (!iconresdir) |
| 831 | { WARN(shell,"No Iconresourcedirectory!\n"); |
| 832 | goto end_4; /* failure */ |
| 833 | } |
| 834 | |
| 835 | for (i=0;i<n;i++) |
| 836 | { PIMAGE_RESOURCE_DIRECTORY xresdir; |
| 837 | xresdir = GetResDirEntryW(iconresdir,(LPWSTR)(DWORD)RetPtr[i],(DWORD)rootresdir,FALSE); |
| 838 | xresdir = GetResDirEntryW(xresdir,(LPWSTR)0,(DWORD)rootresdir,TRUE); |
| 839 | idataent = (PIMAGE_RESOURCE_DATA_ENTRY)xresdir; |
| 840 | idata = NULL; |
| 841 | |
| 842 | /* map virtual to address in image */ |
| 843 | for (j=0;j<pe_header->FileHeader.NumberOfSections;j++) |
| 844 | { if (idataent->OffsetToData < pe_sections[j].VirtualAddress) |
| 845 | continue; |
| 846 | if (idataent->OffsetToData+idataent->Size > pe_sections[j].VirtualAddress+pe_sections[j].SizeOfRawData) |
| 847 | continue; |
| 848 | idata = peimage+(idataent->OffsetToData-pe_sections[j].VirtualAddress+pe_sections[j].PointerToRawData); |
| 849 | } |
| 850 | if (!idata) |
| 851 | { WARN(shell,"no matching real address found for icondata!\n"); |
| 852 | RetPtr[i]=0; |
| 853 | continue; |
Alexandre Julliard | e658d82 | 1997-11-30 17:45:40 +0000 | [diff] [blame] | 854 | } |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame^] | 855 | RetPtr[i] = CreateIconFromResourceEx(idata,idataent->Size,TRUE,0x00030000,SYSMETRICS_CXICON,SYSMETRICS_CYICON,0); |
Juergen Schmied | 72b76d1 | 1998-11-15 13:28:00 +0000 | [diff] [blame] | 856 | } |
| 857 | goto end_3; /* sucess */ |
Alexandre Julliard | e658d82 | 1997-11-30 17:45:40 +0000 | [diff] [blame] | 858 | } |
Juergen Schmied | 72b76d1 | 1998-11-15 13:28:00 +0000 | [diff] [blame] | 859 | goto end_1; /* return array with icon handles */ |
Alexandre Julliard | e658d82 | 1997-11-30 17:45:40 +0000 | [diff] [blame] | 860 | |
Juergen Schmied | 72b76d1 | 1998-11-15 13:28:00 +0000 | [diff] [blame] | 861 | /* cleaning up (try & catch would be nicer) */ |
| 862 | end_4: hRet = 0; /* failure */ |
| 863 | end_3: UnmapViewOfFile(peimage); /* success */ |
| 864 | end_2: CloseHandle(fmapping); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame^] | 865 | end_1: _lclose( hFile); |
Juergen Schmied | 72b76d1 | 1998-11-15 13:28:00 +0000 | [diff] [blame] | 866 | return hRet; |
Alexandre Julliard | 2ace16a | 1996-04-28 15:09:19 +0000 | [diff] [blame] | 867 | } |
| 868 | |
| 869 | /************************************************************************* |
Alexandre Julliard | 2197901 | 1997-03-05 08:22:35 +0000 | [diff] [blame] | 870 | * ExtractIcon16 (SHELL.34) |
Alexandre Julliard | 2ace16a | 1996-04-28 15:09:19 +0000 | [diff] [blame] | 871 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 872 | HICON16 WINAPI ExtractIcon16( HINSTANCE16 hInstance, LPCSTR lpszExeFileName, |
Alexandre Julliard | e658d82 | 1997-11-30 17:45:40 +0000 | [diff] [blame] | 873 | UINT16 nIconIndex ) |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 874 | { TRACE(shell,"\n"); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame^] | 875 | return ExtractIconA( hInstance, lpszExeFileName, nIconIndex ); |
Alexandre Julliard | 2ace16a | 1996-04-28 15:09:19 +0000 | [diff] [blame] | 876 | } |
Alexandre Julliard | d18872d | 1994-05-11 12:18:19 +0000 | [diff] [blame] | 877 | |
Marcus Meissner | 628e3e0 | 1999-01-23 11:56:39 +0000 | [diff] [blame] | 878 | /************************************************************************* |
| 879 | * ExtractIconEx16 (SHELL.40) |
| 880 | */ |
| 881 | HICON16 WINAPI ExtractIconEx16( |
| 882 | LPCSTR lpszFile, INT16 nIconIndex, HICON16 *phiconLarge, |
| 883 | HICON16 *phiconSmall, UINT16 nIcons |
| 884 | ) { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame^] | 885 | HICON *ilarge,*ismall; |
Marcus Meissner | 628e3e0 | 1999-01-23 11:56:39 +0000 | [diff] [blame] | 886 | UINT16 ret; |
| 887 | int i; |
Alexandre Julliard | 2197901 | 1997-03-05 08:22:35 +0000 | [diff] [blame] | 888 | |
Marcus Meissner | 628e3e0 | 1999-01-23 11:56:39 +0000 | [diff] [blame] | 889 | if (phiconLarge) |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame^] | 890 | ilarge = (HICON*)HeapAlloc(GetProcessHeap(),0,nIcons*sizeof(HICON)); |
Marcus Meissner | 628e3e0 | 1999-01-23 11:56:39 +0000 | [diff] [blame] | 891 | else |
| 892 | ilarge = NULL; |
| 893 | if (phiconSmall) |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame^] | 894 | ismall = (HICON*)HeapAlloc(GetProcessHeap(),0,nIcons*sizeof(HICON)); |
Marcus Meissner | 628e3e0 | 1999-01-23 11:56:39 +0000 | [diff] [blame] | 895 | else |
| 896 | ismall = NULL; |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame^] | 897 | ret = ExtractIconExA(lpszFile,nIconIndex,ilarge,ismall,nIcons); |
Marcus Meissner | 628e3e0 | 1999-01-23 11:56:39 +0000 | [diff] [blame] | 898 | if (ilarge) { |
| 899 | for (i=0;i<nIcons;i++) |
| 900 | phiconLarge[i]=ilarge[i]; |
| 901 | HeapFree(GetProcessHeap(),0,ilarge); |
| 902 | } |
| 903 | if (ismall) { |
| 904 | for (i=0;i<nIcons;i++) |
| 905 | phiconSmall[i]=ismall[i]; |
| 906 | HeapFree(GetProcessHeap(),0,ismall); |
| 907 | } |
| 908 | return ret; |
| 909 | } |
Alexandre Julliard | 2197901 | 1997-03-05 08:22:35 +0000 | [diff] [blame] | 910 | |
Alexandre Julliard | d18872d | 1994-05-11 12:18:19 +0000 | [diff] [blame] | 911 | /************************************************************************* |
| 912 | * ExtractAssociatedIcon [SHELL.36] |
Alexandre Julliard | 8b91563 | 1996-06-16 16:16:05 +0000 | [diff] [blame] | 913 | * |
| 914 | * Return icon for given file (either from file itself or from associated |
| 915 | * executable) and patch parameters if needed. |
Alexandre Julliard | d18872d | 1994-05-11 12:18:19 +0000 | [diff] [blame] | 916 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame^] | 917 | HICON WINAPI ExtractAssociatedIconA(HINSTANCE hInst, LPSTR lpIconPath, LPWORD lpiIcon) |
Juergen Schmied | 72b76d1 | 1998-11-15 13:28:00 +0000 | [diff] [blame] | 918 | { TRACE(shell,"\n"); |
Alexandre Julliard | 44ed71f | 1997-12-21 19:17:50 +0000 | [diff] [blame] | 919 | return ExtractAssociatedIcon16(hInst,lpIconPath,lpiIcon); |
| 920 | } |
| 921 | |
Juergen Schmied | 72b76d1 | 1998-11-15 13:28:00 +0000 | [diff] [blame] | 922 | HICON16 WINAPI ExtractAssociatedIcon16(HINSTANCE16 hInst, LPSTR lpIconPath, LPWORD lpiIcon) |
| 923 | { HICON16 hIcon; |
Alexandre Julliard | 2ace16a | 1996-04-28 15:09:19 +0000 | [diff] [blame] | 924 | |
Juergen Schmied | 72b76d1 | 1998-11-15 13:28:00 +0000 | [diff] [blame] | 925 | TRACE(shell,"\n"); |
Alexandre Julliard | 2ace16a | 1996-04-28 15:09:19 +0000 | [diff] [blame] | 926 | |
Juergen Schmied | 72b76d1 | 1998-11-15 13:28:00 +0000 | [diff] [blame] | 927 | hIcon = ExtractIcon16(hInst, lpIconPath, *lpiIcon); |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 928 | |
Juergen Schmied | 72b76d1 | 1998-11-15 13:28:00 +0000 | [diff] [blame] | 929 | if( hIcon < 2 ) |
| 930 | { if( hIcon == 1 ) /* no icons found in given file */ |
| 931 | { char tempPath[0x80]; |
Alexandre Julliard | 2197901 | 1997-03-05 08:22:35 +0000 | [diff] [blame] | 932 | UINT16 uRet = FindExecutable16(lpIconPath,NULL,tempPath); |
Alexandre Julliard | 8b91563 | 1996-06-16 16:16:05 +0000 | [diff] [blame] | 933 | |
| 934 | if( uRet > 32 && tempPath[0] ) |
Juergen Schmied | 72b76d1 | 1998-11-15 13:28:00 +0000 | [diff] [blame] | 935 | { strcpy(lpIconPath,tempPath); |
| 936 | hIcon = ExtractIcon16(hInst, lpIconPath, *lpiIcon); |
| 937 | if( hIcon > 2 ) |
| 938 | return hIcon; |
Alexandre Julliard | e658d82 | 1997-11-30 17:45:40 +0000 | [diff] [blame] | 939 | } |
Alexandre Julliard | 8b91563 | 1996-06-16 16:16:05 +0000 | [diff] [blame] | 940 | else hIcon = 0; |
Juergen Schmied | 72b76d1 | 1998-11-15 13:28:00 +0000 | [diff] [blame] | 941 | } |
Alexandre Julliard | 8b91563 | 1996-06-16 16:16:05 +0000 | [diff] [blame] | 942 | |
Juergen Schmied | 72b76d1 | 1998-11-15 13:28:00 +0000 | [diff] [blame] | 943 | if( hIcon == 1 ) |
Alexandre Julliard | e658d82 | 1997-11-30 17:45:40 +0000 | [diff] [blame] | 944 | *lpiIcon = 2; /* MSDOS icon - we found .exe but no icons in it */ |
Juergen Schmied | 72b76d1 | 1998-11-15 13:28:00 +0000 | [diff] [blame] | 945 | else |
Alexandre Julliard | e658d82 | 1997-11-30 17:45:40 +0000 | [diff] [blame] | 946 | *lpiIcon = 6; /* generic icon - found nothing */ |
| 947 | |
Juergen Schmied | 72b76d1 | 1998-11-15 13:28:00 +0000 | [diff] [blame] | 948 | GetModuleFileName16(hInst, lpIconPath, 0x80); |
| 949 | hIcon = LoadIcon16( hInst, MAKEINTRESOURCE16(*lpiIcon)); |
| 950 | } |
| 951 | return hIcon; |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 952 | } |
| 953 | |
| 954 | /************************************************************************* |
Alexandre Julliard | 2ace16a | 1996-04-28 15:09:19 +0000 | [diff] [blame] | 955 | * FindEnvironmentString [SHELL.38] |
| 956 | * |
| 957 | * Returns a pointer into the DOS environment... Ugh. |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 958 | */ |
Alexandre Julliard | 2ace16a | 1996-04-28 15:09:19 +0000 | [diff] [blame] | 959 | LPSTR SHELL_FindString(LPSTR lpEnv, LPCSTR entry) |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 960 | { UINT16 l; |
Alexandre Julliard | e658d82 | 1997-11-30 17:45:40 +0000 | [diff] [blame] | 961 | |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 962 | TRACE(shell,"\n"); |
| 963 | |
| 964 | l = strlen(entry); |
| 965 | for( ; *lpEnv ; lpEnv+=strlen(lpEnv)+1 ) |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame^] | 966 | { if( lstrncmpiA(lpEnv, entry, l) ) |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 967 | continue; |
Alexandre Julliard | e658d82 | 1997-11-30 17:45:40 +0000 | [diff] [blame] | 968 | if( !*(lpEnv+l) ) |
| 969 | return (lpEnv + l); /* empty entry */ |
| 970 | else if ( *(lpEnv+l)== '=' ) |
| 971 | return (lpEnv + l + 1); |
| 972 | } |
| 973 | return NULL; |
Alexandre Julliard | 2ace16a | 1996-04-28 15:09:19 +0000 | [diff] [blame] | 974 | } |
| 975 | |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame^] | 976 | SEGPTR WINAPI FindEnvironmentString16(LPSTR str) |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 977 | { SEGPTR spEnv; |
| 978 | LPSTR lpEnv,lpString; |
| 979 | TRACE(shell,"\n"); |
| 980 | |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame^] | 981 | spEnv = GetDOSEnvironment16(); |
Alexandre Julliard | 2ace16a | 1996-04-28 15:09:19 +0000 | [diff] [blame] | 982 | |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 983 | lpEnv = (LPSTR)PTR_SEG_TO_LIN(spEnv); |
| 984 | lpString = (spEnv)?SHELL_FindString(lpEnv, str):NULL; |
Alexandre Julliard | 2ace16a | 1996-04-28 15:09:19 +0000 | [diff] [blame] | 985 | |
Alexandre Julliard | e658d82 | 1997-11-30 17:45:40 +0000 | [diff] [blame] | 986 | if( lpString ) /* offset should be small enough */ |
| 987 | return spEnv + (lpString - lpEnv); |
Alexandre Julliard | e658d82 | 1997-11-30 17:45:40 +0000 | [diff] [blame] | 988 | return (SEGPTR)NULL; |
Alexandre Julliard | 2ace16a | 1996-04-28 15:09:19 +0000 | [diff] [blame] | 989 | } |
| 990 | |
| 991 | /************************************************************************* |
| 992 | * DoEnvironmentSubst [SHELL.37] |
| 993 | * |
| 994 | * Replace %KEYWORD% in the str with the value of variable KEYWORD |
| 995 | * from "DOS" environment. |
| 996 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame^] | 997 | DWORD WINAPI DoEnvironmentSubst16(LPSTR str,WORD length) |
Alexandre Julliard | 2ace16a | 1996-04-28 15:09:19 +0000 | [diff] [blame] | 998 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame^] | 999 | LPSTR lpEnv = (LPSTR)PTR_SEG_TO_LIN(GetDOSEnvironment16()); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1000 | LPSTR lpBuffer = (LPSTR)HeapAlloc( GetProcessHeap(), 0, length); |
Alexandre Julliard | 2ace16a | 1996-04-28 15:09:19 +0000 | [diff] [blame] | 1001 | LPSTR lpstr = str; |
| 1002 | LPSTR lpbstr = lpBuffer; |
| 1003 | |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame^] | 1004 | CharToOemA(str,str); |
Alexandre Julliard | 2ace16a | 1996-04-28 15:09:19 +0000 | [diff] [blame] | 1005 | |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 1006 | TRACE(shell,"accept %s\n", str); |
Alexandre Julliard | 2ace16a | 1996-04-28 15:09:19 +0000 | [diff] [blame] | 1007 | |
| 1008 | while( *lpstr && lpbstr - lpBuffer < length ) |
| 1009 | { |
| 1010 | LPSTR lpend = lpstr; |
| 1011 | |
| 1012 | if( *lpstr == '%' ) |
| 1013 | { |
| 1014 | do { lpend++; } while( *lpend && *lpend != '%' ); |
| 1015 | if( *lpend == '%' && lpend - lpstr > 1 ) /* found key */ |
| 1016 | { |
| 1017 | LPSTR lpKey; |
| 1018 | *lpend = '\0'; |
| 1019 | lpKey = SHELL_FindString(lpEnv, lpstr+1); |
| 1020 | if( lpKey ) /* found key value */ |
| 1021 | { |
| 1022 | int l = strlen(lpKey); |
| 1023 | |
| 1024 | if( l > length - (lpbstr - lpBuffer) - 1 ) |
| 1025 | { |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 1026 | WARN(shell,"-- Env subst aborted - string too short\n"); |
Alexandre Julliard | 2ace16a | 1996-04-28 15:09:19 +0000 | [diff] [blame] | 1027 | *lpend = '%'; |
| 1028 | break; |
| 1029 | } |
| 1030 | strcpy(lpbstr, lpKey); |
| 1031 | lpbstr += l; |
| 1032 | } |
| 1033 | else break; |
| 1034 | *lpend = '%'; |
| 1035 | lpstr = lpend + 1; |
| 1036 | } |
| 1037 | else break; /* back off and whine */ |
| 1038 | |
| 1039 | continue; |
| 1040 | } |
| 1041 | |
| 1042 | *lpbstr++ = *lpstr++; |
| 1043 | } |
| 1044 | |
| 1045 | *lpbstr = '\0'; |
| 1046 | if( lpstr - str == strlen(str) ) |
| 1047 | { |
| 1048 | strncpy(str, lpBuffer, length); |
| 1049 | length = 1; |
| 1050 | } |
| 1051 | else |
| 1052 | length = 0; |
| 1053 | |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 1054 | TRACE(shell,"-- return %s\n", str); |
Alexandre Julliard | 2ace16a | 1996-04-28 15:09:19 +0000 | [diff] [blame] | 1055 | |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame^] | 1056 | OemToCharA(str,str); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1057 | HeapFree( GetProcessHeap(), 0, lpBuffer); |
Alexandre Julliard | 2ace16a | 1996-04-28 15:09:19 +0000 | [diff] [blame] | 1058 | |
| 1059 | /* Return str length in the LOWORD |
| 1060 | * and 1 in HIWORD if subst was successful. |
| 1061 | */ |
| 1062 | return (DWORD)MAKELONG(strlen(str), length); |
Alexandre Julliard | d18872d | 1994-05-11 12:18:19 +0000 | [diff] [blame] | 1063 | } |
| 1064 | |
| 1065 | /************************************************************************* |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1066 | * ShellHookProc [SHELL.103] |
| 1067 | * System-wide WH_SHELL hook. |
Alexandre Julliard | 5819953 | 1994-04-21 01:20:00 +0000 | [diff] [blame] | 1068 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame^] | 1069 | LRESULT WINAPI ShellHookProc16(INT16 code, WPARAM16 wParam, LPARAM lParam) |
Alexandre Julliard | 5819953 | 1994-04-21 01:20:00 +0000 | [diff] [blame] | 1070 | { |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 1071 | TRACE(shell,"%i, %04x, %08x\n", code, wParam, |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1072 | (unsigned)lParam ); |
| 1073 | if( SHELL_hHook && SHELL_hWnd ) |
| 1074 | { |
| 1075 | UINT16 uMsg = 0; |
| 1076 | switch( code ) |
| 1077 | { |
| 1078 | case HSHELL_WINDOWCREATED: uMsg = uMsgWndCreated; break; |
| 1079 | case HSHELL_WINDOWDESTROYED: uMsg = uMsgWndDestroyed; break; |
| 1080 | case HSHELL_ACTIVATESHELLWINDOW: uMsg = uMsgShellActivate; |
| 1081 | } |
| 1082 | PostMessage16( SHELL_hWnd, uMsg, wParam, 0 ); |
| 1083 | } |
| 1084 | return CallNextHookEx16( WH_SHELL, code, wParam, lParam ); |
Alexandre Julliard | 5819953 | 1994-04-21 01:20:00 +0000 | [diff] [blame] | 1085 | } |
| 1086 | |
| 1087 | /************************************************************************* |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1088 | * RegisterShellHook [SHELL.102] |
Alexandre Julliard | 5819953 | 1994-04-21 01:20:00 +0000 | [diff] [blame] | 1089 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame^] | 1090 | BOOL WINAPI RegisterShellHook16(HWND16 hWnd, UINT16 uAction) |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 1091 | { TRACE(shell,"%04x [%u]\n", hWnd, uAction ); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1092 | |
| 1093 | switch( uAction ) |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 1094 | { case 2: /* register hWnd as a shell window */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1095 | if( !SHELL_hHook ) |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 1096 | { HMODULE16 hShell = GetModuleHandle16( "SHELL" ); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame^] | 1097 | SHELL_hHook = SetWindowsHookEx16( WH_SHELL, ShellHookProc16, hShell, 0 ); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1098 | if( SHELL_hHook ) |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame^] | 1099 | { uMsgWndCreated = RegisterWindowMessageA( lpstrMsgWndCreated ); |
| 1100 | uMsgWndDestroyed = RegisterWindowMessageA( lpstrMsgWndDestroyed ); |
| 1101 | uMsgShellActivate = RegisterWindowMessageA( lpstrMsgShellActivate ); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1102 | } |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 1103 | else |
| 1104 | WARN(shell,"-- unable to install ShellHookProc()!\n"); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1105 | } |
| 1106 | |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 1107 | if( SHELL_hHook ) |
| 1108 | return ((SHELL_hWnd = hWnd) != 0); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1109 | break; |
| 1110 | |
| 1111 | default: |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 1112 | WARN(shell, "-- unknown code %i\n", uAction ); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1113 | /* just in case */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1114 | SHELL_hWnd = 0; |
| 1115 | } |
| 1116 | return FALSE; |
Alexandre Julliard | 5819953 | 1994-04-21 01:20:00 +0000 | [diff] [blame] | 1117 | } |