Implemented VK_PRIOR and VK_NEXT processing (merged from Corel tree).
[wine] / dlls / shell32 / shell32_main.c
1 /*
2  *                              Shell basics
3  *
4  *  1998 Marcus Meissner
5  *  1998 Juergen Schmied (jsch)  *  <juergen.schmied@metronet.de>
6  */
7 #include <stdlib.h>
8 #include <string.h>
9 #include <stdio.h>
10
11 #include "windef.h"
12 #include "wingdi.h"
13 #include "wine/winuser16.h"
14 #include "winerror.h"
15 #include "heap.h"
16 #include "dlgs.h"
17 #include "ldt.h"
18 #include "debugtools.h"
19 #include "winreg.h"
20 #include "authors.h"
21
22 #include "shellapi.h"
23 #include "pidl.h"
24
25 #include "shell32_main.h"
26 #include "wine/undocshell.h"
27 #include "shlobj.h"
28 #include "shlguid.h"
29 #include "shlwapi.h"
30
31 DEFAULT_DEBUG_CHANNEL(shell);
32
33 #define MORE_DEBUG 1
34 /*************************************************************************
35  * CommandLineToArgvW                   [SHELL32.7]
36  */
37 LPWSTR* WINAPI CommandLineToArgvW(LPWSTR cmdline,LPDWORD numargs)
38 {       LPWSTR  *argv,s,t;
39         int     i;
40         TRACE("\n");
41
42         /* to get writeable copy */
43         cmdline = HEAP_strdupW( GetProcessHeap(), 0, cmdline);
44         s=cmdline;i=0;
45         while (*s)
46         { /* space */
47           if (*s==0x0020) 
48           { i++;
49             s++;
50             while (*s && *s==0x0020)
51               s++;
52             continue;
53           }
54           s++;
55         }
56         argv=(LPWSTR*)HeapAlloc( GetProcessHeap(), 0, sizeof(LPWSTR)*(i+1) );
57         s=t=cmdline;
58         i=0;
59         while (*s)
60         { if (*s==0x0020)
61           { *s=0;
62             argv[i++]=HEAP_strdupW( GetProcessHeap(), 0, t );
63             *s=0x0020;
64             while (*s && *s==0x0020)
65               s++;
66             t=s;
67             continue;
68           }
69           s++;
70         }
71         if (*t)
72           argv[i++]=(LPWSTR)HEAP_strdupW( GetProcessHeap(), 0, t );
73
74         HeapFree( GetProcessHeap(), 0, cmdline );
75         argv[i]=NULL;
76         *numargs=i;
77         return argv;
78 }
79
80 /*************************************************************************
81  * Control_RunDLL                       [SHELL32.12]
82  *
83  * Wild speculation in the following!
84  *
85  * http://premium.microsoft.com/msdn/library/techart/msdn193.htm
86  */
87
88 void WINAPI Control_RunDLL( HWND hwnd, LPCVOID code, LPCSTR cmd, DWORD arg4 )
89 {
90     FIXME("(0x%08x, %p, %s, 0x%08lx): stub\n", hwnd, code,
91           debugstr_a(cmd), arg4);
92 }
93
94 /*************************************************************************
95  * SHGetFileInfoA                       [SHELL32.@]
96  *
97  */
98
99 DWORD WINAPI SHGetFileInfoA(LPCSTR path,DWORD dwFileAttributes,
100                               SHFILEINFOA *psfi, UINT sizeofpsfi,
101                               UINT flags )
102 {
103         char szLoaction[MAX_PATH];
104         int iIndex;
105         DWORD ret = TRUE, dwAttributes = 0;
106         IShellFolder * psfParent = NULL;
107         IExtractIconA * pei = NULL;
108         LPITEMIDLIST    pidlLast = NULL, pidl = NULL;
109         HRESULT hr = S_OK;
110
111         TRACE("(%s fattr=0x%lx sfi=%p(attr=0x%08lx) size=0x%x flags=0x%x)\n", 
112           (flags & SHGFI_PIDL)? "pidl" : path, dwFileAttributes, psfi, psfi->dwAttributes, sizeofpsfi, flags);
113
114         if ((flags & SHGFI_USEFILEATTRIBUTES) && (flags & (SHGFI_ATTRIBUTES|SHGFI_EXETYPE|SHGFI_PIDL)))
115           return FALSE;
116         
117         /* windows initializes this values regardless of the flags */
118         psfi->szDisplayName[0] = '\0';
119         psfi->szTypeName[0] = '\0';
120         psfi->iIcon = 0;
121
122         if (flags & SHGFI_EXETYPE) {
123           BOOL status = FALSE;
124           HANDLE hfile;
125           DWORD BinaryType;
126           IMAGE_DOS_HEADER mz_header;
127           IMAGE_NT_HEADERS nt;
128           DWORD len;
129           char magic[4];
130
131           if (flags != SHGFI_EXETYPE) return 0;
132
133           status = GetBinaryTypeA (path, &BinaryType);
134           if (!status) return 0;
135           if ((BinaryType == SCS_DOS_BINARY)
136                 || (BinaryType == SCS_PIF_BINARY)) return 0x4d5a;
137
138           hfile = CreateFileA( path, GENERIC_READ, FILE_SHARE_READ,
139                 NULL, OPEN_EXISTING, 0, -1 );
140           if ( hfile == INVALID_HANDLE_VALUE ) return 0;
141
142         /* The next section is adapted from MODULE_GetBinaryType, as we need
143          * to examine the image header to get OS and version information. We
144          * know from calling GetBinaryTypeA that the image is valid and either
145          * an NE or PE, so much error handling can be omitted.
146          * Seek to the start of the file and read the header information.
147          */
148
149           SetFilePointer( hfile, 0, NULL, SEEK_SET );  
150           ReadFile( hfile, &mz_header, sizeof(mz_header), &len, NULL );
151
152          SetFilePointer( hfile, mz_header.e_lfanew, NULL, SEEK_SET );
153          ReadFile( hfile, magic, sizeof(magic), &len, NULL );
154          if ( *(DWORD*)magic      == IMAGE_NT_SIGNATURE )
155          {
156              SetFilePointer( hfile, mz_header.e_lfanew, NULL, SEEK_SET ); 
157              ReadFile( hfile, &nt, sizeof(nt), &len, NULL );
158               CloseHandle( hfile );
159               if (nt.OptionalHeader.Subsystem == IMAGE_SUBSYSTEM_WINDOWS_GUI) {
160                  return IMAGE_NT_SIGNATURE
161                         | (nt.OptionalHeader.MajorSubsystemVersion << 24)
162                         | (nt.OptionalHeader.MinorSubsystemVersion << 16);
163               }
164               return IMAGE_NT_SIGNATURE;
165           }
166          else if ( *(WORD*)magic == IMAGE_OS2_SIGNATURE )
167          {
168              IMAGE_OS2_HEADER ne;
169              SetFilePointer( hfile, mz_header.e_lfanew, NULL, SEEK_SET ); 
170              ReadFile( hfile, &ne, sizeof(ne), &len, NULL );
171               CloseHandle( hfile );
172              if (ne.ne_exetyp == 2) return IMAGE_OS2_SIGNATURE
173                         | (ne.ne_expver << 16);
174               return 0;
175           }
176           CloseHandle( hfile );
177           return 0;
178       }
179
180         
181         /* translate the path into a pidl only when SHGFI_USEFILEATTRIBUTES in not specified 
182            the pidl functions fail on not existing file names */
183         if (flags & SHGFI_PIDL)
184         {
185           pidl = (LPCITEMIDLIST) path;
186           if (!pidl )
187           {
188             ERR("pidl is null!\n");
189             return FALSE;
190           }
191         }
192         else if (!(flags & SHGFI_USEFILEATTRIBUTES))
193         {
194           hr = SHILCreateFromPathA ( path, &pidl, &dwAttributes);
195           /* note: the attributes in ISF::ParseDisplayName are not implemented */
196         }
197         
198         /* get the parent shellfolder */
199         if (pidl)
200         {
201           hr = SHBindToParent( pidl, &IID_IShellFolder, (LPVOID*)&psfParent, &pidlLast);
202         }
203         
204         /* get the attributes of the child */
205         if (SUCCEEDED(hr) && (flags & SHGFI_ATTRIBUTES))
206         {
207           if (!(flags & SHGFI_ATTR_SPECIFIED))
208           {
209             psfi->dwAttributes = 0xffffffff;
210           }
211           IShellFolder_GetAttributesOf(psfParent, 1 , &pidlLast, &(psfi->dwAttributes));
212         }
213
214         /* get the displayname */
215         if (SUCCEEDED(hr) && (flags & SHGFI_DISPLAYNAME))
216         { 
217           if (flags & SHGFI_USEFILEATTRIBUTES)
218           {
219             strcpy (psfi->szDisplayName, PathFindFileNameA(path));
220           }
221           else
222           {
223             STRRET str;
224             hr = IShellFolder_GetDisplayNameOf(psfParent, pidlLast, SHGDN_INFOLDER, &str);
225             StrRetToStrNA (psfi->szDisplayName, MAX_PATH, &str, pidlLast);
226           }
227         }
228
229         /* get the type name */
230         if (SUCCEEDED(hr) && (flags & SHGFI_TYPENAME))
231         {
232           _ILGetFileType(pidlLast, psfi->szTypeName, 80);
233         }
234
235         /* ### icons ###*/
236         if (flags & SHGFI_LINKOVERLAY)
237           FIXME("set icon to link, stub\n");
238
239         if (flags & SHGFI_SELECTED)
240           FIXME("set icon to selected, stub\n");
241
242         if (flags & SHGFI_SHELLICONSIZE)
243           FIXME("set icon to shell size, stub\n");
244
245         /* get the iconlocation */
246         if (SUCCEEDED(hr) && (flags & SHGFI_ICONLOCATION ))
247         {
248           UINT uDummy,uFlags;
249           hr = IShellFolder_GetUIObjectOf(psfParent, 0, 1, &pidlLast, &IID_IExtractIconA, &uDummy, (LPVOID*)&pei);
250
251           if (SUCCEEDED(hr))
252           {
253             hr = IExtractIconA_GetIconLocation(pei, (flags & SHGFI_OPENICON)? GIL_OPENICON : 0,szLoaction, MAX_PATH, &iIndex, &uFlags);
254             /* fixme what to do with the index? */
255
256             if(uFlags != GIL_NOTFILENAME)
257               strcpy (psfi->szDisplayName, szLoaction);
258             else
259               ret = FALSE;
260               
261             IExtractIconA_Release(pei);
262           }
263         }
264
265         /* get icon index (or load icon)*/
266         if (SUCCEEDED(hr) && (flags & (SHGFI_ICON | SHGFI_SYSICONINDEX)))
267         {
268           if (flags & SHGFI_USEFILEATTRIBUTES)
269           {
270             char sTemp [MAX_PATH];
271             char * szExt;
272             DWORD dwNr=0;
273
274             lstrcpynA(sTemp, path, MAX_PATH);
275             szExt = (LPSTR) PathFindExtensionA(sTemp);
276             if( szExt && HCR_MapTypeToValue(szExt, sTemp, MAX_PATH, TRUE)
277               && HCR_GetDefaultIcon(sTemp, sTemp, MAX_PATH, &dwNr))
278             {
279               if (!strcmp("%1",sTemp))            /* icon is in the file */
280               {
281                 strcpy(sTemp, path);
282               }
283               /* FIXME: if sTemp contains a valid filename, get the icon 
284                  from there, index is in dwNr
285               */
286               psfi->iIcon = 2;
287             }
288             else                                  /* default icon */
289             {
290               psfi->iIcon = 0;
291             }          
292           }
293           else
294           {
295             if (!(PidlToSicIndex(psfParent, pidlLast, (flags & SHGFI_LARGEICON), 
296               (flags & SHGFI_OPENICON)? GIL_OPENICON : 0, &(psfi->iIcon))))
297             {
298               ret = FALSE;
299             }
300           }
301           if (ret) 
302           {
303             ret = (DWORD) ((flags & SHGFI_LARGEICON) ? ShellBigIconList : ShellSmallIconList);
304           }
305         }
306
307         /* icon handle */
308         if (SUCCEEDED(hr) && (flags & SHGFI_ICON))
309           psfi->hIcon = pImageList_GetIcon((flags & SHGFI_LARGEICON) ? ShellBigIconList:ShellSmallIconList, psfi->iIcon, ILD_NORMAL);
310
311         if (flags & (SHGFI_UNKNOWN1 | SHGFI_UNKNOWN2 | SHGFI_UNKNOWN3))
312           FIXME("unknown attribute!\n");
313
314         if (psfParent)
315           IShellFolder_Release(psfParent);
316
317         if (hr != S_OK)
318           ret = FALSE;
319
320         if(pidlLast) SHFree(pidlLast);
321 #ifdef MORE_DEBUG
322         TRACE ("icon=0x%08x index=0x%08x attr=0x%08lx name=%s type=%s ret=0x%08lx\n", 
323                 psfi->hIcon, psfi->iIcon, psfi->dwAttributes, psfi->szDisplayName, psfi->szTypeName, ret);
324 #endif
325         return ret;
326 }
327
328 /*************************************************************************
329  * SHGetFileInfoW                       [SHELL32.@]
330  */
331
332 DWORD WINAPI SHGetFileInfoW(LPCWSTR path,DWORD dwFileAttributes,
333                               SHFILEINFOW *psfi, UINT sizeofpsfi,
334                               UINT flags )
335 {       FIXME("(%s,0x%lx,%p,0x%x,0x%x)\n",
336               debugstr_w(path),dwFileAttributes,psfi,sizeofpsfi,flags);
337         return 0;
338 }
339
340 /*************************************************************************
341  * SHGetFileInfoAW                      [SHELL32.@]
342  */
343 DWORD WINAPI SHGetFileInfoAW(
344         LPCVOID path,
345         DWORD dwFileAttributes,
346         LPVOID psfi,
347         UINT sizeofpsfi,
348         UINT flags)
349 {
350         if(SHELL_OsIsUnicode())
351           return SHGetFileInfoW(path, dwFileAttributes, psfi, sizeofpsfi, flags );
352         return SHGetFileInfoA(path, dwFileAttributes, psfi, sizeofpsfi, flags );
353 }
354
355 /*************************************************************************
356  * DuplicateIcon                        [SHELL32.188]
357  */
358 HICON WINAPI DuplicateIcon( HINSTANCE hInstance, HICON hIcon)
359 {
360     ICONINFO IconInfo;
361     HICON hDupIcon = NULL;
362
363     TRACE("(%04x, %04x)\n", hInstance, hIcon);
364
365     if(GetIconInfo(hIcon, &IconInfo))
366     {
367         hDupIcon = CreateIconIndirect(&IconInfo);
368
369         /* clean up hbmMask and hbmColor */
370         DeleteObject(IconInfo.hbmMask);        
371         DeleteObject(IconInfo.hbmColor);        
372     }
373  
374     return hDupIcon;
375 }
376     
377
378 /*************************************************************************
379  * ExtractIconA                         [SHELL32.133]
380  *
381  * FIXME
382  *  if the filename is not a file return 1
383  */
384 HICON WINAPI ExtractIconA( HINSTANCE hInstance, LPCSTR lpszExeFileName,
385         UINT nIconIndex )
386 {   HGLOBAL16 handle = InternalExtractIcon16(hInstance,lpszExeFileName,nIconIndex, 1);
387     TRACE("\n");
388     if( handle )
389     {
390         HICON16* ptr = (HICON16*)GlobalLock16(handle);
391         HICON16  hIcon = *ptr;
392
393         GlobalFree16(handle);
394         return hIcon;
395     }
396     return 0;
397 }
398
399 /*************************************************************************
400  * ExtractIconW                         [SHELL32.180]
401  *
402  * fixme
403  *  is the filename is not a file return 1
404  */
405 HICON WINAPI ExtractIconW( HINSTANCE hInstance, LPCWSTR lpszExeFileName,
406         UINT nIconIndex )
407 { LPSTR  exefn;
408   HICON  ret;
409   TRACE("\n");
410
411   exefn = HEAP_strdupWtoA(GetProcessHeap(),0,lpszExeFileName);
412   ret = ExtractIconA(hInstance,exefn,nIconIndex);
413
414         HeapFree(GetProcessHeap(),0,exefn);
415         return ret;
416 }
417
418 /*************************************************************************
419  * FindExecutableA                      [SHELL32.184]
420  */
421 HINSTANCE WINAPI FindExecutableA( LPCSTR lpFile, LPCSTR lpDirectory,
422                                       LPSTR lpResult )
423 { HINSTANCE retval=31;    /* default - 'No association was found' */
424     char old_dir[1024];
425
426   TRACE("File %s, Dir %s\n", 
427                  (lpFile != NULL?lpFile:"-"), 
428                  (lpDirectory != NULL?lpDirectory:"-"));
429
430     lpResult[0]='\0'; /* Start off with an empty return string */
431
432     /* trap NULL parameters on entry */
433     if (( lpFile == NULL ) || ( lpResult == NULL ))
434   { /* FIXME - should throw a warning, perhaps! */
435         return 2; /* File not found. Close enough, I guess. */
436     }
437
438     if (lpDirectory)
439   { GetCurrentDirectoryA( sizeof(old_dir), old_dir );
440         SetCurrentDirectoryA( lpDirectory );
441     }
442
443     retval = SHELL_FindExecutable( lpFile, "open", lpResult );
444
445   TRACE("returning %s\n", lpResult);
446   if (lpDirectory)
447     SetCurrentDirectoryA( old_dir );
448     return retval;
449 }
450
451 /*************************************************************************
452  * FindExecutableW                      [SHELL32.219]
453  */
454 HINSTANCE WINAPI FindExecutableW(LPCWSTR lpFile, LPCWSTR lpDirectory,
455                                      LPWSTR lpResult)
456 {
457   FIXME("(%p,%p,%p): stub\n", lpFile, lpDirectory, lpResult);
458   return 31;    /* default - 'No association was found' */
459 }
460
461 typedef struct
462 { LPCSTR  szApp;
463     LPCSTR  szOtherStuff;
464     HICON hIcon;
465 } ABOUT_INFO;
466
467 #define         IDC_STATIC_TEXT         100
468 #define         IDC_LISTBOX             99
469 #define         IDC_WINE_TEXT           98
470
471 #define         DROP_FIELD_TOP          (-15)
472 #define         DROP_FIELD_HEIGHT       15
473
474 extern HICON hIconTitleFont;
475
476 static BOOL __get_dropline( HWND hWnd, LPRECT lprect )
477 { HWND hWndCtl = GetDlgItem(hWnd, IDC_WINE_TEXT);
478     if( hWndCtl )
479   { GetWindowRect( hWndCtl, lprect );
480         MapWindowPoints( 0, hWnd, (LPPOINT)lprect, 2 );
481         lprect->bottom = (lprect->top += DROP_FIELD_TOP);
482         return TRUE;
483     }
484     return FALSE;
485 }
486
487 /*************************************************************************
488  * SHAppBarMessage                      [SHELL32.207]
489  */
490 UINT WINAPI SHAppBarMessage(DWORD msg, PAPPBARDATA data)
491 {
492         int width=data->rc.right - data->rc.left;
493         int height=data->rc.bottom - data->rc.top;
494         RECT rec=data->rc;
495         switch (msg)
496         { case ABM_GETSTATE:
497                return ABS_ALWAYSONTOP | ABS_AUTOHIDE;
498           case ABM_GETTASKBARPOS:
499                GetWindowRect(data->hWnd, &rec);
500                data->rc=rec;
501                return TRUE;
502           case ABM_ACTIVATE:
503                SetActiveWindow(data->hWnd);
504                return TRUE;
505           case ABM_GETAUTOHIDEBAR:
506                data->hWnd=GetActiveWindow();
507                return TRUE;
508           case ABM_NEW:
509                SetWindowPos(data->hWnd,HWND_TOP,rec.left,rec.top,
510                                         width,height,SWP_SHOWWINDOW);
511                return TRUE;
512           case ABM_QUERYPOS:
513                GetWindowRect(data->hWnd, &(data->rc));
514                return TRUE;
515           case ABM_REMOVE:
516                CloseHandle(data->hWnd);
517                return TRUE;
518           case ABM_SETAUTOHIDEBAR:
519                SetWindowPos(data->hWnd,HWND_TOP,rec.left+1000,rec.top,
520                                        width,height,SWP_SHOWWINDOW);          
521                return TRUE;
522           case ABM_SETPOS:
523                data->uEdge=(ABE_RIGHT | ABE_LEFT);
524                SetWindowPos(data->hWnd,HWND_TOP,data->rc.left,data->rc.top,
525                                   width,height,SWP_SHOWWINDOW);
526                return TRUE;
527           case ABM_WINDOWPOSCHANGED:
528                SetWindowPos(data->hWnd,HWND_TOP,rec.left,rec.top,
529                                         width,height,SWP_SHOWWINDOW);
530                return TRUE;
531           }
532       return FALSE;
533 }
534
535 /*************************************************************************
536  * SHHelpShortcuts_RunDLL               [SHELL32.224]
537  *
538  */
539 DWORD WINAPI SHHelpShortcuts_RunDLL (DWORD dwArg1, DWORD dwArg2, DWORD dwArg3, DWORD dwArg4)
540 { FIXME("(%lx, %lx, %lx, %lx) empty stub!\n",
541         dwArg1, dwArg2, dwArg3, dwArg4);
542
543   return 0;
544 }
545
546 /*************************************************************************
547  * SHLoadInProc                         [SHELL32.225]
548  * Create an instance of specified object class from within 
549  * the shell process and release it immediately
550  */
551
552 DWORD WINAPI SHLoadInProc (REFCLSID rclsid)
553 {
554         IUnknown * pUnk = NULL;
555         TRACE("%s\n", debugstr_guid(rclsid));
556
557         CoCreateInstance(rclsid, NULL, CLSCTX_INPROC_SERVER, &IID_IUnknown,(LPVOID*)pUnk);
558         if(pUnk)
559         {
560           IUnknown_Release(pUnk);
561           return NOERROR;
562         }
563         return DISP_E_MEMBERNOTFOUND;
564 }
565
566 /*************************************************************************
567  * ShellExecuteA                        [SHELL32.245]
568  */
569 HINSTANCE WINAPI ShellExecuteA( HWND hWnd, LPCSTR lpOperation,
570                                     LPCSTR lpFile, LPCSTR lpParameters,
571                                     LPCSTR lpDirectory, INT iShowCmd )
572 {   TRACE("\n");
573     return ShellExecute16( hWnd, lpOperation, lpFile, lpParameters,
574                            lpDirectory, iShowCmd );
575 }
576
577 /*************************************************************************
578  * ShellExecuteW                        [SHELL32.294]
579  * from shellapi.h
580  * WINSHELLAPI HINSTANCE APIENTRY ShellExecuteW(HWND hwnd, LPCWSTR lpOperation, 
581  * LPCWSTR lpFile, LPCWSTR lpParameters, LPCWSTR lpDirectory, INT nShowCmd);   
582  */
583 HINSTANCE WINAPI 
584 ShellExecuteW(
585        HWND hwnd, 
586        LPCWSTR lpOperation, 
587        LPCWSTR lpFile, 
588        LPCWSTR lpParameters, 
589        LPCWSTR lpDirectory, 
590        INT nShowCmd) {
591
592        FIXME(": stub\n");
593        return 0;
594 }
595
596 /*************************************************************************
597  * AboutDlgProc                 (internal)
598  */
599 BOOL WINAPI AboutDlgProc( HWND hWnd, UINT msg, WPARAM wParam,
600                               LPARAM lParam )
601 {   HWND hWndCtl;
602     char Template[512], AppTitle[512];
603
604     TRACE("\n");
605
606     switch(msg)
607     { case WM_INITDIALOG:
608       { ABOUT_INFO *info = (ABOUT_INFO *)lParam;
609             if (info)
610         { const char* const *pstr = SHELL_People;
611                 SendDlgItemMessageA(hWnd, stc1, STM_SETICON,info->hIcon, 0);
612                 GetWindowTextA( hWnd, Template, sizeof(Template) );
613                 sprintf( AppTitle, Template, info->szApp );
614                 SetWindowTextA( hWnd, AppTitle );
615                 SetWindowTextA( GetDlgItem(hWnd, IDC_STATIC_TEXT),
616                                   info->szOtherStuff );
617                 hWndCtl = GetDlgItem(hWnd, IDC_LISTBOX);
618                 SendMessageA( hWndCtl, WM_SETREDRAW, 0, 0 );
619                 SendMessageA( hWndCtl, WM_SETFONT, hIconTitleFont, 0 );
620                 while (*pstr)
621           { SendMessageA( hWndCtl, LB_ADDSTRING, (WPARAM)-1, (LPARAM)*pstr );
622                     pstr++;
623                 }
624                 SendMessageA( hWndCtl, WM_SETREDRAW, 1, 0 );
625             }
626         }
627         return 1;
628
629     case WM_PAINT:
630       { RECT rect;
631             PAINTSTRUCT ps;
632             HDC hDC = BeginPaint( hWnd, &ps );
633
634             if( __get_dropline( hWnd, &rect ) ) {
635                 SelectObject( hDC, GetStockObject( BLACK_PEN ) );
636                 MoveToEx( hDC, rect.left, rect.top, NULL );
637                 LineTo( hDC, rect.right, rect.bottom );
638             }
639             EndPaint( hWnd, &ps );
640         }
641         break;
642
643     case WM_LBTRACKPOINT:
644         hWndCtl = GetDlgItem(hWnd, IDC_LISTBOX);
645         if( (INT16)GetKeyState16( VK_CONTROL ) < 0 )
646       { if( DragDetect( hWndCtl, *((LPPOINT)&lParam) ) )
647         { INT idx = SendMessageA( hWndCtl, LB_GETCURSEL, 0, 0 );
648                 if( idx != -1 )
649           { INT length = SendMessageA( hWndCtl, LB_GETTEXTLEN, (WPARAM)idx, 0 );
650                     HGLOBAL16 hMemObj = GlobalAlloc16( GMEM_MOVEABLE, length + 1 );
651                     char* pstr = (char*)GlobalLock16( hMemObj );
652
653                     if( pstr )
654             { HCURSOR16 hCursor = LoadCursor16( 0, MAKEINTRESOURCE16(OCR_DRAGOBJECT) );
655                         SendMessageA( hWndCtl, LB_GETTEXT, (WPARAM)idx, (LPARAM)pstr );
656                         SendMessageA( hWndCtl, LB_DELETESTRING, (WPARAM)idx, 0 );
657                         UpdateWindow( hWndCtl );
658                         if( !DragObject16((HWND16)hWnd, (HWND16)hWnd, DRAGOBJ_DATA, 0, (WORD)hMemObj, hCursor) )
659                             SendMessageA( hWndCtl, LB_ADDSTRING, (WPARAM)-1, (LPARAM)pstr );
660                     }
661             if( hMemObj )
662               GlobalFree16( hMemObj );
663                 }
664             }
665         }
666         break;
667
668     case WM_QUERYDROPOBJECT:
669         if( wParam == 0 )
670       { LPDRAGINFO16 lpDragInfo = (LPDRAGINFO16)PTR_SEG_TO_LIN((SEGPTR)lParam);
671             if( lpDragInfo && lpDragInfo->wFlags == DRAGOBJ_DATA )
672         { RECT rect;
673                 if( __get_dropline( hWnd, &rect ) )
674           { POINT pt;
675             pt.x=lpDragInfo->pt.x;
676             pt.x=lpDragInfo->pt.y;
677                     rect.bottom += DROP_FIELD_HEIGHT;
678                     if( PtInRect( &rect, pt ) )
679             { SetWindowLongA( hWnd, DWL_MSGRESULT, 1 );
680                         return TRUE;
681                     }
682                 }
683             }
684         }
685         break;
686
687     case WM_DROPOBJECT:
688         if( wParam == hWnd )
689       { LPDRAGINFO16 lpDragInfo = (LPDRAGINFO16)PTR_SEG_TO_LIN((SEGPTR)lParam);
690             if( lpDragInfo && lpDragInfo->wFlags == DRAGOBJ_DATA && lpDragInfo->hList )
691         { char* pstr = (char*)GlobalLock16( (HGLOBAL16)(lpDragInfo->hList) );
692                 if( pstr )
693           { static char __appendix_str[] = " with";
694
695                     hWndCtl = GetDlgItem( hWnd, IDC_WINE_TEXT );
696                     SendMessageA( hWndCtl, WM_GETTEXT, 512, (LPARAM)Template );
697                     if( !strncmp( Template, "WINE", 4 ) )
698                         SetWindowTextA( GetDlgItem(hWnd, IDC_STATIC_TEXT), Template );
699                     else
700           { char* pch = Template + strlen(Template) - strlen(__appendix_str);
701                         *pch = '\0';
702                         SendMessageA( GetDlgItem(hWnd, IDC_LISTBOX), LB_ADDSTRING, 
703                                         (WPARAM)-1, (LPARAM)Template );
704                     }
705
706                     strcpy( Template, pstr );
707                     strcat( Template, __appendix_str );
708                     SetWindowTextA( hWndCtl, Template );
709                     SetWindowLongA( hWnd, DWL_MSGRESULT, 1 );
710                     return TRUE;
711                 }
712             }
713         }
714         break;
715
716     case WM_COMMAND:
717         if (wParam == IDOK)
718     {  EndDialog(hWnd, TRUE);
719             return TRUE;
720         }
721         break;
722     case WM_CLOSE:
723       EndDialog(hWnd, TRUE);
724       break;
725     }
726
727     return 0;
728 }
729
730
731 /*************************************************************************
732  * ShellAboutA                          [SHELL32.243]
733  */
734 BOOL WINAPI ShellAboutA( HWND hWnd, LPCSTR szApp, LPCSTR szOtherStuff,
735                              HICON hIcon )
736 {   ABOUT_INFO info;
737     HRSRC hRes;
738     LPVOID template;
739     TRACE("\n");
740
741     if(!(hRes = FindResourceA(shell32_hInstance, "SHELL_ABOUT_MSGBOX", RT_DIALOGA)))
742         return FALSE;
743     if(!(template = (LPVOID)LoadResource(shell32_hInstance, hRes)))
744         return FALSE;
745
746     info.szApp        = szApp;
747     info.szOtherStuff = szOtherStuff;
748     info.hIcon        = hIcon;
749     if (!hIcon) info.hIcon = LoadIcon16( 0, MAKEINTRESOURCE16(OIC_WINEICON) );
750     return DialogBoxIndirectParamA( GetWindowLongA( hWnd, GWL_HINSTANCE ),
751                                       template, hWnd, AboutDlgProc, (LPARAM)&info );
752 }
753
754
755 /*************************************************************************
756  * ShellAboutW                          [SHELL32.244]
757  */
758 BOOL WINAPI ShellAboutW( HWND hWnd, LPCWSTR szApp, LPCWSTR szOtherStuff,
759                              HICON hIcon )
760 {   BOOL ret;
761     ABOUT_INFO info;
762     HRSRC hRes;
763     LPVOID template;
764
765     TRACE("\n");
766     
767     if(!(hRes = FindResourceA(shell32_hInstance, "SHELL_ABOUT_MSGBOX", RT_DIALOGA)))
768         return FALSE;
769     if(!(template = (LPVOID)LoadResource(shell32_hInstance, hRes)))
770         return FALSE;
771
772     info.szApp        = HEAP_strdupWtoA( GetProcessHeap(), 0, szApp );
773     info.szOtherStuff = HEAP_strdupWtoA( GetProcessHeap(), 0, szOtherStuff );
774     info.hIcon        = hIcon;
775     if (!hIcon) info.hIcon = LoadIcon16( 0, MAKEINTRESOURCE16(OIC_WINEICON) );
776     ret = DialogBoxIndirectParamA( GetWindowLongA( hWnd, GWL_HINSTANCE ),
777                                    template, hWnd, AboutDlgProc, (LPARAM)&info );
778     HeapFree( GetProcessHeap(), 0, (LPSTR)info.szApp );
779     HeapFree( GetProcessHeap(), 0, (LPSTR)info.szOtherStuff );
780     return ret;
781 }
782
783 /*************************************************************************
784  * FreeIconList
785  */
786 void WINAPI FreeIconList( DWORD dw )
787 { FIXME("(%lx): stub\n",dw);
788 }
789
790 /***********************************************************************
791  * DllGetVersion [SHELL32]
792  *
793  * Retrieves version information of the 'SHELL32.DLL'
794  *
795  * PARAMS
796  *     pdvi [O] pointer to version information structure.
797  *
798  * RETURNS
799  *     Success: S_OK
800  *     Failure: E_INVALIDARG
801  *
802  * NOTES
803  *     Returns version of a shell32.dll from IE4.01 SP1.
804  */
805
806 HRESULT WINAPI SHELL32_DllGetVersion (DLLVERSIONINFO *pdvi)
807 {
808         if (pdvi->cbSize != sizeof(DLLVERSIONINFO)) 
809         {
810           WARN("wrong DLLVERSIONINFO size from app");
811           return E_INVALIDARG;
812         }
813
814         pdvi->dwMajorVersion = 4;
815         pdvi->dwMinorVersion = 72;
816         pdvi->dwBuildNumber = 3110;
817         pdvi->dwPlatformID = 1;
818
819         TRACE("%lu.%lu.%lu.%lu\n",
820            pdvi->dwMajorVersion, pdvi->dwMinorVersion,
821            pdvi->dwBuildNumber, pdvi->dwPlatformID);
822
823         return S_OK;
824 }
825 /*************************************************************************
826  * global variables of the shell32.dll
827  * all are once per process
828  *
829  */
830 void    (WINAPI* pDLLInitComctl)(LPVOID);
831 INT     (WINAPI* pImageList_AddIcon) (HIMAGELIST himl, HICON hIcon);
832 INT     (WINAPI* pImageList_ReplaceIcon) (HIMAGELIST, INT, HICON);
833 HIMAGELIST (WINAPI * pImageList_Create) (INT,INT,UINT,INT,INT);
834 BOOL    (WINAPI* pImageList_Draw) (HIMAGELIST himl, int i, HDC hdcDest, int x, int y, UINT fStyle);
835 HICON   (WINAPI * pImageList_GetIcon) (HIMAGELIST, INT, UINT);
836 INT     (WINAPI* pImageList_GetImageCount)(HIMAGELIST);
837 COLORREF (WINAPI *pImageList_SetBkColor)(HIMAGELIST, COLORREF);
838
839 LPVOID  (WINAPI* pCOMCTL32_Alloc) (INT);  
840 BOOL    (WINAPI* pCOMCTL32_Free) (LPVOID);  
841
842 HDPA    (WINAPI* pDPA_Create) (INT);  
843 INT     (WINAPI* pDPA_InsertPtr) (const HDPA, INT, LPVOID); 
844 BOOL    (WINAPI* pDPA_Sort) (const HDPA, PFNDPACOMPARE, LPARAM); 
845 LPVOID  (WINAPI* pDPA_GetPtr) (const HDPA, INT);   
846 BOOL    (WINAPI* pDPA_Destroy) (const HDPA); 
847 INT     (WINAPI *pDPA_Search) (const HDPA, LPVOID, INT, PFNDPACOMPARE, LPARAM, UINT);
848 LPVOID  (WINAPI *pDPA_DeletePtr) (const HDPA hdpa, INT i);
849
850 /* user32 */
851 HICON (WINAPI *pLookupIconIdFromDirectoryEx)(LPBYTE dir, BOOL bIcon, INT width, INT height, UINT cFlag);
852 HICON (WINAPI *pCreateIconFromResourceEx)(LPBYTE bits,UINT cbSize, BOOL bIcon, DWORD dwVersion, INT width, INT height,UINT cFlag);
853
854 static HINSTANCE        hComctl32;
855 static INT              shell32_RefCount = 0;
856
857 LONG            shell32_ObjCount = 0;
858 HINSTANCE       shell32_hInstance = 0; 
859 HMODULE         huser32 = 0;
860 HIMAGELIST      ShellSmallIconList = 0;
861 HIMAGELIST      ShellBigIconList = 0;
862
863
864 /*************************************************************************
865  * SHELL32 LibMain
866  *
867  * NOTES
868  *  calling oleinitialize here breaks sone apps.
869  */
870
871 BOOL WINAPI Shell32LibMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID fImpLoad)
872 {
873         TRACE("0x%x 0x%lx %p\n", hinstDLL, fdwReason, fImpLoad);
874
875         switch (fdwReason)
876         {
877           case DLL_PROCESS_ATTACH:
878             shell32_RefCount++;
879             if (shell32_hInstance) return TRUE;
880
881             shell32_hInstance = hinstDLL;
882             hComctl32 = GetModuleHandleA("COMCTL32.DLL");       
883             if(!huser32) huser32 = GetModuleHandleA("USER32.DLL");
884             DisableThreadLibraryCalls(shell32_hInstance);
885
886             if (!hComctl32 || !huser32)
887             {
888               ERR("P A N I C SHELL32 loading failed\n");
889               return FALSE;
890             }
891
892             /* comctl32 */
893             pDLLInitComctl=(void*)GetProcAddress(hComctl32,"InitCommonControlsEx");
894             pImageList_Create=(void*)GetProcAddress(hComctl32,"ImageList_Create");
895             pImageList_AddIcon=(void*)GetProcAddress(hComctl32,"ImageList_AddIcon");
896             pImageList_ReplaceIcon=(void*)GetProcAddress(hComctl32,"ImageList_ReplaceIcon");
897             pImageList_GetIcon=(void*)GetProcAddress(hComctl32,"ImageList_GetIcon");
898             pImageList_GetImageCount=(void*)GetProcAddress(hComctl32,"ImageList_GetImageCount");
899             pImageList_Draw=(void*)GetProcAddress(hComctl32,"ImageList_Draw");
900             pImageList_SetBkColor=(void*)GetProcAddress(hComctl32,"ImageList_SetBkColor");
901             pCOMCTL32_Alloc=(void*)GetProcAddress(hComctl32, (LPCSTR)71L);
902             pCOMCTL32_Free=(void*)GetProcAddress(hComctl32, (LPCSTR)73L);
903             pDPA_Create=(void*)GetProcAddress(hComctl32, (LPCSTR)328L);
904             pDPA_Destroy=(void*)GetProcAddress(hComctl32, (LPCSTR)329L);
905             pDPA_GetPtr=(void*)GetProcAddress(hComctl32, (LPCSTR)332L);
906             pDPA_InsertPtr=(void*)GetProcAddress(hComctl32, (LPCSTR)334L);
907             pDPA_DeletePtr=(void*)GetProcAddress(hComctl32, (LPCSTR)336L);
908             pDPA_Sort=(void*)GetProcAddress(hComctl32, (LPCSTR)338L);
909             pDPA_Search=(void*)GetProcAddress(hComctl32, (LPCSTR)339L);
910             /* user32 */
911             pLookupIconIdFromDirectoryEx=(void*)GetProcAddress(huser32,"LookupIconIdFromDirectoryEx");
912             pCreateIconFromResourceEx=(void*)GetProcAddress(huser32,"CreateIconFromResourceEx");
913
914             /* initialize the common controls */
915             if (pDLLInitComctl)
916             {
917               pDLLInitComctl(NULL);
918             }
919
920             SIC_Initialize();
921             SYSTRAY_Init();
922             InitChangeNotifications();
923             SHInitRestricted(NULL, NULL);
924             break;
925
926           case DLL_THREAD_ATTACH:
927             shell32_RefCount++;
928             break;
929
930           case DLL_THREAD_DETACH:
931             shell32_RefCount--;
932             break;
933
934           case DLL_PROCESS_DETACH:
935             shell32_RefCount--;
936
937             if ( !shell32_RefCount )
938             { 
939               shell32_hInstance = 0;
940
941               if (pdesktopfolder) 
942               {
943                 IShellFolder_Release(pdesktopfolder);
944                 pdesktopfolder = NULL;
945               }
946
947               SIC_Destroy();
948               FreeChangeNotifications();
949               
950               /* this one is here to check if AddRef/Release is balanced */
951               if (shell32_ObjCount)
952               {
953                 WARN("leaving with %lu objects left (memory leak)\n", shell32_ObjCount);
954               }
955             }
956
957             TRACE("refcount=%u objcount=%lu \n", shell32_RefCount, shell32_ObjCount);
958             break;
959         }
960         return TRUE;
961 }
962
963 /*************************************************************************
964  * DllInstall         [SHELL32.202]
965  *
966  * PARAMETERS
967  *   
968  *    BOOL bInstall - TRUE for install, FALSE for uninstall
969  *    LPCWSTR pszCmdLine - command line (unused by shell32?)
970  */
971
972 HRESULT WINAPI SHELL32_DllInstall(BOOL bInstall, LPCWSTR cmdline)
973 {
974    FIXME("(%s, %s): stub!\n", bInstall ? "TRUE":"FALSE", debugstr_w(cmdline));
975
976    return S_OK;         /* indicate success */
977 }
978
979 /***********************************************************************
980  *              DllCanUnloadNow (SHELL32.@)
981  */
982 HRESULT WINAPI SHELL32_DllCanUnloadNow(void)
983 {
984     FIXME("(void): stub\n");
985
986     return S_FALSE;
987 }