| 1 | /* $Id: shell32_odin.cpp,v 1.1 2000-08-30 13:52:54 sandervl Exp $ */
|
|---|
| 2 |
|
|---|
| 3 | /*
|
|---|
| 4 | * Win32 SHELL32 for OS/2
|
|---|
| 5 | *
|
|---|
| 6 | * Copyright 1999 Patrick Haller (haller@zebra.fh-weingarten.de)
|
|---|
| 7 | * Project Odin Software License can be found in LICENSE.TXT
|
|---|
| 8 | *
|
|---|
| 9 | * Shell basics
|
|---|
| 10 | *
|
|---|
| 11 | * 1998 Marcus Meissner
|
|---|
| 12 | * 1998 Juergen Schmied (jsch) * <juergen.schmied@metronet.de>
|
|---|
| 13 | *
|
|---|
| 14 | */
|
|---|
| 15 |
|
|---|
| 16 | /*****************************************************************************
|
|---|
| 17 | * Includes *
|
|---|
| 18 | *****************************************************************************/
|
|---|
| 19 |
|
|---|
| 20 | #include <odin.h>
|
|---|
| 21 | #include <odinwrap.h>
|
|---|
| 22 | #include <os2sel.h>
|
|---|
| 23 |
|
|---|
| 24 | #include <stdlib.h>
|
|---|
| 25 | #include <string.h>
|
|---|
| 26 |
|
|---|
| 27 | #define ICOM_CINTERFACE 1
|
|---|
| 28 | #define CINTERFACE 1
|
|---|
| 29 |
|
|---|
| 30 | #include "winerror.h"
|
|---|
| 31 | #include "heap.h"
|
|---|
| 32 | #include "resource.h"
|
|---|
| 33 | #include "dlgs.h"
|
|---|
| 34 | #include "sysmetrics.h"
|
|---|
| 35 | #include "debugtools.h"
|
|---|
| 36 | #include "winreg.h"
|
|---|
| 37 | #include "authors.h"
|
|---|
| 38 | #include "winversion.h"
|
|---|
| 39 |
|
|---|
| 40 | #include "shellapi.h"
|
|---|
| 41 | #include "pidl.h"
|
|---|
| 42 |
|
|---|
| 43 | #include "shlobj.h"
|
|---|
| 44 | #include "shell32_main.h"
|
|---|
| 45 | #include "shlguid.h"
|
|---|
| 46 | #include "wine/undocshell.h"
|
|---|
| 47 | #include "shpolicy.h"
|
|---|
| 48 | #include "shlwapi.h"
|
|---|
| 49 |
|
|---|
| 50 | #include <heapstring.h>
|
|---|
| 51 | #include <misc.h>
|
|---|
| 52 | #include <peexe.h>
|
|---|
| 53 | #include <neexe.h>
|
|---|
| 54 | #include <cursoricon.h>
|
|---|
| 55 | #include <ctype.h>
|
|---|
| 56 | #include <module.h>
|
|---|
| 57 |
|
|---|
| 58 | /*****************************************************************************
|
|---|
| 59 | * Local Variables *
|
|---|
| 60 | *****************************************************************************/
|
|---|
| 61 |
|
|---|
| 62 | ODINDEBUGCHANNEL(SHELL32-MAIN)
|
|---|
| 63 |
|
|---|
| 64 | typedef struct
|
|---|
| 65 | { LPCSTR szApp;
|
|---|
| 66 | LPCSTR szOtherStuff;
|
|---|
| 67 | HICON hIcon;
|
|---|
| 68 | } ABOUT_INFO;
|
|---|
| 69 |
|
|---|
| 70 | #define IDC_STATIC_TEXT 100
|
|---|
| 71 | #define IDC_LISTBOX 99
|
|---|
| 72 | #define IDC_WINE_TEXT 98
|
|---|
| 73 | #define IDC_ODIN_TEXT 98
|
|---|
| 74 |
|
|---|
| 75 | #define DROP_FIELD_TOP (-15)
|
|---|
| 76 | #define DROP_FIELD_HEIGHT 15
|
|---|
| 77 |
|
|---|
| 78 | extern HICON hIconTitleFont;
|
|---|
| 79 |
|
|---|
| 80 | static BOOL __get_dropline( HWND hWnd, LPRECT lprect )
|
|---|
| 81 | { HWND hWndCtl = GetDlgItem(hWnd, IDC_WINE_TEXT);
|
|---|
| 82 | if( hWndCtl )
|
|---|
| 83 | { GetWindowRect( hWndCtl, lprect );
|
|---|
| 84 | MapWindowPoints( 0, hWnd, (LPPOINT)lprect, 2 );
|
|---|
| 85 | lprect->bottom = (lprect->top += DROP_FIELD_TOP);
|
|---|
| 86 | return TRUE;
|
|---|
| 87 | }
|
|---|
| 88 | return FALSE;
|
|---|
| 89 | }
|
|---|
| 90 |
|
|---|
| 91 |
|
|---|
| 92 | /*************************************************************************
|
|---|
| 93 | * AboutDlgProc32 (internal)
|
|---|
| 94 | */
|
|---|
| 95 | #define IDC_ODINLOGO 2001
|
|---|
| 96 | #define IDB_ODINLOGO 5555
|
|---|
| 97 |
|
|---|
| 98 | BOOL WINAPI AboutDlgProc( HWND hWnd, UINT msg, WPARAM wParam,
|
|---|
| 99 | LPARAM lParam )
|
|---|
| 100 | {
|
|---|
| 101 | HWND hWndCtl;
|
|---|
| 102 | char Template[512], AppTitle[512];
|
|---|
| 103 |
|
|---|
| 104 | switch(msg)
|
|---|
| 105 | {
|
|---|
| 106 | case WM_INITDIALOG:
|
|---|
| 107 | {
|
|---|
| 108 | ABOUT_INFO *info = (ABOUT_INFO *)lParam;
|
|---|
| 109 | if(info)
|
|---|
| 110 | {
|
|---|
| 111 | const char* const *pstr = SHELL_People;
|
|---|
| 112 |
|
|---|
| 113 | SendDlgItemMessageA(hWnd, stc1, STM_SETICON,info->hIcon, 0);
|
|---|
| 114 | GetWindowTextA( hWnd, Template, sizeof(Template) );
|
|---|
| 115 | sprintf( AppTitle, Template, info->szApp );
|
|---|
| 116 | SetWindowTextA( hWnd, AppTitle );
|
|---|
| 117 | SetWindowTextA( GetDlgItem(hWnd, IDC_STATIC_TEXT), info->szOtherStuff );
|
|---|
| 118 |
|
|---|
| 119 | HWND hwndOdinLogo = GetDlgItem(hWnd, IDC_ODINLOGO);
|
|---|
| 120 | if(hwndOdinLogo) {
|
|---|
| 121 | HBITMAP hBitmap = LoadBitmapA(shell32_hInstance, MAKEINTRESOURCEA(IDB_ODINLOGO));
|
|---|
| 122 | SendMessageA(hwndOdinLogo, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBitmap);
|
|---|
| 123 | }
|
|---|
| 124 |
|
|---|
| 125 | hWndCtl = GetDlgItem(hWnd, IDC_LISTBOX);
|
|---|
| 126 | SendMessageA( hWndCtl, WM_SETREDRAW, 0, 0 );
|
|---|
| 127 | #if 0 //CB: not used (hIconTitleFont not valid!!!), default font is ok
|
|---|
| 128 | SendMessageA( hWndCtl, WM_SETFONT, hIconTitleFont, 0 );
|
|---|
| 129 | #endif
|
|---|
| 130 | while (*pstr)
|
|---|
| 131 | {
|
|---|
| 132 | SendMessageA( hWndCtl, LB_ADDSTRING, (WPARAM)-1, (LPARAM)*pstr );
|
|---|
| 133 | pstr++;
|
|---|
| 134 | }
|
|---|
| 135 | SendMessageA( hWndCtl, WM_SETREDRAW, 1, 0 );
|
|---|
| 136 | }
|
|---|
| 137 | return 1;
|
|---|
| 138 | }
|
|---|
| 139 |
|
|---|
| 140 | case WM_PAINT:
|
|---|
| 141 | {
|
|---|
| 142 | RECT rect;
|
|---|
| 143 | PAINTSTRUCT ps;
|
|---|
| 144 | HDC hDC = BeginPaint( hWnd, &ps );
|
|---|
| 145 |
|
|---|
| 146 | if( __get_dropline( hWnd, &rect ) ) {
|
|---|
| 147 | SelectObject( hDC, GetStockObject( BLACK_PEN ) );
|
|---|
| 148 | MoveToEx( hDC, rect.left, rect.top, NULL );
|
|---|
| 149 | LineTo( hDC, rect.right, rect.bottom );
|
|---|
| 150 | }
|
|---|
| 151 | EndPaint( hWnd, &ps );
|
|---|
| 152 | break;
|
|---|
| 153 | }
|
|---|
| 154 |
|
|---|
| 155 | case WM_LBTRACKPOINT:
|
|---|
| 156 | hWndCtl = GetDlgItem(hWnd, IDC_LISTBOX);
|
|---|
| 157 | if( (INT)GetKeyState( VK_CONTROL ) < 0 )
|
|---|
| 158 | { if( DragDetect( hWndCtl, *((LPPOINT)&lParam) ) )
|
|---|
| 159 | { INT idx = SendMessageA( hWndCtl, LB_GETCURSEL, 0, 0 );
|
|---|
| 160 | if( idx != -1 )
|
|---|
| 161 | { INT length = SendMessageA( hWndCtl, LB_GETTEXTLEN, (WPARAM)idx, 0 );
|
|---|
| 162 | HGLOBAL hMemObj = GlobalAlloc( GMEM_MOVEABLE, length + 1 );
|
|---|
| 163 | char* pstr = (char*)GlobalLock( hMemObj );
|
|---|
| 164 |
|
|---|
| 165 | if( pstr )
|
|---|
| 166 | { HCURSOR hCursor = LoadCursorA( 0, (LPCSTR)OCR_DRAGOBJECT );
|
|---|
| 167 | SendMessageA( hWndCtl, LB_GETTEXT, (WPARAM)idx, (LPARAM)pstr );
|
|---|
| 168 | SendMessageA( hWndCtl, LB_DELETESTRING, (WPARAM)idx, 0 );
|
|---|
| 169 | UpdateWindow( hWndCtl );
|
|---|
| 170 |
|
|---|
| 171 | if( !DragObject(hWnd, hWnd, DRAGOBJ_DATA, hMemObj, hCursor) )
|
|---|
| 172 | SendMessageA( hWndCtl, LB_ADDSTRING, (WPARAM)-1, (LPARAM)pstr );
|
|---|
| 173 | }
|
|---|
| 174 | if( hMemObj )
|
|---|
| 175 | GlobalFree( hMemObj );
|
|---|
| 176 | }
|
|---|
| 177 | }
|
|---|
| 178 | }
|
|---|
| 179 | break;
|
|---|
| 180 |
|
|---|
| 181 | case WM_QUERYDROPOBJECT:
|
|---|
| 182 | if( wParam == 0 )
|
|---|
| 183 | { LPDRAGINFO lpDragInfo = (LPDRAGINFO)lParam;
|
|---|
| 184 | if( lpDragInfo && lpDragInfo->wFlags == DRAGOBJ_DATA )
|
|---|
| 185 | { RECT rect;
|
|---|
| 186 | if( __get_dropline( hWnd, &rect ) )
|
|---|
| 187 | { POINT pt;
|
|---|
| 188 | pt.x=lpDragInfo->pt.x;
|
|---|
| 189 | pt.x=lpDragInfo->pt.y;
|
|---|
| 190 | rect.bottom += DROP_FIELD_HEIGHT;
|
|---|
| 191 | if( PtInRect( &rect, pt ) )
|
|---|
| 192 | { SetWindowLongA( hWnd, DWL_MSGRESULT, 1 );
|
|---|
| 193 | return TRUE;
|
|---|
| 194 | }
|
|---|
| 195 | }
|
|---|
| 196 | }
|
|---|
| 197 | }
|
|---|
| 198 | break;
|
|---|
| 199 |
|
|---|
| 200 | case WM_DROPOBJECT:
|
|---|
| 201 | if( wParam == hWnd )
|
|---|
| 202 | { LPDRAGINFO lpDragInfo = (LPDRAGINFO)lParam;
|
|---|
| 203 | if( lpDragInfo && lpDragInfo->wFlags == DRAGOBJ_DATA && lpDragInfo->hList )
|
|---|
| 204 | { char* pstr = (char*)GlobalLock( (HGLOBAL)(lpDragInfo->hList) );
|
|---|
| 205 | if( pstr )
|
|---|
| 206 | { static char __appendix_str[] = " with";
|
|---|
| 207 |
|
|---|
| 208 | hWndCtl = GetDlgItem( hWnd, IDC_ODIN_TEXT );
|
|---|
| 209 | SendMessageA( hWndCtl, WM_GETTEXT, 512, (LPARAM)Template );
|
|---|
| 210 | if( !strncmp( Template, "ODIN", 4 ) )
|
|---|
| 211 | SetWindowTextA( GetDlgItem(hWnd, IDC_STATIC_TEXT), Template );
|
|---|
| 212 | else
|
|---|
| 213 | { char* pch = Template + strlen(Template) - strlen(__appendix_str);
|
|---|
| 214 | *pch = '\0';
|
|---|
| 215 | SendMessageA( GetDlgItem(hWnd, IDC_LISTBOX), LB_ADDSTRING,
|
|---|
| 216 | (WPARAM)-1, (LPARAM)Template );
|
|---|
| 217 | }
|
|---|
| 218 |
|
|---|
| 219 | strcpy( Template, pstr );
|
|---|
| 220 | strcat( Template, __appendix_str );
|
|---|
| 221 | SetWindowTextA( hWndCtl, Template );
|
|---|
| 222 | SetWindowLongA( hWnd, DWL_MSGRESULT, 1 );
|
|---|
| 223 | return TRUE;
|
|---|
| 224 | }
|
|---|
| 225 | }
|
|---|
| 226 | }
|
|---|
| 227 | break;
|
|---|
| 228 |
|
|---|
| 229 | case WM_COMMAND:
|
|---|
| 230 | if (wParam == IDOK)
|
|---|
| 231 | {
|
|---|
| 232 | EndDialog(hWnd, TRUE);
|
|---|
| 233 | return TRUE;
|
|---|
| 234 | }
|
|---|
| 235 | break;
|
|---|
| 236 |
|
|---|
| 237 | case WM_CLOSE:
|
|---|
| 238 | EndDialog(hWnd, TRUE);
|
|---|
| 239 | break;
|
|---|
| 240 | }
|
|---|
| 241 | return 0;
|
|---|
| 242 | }
|
|---|
| 243 |
|
|---|
| 244 |
|
|---|
| 245 | /*************************************************************************
|
|---|
| 246 | * ShellAboutA [SHELL32.243]
|
|---|
| 247 | */
|
|---|
| 248 |
|
|---|
| 249 | ODINFUNCTION4(BOOL,ShellAboutA, HWND, hWnd,
|
|---|
| 250 | LPCSTR, szApp,
|
|---|
| 251 | LPCSTR, szOtherStuff,
|
|---|
| 252 | HICON, hIcon )
|
|---|
| 253 | { ABOUT_INFO info;
|
|---|
| 254 | HRSRC hRes;
|
|---|
| 255 | LPVOID dlgTemplate;
|
|---|
| 256 |
|
|---|
| 257 | if(!(hRes = FindResourceA(shell32_hInstance, "SHELL_ABOUT_MSGBOX", RT_DIALOGA)))
|
|---|
| 258 | return FALSE;
|
|---|
| 259 | if(!(dlgTemplate = (LPVOID)LoadResource(shell32_hInstance, hRes)))
|
|---|
| 260 | return FALSE;
|
|---|
| 261 |
|
|---|
| 262 | info.szApp = szApp;
|
|---|
| 263 | info.szOtherStuff = szOtherStuff;
|
|---|
| 264 | info.hIcon = hIcon;
|
|---|
| 265 | if (!hIcon) info.hIcon = LoadIconA( 0, MAKEINTRESOURCEA(OIC_ODINICON) );
|
|---|
| 266 | return DialogBoxIndirectParamA( GetWindowLongA( hWnd, GWL_HINSTANCE ),
|
|---|
| 267 | (DLGTEMPLATE*)dlgTemplate , hWnd, AboutDlgProc, (LPARAM)&info );
|
|---|
| 268 | }
|
|---|
| 269 |
|
|---|
| 270 |
|
|---|
| 271 | /*************************************************************************
|
|---|
| 272 | * ShellAboutW [SHELL32.244]
|
|---|
| 273 | */
|
|---|
| 274 | ODINFUNCTION4(BOOL,ShellAboutW, HWND, hWnd,
|
|---|
| 275 | LPCWSTR, szApp,
|
|---|
| 276 | LPCWSTR, szOtherStuff,
|
|---|
| 277 | HICON, hIcon )
|
|---|
| 278 | { INT ret;
|
|---|
| 279 | ABOUT_INFO info;
|
|---|
| 280 | HRSRC hRes;
|
|---|
| 281 | LPVOID dlgTemplate;
|
|---|
| 282 |
|
|---|
| 283 | if(!(hRes = FindResourceA(shell32_hInstance, "SHELL_ABOUT_MSGBOX", RT_DIALOGA)))
|
|---|
| 284 | return FALSE;
|
|---|
| 285 | if(!(dlgTemplate = (LPVOID)LoadResource(shell32_hInstance, hRes)))
|
|---|
| 286 | return FALSE;
|
|---|
| 287 |
|
|---|
| 288 | info.szApp = HEAP_strdupWtoA( GetProcessHeap(), 0, szApp );
|
|---|
| 289 | info.szOtherStuff = HEAP_strdupWtoA( GetProcessHeap(), 0, szOtherStuff );
|
|---|
| 290 | info.hIcon = hIcon;
|
|---|
| 291 | if (!hIcon) info.hIcon = LoadIconA( 0, MAKEINTRESOURCEA(OIC_ODINICON) );
|
|---|
| 292 | ret = DialogBoxIndirectParamA( GetWindowLongA( hWnd, GWL_HINSTANCE ),
|
|---|
| 293 | (DLGTEMPLATE*)dlgTemplate, hWnd, AboutDlgProc, (LPARAM)&info );
|
|---|
| 294 | HeapFree( GetProcessHeap(), 0, (LPSTR)info.szApp );
|
|---|
| 295 | HeapFree( GetProcessHeap(), 0, (LPSTR)info.szOtherStuff );
|
|---|
| 296 | return ret;
|
|---|
| 297 | }
|
|---|
| 298 |
|
|---|
| 299 | /*************************************************************************
|
|---|
| 300 | * ExtractAssociatedIcon [SHELL.36]
|
|---|
| 301 | *
|
|---|
| 302 | * Return icon for given file (either from file itself or from associated
|
|---|
| 303 | * executable) and patch parameters if needed.
|
|---|
| 304 | */
|
|---|
| 305 | ODINFUNCTION3(HICON, ExtractAssociatedIconA,
|
|---|
| 306 | HINSTANCE, hInst,
|
|---|
| 307 | LPSTR, lpIconPath,
|
|---|
| 308 | LPWORD, lpiIcon)
|
|---|
| 309 | {
|
|---|
| 310 | HICON hIcon;
|
|---|
| 311 |
|
|---|
| 312 | hIcon = ExtractIconA(hInst, lpIconPath, *lpiIcon);
|
|---|
| 313 |
|
|---|
| 314 | if( hIcon < 2 )
|
|---|
| 315 | { if( hIcon == 1 ) /* no icons found in given file */
|
|---|
| 316 | { char tempPath[0x104];
|
|---|
| 317 | UINT uRet = FindExecutableA(lpIconPath,NULL,tempPath);
|
|---|
| 318 |
|
|---|
| 319 | if( uRet > 32 && tempPath[0] )
|
|---|
| 320 | { strcpy(lpIconPath,tempPath);
|
|---|
| 321 | hIcon = ExtractIconA(hInst, lpIconPath, *lpiIcon);
|
|---|
| 322 | if( hIcon > 2 )
|
|---|
| 323 | return hIcon;
|
|---|
| 324 | }
|
|---|
| 325 | else hIcon = 0;
|
|---|
| 326 | }
|
|---|
| 327 |
|
|---|
| 328 | if( hIcon == 1 )
|
|---|
| 329 | *lpiIcon = 2; /* MSDOS icon - we found .exe but no icons in it */
|
|---|
| 330 | else
|
|---|
| 331 | *lpiIcon = 6; /* generic icon - found nothing */
|
|---|
| 332 |
|
|---|
| 333 | GetModuleFileNameA(hInst, lpIconPath, 0x80);
|
|---|
| 334 | hIcon = LoadIconA( hInst, (LPCSTR)*lpiIcon);
|
|---|
| 335 | }
|
|---|
| 336 | return hIcon;
|
|---|
| 337 | }
|
|---|
| 338 |
|
|---|
| 339 | #if 0 //CB: DirectResAlloc16 not yet ported
|
|---|
| 340 | /*************************************************************************
|
|---|
| 341 | * SHELL_LoadResource
|
|---|
| 342 | */
|
|---|
| 343 | static HGLOBAL SHELL_LoadResource(HINSTANCE hInst, HFILE hFile, NE_NAMEINFO* pNInfo, WORD sizeShift)
|
|---|
| 344 | { BYTE* ptr;
|
|---|
| 345 | HGLOBAL handle = DirectResAlloc( hInst, 0x10, (DWORD)pNInfo->length << sizeShift);
|
|---|
| 346 |
|
|---|
| 347 | TRACE("\n");
|
|---|
| 348 |
|
|---|
| 349 | if( (ptr = (BYTE*)GlobalLock( handle )) )
|
|---|
| 350 | { _llseek( hFile, (DWORD)pNInfo->offset << sizeShift, SEEK_SET);
|
|---|
| 351 | _lread( hFile, (char*)ptr, pNInfo->length << sizeShift);
|
|---|
| 352 | return handle;
|
|---|
| 353 | }
|
|---|
| 354 | return 0;
|
|---|
| 355 | }
|
|---|
| 356 |
|
|---|
| 357 | /*************************************************************************
|
|---|
| 358 | * ICO_LoadIcon
|
|---|
| 359 | */
|
|---|
| 360 | static HGLOBAL ICO_LoadIcon(HINSTANCE hInst, HFILE hFile, LPicoICONDIRENTRY lpiIDE)
|
|---|
| 361 | { BYTE* ptr;
|
|---|
| 362 | HGLOBAL handle = DirectResAlloc( hInst, 0x10, lpiIDE->dwBytesInRes);
|
|---|
| 363 | TRACE("\n");
|
|---|
| 364 | if( (ptr = (BYTE*)GlobalLock( handle )) )
|
|---|
| 365 | { _llseek( hFile, lpiIDE->dwImageOffset, SEEK_SET);
|
|---|
| 366 | _lread( hFile, (char*)ptr, lpiIDE->dwBytesInRes);
|
|---|
| 367 | return handle;
|
|---|
| 368 | }
|
|---|
| 369 | return 0;
|
|---|
| 370 | }
|
|---|
| 371 |
|
|---|
| 372 | /*************************************************************************
|
|---|
| 373 | * ICO_GetIconDirectory
|
|---|
| 374 | *
|
|---|
| 375 | * Read .ico file and build phony ICONDIR struct for GetIconID
|
|---|
| 376 | */
|
|---|
| 377 | static HGLOBAL ICO_GetIconDirectory(HINSTANCE hInst, HFILE hFile, LPicoICONDIR* lplpiID )
|
|---|
| 378 | { WORD id[3]; /* idReserved, idType, idCount */
|
|---|
| 379 | LPicoICONDIR lpiID;
|
|---|
| 380 | int i;
|
|---|
| 381 |
|
|---|
| 382 | TRACE("\n");
|
|---|
| 383 | _llseek( hFile, 0, SEEK_SET );
|
|---|
| 384 | if( _lread(hFile,(char*)id,sizeof(id)) != sizeof(id) ) return 0;
|
|---|
| 385 |
|
|---|
| 386 | /* check .ICO header
|
|---|
| 387 | *
|
|---|
| 388 | * - see http://www.microsoft.com/win32dev/ui/icons.htm
|
|---|
| 389 | */
|
|---|
| 390 |
|
|---|
| 391 | if( id[0] || id[1] != 1 || !id[2] ) return 0;
|
|---|
| 392 |
|
|---|
| 393 | i = id[2]*sizeof(icoICONDIRENTRY) ;
|
|---|
| 394 |
|
|---|
| 395 | lpiID = (LPicoICONDIR)HeapAlloc( GetProcessHeap(), 0, i + sizeof(id));
|
|---|
| 396 |
|
|---|
| 397 | if( _lread(hFile,(char*)lpiID->idEntries,i) == i )
|
|---|
| 398 | { HGLOBAL handle = DirectResAlloc( hInst, 0x10,
|
|---|
| 399 | id[2]*sizeof(CURSORICONDIRENTRY) + sizeof(id) );
|
|---|
| 400 | if( handle )
|
|---|
| 401 | { CURSORICONDIR* lpID = (CURSORICONDIR*)GlobalLock( handle );
|
|---|
| 402 | lpID->idReserved = lpiID->idReserved = id[0];
|
|---|
| 403 | lpID->idType = lpiID->idType = id[1];
|
|---|
| 404 | lpID->idCount = lpiID->idCount = id[2];
|
|---|
| 405 | for( i=0; i < lpiID->idCount; i++ )
|
|---|
| 406 | { memcpy((void*)(lpID->idEntries + i),
|
|---|
| 407 | (void*)(lpiID->idEntries + i), sizeof(CURSORICONDIRENTRY) - 2);
|
|---|
| 408 | lpID->idEntries[i].wResId = i;
|
|---|
| 409 | }
|
|---|
| 410 | *lplpiID = lpiID;
|
|---|
| 411 | return handle;
|
|---|
| 412 | }
|
|---|
| 413 | }
|
|---|
| 414 | /* fail */
|
|---|
| 415 |
|
|---|
| 416 | HeapFree( GetProcessHeap(), 0, lpiID);
|
|---|
| 417 | return 0;
|
|---|
| 418 | }
|
|---|
| 419 | #endif
|
|---|
| 420 |
|
|---|
| 421 | //iconcache.c
|
|---|
| 422 | DWORD SHELL_GetResourceTable(HFILE hFile, LPBYTE *retptr);
|
|---|
| 423 |
|
|---|
| 424 | //CB: from loader/pe_resource.c
|
|---|
| 425 |
|
|---|
| 426 | /**********************************************************************
|
|---|
| 427 | * GetResDirEntryW
|
|---|
| 428 | *
|
|---|
| 429 | * Helper function - goes down one level of PE resource tree
|
|---|
| 430 | *
|
|---|
| 431 | */
|
|---|
| 432 | PIMAGE_RESOURCE_DIRECTORY GetResDirEntryW(PIMAGE_RESOURCE_DIRECTORY resdirptr,
|
|---|
| 433 | LPCWSTR name,DWORD root,
|
|---|
| 434 | BOOL allowdefault)
|
|---|
| 435 | {
|
|---|
| 436 | int entrynum;
|
|---|
| 437 | PIMAGE_RESOURCE_DIRECTORY_ENTRY entryTable;
|
|---|
| 438 | int namelen;
|
|---|
| 439 |
|
|---|
| 440 | if (HIWORD(name)) {
|
|---|
| 441 | if (name[0]=='#') {
|
|---|
| 442 | char buf[10];
|
|---|
| 443 |
|
|---|
| 444 | lstrcpynWtoA(buf,name+1,10);
|
|---|
| 445 | return GetResDirEntryW(resdirptr,(LPCWSTR)atoi(buf),root,allowdefault);
|
|---|
| 446 | }
|
|---|
| 447 | entryTable = (PIMAGE_RESOURCE_DIRECTORY_ENTRY) (
|
|---|
| 448 | (BYTE *) resdirptr +
|
|---|
| 449 | sizeof(IMAGE_RESOURCE_DIRECTORY));
|
|---|
| 450 | namelen = lstrlenW(name);
|
|---|
| 451 | for (entrynum = 0; entrynum < resdirptr->NumberOfNamedEntries; entrynum++)
|
|---|
| 452 | {
|
|---|
| 453 | PIMAGE_RESOURCE_DIR_STRING_U str =
|
|---|
| 454 | (PIMAGE_RESOURCE_DIR_STRING_U) (root +
|
|---|
| 455 | entryTable[entrynum].u1.s.NameOffset);
|
|---|
| 456 | if(namelen != str->Length)
|
|---|
| 457 | continue;
|
|---|
| 458 | if(lstrncmpiW(name,str->NameString,str->Length)==0)
|
|---|
| 459 | return (PIMAGE_RESOURCE_DIRECTORY) (
|
|---|
| 460 | root +
|
|---|
| 461 | entryTable[entrynum].u2.s.OffsetToDirectory);
|
|---|
| 462 | }
|
|---|
| 463 | return NULL;
|
|---|
| 464 | } else {
|
|---|
| 465 | entryTable = (PIMAGE_RESOURCE_DIRECTORY_ENTRY) (
|
|---|
| 466 | (BYTE *) resdirptr +
|
|---|
| 467 | sizeof(IMAGE_RESOURCE_DIRECTORY) +
|
|---|
| 468 | resdirptr->NumberOfNamedEntries * sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY));
|
|---|
| 469 | for (entrynum = 0; entrynum < resdirptr->NumberOfIdEntries; entrynum++)
|
|---|
| 470 | if ((DWORD)entryTable[entrynum].u1.Name == (DWORD)name)
|
|---|
| 471 | return (PIMAGE_RESOURCE_DIRECTORY) (
|
|---|
| 472 | root +
|
|---|
| 473 | entryTable[entrynum].u2.s.OffsetToDirectory);
|
|---|
| 474 | /* just use first entry if no default can be found */
|
|---|
| 475 | if (allowdefault && !name && resdirptr->NumberOfIdEntries)
|
|---|
| 476 | return (PIMAGE_RESOURCE_DIRECTORY) (
|
|---|
| 477 | root +
|
|---|
| 478 | entryTable[0].u2.s.OffsetToDirectory);
|
|---|
| 479 | return NULL;
|
|---|
| 480 | }
|
|---|
| 481 | }
|
|---|
| 482 |
|
|---|
| 483 | /*************************************************************************
|
|---|
| 484 | * InternalExtractIcon [SHELL.39]
|
|---|
| 485 | *
|
|---|
| 486 | * This abortion is called directly by Progman
|
|---|
| 487 | */
|
|---|
| 488 | HGLOBAL WINAPI InternalExtractIcon(HINSTANCE hInstance,
|
|---|
| 489 | LPCSTR lpszExeFileName, UINT nIconIndex, WORD n )
|
|---|
| 490 | { HGLOBAL hRet = 0;
|
|---|
| 491 | HGLOBAL* RetPtr = NULL;
|
|---|
| 492 | LPBYTE pData;
|
|---|
| 493 | OFSTRUCT ofs;
|
|---|
| 494 | DWORD sig;
|
|---|
| 495 | HFILE hFile = OpenFile( lpszExeFileName, &ofs, OF_READ );
|
|---|
| 496 | UINT iconDirCount = 0,iconCount = 0;
|
|---|
| 497 | LPBYTE peimage;
|
|---|
| 498 | HANDLE fmapping;
|
|---|
| 499 |
|
|---|
| 500 | TRACE("(%04x,file %s,start %d,extract %d\n",
|
|---|
| 501 | hInstance, lpszExeFileName, nIconIndex, n);
|
|---|
| 502 |
|
|---|
| 503 | if( hFile == HFILE_ERROR || !n )
|
|---|
| 504 | return 0;
|
|---|
| 505 |
|
|---|
| 506 | hRet = GlobalAlloc( GMEM_FIXED | GMEM_ZEROINIT, sizeof(HICON16)*n);
|
|---|
| 507 | RetPtr = (HGLOBAL*)GlobalLock(hRet);
|
|---|
| 508 |
|
|---|
| 509 | *RetPtr = (n == 0xFFFF)? 0: 1; /* error return values */
|
|---|
| 510 |
|
|---|
| 511 | sig = SHELL_GetResourceTable(hFile,&pData);
|
|---|
| 512 | #if 0 //CB: some functions not (yet) supported
|
|---|
| 513 | if( sig==IMAGE_OS2_SIGNATURE || sig==1 ) /* .ICO file */
|
|---|
| 514 | { HICON hIcon = 0;
|
|---|
| 515 | NE_TYPEINFO* pTInfo = (NE_TYPEINFO*)(pData + 2);
|
|---|
| 516 | NE_NAMEINFO* pIconStorage = NULL;
|
|---|
| 517 | NE_NAMEINFO* pIconDir = NULL;
|
|---|
| 518 | LPicoICONDIR lpiID = NULL;
|
|---|
| 519 |
|
|---|
| 520 | if( pData == (BYTE*)-1 )
|
|---|
| 521 | { hIcon = ICO_GetIconDirectory(hInstance, hFile, &lpiID); /* check for .ICO file */
|
|---|
| 522 | if( hIcon )
|
|---|
| 523 | { iconDirCount = 1; iconCount = lpiID->idCount;
|
|---|
| 524 | }
|
|---|
| 525 | }
|
|---|
| 526 | else while( pTInfo->type_id && !(pIconStorage && pIconDir) )
|
|---|
| 527 | { if( pTInfo->type_id == NE_RSCTYPE_GROUP_ICON ) /* find icon directory and icon repository */
|
|---|
| 528 | { iconDirCount = pTInfo->count;
|
|---|
| 529 | pIconDir = ((NE_NAMEINFO*)(pTInfo + 1));
|
|---|
| 530 | TRACE("\tfound directory - %i icon families\n", iconDirCount);
|
|---|
| 531 | }
|
|---|
| 532 | if( pTInfo->type_id == NE_RSCTYPE_ICON )
|
|---|
| 533 | { iconCount = pTInfo->count;
|
|---|
| 534 | pIconStorage = ((NE_NAMEINFO*)(pTInfo + 1));
|
|---|
| 535 | TRACE("\ttotal icons - %i\n", iconCount);
|
|---|
| 536 | }
|
|---|
| 537 | pTInfo = (NE_TYPEINFO *)((char*)(pTInfo+1)+pTInfo->count*sizeof(NE_NAMEINFO));
|
|---|
| 538 | }
|
|---|
| 539 |
|
|---|
| 540 | /* load resources and create icons */
|
|---|
| 541 |
|
|---|
| 542 | if( (pIconStorage && pIconDir) || lpiID )
|
|---|
| 543 | { if( nIconIndex == (UINT16)-1 )
|
|---|
| 544 | { RetPtr[0] = iconDirCount;
|
|---|
| 545 | }
|
|---|
| 546 | else if( nIconIndex < iconDirCount )
|
|---|
| 547 | { UINT i, icon;
|
|---|
| 548 | if( n > iconDirCount - nIconIndex )
|
|---|
| 549 | n = iconDirCount - nIconIndex;
|
|---|
| 550 |
|
|---|
| 551 | for( i = nIconIndex; i < nIconIndex + n; i++ )
|
|---|
| 552 | { /* .ICO files have only one icon directory */
|
|---|
| 553 |
|
|---|
| 554 | if( lpiID == NULL )
|
|---|
| 555 | hIcon = SHELL_LoadResource( hInstance, hFile, pIconDir + i, *(WORD*)pData );
|
|---|
| 556 | RetPtr[i-nIconIndex] = GetIconID( hIcon, 3 );
|
|---|
| 557 | GlobalFree(hIcon);
|
|---|
| 558 | }
|
|---|
| 559 |
|
|---|
| 560 | for( icon = nIconIndex; icon < nIconIndex + n; icon++ )
|
|---|
| 561 | { hIcon = 0;
|
|---|
| 562 | if( lpiID )
|
|---|
| 563 | { hIcon = ICO_LoadIcon( hInstance, hFile, lpiID->idEntries + RetPtr[icon-nIconIndex]);
|
|---|
| 564 | }
|
|---|
| 565 | else
|
|---|
| 566 | { for( i = 0; i < iconCount; i++ )
|
|---|
| 567 | { if( pIconStorage[i].id == (RetPtr[icon-nIconIndex] | 0x8000) )
|
|---|
| 568 | { hIcon = SHELL_LoadResource( hInstance, hFile, pIconStorage + i,*(WORD*)pData );
|
|---|
| 569 | }
|
|---|
| 570 | }
|
|---|
| 571 | }
|
|---|
| 572 | if( hIcon )
|
|---|
| 573 | { RetPtr[icon-nIconIndex] = LoadIconHandler16( hIcon, TRUE );
|
|---|
| 574 | FarSetOwner16( RetPtr[icon-nIconIndex], GetExePtr(hInstance) );
|
|---|
| 575 | }
|
|---|
| 576 | else
|
|---|
| 577 | { RetPtr[icon-nIconIndex] = 0;
|
|---|
| 578 | }
|
|---|
| 579 | }
|
|---|
| 580 | }
|
|---|
| 581 | }
|
|---|
| 582 | if( lpiID )
|
|---|
| 583 | HeapFree( GetProcessHeap(), 0, lpiID);
|
|---|
| 584 | else
|
|---|
| 585 | HeapFree( GetProcessHeap(), 0, pData);
|
|---|
| 586 | }
|
|---|
| 587 | #endif
|
|---|
| 588 | if( sig == IMAGE_NT_SIGNATURE)
|
|---|
| 589 | { LPBYTE idata,igdata;
|
|---|
| 590 | PIMAGE_DOS_HEADER dheader;
|
|---|
| 591 | PIMAGE_NT_HEADERS pe_header;
|
|---|
| 592 | PIMAGE_SECTION_HEADER pe_sections;
|
|---|
| 593 | PIMAGE_RESOURCE_DIRECTORY rootresdir,iconresdir,icongroupresdir;
|
|---|
| 594 | PIMAGE_RESOURCE_DATA_ENTRY idataent,igdataent;
|
|---|
| 595 | int i,j;
|
|---|
| 596 | PIMAGE_RESOURCE_DIRECTORY_ENTRY xresent;
|
|---|
| 597 | CURSORICONDIR **cids;
|
|---|
| 598 |
|
|---|
| 599 | fmapping = CreateFileMappingA(hFile,NULL,PAGE_READONLY|SEC_COMMIT,0,0,NULL);
|
|---|
| 600 | if (fmapping == 0)
|
|---|
| 601 | { /* FIXME, INVALID_HANDLE_VALUE? */
|
|---|
| 602 | WARN("failed to create filemap.\n");
|
|---|
| 603 | hRet = 0;
|
|---|
| 604 | goto end_2; /* failure */
|
|---|
| 605 | }
|
|---|
| 606 | peimage = (BYTE*)MapViewOfFile(fmapping,FILE_MAP_READ,0,0,0);
|
|---|
| 607 | if (!peimage)
|
|---|
| 608 | { WARN("failed to mmap filemap.\n");
|
|---|
| 609 | hRet = 0;
|
|---|
| 610 | goto end_2; /* failure */
|
|---|
| 611 | }
|
|---|
| 612 | dheader = (PIMAGE_DOS_HEADER)peimage;
|
|---|
| 613 |
|
|---|
| 614 | /* it is a pe header, SHELL_GetResourceTable checked that */
|
|---|
| 615 | pe_header = (PIMAGE_NT_HEADERS)(peimage+dheader->e_lfanew);
|
|---|
| 616 |
|
|---|
| 617 | /* probably makes problems with short PE headers... but I haven't seen
|
|---|
| 618 | * one yet...
|
|---|
| 619 | */
|
|---|
| 620 | pe_sections = (PIMAGE_SECTION_HEADER)(((char*)pe_header)+sizeof(*pe_header));
|
|---|
| 621 | rootresdir = NULL;
|
|---|
| 622 |
|
|---|
| 623 | for (i=0;i<pe_header->FileHeader.NumberOfSections;i++)
|
|---|
| 624 | { if (pe_sections[i].Characteristics & IMAGE_SCN_CNT_UNINITIALIZED_DATA)
|
|---|
| 625 | continue;
|
|---|
| 626 | /* FIXME: doesn't work when the resources are not in a seperate section */
|
|---|
| 627 | if (pe_sections[i].VirtualAddress == pe_header->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_RESOURCE].VirtualAddress)
|
|---|
| 628 | { rootresdir = (PIMAGE_RESOURCE_DIRECTORY)((char*)peimage+pe_sections[i].PointerToRawData);
|
|---|
| 629 | break;
|
|---|
| 630 | }
|
|---|
| 631 | }
|
|---|
| 632 |
|
|---|
| 633 | if (!rootresdir)
|
|---|
| 634 | { WARN("haven't found section for resource directory.\n");
|
|---|
| 635 | goto end_4; /* failure */
|
|---|
| 636 | }
|
|---|
| 637 |
|
|---|
| 638 | icongroupresdir = GetResDirEntryW(rootresdir,RT_GROUP_ICONW, (DWORD)rootresdir,FALSE);
|
|---|
| 639 |
|
|---|
| 640 | if (!icongroupresdir)
|
|---|
| 641 | { WARN("No Icongroupresourcedirectory!\n");
|
|---|
| 642 | goto end_4; /* failure */
|
|---|
| 643 | }
|
|---|
| 644 |
|
|---|
| 645 | iconDirCount = icongroupresdir->NumberOfNamedEntries+icongroupresdir->NumberOfIdEntries;
|
|---|
| 646 |
|
|---|
| 647 | if( nIconIndex == (UINT)-1 )
|
|---|
| 648 | { RetPtr[0] = iconDirCount;
|
|---|
| 649 | goto end_3; /* success */
|
|---|
| 650 | }
|
|---|
| 651 |
|
|---|
| 652 | if (nIconIndex >= iconDirCount)
|
|---|
| 653 | { WARN("nIconIndex %d is larger than iconDirCount %d\n",nIconIndex,iconDirCount);
|
|---|
| 654 | GlobalFree(hRet);
|
|---|
| 655 | goto end_4; /* failure */
|
|---|
| 656 | }
|
|---|
| 657 |
|
|---|
| 658 | cids = (CURSORICONDIR**)HeapAlloc(GetProcessHeap(),0,n*sizeof(CURSORICONDIR*));
|
|---|
| 659 |
|
|---|
| 660 | /* caller just wanted the number of entries */
|
|---|
| 661 | xresent = (PIMAGE_RESOURCE_DIRECTORY_ENTRY)(icongroupresdir+1);
|
|---|
| 662 |
|
|---|
| 663 | /* assure we don't get too much ... */
|
|---|
| 664 | if( n > iconDirCount - nIconIndex )
|
|---|
| 665 | { n = iconDirCount - nIconIndex;
|
|---|
| 666 | }
|
|---|
| 667 |
|
|---|
| 668 | /* starting from specified index ... */
|
|---|
| 669 | xresent = xresent+nIconIndex;
|
|---|
| 670 |
|
|---|
| 671 | for (i=0;i<n;i++,xresent++)
|
|---|
| 672 | { CURSORICONDIR *cid;
|
|---|
| 673 | PIMAGE_RESOURCE_DIRECTORY resdir;
|
|---|
| 674 |
|
|---|
| 675 | /* go down this resource entry, name */
|
|---|
| 676 | resdir = (PIMAGE_RESOURCE_DIRECTORY)((DWORD)rootresdir+(xresent->u2.s.OffsetToDirectory));
|
|---|
| 677 |
|
|---|
| 678 | /* default language (0) */
|
|---|
| 679 | resdir = GetResDirEntryW(resdir,(LPWSTR)0,(DWORD)rootresdir,TRUE);
|
|---|
| 680 | igdataent = (PIMAGE_RESOURCE_DATA_ENTRY)resdir;
|
|---|
| 681 |
|
|---|
| 682 | /* lookup address in mapped image for virtual address */
|
|---|
| 683 | igdata = NULL;
|
|---|
| 684 |
|
|---|
| 685 | for (j=0;j<pe_header->FileHeader.NumberOfSections;j++)
|
|---|
| 686 | { if (igdataent->OffsetToData < pe_sections[j].VirtualAddress)
|
|---|
| 687 | continue;
|
|---|
| 688 | if (igdataent->OffsetToData+igdataent->Size > pe_sections[j].VirtualAddress+pe_sections[j].SizeOfRawData)
|
|---|
| 689 | continue;
|
|---|
| 690 | igdata = peimage+(igdataent->OffsetToData-pe_sections[j].VirtualAddress+pe_sections[j].PointerToRawData);
|
|---|
| 691 | }
|
|---|
| 692 |
|
|---|
| 693 | if (!igdata)
|
|---|
| 694 | { WARN("no matching real address for icongroup!\n");
|
|---|
| 695 | goto end_4; /* failure */
|
|---|
| 696 | }
|
|---|
| 697 | /* found */
|
|---|
| 698 | cid = (CURSORICONDIR*)igdata;
|
|---|
| 699 | cids[i] = cid;
|
|---|
| 700 | RetPtr[i] = LookupIconIdFromDirectoryEx(igdata,TRUE,GetSystemMetrics(SM_CXICON),GetSystemMetrics(SM_CYICON),0);
|
|---|
| 701 | }
|
|---|
| 702 |
|
|---|
| 703 | iconresdir=GetResDirEntryW(rootresdir,RT_ICONW,(DWORD)rootresdir,FALSE);
|
|---|
| 704 |
|
|---|
| 705 | if (!iconresdir)
|
|---|
| 706 | { WARN("No Iconresourcedirectory!\n");
|
|---|
| 707 | goto end_4; /* failure */
|
|---|
| 708 | }
|
|---|
| 709 |
|
|---|
| 710 | for (i=0;i<n;i++)
|
|---|
| 711 | { PIMAGE_RESOURCE_DIRECTORY xresdir;
|
|---|
| 712 | xresdir = GetResDirEntryW(iconresdir,(LPWSTR)(DWORD)RetPtr[i],(DWORD)rootresdir,FALSE);
|
|---|
| 713 | xresdir = GetResDirEntryW(xresdir,(LPWSTR)0,(DWORD)rootresdir,TRUE);
|
|---|
| 714 | idataent = (PIMAGE_RESOURCE_DATA_ENTRY)xresdir;
|
|---|
| 715 | idata = NULL;
|
|---|
| 716 |
|
|---|
| 717 | /* map virtual to address in image */
|
|---|
| 718 | for (j=0;j<pe_header->FileHeader.NumberOfSections;j++)
|
|---|
| 719 | { if (idataent->OffsetToData < pe_sections[j].VirtualAddress)
|
|---|
| 720 | continue;
|
|---|
| 721 | if (idataent->OffsetToData+idataent->Size > pe_sections[j].VirtualAddress+pe_sections[j].SizeOfRawData)
|
|---|
| 722 | continue;
|
|---|
| 723 | idata = peimage+(idataent->OffsetToData-pe_sections[j].VirtualAddress+pe_sections[j].PointerToRawData);
|
|---|
| 724 | }
|
|---|
| 725 | if (!idata)
|
|---|
| 726 | { WARN("no matching real address found for icondata!\n");
|
|---|
| 727 | RetPtr[i]=0;
|
|---|
| 728 | continue;
|
|---|
| 729 | }
|
|---|
| 730 | RetPtr[i] = CreateIconFromResourceEx(idata,idataent->Size,TRUE,0x00030000,GetSystemMetrics(SM_CXICON),GetSystemMetrics(SM_CYICON),0);
|
|---|
| 731 | }
|
|---|
| 732 | goto end_3; /* sucess */
|
|---|
| 733 | }
|
|---|
| 734 | goto end_1; /* return array with icon handles */
|
|---|
| 735 |
|
|---|
| 736 | /* cleaning up (try & catch would be nicer) */
|
|---|
| 737 | end_4: hRet = 0; /* failure */
|
|---|
| 738 | end_3: UnmapViewOfFile(peimage); /* success */
|
|---|
| 739 | end_2: CloseHandle(fmapping);
|
|---|
| 740 | end_1: _lclose( hFile);
|
|---|
| 741 | return hRet;
|
|---|
| 742 | }
|
|---|
| 743 |
|
|---|
| 744 | /*************************************************************************
|
|---|
| 745 | * SHELL_GetResourceTable
|
|---|
| 746 | */
|
|---|
| 747 | DWORD SHELL_GetResourceTable(HFILE hFile,LPBYTE *retptr)
|
|---|
| 748 | { IMAGE_DOS_HEADER mz_header;
|
|---|
| 749 | char magic[4];
|
|---|
| 750 | int size;
|
|---|
| 751 |
|
|---|
| 752 | TRACE("\n");
|
|---|
| 753 |
|
|---|
| 754 | *retptr = NULL;
|
|---|
| 755 | _llseek( hFile, 0, SEEK_SET );
|
|---|
| 756 | if ((_lread(hFile,&mz_header,sizeof(mz_header)) != sizeof(mz_header)) || (mz_header.e_magic != IMAGE_DOS_SIGNATURE))
|
|---|
| 757 | { /* .ICO file ? */
|
|---|
| 758 | if (mz_header.e_cblp == 1)
|
|---|
| 759 | { /* ICONHEADER.idType, must be 1 */
|
|---|
| 760 | *retptr = (LPBYTE)-1;
|
|---|
| 761 | return 1;
|
|---|
| 762 | }
|
|---|
| 763 | else
|
|---|
| 764 | return 0; /* failed */
|
|---|
| 765 | }
|
|---|
| 766 | _llseek( hFile, mz_header.e_lfanew, SEEK_SET );
|
|---|
| 767 |
|
|---|
| 768 | if (_lread( hFile, magic, sizeof(magic) ) != sizeof(magic))
|
|---|
| 769 | return 0;
|
|---|
| 770 |
|
|---|
| 771 | _llseek( hFile, mz_header.e_lfanew, SEEK_SET);
|
|---|
| 772 |
|
|---|
| 773 | if (*(DWORD*)magic == IMAGE_NT_SIGNATURE)
|
|---|
| 774 | return IMAGE_NT_SIGNATURE;
|
|---|
| 775 |
|
|---|
| 776 | if (*(WORD*)magic == IMAGE_OS2_SIGNATURE)
|
|---|
| 777 | { IMAGE_OS2_HEADER ne_header;
|
|---|
| 778 | LPBYTE pTypeInfo = (LPBYTE)-1;
|
|---|
| 779 |
|
|---|
| 780 | if (_lread(hFile,&ne_header,sizeof(ne_header))!=sizeof(ne_header))
|
|---|
| 781 | return 0;
|
|---|
| 782 |
|
|---|
| 783 | if (ne_header.ne_magic != IMAGE_OS2_SIGNATURE)
|
|---|
| 784 | return 0;
|
|---|
| 785 |
|
|---|
| 786 | size = ne_header.ne_restab - ne_header.ne_rsrctab;
|
|---|
| 787 |
|
|---|
| 788 | if( size > sizeof(NE_TYPEINFO) )
|
|---|
| 789 | { pTypeInfo = (BYTE*)HeapAlloc( GetProcessHeap(), 0, size);
|
|---|
| 790 | if( pTypeInfo )
|
|---|
| 791 | { _llseek(hFile, mz_header.e_lfanew+ne_header.ne_rsrctab, SEEK_SET);
|
|---|
| 792 | if( _lread( hFile, (char*)pTypeInfo, size) != size )
|
|---|
| 793 | { HeapFree( GetProcessHeap(), 0, pTypeInfo);
|
|---|
| 794 | pTypeInfo = NULL;
|
|---|
| 795 | }
|
|---|
| 796 | }
|
|---|
| 797 | }
|
|---|
| 798 | *retptr = pTypeInfo;
|
|---|
| 799 | return IMAGE_OS2_SIGNATURE;
|
|---|
| 800 | }
|
|---|
| 801 | return 0; /* failed */
|
|---|
| 802 | }
|
|---|
| 803 |
|
|---|
| 804 | /*************************************************************************
|
|---|
| 805 | * SHELL_FindExecutable [Internal]
|
|---|
| 806 | *
|
|---|
| 807 | * Utility for code sharing between FindExecutable and ShellExecute
|
|---|
| 808 | */
|
|---|
| 809 | HINSTANCE SHELL_FindExecutable( LPCSTR lpFile,
|
|---|
| 810 | LPCSTR lpOperation,
|
|---|
| 811 | LPSTR lpResult)
|
|---|
| 812 | { char *extension = NULL; /* pointer to file extension */
|
|---|
| 813 | char tmpext[5]; /* local copy to mung as we please */
|
|---|
| 814 | char filetype[256]; /* registry name for this filetype */
|
|---|
| 815 | LONG filetypelen=256; /* length of above */
|
|---|
| 816 | char command[256]; /* command from registry */
|
|---|
| 817 | LONG commandlen=256; /* This is the most DOS can handle :) */
|
|---|
| 818 | char buffer[256]; /* Used to GetProfileString */
|
|---|
| 819 | HINSTANCE retval=31; /* default - 'No association was found' */
|
|---|
| 820 | char *tok; /* token pointer */
|
|---|
| 821 | int i; /* random counter */
|
|---|
| 822 | char xlpFile[256]; /* result of SearchPath */
|
|---|
| 823 |
|
|---|
| 824 | dprintf(("SHELL32:SHELL:SHELL_FindExecutable(%s,%s,%08xh)\n",
|
|---|
| 825 | lpFile,
|
|---|
| 826 | lpOperation,
|
|---|
| 827 | lpResult));
|
|---|
| 828 |
|
|---|
| 829 | lpResult[0]='\0'; /* Start off with an empty return string */
|
|---|
| 830 |
|
|---|
| 831 | /* trap NULL parameters on entry */
|
|---|
| 832 | if (( lpFile == NULL ) || ( lpResult == NULL ) || ( lpOperation == NULL ))
|
|---|
| 833 | { dprintf(("SHELL32:SHELL:SHELL_FindExecutable(lpFile=%s,lpResult=%s,lpOperation=%s): NULL parameter\n",
|
|---|
| 834 | lpFile, lpOperation, lpResult));
|
|---|
| 835 | return 2; /* File not found. Close enough, I guess. */
|
|---|
| 836 | }
|
|---|
| 837 |
|
|---|
| 838 | if (SearchPathA( NULL, lpFile,".exe",sizeof(xlpFile),xlpFile,NULL))
|
|---|
| 839 | { dprintf(("SHELL32:SHELL:SHELL_FindExecutable(SearchPath32A returned non-zero\n"));
|
|---|
| 840 | lpFile = xlpFile;
|
|---|
| 841 | }
|
|---|
| 842 |
|
|---|
| 843 | /* First thing we need is the file's extension */
|
|---|
| 844 | extension = strrchr( xlpFile, '.' ); /* Assume last "." is the one; */
|
|---|
| 845 | /* File->Run in progman uses */
|
|---|
| 846 | /* .\FILE.EXE :( */
|
|---|
| 847 | dprintf(("SHELL32:SHELL:SHELL_FindExecutable(xlpFile=%s,extension=%s)\n",
|
|---|
| 848 | xlpFile, extension));
|
|---|
| 849 |
|
|---|
| 850 | if ((extension == NULL) || (extension == &xlpFile[strlen(xlpFile)]))
|
|---|
| 851 | { dprintf(("SHELL32:SHELL:SHELL_FindExecutable Returning 31 - No association\n"));
|
|---|
| 852 | return 31; /* no association */
|
|---|
| 853 | }
|
|---|
| 854 |
|
|---|
| 855 | /* Make local copy & lowercase it for reg & 'programs=' lookup */
|
|---|
| 856 | lstrcpynA( tmpext, extension, 5 );
|
|---|
| 857 | CharLowerA( tmpext );
|
|---|
| 858 |
|
|---|
| 859 |
|
|---|
| 860 | dprintf(("SHELL32:SHELL:SHELL_FindExecutable(%s file)\n", tmpext));
|
|---|
| 861 |
|
|---|
| 862 | /* Three places to check: */
|
|---|
| 863 | /* 1. win.ini, [windows], programs (NB no leading '.') */
|
|---|
| 864 | /* 2. Registry, HKEY_CLASS_ROOT\<filetype>\shell\open\command */
|
|---|
| 865 | /* 3. win.ini, [extensions], extension (NB no leading '.' */
|
|---|
| 866 | /* All I know of the order is that registry is checked before */
|
|---|
| 867 | /* extensions; however, it'd make sense to check the programs */
|
|---|
| 868 | /* section first, so that's what happens here. */
|
|---|
| 869 |
|
|---|
| 870 | /* See if it's a program - if GetProfileString fails, we skip this
|
|---|
| 871 | * section. Actually, if GetProfileString fails, we've probably
|
|---|
| 872 | * got a lot more to worry about than running a program... */
|
|---|
| 873 | if ( GetProfileStringA("windows", "programs", "exe pif bat com",
|
|---|
| 874 | buffer, sizeof(buffer)) > 0 )
|
|---|
| 875 | { for (i=0;i<strlen(buffer); i++) buffer[i]=tolower(buffer[i]);
|
|---|
| 876 |
|
|---|
| 877 | tok = strtok(buffer, " \t"); /* ? */
|
|---|
| 878 | while( tok!= NULL)
|
|---|
| 879 | {
|
|---|
| 880 | if (strcmp(tok, &tmpext[1])==0) /* have to skip the leading "." */
|
|---|
| 881 | {
|
|---|
| 882 | strcpy(lpResult, xlpFile);
|
|---|
| 883 | /* Need to perhaps check that the file has a path
|
|---|
| 884 | * attached */
|
|---|
| 885 | dprintf(("SHELL32:SHELL:SHELL_FindExecutable found %s\n",
|
|---|
| 886 | lpResult));
|
|---|
| 887 | return 33;
|
|---|
| 888 |
|
|---|
| 889 | /* Greater than 32 to indicate success FIXME According to the
|
|---|
| 890 | * docs, I should be returning a handle for the
|
|---|
| 891 | * executable. Does this mean I'm supposed to open the
|
|---|
| 892 | * executable file or something? More RTFM, I guess... */
|
|---|
| 893 | }
|
|---|
| 894 | tok=strtok(NULL, " \t");
|
|---|
| 895 | }
|
|---|
| 896 | }
|
|---|
| 897 |
|
|---|
| 898 | /* Check registry */
|
|---|
| 899 | if (RegQueryValueA( HKEY_CLASSES_ROOT, tmpext, filetype,
|
|---|
| 900 | &filetypelen ) == ERROR_SUCCESS )
|
|---|
| 901 | {
|
|---|
| 902 | filetype[filetypelen]='\0';
|
|---|
| 903 | dprintf(("SHELL32:SHELL:SHELL_FindExecutable(File type: %s)\n",
|
|---|
| 904 | filetype));
|
|---|
| 905 |
|
|---|
| 906 | /* Looking for ...buffer\shell\lpOperation\command */
|
|---|
| 907 | strcat( filetype, "\\shell\\" );
|
|---|
| 908 | strcat( filetype, lpOperation );
|
|---|
| 909 | strcat( filetype, "\\command" );
|
|---|
| 910 |
|
|---|
| 911 | if (RegQueryValueA( HKEY_CLASSES_ROOT, filetype, command,
|
|---|
| 912 | &commandlen ) == ERROR_SUCCESS )
|
|---|
| 913 | {
|
|---|
| 914 | LPSTR tmp;
|
|---|
| 915 | char param[256];
|
|---|
| 916 | LONG paramlen = 256;
|
|---|
| 917 |
|
|---|
| 918 | /* Get the parameters needed by the application
|
|---|
| 919 | from the associated ddeexec key */
|
|---|
| 920 | tmp = strstr(filetype,"command");
|
|---|
| 921 | tmp[0] = '\0';
|
|---|
| 922 | strcat(filetype,"ddeexec");
|
|---|
| 923 |
|
|---|
| 924 | if(RegQueryValueA( HKEY_CLASSES_ROOT, filetype, param,¶mlen ) == ERROR_SUCCESS)
|
|---|
| 925 | {
|
|---|
| 926 | strcat(command," ");
|
|---|
| 927 | strcat(command,param);
|
|---|
| 928 | commandlen += paramlen;
|
|---|
| 929 | }
|
|---|
| 930 |
|
|---|
| 931 | /* Is there a replace() function anywhere? */
|
|---|
| 932 | command[commandlen]='\0';
|
|---|
| 933 | strcpy( lpResult, command );
|
|---|
| 934 | tok=strstr( lpResult, "%1" );
|
|---|
| 935 | if (tok != NULL)
|
|---|
| 936 | {
|
|---|
| 937 | tok[0]='\0'; /* truncate string at the percent */
|
|---|
| 938 | strcat( lpResult, xlpFile ); /* what if no dir in xlpFile? */
|
|---|
| 939 | tok=strstr( command, "%1" );
|
|---|
| 940 | if ((tok!=NULL) && (strlen(tok)>2))
|
|---|
| 941 | {
|
|---|
| 942 | strcat( lpResult, &tok[2] );
|
|---|
| 943 | }
|
|---|
| 944 | }
|
|---|
| 945 | retval=33; /* FIXME see above */
|
|---|
| 946 | }
|
|---|
| 947 | }
|
|---|
| 948 | else /* Check win.ini */
|
|---|
| 949 | {
|
|---|
| 950 | /* Toss the leading dot */
|
|---|
| 951 | extension++;
|
|---|
| 952 | if ( GetProfileStringA( "extensions", extension, "", command,
|
|---|
| 953 | sizeof(command)) > 0)
|
|---|
| 954 | {
|
|---|
| 955 | if (strlen(command)!=0)
|
|---|
| 956 | {
|
|---|
| 957 | strcpy( lpResult, command );
|
|---|
| 958 | tok=strstr( lpResult, "^" ); /* should be ^.extension? */
|
|---|
| 959 | if (tok != NULL)
|
|---|
| 960 | {
|
|---|
| 961 | tok[0]='\0';
|
|---|
| 962 | strcat( lpResult, xlpFile ); /* what if no dir in xlpFile? */
|
|---|
| 963 | tok=strstr( command, "^" ); /* see above */
|
|---|
| 964 | if ((tok != NULL) && (strlen(tok)>5))
|
|---|
| 965 | {
|
|---|
| 966 | strcat( lpResult, &tok[5]);
|
|---|
| 967 | }
|
|---|
| 968 | }
|
|---|
| 969 | retval=33; /* FIXME - see above */
|
|---|
| 970 | }
|
|---|
| 971 | }
|
|---|
| 972 | }
|
|---|
| 973 |
|
|---|
| 974 | dprintf(("SHELL32:SHELL:SHELL_FindExecutable (returning %s)\n", lpResult));
|
|---|
| 975 | return retval;
|
|---|
| 976 | }
|
|---|
| 977 |
|
|---|
| 978 | /*************************************************************************
|
|---|
| 979 | * ShellExecuteA [SHELL32.245]
|
|---|
| 980 | */
|
|---|
| 981 |
|
|---|
| 982 | ODINFUNCTION6(HINSTANCE, ShellExecuteA, HWND, hWnd,
|
|---|
| 983 | LPCSTR, lpOperation,
|
|---|
| 984 | LPCSTR, lpFile,
|
|---|
| 985 | LPCSTR, lpParameters,
|
|---|
| 986 | LPCSTR, lpDirectory,
|
|---|
| 987 | INT, iShowCmd )
|
|---|
| 988 | { HINSTANCE retval=31;
|
|---|
| 989 | char old_dir[1024];
|
|---|
| 990 | char cmd[256];
|
|---|
| 991 |
|
|---|
| 992 | if (lpFile==NULL) return 0; /* should not happen */
|
|---|
| 993 | if (lpOperation==NULL) /* default is open */
|
|---|
| 994 | lpOperation="open";
|
|---|
| 995 |
|
|---|
| 996 | if (lpDirectory)
|
|---|
| 997 | { GetCurrentDirectoryA( sizeof(old_dir), old_dir );
|
|---|
| 998 | SetCurrentDirectoryA( lpDirectory );
|
|---|
| 999 | }
|
|---|
| 1000 |
|
|---|
| 1001 | cmd[0] = '\0';
|
|---|
| 1002 | retval = SHELL_FindExecutable( lpFile, lpOperation, cmd );
|
|---|
| 1003 |
|
|---|
| 1004 | if (retval > 32) /* Found */
|
|---|
| 1005 | {
|
|---|
| 1006 | if (lpParameters)
|
|---|
| 1007 | {
|
|---|
| 1008 | strcat(cmd," ");
|
|---|
| 1009 | strcat(cmd,lpParameters);
|
|---|
| 1010 | }
|
|---|
| 1011 |
|
|---|
| 1012 | dprintf(("starting %s\n",cmd));
|
|---|
| 1013 | retval = WinExec( cmd, iShowCmd );
|
|---|
| 1014 | }
|
|---|
| 1015 | else if(PathIsURLA((LPSTR)lpFile)) /* File not found, check for URL */
|
|---|
| 1016 | {
|
|---|
| 1017 | char lpstrProtocol[256];
|
|---|
| 1018 | LONG cmdlen = 512;
|
|---|
| 1019 | LPSTR lpstrRes;
|
|---|
| 1020 | INT iSize;
|
|---|
| 1021 |
|
|---|
| 1022 | lpstrRes = strchr(lpFile,':');
|
|---|
| 1023 | iSize = lpstrRes - lpFile;
|
|---|
| 1024 |
|
|---|
| 1025 | /* Looking for ...protocol\shell\lpOperation\command */
|
|---|
| 1026 | strncpy(lpstrProtocol,lpFile,iSize);
|
|---|
| 1027 | lpstrProtocol[iSize]='\0';
|
|---|
| 1028 | strcat( lpstrProtocol, "\\shell\\" );
|
|---|
| 1029 | strcat( lpstrProtocol, lpOperation );
|
|---|
| 1030 | strcat( lpstrProtocol, "\\command" );
|
|---|
| 1031 |
|
|---|
| 1032 | /* Remove File Protocol from lpFile */
|
|---|
| 1033 | /* In the case file://path/file */
|
|---|
| 1034 | if(!strnicmp(lpFile,"file",iSize))
|
|---|
| 1035 | {
|
|---|
| 1036 | lpFile += iSize;
|
|---|
| 1037 | while(*lpFile == ':') lpFile++;
|
|---|
| 1038 | }
|
|---|
| 1039 |
|
|---|
| 1040 |
|
|---|
| 1041 | /* Get the application for the protocol and execute it */
|
|---|
| 1042 | if (RegQueryValueA( HKEY_CLASSES_ROOT, lpstrProtocol, cmd,
|
|---|
| 1043 | &cmdlen ) == ERROR_SUCCESS )
|
|---|
| 1044 | {
|
|---|
| 1045 | LPSTR tok;
|
|---|
| 1046 | LPSTR tmp;
|
|---|
| 1047 | char param[256] = "";
|
|---|
| 1048 | LONG paramlen = 256;
|
|---|
| 1049 |
|
|---|
| 1050 | /* Get the parameters needed by the application
|
|---|
| 1051 | from the associated ddeexec key */
|
|---|
| 1052 | tmp = strstr(lpstrProtocol,"command");
|
|---|
| 1053 | tmp[0] = '\0';
|
|---|
| 1054 | strcat(lpstrProtocol,"ddeexec");
|
|---|
| 1055 |
|
|---|
| 1056 | if(RegQueryValueA( HKEY_CLASSES_ROOT, lpstrProtocol, param,¶mlen ) == ERROR_SUCCESS)
|
|---|
| 1057 | {
|
|---|
| 1058 | strcat(cmd," ");
|
|---|
| 1059 | strcat(cmd,param);
|
|---|
| 1060 | cmdlen += paramlen;
|
|---|
| 1061 | }
|
|---|
| 1062 |
|
|---|
| 1063 | /* Is there a replace() function anywhere? */
|
|---|
| 1064 | cmd[cmdlen]='\0';
|
|---|
| 1065 | tok=strstr( cmd, "%1" );
|
|---|
| 1066 | if (tok != NULL)
|
|---|
| 1067 | {
|
|---|
| 1068 | tok[0]='\0'; /* truncate string at the percent */
|
|---|
| 1069 | strcat( cmd, lpFile ); /* what if no dir in xlpFile? */
|
|---|
| 1070 | tok=strstr( cmd, "%1" );
|
|---|
| 1071 | if ((tok!=NULL) && (strlen(tok)>2))
|
|---|
| 1072 | {
|
|---|
| 1073 | strcat( cmd, &tok[2] );
|
|---|
| 1074 | }
|
|---|
| 1075 | }
|
|---|
| 1076 |
|
|---|
| 1077 | retval = WinExec( cmd, iShowCmd );
|
|---|
| 1078 | }
|
|---|
| 1079 | }
|
|---|
| 1080 | /* Check if file specified is in the form www.??????.*** */
|
|---|
| 1081 | else if(!strnicmp(lpFile,"www",3))
|
|---|
| 1082 | {
|
|---|
| 1083 | /* if so, append lpFile http:// and call ShellExecute */
|
|---|
| 1084 | char lpstrTmpFile[256] = "http://" ;
|
|---|
| 1085 | strcat(lpstrTmpFile,lpFile);
|
|---|
| 1086 | retval = ShellExecuteA(hWnd,lpOperation,lpstrTmpFile,NULL,NULL,0);
|
|---|
| 1087 | }
|
|---|
| 1088 | /* Nothing was done yet, try to execute the cmdline directly,
|
|---|
| 1089 | maybe it's an OS/2 program */
|
|---|
| 1090 | else
|
|---|
| 1091 | {
|
|---|
| 1092 | strcpy(cmd,lpFile);
|
|---|
| 1093 | strcat(cmd,lpParameters ? lpParameters : "");
|
|---|
| 1094 | retval = WinExec( cmd, iShowCmd );
|
|---|
| 1095 | }
|
|---|
| 1096 |
|
|---|
| 1097 | if (lpDirectory)
|
|---|
| 1098 | SetCurrentDirectoryA( old_dir );
|
|---|
| 1099 | return retval;
|
|---|
| 1100 | }
|
|---|
| 1101 |
|
|---|
| 1102 |
|
|---|
| 1103 | /*****************************************************************************
|
|---|
| 1104 | * Name : UINT DragQueryFileAorW
|
|---|
| 1105 | * Purpose :
|
|---|
| 1106 | * Parameters: HDROP hDrop - drop structure handle
|
|---|
| 1107 | * UINT iFile - index of file to query
|
|---|
| 1108 | * LPTSTR lpszFile - target buffer
|
|---|
| 1109 | * UINT cch - target buffer size
|
|---|
| 1110 | * Variables :
|
|---|
| 1111 | * Result :
|
|---|
| 1112 | * Remark :
|
|---|
| 1113 | * Status : UNTESTED STUB
|
|---|
| 1114 | *
|
|---|
| 1115 | * Author : Patrick Haller [Tue, 1999/06/09 20:00]
|
|---|
| 1116 | *****************************************************************************/
|
|---|
| 1117 |
|
|---|
| 1118 | ODINFUNCTION4(UINT, DragQueryFileAorW,
|
|---|
| 1119 | HDROP, hDrop,
|
|---|
| 1120 | UINT, iFile,
|
|---|
| 1121 | LPTSTR, lpszFile,
|
|---|
| 1122 | UINT, cch)
|
|---|
| 1123 | {
|
|---|
| 1124 | // @@@PH maybe they want automatic determination here
|
|---|
| 1125 | if (SHELL_OsIsUnicode())
|
|---|
| 1126 | return DragQueryFileW(hDrop, iFile, (LPWSTR)lpszFile, cch);
|
|---|
| 1127 | else
|
|---|
| 1128 | return DragQueryFileA(hDrop, iFile, lpszFile, cch);
|
|---|
| 1129 | }
|
|---|
| 1130 |
|
|---|
| 1131 |
|
|---|
| 1132 | LPCSTR debugstr_guid1( void *id1 )
|
|---|
| 1133 | {
|
|---|
| 1134 | static char str[40];
|
|---|
| 1135 | GUID *id = (GUID *)id1;
|
|---|
| 1136 |
|
|---|
| 1137 | if (!id) return "(null)";
|
|---|
| 1138 | if (!HIWORD(id))
|
|---|
| 1139 | {
|
|---|
| 1140 | sprintf( str, "<guid-0x%04x>", LOWORD(id) );
|
|---|
| 1141 | }
|
|---|
| 1142 | else
|
|---|
| 1143 | {
|
|---|
| 1144 | sprintf( str, "{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
|
|---|
| 1145 | id->Data1, id->Data2, id->Data3,
|
|---|
| 1146 | id->Data4[0], id->Data4[1], id->Data4[2], id->Data4[3],
|
|---|
| 1147 | id->Data4[4], id->Data4[5], id->Data4[6], id->Data4[7] );
|
|---|
| 1148 | }
|
|---|
| 1149 | return str;
|
|---|
| 1150 | }
|
|---|
| 1151 |
|
|---|