Added tests for GetSystemDirectoryA/W and GetWindowsDirectoryA/W.
[wine/hacks.git] / dlls / shell32 / shell32_main.c
blobb10acd1cd22f6e239cb04049b2981b9dd84b3c04
1 /*
2 * Shell basics
4 * Copyright 1998 Marcus Meissner
5 * Copyright 1998 Juergen Schmied (jsch) * <juergen.schmied@metronet.de>
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
22 #include "config.h"
24 #include <stdlib.h>
25 #include <string.h>
26 #include <stdio.h>
28 #include "windef.h"
29 #include "winerror.h"
30 #include "winreg.h"
31 #include "dlgs.h"
32 #include "shellapi.h"
33 #include "shlobj.h"
34 #include "shlguid.h"
35 #include "shlwapi.h"
37 #include "undocshell.h"
38 #include "wine/winuser16.h"
39 #include "authors.h"
40 #include "heap.h"
41 #include "pidl.h"
42 #include "shell32_main.h"
44 #include "wine/debug.h"
46 WINE_DEFAULT_DEBUG_CHANNEL(shell);
48 #define MORE_DEBUG 1
49 /*************************************************************************
50 * CommandLineToArgvW [SHELL32.@]
52 * We must interpret the quotes in the command line to rebuild the argv
53 * array correctly:
54 * - arguments are separated by spaces or tabs
55 * - quotes serve as optional argument delimiters
56 * '"a b"' -> 'a b'
57 * - escaped quotes must be converted back to '"'
58 * '\"' -> '"'
59 * - an odd number of '\'s followed by '"' correspond to half that number
60 * of '\' followed by a '"' (extension of the above)
61 * '\\\"' -> '\"'
62 * '\\\\\"' -> '\\"'
63 * - an even number of '\'s followed by a '"' correspond to half that number
64 * of '\', plus a regular quote serving as an argument delimiter (which
65 * means it does not appear in the result)
66 * 'a\\"b c"' -> 'a\b c'
67 * 'a\\\\"b c"' -> 'a\\b c'
68 * - '\' that are not followed by a '"' are copied literally
69 * 'a\b' -> 'a\b'
70 * 'a\\b' -> 'a\\b'
72 * Note:
73 * '\t' == 0x0009
74 * ' ' == 0x0020
75 * '"' == 0x0022
76 * '\\' == 0x005c
78 LPWSTR* WINAPI CommandLineToArgvW(LPCWSTR lpCmdline, int* numargs)
80 DWORD argc;
81 HGLOBAL hargv;
82 LPWSTR *argv;
83 LPCWSTR cs;
84 LPWSTR arg,s,d;
85 LPWSTR cmdline;
86 int in_quotes,bcount;
88 if (*lpCmdline==0) {
89 /* Return the path to the executable */
90 DWORD size;
92 hargv=0;
93 size=16;
94 do {
95 size*=2;
96 hargv=GlobalReAlloc(hargv, size, 0);
97 argv=GlobalLock(hargv);
98 } while (GetModuleFileNameW((HMODULE)0, (LPWSTR)(argv+1), size-sizeof(LPWSTR)) == 0);
99 argv[0]=(LPWSTR)(argv+1);
100 if (numargs)
101 *numargs=2;
103 return argv;
106 /* to get a writeable copy */
107 argc=0;
108 bcount=0;
109 in_quotes=0;
110 cs=lpCmdline;
111 while (1) {
112 if (*cs==0 || ((*cs==0x0009 || *cs==0x0020) && !in_quotes)) {
113 /* space */
114 argc++;
115 /* skip the remaining spaces */
116 while (*cs==0x0009 || *cs==0x0020) {
117 cs++;
119 if (*cs==0)
120 break;
121 bcount=0;
122 continue;
123 } else if (*cs==0x005c) {
124 /* '\', count them */
125 bcount++;
126 } else if ((*cs==0x0022) && ((bcount & 1)==0)) {
127 /* unescaped '"' */
128 in_quotes=!in_quotes;
129 bcount=0;
130 } else {
131 /* a regular character */
132 bcount=0;
134 cs++;
136 /* Allocate in a single lump, the string array, and the strings that go with it.
137 * This way the caller can make a single GlobalFree call to free both, as per MSDN.
139 hargv=GlobalAlloc(0, argc*sizeof(LPWSTR)+(strlenW(lpCmdline)+1)*sizeof(WCHAR));
140 argv=GlobalLock(hargv);
141 if (!argv)
142 return NULL;
143 cmdline=(LPWSTR)(argv+argc);
144 strcpyW(cmdline, lpCmdline);
146 argc=0;
147 bcount=0;
148 in_quotes=0;
149 arg=d=s=cmdline;
150 while (*s) {
151 if ((*s==0x0009 || *s==0x0020) && !in_quotes) {
152 /* Close the argument and copy it */
153 *d=0;
154 argv[argc++]=arg;
156 /* skip the remaining spaces */
157 do {
158 s++;
159 } while (*s==0x0009 || *s==0x0020);
161 /* Start with a new argument */
162 arg=d=s;
163 bcount=0;
164 } else if (*s==0x005c) {
165 /* '\\' */
166 *d++=*s++;
167 bcount++;
168 } else if (*s==0x0022) {
169 /* '"' */
170 if ((bcount & 1)==0) {
171 /* Preceeded by an even number of '\', this is half that
172 * number of '\', plus a quote which we erase.
174 d-=bcount/2;
175 in_quotes=!in_quotes;
176 s++;
177 } else {
178 /* Preceeded by an odd number of '\', this is half that
179 * number of '\' followed by a '"'
181 d=d-bcount/2-1;
182 *d++='"';
183 s++;
185 bcount=0;
186 } else {
187 /* a regular character */
188 *d++=*s++;
189 bcount=0;
192 if (*arg) {
193 *d='\0';
194 argv[argc]=arg;
196 if (numargs)
197 *numargs=argc;
199 return argv;
202 /*************************************************************************
203 * SHGetFileInfoA [SHELL32.@]
207 DWORD WINAPI SHGetFileInfoA(LPCSTR path,DWORD dwFileAttributes,
208 SHFILEINFOA *psfi, UINT sizeofpsfi,
209 UINT flags )
211 char szLoaction[MAX_PATH];
212 int iIndex;
213 DWORD ret = TRUE, dwAttributes = 0;
214 IShellFolder * psfParent = NULL;
215 IExtractIconA * pei = NULL;
216 LPITEMIDLIST pidlLast = NULL, pidl = NULL;
217 HRESULT hr = S_OK;
218 BOOL IconNotYetLoaded=TRUE;
220 TRACE("(%s fattr=0x%lx sfi=%p(attr=0x%08lx) size=0x%x flags=0x%x)\n",
221 (flags & SHGFI_PIDL)? "pidl" : path, dwFileAttributes, psfi, psfi->dwAttributes, sizeofpsfi, flags);
223 if ((flags & SHGFI_USEFILEATTRIBUTES) && (flags & (SHGFI_ATTRIBUTES|SHGFI_EXETYPE|SHGFI_PIDL)))
224 return FALSE;
226 /* windows initializes this values regardless of the flags */
227 psfi->szDisplayName[0] = '\0';
228 psfi->szTypeName[0] = '\0';
229 psfi->iIcon = 0;
231 if (flags & SHGFI_EXETYPE) {
232 BOOL status = FALSE;
233 HANDLE hfile;
234 DWORD BinaryType;
235 IMAGE_DOS_HEADER mz_header;
236 IMAGE_NT_HEADERS nt;
237 DWORD len;
238 char magic[4];
240 if (flags != SHGFI_EXETYPE) return 0;
242 status = GetBinaryTypeA (path, &BinaryType);
243 if (!status) return 0;
244 if ((BinaryType == SCS_DOS_BINARY)
245 || (BinaryType == SCS_PIF_BINARY)) return 0x4d5a;
247 hfile = CreateFileA( path, GENERIC_READ, FILE_SHARE_READ,
248 NULL, OPEN_EXISTING, 0, 0 );
249 if ( hfile == INVALID_HANDLE_VALUE ) return 0;
251 /* The next section is adapted from MODULE_GetBinaryType, as we need
252 * to examine the image header to get OS and version information. We
253 * know from calling GetBinaryTypeA that the image is valid and either
254 * an NE or PE, so much error handling can be omitted.
255 * Seek to the start of the file and read the header information.
258 SetFilePointer( hfile, 0, NULL, SEEK_SET );
259 ReadFile( hfile, &mz_header, sizeof(mz_header), &len, NULL );
261 SetFilePointer( hfile, mz_header.e_lfanew, NULL, SEEK_SET );
262 ReadFile( hfile, magic, sizeof(magic), &len, NULL );
263 if ( *(DWORD*)magic == IMAGE_NT_SIGNATURE )
265 SetFilePointer( hfile, mz_header.e_lfanew, NULL, SEEK_SET );
266 ReadFile( hfile, &nt, sizeof(nt), &len, NULL );
267 CloseHandle( hfile );
268 if (nt.OptionalHeader.Subsystem == IMAGE_SUBSYSTEM_WINDOWS_GUI) {
269 return IMAGE_NT_SIGNATURE
270 | (nt.OptionalHeader.MajorSubsystemVersion << 24)
271 | (nt.OptionalHeader.MinorSubsystemVersion << 16);
273 return IMAGE_NT_SIGNATURE;
275 else if ( *(WORD*)magic == IMAGE_OS2_SIGNATURE )
277 IMAGE_OS2_HEADER ne;
278 SetFilePointer( hfile, mz_header.e_lfanew, NULL, SEEK_SET );
279 ReadFile( hfile, &ne, sizeof(ne), &len, NULL );
280 CloseHandle( hfile );
281 if (ne.ne_exetyp == 2) return IMAGE_OS2_SIGNATURE
282 | (ne.ne_expver << 16);
283 return 0;
285 CloseHandle( hfile );
286 return 0;
290 /* translate the path into a pidl only when SHGFI_USEFILEATTRIBUTES in not specified
291 the pidl functions fail on not existing file names */
292 if (flags & SHGFI_PIDL)
294 pidl = (LPCITEMIDLIST) path;
295 if (!pidl )
297 ERR("pidl is null!\n");
298 return FALSE;
301 else if (!(flags & SHGFI_USEFILEATTRIBUTES))
303 hr = SHILCreateFromPathA ( path, &pidl, &dwAttributes);
304 /* note: the attributes in ISF::ParseDisplayName are not implemented */
307 /* get the parent shellfolder */
308 if (pidl)
310 hr = SHBindToParent( pidl, &IID_IShellFolder, (LPVOID*)&psfParent, &pidlLast);
313 /* get the attributes of the child */
314 if (SUCCEEDED(hr) && (flags & SHGFI_ATTRIBUTES))
316 if (!(flags & SHGFI_ATTR_SPECIFIED))
318 psfi->dwAttributes = 0xffffffff;
320 IShellFolder_GetAttributesOf(psfParent, 1 , &pidlLast, &(psfi->dwAttributes));
323 /* get the displayname */
324 if (SUCCEEDED(hr) && (flags & SHGFI_DISPLAYNAME))
326 if (flags & SHGFI_USEFILEATTRIBUTES)
328 strcpy (psfi->szDisplayName, PathFindFileNameA(path));
330 else
332 STRRET str;
333 hr = IShellFolder_GetDisplayNameOf(psfParent, pidlLast, SHGDN_INFOLDER, &str);
334 StrRetToStrNA (psfi->szDisplayName, MAX_PATH, &str, pidlLast);
338 /* get the type name */
339 if (SUCCEEDED(hr) && (flags & SHGFI_TYPENAME))
341 if (!(flags & SHGFI_USEFILEATTRIBUTES))
342 _ILGetFileType(pidlLast, psfi->szTypeName, 80);
343 else
345 char sTemp[64];
346 strcpy(sTemp,PathFindExtensionA(path));
347 if (!( HCR_MapTypeToValue(sTemp, sTemp, 64, TRUE)
348 && HCR_MapTypeToValue(sTemp, psfi->szTypeName, 80, FALSE )))
350 lstrcpynA (psfi->szTypeName, sTemp, 80 - 6);
351 strcat (psfi->szTypeName, "-file");
356 /* ### icons ###*/
357 if (flags & SHGFI_LINKOVERLAY)
358 FIXME("set icon to link, stub\n");
360 if (flags & SHGFI_SELECTED)
361 FIXME("set icon to selected, stub\n");
363 if (flags & SHGFI_SHELLICONSIZE)
364 FIXME("set icon to shell size, stub\n");
366 /* get the iconlocation */
367 if (SUCCEEDED(hr) && (flags & SHGFI_ICONLOCATION ))
369 UINT uDummy,uFlags;
370 hr = IShellFolder_GetUIObjectOf(psfParent, 0, 1, &pidlLast, &IID_IExtractIconA, &uDummy, (LPVOID*)&pei);
372 if (SUCCEEDED(hr))
374 hr = IExtractIconA_GetIconLocation(pei, (flags & SHGFI_OPENICON)? GIL_OPENICON : 0,szLoaction, MAX_PATH, &iIndex, &uFlags);
375 /* FIXME what to do with the index? */
377 if(uFlags != GIL_NOTFILENAME)
378 strcpy (psfi->szDisplayName, szLoaction);
379 else
380 ret = FALSE;
382 IExtractIconA_Release(pei);
386 /* get icon index (or load icon)*/
387 if (SUCCEEDED(hr) && (flags & (SHGFI_ICON | SHGFI_SYSICONINDEX)))
390 if (flags & SHGFI_USEFILEATTRIBUTES)
392 char sTemp [MAX_PATH];
393 char * szExt;
394 DWORD dwNr=0;
396 lstrcpynA(sTemp, path, MAX_PATH);
397 szExt = (LPSTR) PathFindExtensionA(sTemp);
398 if( szExt && HCR_MapTypeToValue(szExt, sTemp, MAX_PATH, TRUE)
399 && HCR_GetDefaultIcon(sTemp, sTemp, MAX_PATH, &dwNr))
401 if (!strcmp("%1",sTemp)) /* icon is in the file */
403 strcpy(sTemp, path);
405 IconNotYetLoaded=FALSE;
406 psfi->iIcon = 0;
407 if (SHGFI_LARGEICON)
408 PrivateExtractIconsA(sTemp,dwNr,GetSystemMetrics(SM_CXICON),
409 GetSystemMetrics(SM_CYICON),
410 &psfi->hIcon,0,1,0);
411 else
412 PrivateExtractIconsA(sTemp,dwNr,GetSystemMetrics(SM_CXSMICON),
413 GetSystemMetrics(SM_CYSMICON),
414 &psfi->hIcon,0,1,0);
416 else /* default icon */
418 psfi->iIcon = 0;
421 else
423 if (!(PidlToSicIndex(psfParent, pidlLast, (flags & SHGFI_LARGEICON),
424 (flags & SHGFI_OPENICON)? GIL_OPENICON : 0, &(psfi->iIcon))))
426 ret = FALSE;
429 if (ret)
431 ret = (DWORD) ((flags & SHGFI_LARGEICON) ? ShellBigIconList : ShellSmallIconList);
435 /* icon handle */
436 if (SUCCEEDED(hr) && (flags & SHGFI_ICON) && IconNotYetLoaded)
437 psfi->hIcon = ImageList_GetIcon((flags & SHGFI_LARGEICON) ? ShellBigIconList:ShellSmallIconList, psfi->iIcon, ILD_NORMAL);
439 if (flags & (SHGFI_UNKNOWN1 | SHGFI_UNKNOWN2 | SHGFI_UNKNOWN3))
440 FIXME("unknown attribute!\n");
442 if (psfParent)
443 IShellFolder_Release(psfParent);
445 if (hr != S_OK)
446 ret = FALSE;
448 if(pidlLast) SHFree(pidlLast);
449 #ifdef MORE_DEBUG
450 TRACE ("icon=0x%08x index=0x%08x attr=0x%08lx name=%s type=%s ret=0x%08lx\n",
451 psfi->hIcon, psfi->iIcon, psfi->dwAttributes, psfi->szDisplayName, psfi->szTypeName, ret);
452 #endif
453 return ret;
456 /*************************************************************************
457 * SHGetFileInfoW [SHELL32.@]
460 DWORD WINAPI SHGetFileInfoW(LPCWSTR path,DWORD dwFileAttributes,
461 SHFILEINFOW *psfi, UINT sizeofpsfi,
462 UINT flags )
464 INT len;
465 LPSTR temppath;
466 DWORD ret;
467 SHFILEINFOA temppsfi;
469 len = WideCharToMultiByte(CP_ACP, 0, path, -1, NULL, 0, NULL, NULL);
470 temppath = HeapAlloc(GetProcessHeap(), 0, len);
471 WideCharToMultiByte(CP_ACP, 0, path, -1, temppath, len, NULL, NULL);
473 WideCharToMultiByte(CP_ACP, 0, psfi->szDisplayName, -1, temppsfi.szDisplayName,
474 sizeof(temppsfi.szDisplayName), NULL, NULL);
475 WideCharToMultiByte(CP_ACP, 0, psfi->szTypeName, -1, temppsfi.szTypeName,
476 sizeof(temppsfi.szTypeName), NULL, NULL);
478 ret = SHGetFileInfoA(temppath, dwFileAttributes, &temppsfi, sizeof(temppsfi), flags);
480 HeapFree(GetProcessHeap(), 0, temppath);
482 return ret;
485 /*************************************************************************
486 * SHGetFileInfo [SHELL32.@]
488 DWORD WINAPI SHGetFileInfoAW(
489 LPCVOID path,
490 DWORD dwFileAttributes,
491 LPVOID psfi,
492 UINT sizeofpsfi,
493 UINT flags)
495 if(SHELL_OsIsUnicode())
496 return SHGetFileInfoW(path, dwFileAttributes, psfi, sizeofpsfi, flags );
497 return SHGetFileInfoA(path, dwFileAttributes, psfi, sizeofpsfi, flags );
500 /*************************************************************************
501 * DuplicateIcon [SHELL32.@]
503 HICON WINAPI DuplicateIcon( HINSTANCE hInstance, HICON hIcon)
505 ICONINFO IconInfo;
506 HICON hDupIcon = 0;
508 TRACE("(%04x, %04x)\n", hInstance, hIcon);
510 if(GetIconInfo(hIcon, &IconInfo))
512 hDupIcon = CreateIconIndirect(&IconInfo);
514 /* clean up hbmMask and hbmColor */
515 DeleteObject(IconInfo.hbmMask);
516 DeleteObject(IconInfo.hbmColor);
519 return hDupIcon;
523 /*************************************************************************
524 * ExtractIconA [SHELL32.@]
526 * FIXME
527 * if the filename is not a file return 1
529 HICON WINAPI ExtractIconA( HINSTANCE hInstance, LPCSTR lpszExeFileName,
530 UINT nIconIndex )
531 { HGLOBAL16 handle = InternalExtractIcon16(hInstance,lpszExeFileName,nIconIndex, 1);
532 TRACE("\n");
533 if( handle )
535 HICON16* ptr = (HICON16*)GlobalLock16(handle);
536 HICON16 hIcon = *ptr;
538 GlobalFree16(handle);
539 return hIcon;
541 return 0;
544 /*************************************************************************
545 * ExtractIconW [SHELL32.@]
547 * FIXME: if the filename is not a file return 1
549 HICON WINAPI ExtractIconW( HINSTANCE hInstance, LPCWSTR lpszExeFileName,
550 UINT nIconIndex )
551 { LPSTR exefn;
552 HICON ret;
553 TRACE("\n");
555 exefn = HEAP_strdupWtoA(GetProcessHeap(),0,lpszExeFileName);
556 ret = ExtractIconA(hInstance,exefn,nIconIndex);
558 HeapFree(GetProcessHeap(),0,exefn);
559 return ret;
562 typedef struct
563 { LPCSTR szApp;
564 LPCSTR szOtherStuff;
565 HICON hIcon;
566 } ABOUT_INFO;
568 #define IDC_STATIC_TEXT 100
569 #define IDC_LISTBOX 99
570 #define IDC_WINE_TEXT 98
572 #define DROP_FIELD_TOP (-15)
573 #define DROP_FIELD_HEIGHT 15
575 static HICON hIconTitleFont;
577 static BOOL __get_dropline( HWND hWnd, LPRECT lprect )
578 { HWND hWndCtl = GetDlgItem(hWnd, IDC_WINE_TEXT);
579 if( hWndCtl )
580 { GetWindowRect( hWndCtl, lprect );
581 MapWindowPoints( 0, hWnd, (LPPOINT)lprect, 2 );
582 lprect->bottom = (lprect->top += DROP_FIELD_TOP);
583 return TRUE;
585 return FALSE;
588 /*************************************************************************
589 * SHAppBarMessage [SHELL32.@]
591 UINT WINAPI SHAppBarMessage(DWORD msg, PAPPBARDATA data)
593 int width=data->rc.right - data->rc.left;
594 int height=data->rc.bottom - data->rc.top;
595 RECT rec=data->rc;
596 switch (msg)
597 { case ABM_GETSTATE:
598 return ABS_ALWAYSONTOP | ABS_AUTOHIDE;
599 case ABM_GETTASKBARPOS:
600 GetWindowRect(data->hWnd, &rec);
601 data->rc=rec;
602 return TRUE;
603 case ABM_ACTIVATE:
604 SetActiveWindow(data->hWnd);
605 return TRUE;
606 case ABM_GETAUTOHIDEBAR:
607 data->hWnd=GetActiveWindow();
608 return TRUE;
609 case ABM_NEW:
610 SetWindowPos(data->hWnd,HWND_TOP,rec.left,rec.top,
611 width,height,SWP_SHOWWINDOW);
612 return TRUE;
613 case ABM_QUERYPOS:
614 GetWindowRect(data->hWnd, &(data->rc));
615 return TRUE;
616 case ABM_REMOVE:
617 FIXME("ABM_REMOVE broken\n");
618 /* FIXME: this is wrong; should it be DestroyWindow instead? */
619 /*CloseHandle(data->hWnd);*/
620 return TRUE;
621 case ABM_SETAUTOHIDEBAR:
622 SetWindowPos(data->hWnd,HWND_TOP,rec.left+1000,rec.top,
623 width,height,SWP_SHOWWINDOW);
624 return TRUE;
625 case ABM_SETPOS:
626 data->uEdge=(ABE_RIGHT | ABE_LEFT);
627 SetWindowPos(data->hWnd,HWND_TOP,data->rc.left,data->rc.top,
628 width,height,SWP_SHOWWINDOW);
629 return TRUE;
630 case ABM_WINDOWPOSCHANGED:
631 SetWindowPos(data->hWnd,HWND_TOP,rec.left,rec.top,
632 width,height,SWP_SHOWWINDOW);
633 return TRUE;
635 return FALSE;
638 /*************************************************************************
639 * SHHelpShortcuts_RunDLL [SHELL32.@]
642 DWORD WINAPI SHHelpShortcuts_RunDLL (DWORD dwArg1, DWORD dwArg2, DWORD dwArg3, DWORD dwArg4)
643 { FIXME("(%lx, %lx, %lx, %lx) empty stub!\n",
644 dwArg1, dwArg2, dwArg3, dwArg4);
646 return 0;
649 /*************************************************************************
650 * SHLoadInProc [SHELL32.@]
651 * Create an instance of specified object class from within
652 * the shell process and release it immediately
655 DWORD WINAPI SHLoadInProc (REFCLSID rclsid)
657 IUnknown * pUnk = NULL;
658 TRACE("%s\n", debugstr_guid(rclsid));
660 CoCreateInstance(rclsid, NULL, CLSCTX_INPROC_SERVER, &IID_IUnknown,(LPVOID*)pUnk);
661 if(pUnk)
663 IUnknown_Release(pUnk);
664 return NOERROR;
666 return DISP_E_MEMBERNOTFOUND;
669 /*************************************************************************
670 * AboutDlgProc (internal)
672 BOOL WINAPI AboutDlgProc( HWND hWnd, UINT msg, WPARAM wParam,
673 LPARAM lParam )
674 { HWND hWndCtl;
675 char Template[512], AppTitle[512];
677 TRACE("\n");
679 switch(msg)
680 { case WM_INITDIALOG:
681 { ABOUT_INFO *info = (ABOUT_INFO *)lParam;
682 if (info)
683 { const char* const *pstr = SHELL_People;
684 SendDlgItemMessageA(hWnd, stc1, STM_SETICON,info->hIcon, 0);
685 GetWindowTextA( hWnd, Template, sizeof(Template) );
686 sprintf( AppTitle, Template, info->szApp );
687 SetWindowTextA( hWnd, AppTitle );
688 SetWindowTextA( GetDlgItem(hWnd, IDC_STATIC_TEXT),
689 info->szOtherStuff );
690 hWndCtl = GetDlgItem(hWnd, IDC_LISTBOX);
691 SendMessageA( hWndCtl, WM_SETREDRAW, 0, 0 );
692 if (!hIconTitleFont)
694 LOGFONTA logFont;
695 SystemParametersInfoA( SPI_GETICONTITLELOGFONT, 0, &logFont, 0 );
696 hIconTitleFont = CreateFontIndirectA( &logFont );
698 SendMessageA( hWndCtl, WM_SETFONT, hIconTitleFont, 0 );
699 while (*pstr)
700 { SendMessageA( hWndCtl, LB_ADDSTRING, (WPARAM)-1, (LPARAM)*pstr );
701 pstr++;
703 SendMessageA( hWndCtl, WM_SETREDRAW, 1, 0 );
706 return 1;
708 case WM_PAINT:
709 { RECT rect;
710 PAINTSTRUCT ps;
711 HDC hDC = BeginPaint( hWnd, &ps );
713 if( __get_dropline( hWnd, &rect ) ) {
714 SelectObject( hDC, GetStockObject( BLACK_PEN ) );
715 MoveToEx( hDC, rect.left, rect.top, NULL );
716 LineTo( hDC, rect.right, rect.bottom );
718 EndPaint( hWnd, &ps );
720 break;
722 #if 0 /* FIXME: should use DoDragDrop */
723 case WM_LBTRACKPOINT:
724 hWndCtl = GetDlgItem(hWnd, IDC_LISTBOX);
725 if( (INT16)GetKeyState( VK_CONTROL ) < 0 )
726 { if( DragDetect( hWndCtl, *((LPPOINT)&lParam) ) )
727 { INT idx = SendMessageA( hWndCtl, LB_GETCURSEL, 0, 0 );
728 if( idx != -1 )
729 { INT length = SendMessageA( hWndCtl, LB_GETTEXTLEN, (WPARAM)idx, 0 );
730 HGLOBAL16 hMemObj = GlobalAlloc16( GMEM_MOVEABLE, length + 1 );
731 char* pstr = (char*)GlobalLock16( hMemObj );
733 if( pstr )
734 { HCURSOR hCursor = LoadCursorA( 0, MAKEINTRESOURCEA(OCR_DRAGOBJECT) );
735 SendMessageA( hWndCtl, LB_GETTEXT, (WPARAM)idx, (LPARAM)pstr );
736 SendMessageA( hWndCtl, LB_DELETESTRING, (WPARAM)idx, 0 );
737 UpdateWindow( hWndCtl );
738 if( !DragObject16((HWND16)hWnd, (HWND16)hWnd, DRAGOBJ_DATA, 0, (WORD)hMemObj, hCursor) )
739 SendMessageA( hWndCtl, LB_ADDSTRING, (WPARAM)-1, (LPARAM)pstr );
741 if( hMemObj )
742 GlobalFree16( hMemObj );
746 break;
747 #endif
749 case WM_QUERYDROPOBJECT:
750 if( wParam == 0 )
751 { LPDRAGINFO16 lpDragInfo = MapSL((SEGPTR)lParam);
752 if( lpDragInfo && lpDragInfo->wFlags == DRAGOBJ_DATA )
753 { RECT rect;
754 if( __get_dropline( hWnd, &rect ) )
755 { POINT pt;
756 pt.x=lpDragInfo->pt.x;
757 pt.x=lpDragInfo->pt.y;
758 rect.bottom += DROP_FIELD_HEIGHT;
759 if( PtInRect( &rect, pt ) )
760 { SetWindowLongA( hWnd, DWL_MSGRESULT, 1 );
761 return TRUE;
766 break;
768 case WM_DROPOBJECT:
769 if( wParam == hWnd )
770 { LPDRAGINFO16 lpDragInfo = MapSL((SEGPTR)lParam);
771 if( lpDragInfo && lpDragInfo->wFlags == DRAGOBJ_DATA && lpDragInfo->hList )
772 { char* pstr = (char*)GlobalLock16( (HGLOBAL16)(lpDragInfo->hList) );
773 if( pstr )
774 { static char __appendix_str[] = " with";
776 hWndCtl = GetDlgItem( hWnd, IDC_WINE_TEXT );
777 SendMessageA( hWndCtl, WM_GETTEXT, 512, (LPARAM)Template );
778 if( !strncmp( Template, "WINE", 4 ) )
779 SetWindowTextA( GetDlgItem(hWnd, IDC_STATIC_TEXT), Template );
780 else
781 { char* pch = Template + strlen(Template) - strlen(__appendix_str);
782 *pch = '\0';
783 SendMessageA( GetDlgItem(hWnd, IDC_LISTBOX), LB_ADDSTRING,
784 (WPARAM)-1, (LPARAM)Template );
787 strcpy( Template, pstr );
788 strcat( Template, __appendix_str );
789 SetWindowTextA( hWndCtl, Template );
790 SetWindowLongA( hWnd, DWL_MSGRESULT, 1 );
791 return TRUE;
795 break;
797 case WM_COMMAND:
798 if (wParam == IDOK)
799 { EndDialog(hWnd, TRUE);
800 return TRUE;
802 break;
803 case WM_CLOSE:
804 EndDialog(hWnd, TRUE);
805 break;
808 return 0;
812 /*************************************************************************
813 * ShellAboutA [SHELL32.288]
815 BOOL WINAPI ShellAboutA( HWND hWnd, LPCSTR szApp, LPCSTR szOtherStuff,
816 HICON hIcon )
817 { ABOUT_INFO info;
818 HRSRC hRes;
819 LPVOID template;
820 TRACE("\n");
822 if(!(hRes = FindResourceA(shell32_hInstance, "SHELL_ABOUT_MSGBOX", RT_DIALOGA)))
823 return FALSE;
824 if(!(template = (LPVOID)LoadResource(shell32_hInstance, hRes)))
825 return FALSE;
827 info.szApp = szApp;
828 info.szOtherStuff = szOtherStuff;
829 info.hIcon = hIcon;
830 if (!hIcon) info.hIcon = LoadIconA( 0, IDI_WINLOGOA );
831 return DialogBoxIndirectParamA( GetWindowLongA( hWnd, GWL_HINSTANCE ),
832 template, hWnd, AboutDlgProc, (LPARAM)&info );
836 /*************************************************************************
837 * ShellAboutW [SHELL32.289]
839 BOOL WINAPI ShellAboutW( HWND hWnd, LPCWSTR szApp, LPCWSTR szOtherStuff,
840 HICON hIcon )
841 { BOOL ret;
842 ABOUT_INFO info;
843 HRSRC hRes;
844 LPVOID template;
846 TRACE("\n");
848 if(!(hRes = FindResourceA(shell32_hInstance, "SHELL_ABOUT_MSGBOX", RT_DIALOGA)))
849 return FALSE;
850 if(!(template = (LPVOID)LoadResource(shell32_hInstance, hRes)))
851 return FALSE;
853 info.szApp = HEAP_strdupWtoA( GetProcessHeap(), 0, szApp );
854 info.szOtherStuff = HEAP_strdupWtoA( GetProcessHeap(), 0, szOtherStuff );
855 info.hIcon = hIcon;
856 if (!hIcon) info.hIcon = LoadIconA( 0, IDI_WINLOGOA );
857 ret = DialogBoxIndirectParamA( GetWindowLongA( hWnd, GWL_HINSTANCE ),
858 template, hWnd, AboutDlgProc, (LPARAM)&info );
859 HeapFree( GetProcessHeap(), 0, (LPSTR)info.szApp );
860 HeapFree( GetProcessHeap(), 0, (LPSTR)info.szOtherStuff );
861 return ret;
864 /*************************************************************************
865 * FreeIconList (SHELL32.@)
867 void WINAPI FreeIconList( DWORD dw )
868 { FIXME("(%lx): stub\n",dw);
871 /***********************************************************************
872 * DllGetVersion [SHELL32.@]
874 * Retrieves version information of the 'SHELL32.DLL'
876 * PARAMS
877 * pdvi [O] pointer to version information structure.
879 * RETURNS
880 * Success: S_OK
881 * Failure: E_INVALIDARG
883 * NOTES
884 * Returns version of a shell32.dll from IE4.01 SP1.
887 HRESULT WINAPI SHELL32_DllGetVersion (DLLVERSIONINFO *pdvi)
889 if (pdvi->cbSize != sizeof(DLLVERSIONINFO))
891 WARN("wrong DLLVERSIONINFO size from app\n");
892 return E_INVALIDARG;
895 pdvi->dwMajorVersion = 4;
896 pdvi->dwMinorVersion = 72;
897 pdvi->dwBuildNumber = 3110;
898 pdvi->dwPlatformID = 1;
900 TRACE("%lu.%lu.%lu.%lu\n",
901 pdvi->dwMajorVersion, pdvi->dwMinorVersion,
902 pdvi->dwBuildNumber, pdvi->dwPlatformID);
904 return S_OK;
906 /*************************************************************************
907 * global variables of the shell32.dll
908 * all are once per process
911 void (WINAPI *pDLLInitComctl)(LPVOID);
913 LPVOID (WINAPI *pCOMCTL32_Alloc) (INT);
914 BOOL (WINAPI *pCOMCTL32_Free) (LPVOID);
916 HDPA (WINAPI *pDPA_Create) (INT);
917 INT (WINAPI *pDPA_InsertPtr) (const HDPA, INT, LPVOID);
918 BOOL (WINAPI *pDPA_Sort) (const HDPA, PFNDPACOMPARE, LPARAM);
919 LPVOID (WINAPI *pDPA_GetPtr) (const HDPA, INT);
920 BOOL (WINAPI *pDPA_Destroy) (const HDPA);
921 INT (WINAPI *pDPA_Search) (const HDPA, LPVOID, INT, PFNDPACOMPARE, LPARAM, UINT);
922 LPVOID (WINAPI *pDPA_DeletePtr) (const HDPA hdpa, INT i);
923 HANDLE (WINAPI *pCreateMRUListA) (LPVOID lpcml);
924 DWORD (WINAPI *pFreeMRUListA) (HANDLE hMRUList);
925 INT (WINAPI *pAddMRUData) (HANDLE hList, LPCVOID lpData, DWORD cbData);
926 INT (WINAPI *pFindMRUData) (HANDLE hList, LPCVOID lpData, DWORD cbData, LPINT lpRegNum);
927 INT (WINAPI *pEnumMRUListA) (HANDLE hList, INT nItemPos, LPVOID lpBuffer, DWORD nBufferSize);
929 static HINSTANCE hComctl32;
931 LONG shell32_ObjCount = 0;
932 HINSTANCE shell32_hInstance = 0;
933 HIMAGELIST ShellSmallIconList = 0;
934 HIMAGELIST ShellBigIconList = 0;
937 /*************************************************************************
938 * SHELL32 LibMain
940 * NOTES
941 * calling oleinitialize here breaks sone apps.
944 BOOL WINAPI Shell32LibMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID fImpLoad)
946 TRACE("0x%x 0x%lx %p\n", hinstDLL, fdwReason, fImpLoad);
948 switch (fdwReason)
950 case DLL_PROCESS_ATTACH:
951 shell32_hInstance = hinstDLL;
952 hComctl32 = GetModuleHandleA("COMCTL32.DLL");
953 DisableThreadLibraryCalls(shell32_hInstance);
955 if (!hComctl32)
957 ERR("P A N I C SHELL32 loading failed\n");
958 return FALSE;
961 /* comctl32 */
962 pDLLInitComctl=(void*)GetProcAddress(hComctl32,"InitCommonControlsEx");
963 pCOMCTL32_Alloc=(void*)GetProcAddress(hComctl32, (LPCSTR)71L);
964 pCOMCTL32_Free=(void*)GetProcAddress(hComctl32, (LPCSTR)73L);
965 pDPA_Create=(void*)GetProcAddress(hComctl32, (LPCSTR)328L);
966 pDPA_Destroy=(void*)GetProcAddress(hComctl32, (LPCSTR)329L);
967 pDPA_GetPtr=(void*)GetProcAddress(hComctl32, (LPCSTR)332L);
968 pDPA_InsertPtr=(void*)GetProcAddress(hComctl32, (LPCSTR)334L);
969 pDPA_DeletePtr=(void*)GetProcAddress(hComctl32, (LPCSTR)336L);
970 pDPA_Sort=(void*)GetProcAddress(hComctl32, (LPCSTR)338L);
971 pDPA_Search=(void*)GetProcAddress(hComctl32, (LPCSTR)339L);
972 pCreateMRUListA=(void*)GetProcAddress(hComctl32, (LPCSTR)151L /*"CreateMRUListA"*/);
973 pFreeMRUListA=(void*)GetProcAddress(hComctl32, (LPCSTR)152L /*"FreeMRUList"*/);
974 pAddMRUData=(void*)GetProcAddress(hComctl32, (LPCSTR)167L /*"AddMRUData"*/);
975 pFindMRUData=(void*)GetProcAddress(hComctl32, (LPCSTR)169L /*"FindMRUData"*/);
976 pEnumMRUListA=(void*)GetProcAddress(hComctl32, (LPCSTR)154L /*"EnumMRUListA"*/);
978 /* initialize the common controls */
979 if (pDLLInitComctl)
981 pDLLInitComctl(NULL);
984 SIC_Initialize();
985 SYSTRAY_Init();
986 InitChangeNotifications();
987 SHInitRestricted(NULL, NULL);
988 break;
990 case DLL_THREAD_ATTACH:
991 break;
993 case DLL_THREAD_DETACH:
994 break;
996 case DLL_PROCESS_DETACH:
997 shell32_hInstance = 0;
999 if (pdesktopfolder)
1001 IShellFolder_Release(pdesktopfolder);
1002 pdesktopfolder = NULL;
1005 SIC_Destroy();
1006 FreeChangeNotifications();
1008 /* this one is here to check if AddRef/Release is balanced */
1009 if (shell32_ObjCount)
1011 WARN("leaving with %lu objects left (memory leak)\n", shell32_ObjCount);
1013 break;
1015 return TRUE;
1018 /*************************************************************************
1019 * DllInstall [SHELL32.@]
1021 * PARAMETERS
1023 * BOOL bInstall - TRUE for install, FALSE for uninstall
1024 * LPCWSTR pszCmdLine - command line (unused by shell32?)
1027 HRESULT WINAPI SHELL32_DllInstall(BOOL bInstall, LPCWSTR cmdline)
1029 FIXME("(%s, %s): stub!\n", bInstall ? "TRUE":"FALSE", debugstr_w(cmdline));
1031 return S_OK; /* indicate success */
1034 /***********************************************************************
1035 * DllCanUnloadNow (SHELL32.@)
1037 HRESULT WINAPI SHELL32_DllCanUnloadNow(void)
1039 FIXME("(void): stub\n");
1041 return S_FALSE;