2 * Shell Library Functions
4 * Copyright 1998 Marcus Meissner
5 * Copyright 2002 Eric Pouech
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
38 #include "wine/winbase16.h"
39 #include "wine/winuser16.h"
40 #include "shell32_main.h"
42 #include "wine/debug.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(shell
);
45 WINE_DECLARE_DEBUG_CHANNEL(exec
);
48 typedef struct { /* structure for dropped files */
51 BOOL16 fInNonClientArea
;
52 /* memory block with filenames follows */
53 } DROPFILESTRUCT16
, *LPDROPFILESTRUCT16
;
55 static const char* lpstrMsgWndCreated
= "OTHERWINDOWCREATED";
56 static const char* lpstrMsgWndDestroyed
= "OTHERWINDOWDESTROYED";
57 static const char* lpstrMsgShellActivate
= "ACTIVATESHELLWINDOW";
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;
64 HINSTANCE16 SHELL_hInstance
= 0;
65 HINSTANCE SHELL_hInstance32
;
66 static int SHELL_Attach
= 0;
68 /***********************************************************************
69 * DllEntryPoint [SHELL.101]
71 * Initialization code for shell.dll. Automatically loads the
72 * 32-bit shell32.dll to allow thunking up to 32-bit code.
76 BOOL WINAPI
SHELL_DllEntryPoint(DWORD Reason
, HINSTANCE16 hInst
,
77 WORD ds
, WORD HeapSize
, DWORD res1
, WORD res2
)
79 TRACE("(%08lx, %04x, %04x, %04x, %08lx, %04x)\n",
80 Reason
, hInst
, ds
, HeapSize
, res1
, res2
);
84 case DLL_PROCESS_ATTACH
:
85 if (SHELL_Attach
++) break;
86 SHELL_hInstance
= hInst
;
87 if(!SHELL_hInstance32
)
89 if(!(SHELL_hInstance32
= LoadLibraryA("shell32.dll")))
91 ERR("Could not load sibling shell32.dll\n");
97 case DLL_PROCESS_DETACH
:
101 if(SHELL_hInstance32
)
102 FreeLibrary(SHELL_hInstance32
);
109 /*************************************************************************
110 * DragAcceptFiles [SHELL.9]
112 void WINAPI
DragAcceptFiles16(HWND16 hWnd
, BOOL16 b
)
114 DragAcceptFiles(hWnd
, b
);
117 /*************************************************************************
118 * DragQueryFile [SHELL.11]
120 UINT16 WINAPI
DragQueryFile16(
128 LPDROPFILESTRUCT16 lpDropFileStruct
= (LPDROPFILESTRUCT16
) GlobalLock16(hDrop
);
130 TRACE("(%04x, %x, %p, %u)\n", hDrop
,wFile
,lpszFile
,wLength
);
132 if(!lpDropFileStruct
) goto end
;
134 lpDrop
= (LPSTR
) lpDropFileStruct
+ lpDropFileStruct
->wSize
;
135 wFile
= (wFile
==0xffff) ? 0xffffffff : wFile
;
139 while (*lpDrop
++); /* skip filename */
142 i
= (wFile
== 0xFFFFFFFF) ? i
: 0;
149 if (!lpszFile
) goto end
; /* needed buffer size */
150 i
= (wLength
> i
) ? i
: wLength
;
151 lstrcpynA (lpszFile
, lpDrop
, i
);
153 GlobalUnlock16(hDrop
);
157 /*************************************************************************
158 * DragFinish [SHELL.12]
160 void WINAPI
DragFinish16(HDROP16 h
)
163 GlobalFree16((HGLOBAL16
)h
);
167 /*************************************************************************
168 * DragQueryPoint [SHELL.13]
170 BOOL16 WINAPI
DragQueryPoint16(HDROP16 hDrop
, POINT16
*p
)
172 LPDROPFILESTRUCT16 lpDropFileStruct
;
175 lpDropFileStruct
= (LPDROPFILESTRUCT16
) GlobalLock16(hDrop
);
177 memcpy(p
,&lpDropFileStruct
->ptMousePos
,sizeof(POINT16
));
178 bRet
= lpDropFileStruct
->fInNonClientArea
;
180 GlobalUnlock16(hDrop
);
184 /*************************************************************************
185 * FindExecutable (SHELL.21)
187 HINSTANCE16 WINAPI
FindExecutable16( LPCSTR lpFile
, LPCSTR lpDirectory
,
189 { return (HINSTANCE16
)FindExecutableA( lpFile
, lpDirectory
, lpResult
);
193 /*************************************************************************
194 * AboutDlgProc (SHELL.33)
196 BOOL16 WINAPI
AboutDlgProc16( HWND16 hWnd
, UINT16 msg
, WPARAM16 wParam
,
198 { return AboutDlgProc( hWnd
, msg
, wParam
, lParam
);
202 /*************************************************************************
203 * ShellAbout (SHELL.22)
205 BOOL16 WINAPI
ShellAbout16( HWND16 hWnd
, LPCSTR szApp
, LPCSTR szOtherStuff
,
207 { return ShellAboutA( hWnd
, szApp
, szOtherStuff
, hIcon
);
210 /*************************************************************************
211 * InternalExtractIcon [SHELL.39]
213 * This abortion is called directly by Progman
215 HGLOBAL16 WINAPI
InternalExtractIcon16(HINSTANCE16 hInstance
,
216 LPCSTR lpszExeFileName
, UINT16 nIconIndex
, WORD n
)
219 HICON16
*RetPtr
= NULL
;
223 TRACE("(%04x,file %s,start %d,extract %d\n",
224 hInstance
, lpszExeFileName
, nIconIndex
, n
);
229 hFile
= OpenFile( lpszExeFileName
, &ofs
, OF_READ
|OF_EXIST
);
231 hRet
= GlobalAlloc16( GMEM_FIXED
| GMEM_ZEROINIT
, sizeof(HICON16
)*n
);
232 RetPtr
= (HICON16
*)GlobalLock16(hRet
);
234 if (hFile
== HFILE_ERROR
)
235 { /* not found - load from builtin module if available */
236 HINSTANCE hInst
= (HINSTANCE
)LoadLibrary16(lpszExeFileName
);
238 if (hInst
< 32) /* hmm, no Win16 module - try Win32 :-) */
239 hInst
= LoadLibraryA(lpszExeFileName
);
243 for (i
=nIconIndex
; i
< nIconIndex
+ n
; i
++)
244 RetPtr
[i
-nIconIndex
] =
245 (HICON16
)LoadIconA(hInst
, (LPCSTR
)(DWORD
)i
);
249 GlobalFree16( hRet
);
253 if (nIconIndex
== (UINT16
)-1) /* get number of icons */
255 RetPtr
[0] = PrivateExtractIconsA( ofs
.szPathName
, -1, 0, 0, NULL
, 0, 0, 0 );
261 icons
= HeapAlloc( GetProcessHeap(), 0, n
* sizeof(*icons
) );
262 res
= PrivateExtractIconsA( ofs
.szPathName
, nIconIndex
,
263 GetSystemMetrics(SM_CXICON
),
264 GetSystemMetrics(SM_CYICON
),
269 for (i
= 0; i
< n
; i
++) RetPtr
[i
] = (HICON16
)icons
[i
];
273 GlobalFree16( hRet
);
276 HeapFree( GetProcessHeap(), 0, icons
);
281 /*************************************************************************
282 * ExtractIcon (SHELL.34)
284 HICON16 WINAPI
ExtractIcon16( HINSTANCE16 hInstance
, LPCSTR lpszExeFileName
,
287 return ExtractIconA( hInstance
, lpszExeFileName
, nIconIndex
);
290 /*************************************************************************
291 * ExtractIconEx (SHELL.40)
293 HICON16 WINAPI
ExtractIconEx16(
294 LPCSTR lpszFile
, INT16 nIconIndex
, HICON16
*phiconLarge
,
295 HICON16
*phiconSmall
, UINT16 nIcons
297 HICON
*ilarge
,*ismall
;
302 ilarge
= (HICON
*)HeapAlloc(GetProcessHeap(),0,nIcons
*sizeof(HICON
));
306 ismall
= (HICON
*)HeapAlloc(GetProcessHeap(),0,nIcons
*sizeof(HICON
));
309 ret
= ExtractIconExA(lpszFile
,nIconIndex
,ilarge
,ismall
,nIcons
);
311 for (i
=0;i
<nIcons
;i
++)
312 phiconLarge
[i
]=ilarge
[i
];
313 HeapFree(GetProcessHeap(),0,ilarge
);
316 for (i
=0;i
<nIcons
;i
++)
317 phiconSmall
[i
]=ismall
[i
];
318 HeapFree(GetProcessHeap(),0,ismall
);
323 /*************************************************************************
324 * ExtractAssociatedIcon [SHELL.36]
326 * Return icon for given file (either from file itself or from associated
327 * executable) and patch parameters if needed.
329 HICON16 WINAPI
ExtractAssociatedIcon16(HINSTANCE16 hInst
, LPSTR lpIconPath
, LPWORD lpiIcon
)
336 lpiIcon
= &wDummyIcon
;
338 hIcon
= ExtractIcon16(hInst
, lpIconPath
, *lpiIcon
);
341 { if( hIcon
== 1 ) /* no icons found in given file */
342 { char tempPath
[0x80];
343 UINT16 uRet
= FindExecutable16(lpIconPath
,NULL
,tempPath
);
345 if( uRet
> 32 && tempPath
[0] )
346 { strcpy(lpIconPath
,tempPath
);
347 hIcon
= ExtractIcon16(hInst
, lpIconPath
, *lpiIcon
);
355 *lpiIcon
= 2; /* MSDOS icon - we found .exe but no icons in it */
357 *lpiIcon
= 6; /* generic icon - found nothing */
359 GetModuleFileName16(hInst
, lpIconPath
, 0x80);
360 hIcon
= LoadIconA( hInst
, MAKEINTRESOURCEA(*lpiIcon
));
365 /*************************************************************************
366 * ExtractAssociatedIconA (SHELL32.@)
368 * Return icon for given file (either from file itself or from associated
369 * executable) and patch parameters if needed.
371 HICON WINAPI
ExtractAssociatedIconA(HINSTANCE hInst
, LPSTR lpIconPath
, LPWORD lpiIcon
)
373 return ExtractAssociatedIcon16(hInst
,lpIconPath
,lpiIcon
);
376 /*************************************************************************
377 * ExtractAssociatedIconExA (SHELL32.@)
379 * Return icon for given file (either from file itself or from associated
380 * executable) and patch parameters if needed.
382 HICON WINAPI
ExtractAssociatedIconExA(DWORD d1
, DWORD d2
, DWORD d3
, DWORD d4
)
384 FIXME("(%lx %lx %lx %lx): stub\n", d1
, d2
, d3
, d4
);
388 /*************************************************************************
389 * ExtractAssociatedIconExW (SHELL32.@)
391 * Return icon for given file (either from file itself or from associated
392 * executable) and patch parameters if needed.
394 HICON WINAPI
ExtractAssociatedIconExW(DWORD d1
, DWORD d2
, DWORD d3
, DWORD d4
)
396 FIXME("(%lx %lx %lx %lx): stub\n", d1
, d2
, d3
, d4
);
400 /*************************************************************************
401 * FindEnvironmentString [SHELL.38]
403 * Returns a pointer into the DOS environment... Ugh.
405 LPSTR
SHELL_FindString(LPSTR lpEnv
, LPCSTR entry
)
411 for( ; *lpEnv
; lpEnv
+=strlen(lpEnv
)+1 )
412 { if( strncasecmp(lpEnv
, entry
, l
) )
415 return (lpEnv
+ l
); /* empty entry */
416 else if ( *(lpEnv
+l
)== '=' )
417 return (lpEnv
+ l
+ 1);
422 /**********************************************************************/
424 SEGPTR WINAPI
FindEnvironmentString16(LPSTR str
)
426 LPSTR lpEnv
,lpString
;
429 spEnv
= GetDOSEnvironment16();
431 lpEnv
= MapSL(spEnv
);
432 lpString
= (spEnv
)?SHELL_FindString(lpEnv
, str
):NULL
;
434 if( lpString
) /* offset should be small enough */
435 return spEnv
+ (lpString
- lpEnv
);
439 /*************************************************************************
440 * DoEnvironmentSubst [SHELL.37]
442 * Replace %KEYWORD% in the str with the value of variable KEYWORD
443 * from "DOS" environment.
445 DWORD WINAPI
DoEnvironmentSubst16(LPSTR str
,WORD length
)
447 LPSTR lpEnv
= MapSL(GetDOSEnvironment16());
448 LPSTR lpBuffer
= (LPSTR
)HeapAlloc( GetProcessHeap(), 0, length
);
450 LPSTR lpbstr
= lpBuffer
;
454 TRACE("accept %s\n", str
);
456 while( *lpstr
&& lpbstr
- lpBuffer
< length
)
462 do { lpend
++; } while( *lpend
&& *lpend
!= '%' );
463 if( *lpend
== '%' && lpend
- lpstr
> 1 ) /* found key */
467 lpKey
= SHELL_FindString(lpEnv
, lpstr
+1);
468 if( lpKey
) /* found key value */
470 int l
= strlen(lpKey
);
472 if( l
> length
- (lpbstr
- lpBuffer
) - 1 )
474 WARN("-- Env subst aborted - string too short\n");
478 strcpy(lpbstr
, lpKey
);
485 else break; /* back off and whine */
490 *lpbstr
++ = *lpstr
++;
494 if( lpstr
- str
== strlen(str
) )
496 strncpy(str
, lpBuffer
, length
);
502 TRACE("-- return %s\n", str
);
505 HeapFree( GetProcessHeap(), 0, lpBuffer
);
507 /* Return str length in the LOWORD
508 * and 1 in HIWORD if subst was successful.
510 return (DWORD
)MAKELONG(strlen(str
), length
);
513 /*************************************************************************
514 * ShellHookProc [SHELL.103]
515 * System-wide WH_SHELL hook.
517 LRESULT WINAPI
ShellHookProc16(INT16 code
, WPARAM16 wParam
, LPARAM lParam
)
519 TRACE("%i, %04x, %08x\n", code
, wParam
,
521 if( SHELL_hHook
&& SHELL_hWnd
)
526 case HSHELL_WINDOWCREATED
: uMsg
= uMsgWndCreated
; break;
527 case HSHELL_WINDOWDESTROYED
: uMsg
= uMsgWndDestroyed
; break;
528 case HSHELL_ACTIVATESHELLWINDOW
: uMsg
= uMsgShellActivate
;
530 PostMessageA( SHELL_hWnd
, uMsg
, wParam
, 0 );
532 return CallNextHookEx16( WH_SHELL
, code
, wParam
, lParam
);
535 /*************************************************************************
536 * RegisterShellHook [SHELL.102]
538 BOOL WINAPI
RegisterShellHook16(HWND16 hWnd
, UINT16 uAction
)
540 TRACE("%04x [%u]\n", hWnd
, uAction
);
544 case 2: /* register hWnd as a shell window */
547 HMODULE16 hShell
= GetModuleHandle16( "SHELL" );
548 HOOKPROC16 hookProc
= (HOOKPROC16
)GetProcAddress16( hShell
, (LPCSTR
)103 );
549 SHELL_hHook
= SetWindowsHookEx16( WH_SHELL
, hookProc
, hShell
, 0 );
552 uMsgWndCreated
= RegisterWindowMessageA( lpstrMsgWndCreated
);
553 uMsgWndDestroyed
= RegisterWindowMessageA( lpstrMsgWndDestroyed
);
554 uMsgShellActivate
= RegisterWindowMessageA( lpstrMsgShellActivate
);
557 WARN("-- unable to install ShellHookProc()!\n");
561 return ((SHELL_hWnd
= hWnd
) != 0);
565 WARN("-- unknown code %i\n", uAction
);
566 SHELL_hWnd
= 0; /* just in case */
572 /***********************************************************************
573 * DriveType (SHELL.262)
575 UINT16 WINAPI
DriveType16( UINT16 drive
)
578 char path
[] = "A:\\";
580 ret
= GetDriveTypeA(path
);
581 switch(ret
) /* some values are not supported in Win16 */
586 case DRIVE_NO_ROOT_DIR
: