ole32_main.c 2.86 KB
Newer Older
1 2 3
/*
 *  OLE32 Initialization
 *
4
 * Copyright 2000 Huw D M Davies for CodeWeavers
5 6 7 8 9 10 11 12 13 14 15 16 17 18
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19
 */
20

21
#include <stdarg.h>
22
#include <stdio.h>
23

24
#include "windef.h"
25
#include "winerror.h"
26 27 28
#include "winbase.h"
#include "wingdi.h"
#include "winuser.h"
29
#include "winnls.h"
30
#include "objbase.h"
31
#include "wine/debug.h"
32

33
WINE_DEFAULT_DEBUG_CHANNEL(ole);
34

35
/***********************************************************************
36
 *		OleMetafilePictFromIconAndLabel (OLE32.@)
37
 */
38 39 40
HGLOBAL WINAPI OleMetafilePictFromIconAndLabel(HICON hIcon, LPOLESTR lpszLabel,
                                               LPOLESTR lpszSourceFile, UINT iIconIndex)
{
41
	METAFILEPICT mfp;
42
	HDC hdc;
43 44
	UINT dy;
	HGLOBAL hmem = NULL;
45
	LPVOID mfdata;
46
	static const char szIconOnly[] = "IconOnly";
47

48
	TRACE("%p %p %s %d\n", hIcon, lpszLabel, debugstr_w(lpszSourceFile), iIconIndex);
49 50

	if( !hIcon )
51
		return NULL;
52 53 54

	hdc = CreateMetaFileW(NULL);
	if( !hdc )
55 56 57
		return NULL;

	ExtEscape(hdc, MFCOMMENT, sizeof(szIconOnly), szIconOnly, 0, NULL);
58 59 60 61 62 63 64

	/* FIXME: things are drawn in the wrong place */
	DrawIcon(hdc, 0, 0, hIcon);
	dy = GetSystemMetrics(SM_CXICON);
	if(lpszLabel)
		TextOutW(hdc, 0, dy, lpszLabel, lstrlenW(lpszLabel));

65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
	if (lpszSourceFile)
	{
		char szIconIndex[10];
		int path_length = WideCharToMultiByte(CP_ACP,0,lpszSourceFile,-1,NULL,0,NULL,NULL);
		if (path_length > 1)
		{
			char * szPath = CoTaskMemAlloc(path_length * sizeof(CHAR));
			if (szPath)
			{
				WideCharToMultiByte(CP_ACP,0,lpszSourceFile,-1,szPath,path_length,NULL,NULL);
				ExtEscape(hdc, MFCOMMENT, path_length, szPath, 0, NULL);
				CoTaskMemFree(szPath);
			}
		}
		snprintf(szIconIndex, 10, "%u", iIconIndex);
		ExtEscape(hdc, MFCOMMENT, strlen(szIconIndex)+1, szIconIndex, 0, NULL);
	}
82

83 84 85 86 87
	mfp.mm = MM_ISOTROPIC;
	mfp.xExt = mfp.yExt = 0; /* FIXME ? */
	mfp.hMF = CloseMetaFile(hdc);
	if( !mfp.hMF )
		return NULL;
88

89
	hmem = GlobalAlloc( GMEM_MOVEABLE, sizeof(mfp) );
90
	if( !hmem )
91 92 93 94
	{
		DeleteMetaFile(mfp.hMF);
		return NULL;
	}
95

96 97 98 99
	mfdata = GlobalLock( hmem );
	if( !mfdata )
	{
		GlobalFree( hmem );
100 101
		DeleteMetaFile(mfp.hMF);
		return NULL;
102 103
	}

104
	memcpy(mfdata,&mfp,sizeof(mfp));
105 106 107 108 109 110
	GlobalUnlock( hmem );

	TRACE("returning %p\n",hmem);

	return hmem;
}