ReactOS 0.4.16-dev-303-g11d5cb8
ole32_main.c
Go to the documentation of this file.
1/*
2 * OLE32 Initialization
3 *
4 * Copyright 2000 Huw D M Davies for CodeWeavers
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20
21#include <stdarg.h>
22#include <stdio.h>
23
24#include "windef.h"
25#include "winbase.h"
26#include "wingdi.h"
27#include "winuser.h"
28#include "winnls.h"
29#include "objbase.h"
30#include "ole2.h"
31#include "wine/debug.h"
32
34
35#define HIMETRIC_INCHES 2540
36
37/***********************************************************************
38 * OleMetafilePictFromIconAndLabel (OLE32.@)
39 */
41 LPOLESTR lpszSourceFile, UINT iIconIndex)
42{
43 METAFILEPICT mfp;
44 HDC hdc;
45 HGLOBAL hmem = NULL;
46 LPVOID mfdata;
47 static const char szIconOnly[] = "IconOnly";
48 SIZE text_size = { 0, 0 };
49 INT width;
50 INT icon_width;
51 INT icon_height;
52 INT label_offset;
53 HDC hdcScreen;
54 LOGFONTW lf;
55 HFONT font;
56
57 TRACE("%p %p %s %d\n", hIcon, lpszLabel, debugstr_w(lpszSourceFile), iIconIndex);
58
59 if( !hIcon )
60 return NULL;
61
62 if (!SystemParametersInfoW(SPI_GETICONTITLELOGFONT, sizeof(lf), &lf, 0))
63 return NULL;
64
66 if (!font)
67 return NULL;
68
70 if( !hdc )
71 {
73 return NULL;
74 }
75
77
78 ExtEscape(hdc, MFCOMMENT, sizeof(szIconOnly), szIconOnly, 0, NULL);
79
80 icon_width = GetSystemMetrics(SM_CXICON);
81 icon_height = GetSystemMetrics(SM_CYICON);
82 /* FIXME: should we give the label a bit of padding here? */
83 label_offset = icon_height;
84 if (lpszLabel)
85 {
86 HFONT screen_old_font;
87 /* metafile DCs don't support GetTextExtentPoint32, so size the font
88 * using the desktop window DC */
89 hdcScreen = GetDC(NULL);
90 screen_old_font = SelectObject(hdcScreen, font);
91 GetTextExtentPoint32W(hdcScreen, lpszLabel, lstrlenW(lpszLabel), &text_size);
92 SelectObject(hdcScreen, screen_old_font);
93 ReleaseDC(NULL, hdcScreen);
94
95 width = 3 * icon_width;
96 }
97 else
98 width = icon_width;
99
101 SetWindowOrgEx(hdc, 0, 0, NULL);
102 SetWindowExtEx(hdc, width, label_offset + text_size.cy, NULL);
103
104 /* draw the icon centered */
105 DrawIcon(hdc, (width-icon_width) / 2, 0, hIcon);
106 if(lpszLabel)
107 /* draw the label centered too, if provided */
108 TextOutW(hdc, (width-text_size.cx) / 2, label_offset, lpszLabel, lstrlenW(lpszLabel));
109
110 if (lpszSourceFile)
111 {
112 char szIconIndex[10];
113 int path_length = WideCharToMultiByte(CP_ACP,0,lpszSourceFile,-1,NULL,0,NULL,NULL);
114 if (path_length > 1)
115 {
116 char * szPath = CoTaskMemAlloc(path_length * sizeof(CHAR));
117 if (szPath)
118 {
122 }
123 }
124 snprintf(szIconIndex, 10, "%u", iIconIndex);
125 ExtEscape(hdc, MFCOMMENT, strlen(szIconIndex)+1, szIconIndex, 0, NULL);
126 }
127
128 mfp.mm = MM_ANISOTROPIC;
129 hdcScreen = GetDC(NULL);
131 mfp.yExt = MulDiv(label_offset + text_size.cy, HIMETRIC_INCHES, GetDeviceCaps(hdcScreen, LOGPIXELSY));
132 ReleaseDC(NULL, hdcScreen);
133 mfp.hMF = CloseMetaFile(hdc);
135 if( !mfp.hMF )
136 return NULL;
137
138 hmem = GlobalAlloc( GMEM_MOVEABLE, sizeof(mfp) );
139 if( !hmem )
140 {
141 DeleteMetaFile(mfp.hMF);
142 return NULL;
143 }
144
145 mfdata = GlobalLock( hmem );
146 if( !mfdata )
147 {
148 GlobalFree( hmem );
149 DeleteMetaFile(mfp.hMF);
150 return NULL;
151 }
152
153 memcpy(mfdata,&mfp,sizeof(mfp));
154 GlobalUnlock( hmem );
155
156 TRACE("returning %p\n",hmem);
157
158 return hmem;
159}
160
161/***********************************************************************
162 * CoGetActivationState (ole32.@)
163 */
165{
166 FIXME("%s, %x, %p\n", debugstr_guid(&guid), unknown, unknown2);
167 return E_NOTIMPL;
168}
169
170/***********************************************************************
171 * CoGetCallState (ole32.@)
172 */
174{
175 FIXME("%d, %p\n", unknown, unknown2);
176 return E_NOTIMPL;
177}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
static long path_length
Definition: maze.c:116
#define WINE_DEFAULT_DEBUG_CHANNEL(t)
Definition: precomp.h:23
#define FIXME(fmt,...)
Definition: precomp.h:53
#define E_NOTIMPL
Definition: ddrawi.h:99
#define NULL
Definition: types.h:112
static WCHAR unknown[MAX_STRING_RESOURCE_LEN]
Definition: object.c:1605
#define CP_ACP
Definition: compat.h:109
#define WideCharToMultiByte
Definition: compat.h:111
#define lstrlenW
Definition: compat.h:750
unsigned long DWORD
Definition: ntddk_ex.h:95
pKey DeleteObject()
GLint GLint GLsizei width
Definition: gl.h:1546
LPVOID NTAPI GlobalLock(HGLOBAL hMem)
Definition: heapmem.c:755
HGLOBAL NTAPI GlobalFree(HGLOBAL hMem)
Definition: heapmem.c:611
BOOL NTAPI GlobalUnlock(HGLOBAL hMem)
Definition: heapmem.c:1190
HGLOBAL NTAPI GlobalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:368
VOID WINAPI CoTaskMemFree(LPVOID ptr)
Definition: ifs.c:442
LPVOID WINAPI CoTaskMemAlloc(SIZE_T size)
Definition: ifs.c:426
#define debugstr_guid
Definition: kernel32.h:35
#define debugstr_w
Definition: kernel32.h:32
const GUID * guid
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
LPCWSTR szPath
Definition: env.c:37
HDC hdc
Definition: main.c:9
static HDC
Definition: imagelist.c:88
static HICON
Definition: imagelist.c:80
static DWORD *static HFONT(WINAPI *pCreateFontIndirectExA)(const ENUMLOGFONTEXDVA *)
static LPOLESTR
Definition: stg_prop.c:27
HICON hIcon
Definition: msconfig.c:44
INT WINAPI MulDiv(INT nNumber, INT nNumerator, INT nDenominator)
Definition: muldiv.c:25
Definition: mk_font.cpp:20
unsigned int UINT
Definition: ndis.h:50
#define HIMETRIC_INCHES
Definition: ole32_main.c:35
HRESULT WINAPI CoGetActivationState(GUID guid, DWORD unknown, DWORD *unknown2)
Definition: ole32_main.c:164
HRESULT WINAPI CoGetCallState(int unknown, PULONG unknown2)
Definition: ole32_main.c:173
HGLOBAL WINAPI OleMetafilePictFromIconAndLabel(HICON hIcon, LPOLESTR lpszLabel, LPOLESTR lpszSourceFile, UINT iIconIndex)
Definition: ole32_main.c:40
#define TRACE(s)
Definition: solgame.cpp:4
LONG cx
Definition: kdterminal.h:27
LONG cy
Definition: kdterminal.h:28
HMETAFILE hMF
Definition: wingdi.h:2608
uint32_t * PULONG
Definition: typedefs.h:59
int32_t INT
Definition: typedefs.h:58
#define GMEM_MOVEABLE
Definition: winbase.h:320
#define WINAPI
Definition: msvc.h:6
BOOL WINAPI DeleteMetaFile(_In_ HMETAFILE)
int WINAPI SetMapMode(_In_ HDC, _In_ int)
int WINAPI GetDeviceCaps(_In_opt_ HDC, _In_ int)
BOOL WINAPI SetWindowOrgEx(_In_ HDC, _In_ int, _In_ int, _Out_opt_ LPPOINT)
Definition: coord.c:532
#define LOGPIXELSY
Definition: wingdi.h:719
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1546
#define MM_ANISOTROPIC
Definition: wingdi.h:867
HMETAFILE WINAPI CloseMetaFile(_In_ HDC hdc)
BOOL WINAPI SetWindowExtEx(_In_ HDC, _In_ int, _In_ int, _Out_opt_ LPSIZE)
HDC WINAPI CreateMetaFileW(_In_opt_ LPCWSTR)
#define LOGPIXELSX
Definition: wingdi.h:718
BOOL WINAPI TextOutW(_In_ HDC hdc, _In_ int x, _In_ int y, _In_reads_(c) LPCWSTR lpString, _In_ int c)
HFONT WINAPI CreateFontIndirectW(_In_ const LOGFONTW *)
int WINAPI ExtEscape(_In_ HDC hdc, _In_ int iEscape, _In_ int cjInput, _In_reads_bytes_opt_(cjInput) LPCSTR lpInData, _In_ int cjOutput, _Out_writes_bytes_opt_(cjOutput) LPSTR lpOutData)
BOOL WINAPI GetTextExtentPoint32W(_In_ HDC hdc, _In_reads_(c) LPCWSTR lpString, _In_ int c, _Out_ LPSIZE psizl)
#define MFCOMMENT
Definition: wingdi.h:1008
#define snprintf
Definition: wintirpc.h:48
int WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
BOOL WINAPI DrawIcon(_In_ HDC, _In_ int, _In_ int, _In_ HICON)
Definition: cursoricon.c:2070
#define SPI_GETICONTITLELOGFONT
Definition: winuser.h:1383
#define SM_CYICON
Definition: winuser.h:976
HDC WINAPI GetDC(_In_opt_ HWND)
BOOL WINAPI SystemParametersInfoW(_In_ UINT uiAction, _In_ UINT uiParam, _Inout_opt_ PVOID pvParam, _In_ UINT fWinIni)
#define SM_CXICON
Definition: winuser.h:975
int WINAPI GetSystemMetrics(_In_ int)
char CHAR
Definition: xmlstorage.h:175