Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenole32_main.c
Go to the documentation of this file.
00001 /* 00002 * OLE32 Initialization 00003 * 00004 * Copyright 2000 Huw D M Davies for CodeWeavers 00005 * 00006 * This library is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Lesser General Public 00008 * License as published by the Free Software Foundation; either 00009 * version 2.1 of the License, or (at your option) any later version. 00010 * 00011 * This library is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public 00017 * License along with this library; if not, write to the Free Software 00018 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 00019 */ 00020 00021 #include "config.h" 00022 #include "wine/port.h" 00023 00024 #include <stdarg.h> 00025 #include <stdio.h> 00026 00027 #include "windef.h" 00028 #include "winbase.h" 00029 #include "wingdi.h" 00030 #include "winuser.h" 00031 #include "winnls.h" 00032 #include "objbase.h" 00033 #include "ole2.h" 00034 #include "wine/debug.h" 00035 00036 WINE_DEFAULT_DEBUG_CHANNEL(ole); 00037 00038 #define HIMETRIC_INCHES 2540 00039 00040 /*********************************************************************** 00041 * OleMetafilePictFromIconAndLabel (OLE32.@) 00042 */ 00043 HGLOBAL WINAPI OleMetafilePictFromIconAndLabel(HICON hIcon, LPOLESTR lpszLabel, 00044 LPOLESTR lpszSourceFile, UINT iIconIndex) 00045 { 00046 METAFILEPICT mfp; 00047 HDC hdc; 00048 HGLOBAL hmem = NULL; 00049 LPVOID mfdata; 00050 static const char szIconOnly[] = "IconOnly"; 00051 SIZE text_size = { 0, 0 }; 00052 INT width; 00053 INT icon_width; 00054 INT icon_height; 00055 INT label_offset; 00056 HDC hdcScreen; 00057 LOGFONTW lf; 00058 HFONT font; 00059 00060 TRACE("%p %p %s %d\n", hIcon, lpszLabel, debugstr_w(lpszSourceFile), iIconIndex); 00061 00062 if( !hIcon ) 00063 return NULL; 00064 00065 if (!SystemParametersInfoW(SPI_GETICONTITLELOGFONT, sizeof(lf), &lf, 0)) 00066 return NULL; 00067 00068 font = CreateFontIndirectW(&lf); 00069 if (!font) 00070 return NULL; 00071 00072 hdc = CreateMetaFileW(NULL); 00073 if( !hdc ) 00074 { 00075 DeleteObject(font); 00076 return NULL; 00077 } 00078 00079 SelectObject(hdc, font); 00080 00081 ExtEscape(hdc, MFCOMMENT, sizeof(szIconOnly), szIconOnly, 0, NULL); 00082 00083 icon_width = GetSystemMetrics(SM_CXICON); 00084 icon_height = GetSystemMetrics(SM_CYICON); 00085 /* FIXME: should we give the label a bit of padding here? */ 00086 label_offset = icon_height; 00087 if (lpszLabel) 00088 { 00089 HFONT screen_old_font; 00090 /* metafile DCs don't support GetTextExtentPoint32, so size the font 00091 * using the desktop window DC */ 00092 hdcScreen = GetDC(NULL); 00093 screen_old_font = SelectObject(hdcScreen, font); 00094 GetTextExtentPoint32W(hdcScreen, lpszLabel, lstrlenW(lpszLabel), &text_size); 00095 SelectObject(hdcScreen, screen_old_font); 00096 ReleaseDC(NULL, hdcScreen); 00097 00098 width = 3 * icon_width; 00099 } 00100 else 00101 width = icon_width; 00102 00103 SetMapMode(hdc, MM_ANISOTROPIC); 00104 SetWindowOrgEx(hdc, 0, 0, NULL); 00105 SetWindowExtEx(hdc, width, label_offset + text_size.cy, NULL); 00106 00107 /* draw the icon centered */ 00108 DrawIcon(hdc, (width-icon_width) / 2, 0, hIcon); 00109 if(lpszLabel) 00110 /* draw the label centered too, if provided */ 00111 TextOutW(hdc, (width-text_size.cx) / 2, label_offset, lpszLabel, lstrlenW(lpszLabel)); 00112 00113 if (lpszSourceFile) 00114 { 00115 char szIconIndex[10]; 00116 int path_length = WideCharToMultiByte(CP_ACP,0,lpszSourceFile,-1,NULL,0,NULL,NULL); 00117 if (path_length > 1) 00118 { 00119 char * szPath = CoTaskMemAlloc(path_length * sizeof(CHAR)); 00120 if (szPath) 00121 { 00122 WideCharToMultiByte(CP_ACP,0,lpszSourceFile,-1,szPath,path_length,NULL,NULL); 00123 ExtEscape(hdc, MFCOMMENT, path_length, szPath, 0, NULL); 00124 CoTaskMemFree(szPath); 00125 } 00126 } 00127 snprintf(szIconIndex, 10, "%u", iIconIndex); 00128 ExtEscape(hdc, MFCOMMENT, strlen(szIconIndex)+1, szIconIndex, 0, NULL); 00129 } 00130 00131 mfp.mm = MM_ANISOTROPIC; 00132 hdcScreen = GetDC(NULL); 00133 mfp.xExt = MulDiv(width, HIMETRIC_INCHES, GetDeviceCaps(hdcScreen, LOGPIXELSX)); 00134 mfp.yExt = MulDiv(label_offset + text_size.cy, HIMETRIC_INCHES, GetDeviceCaps(hdcScreen, LOGPIXELSY)); 00135 ReleaseDC(NULL, hdcScreen); 00136 mfp.hMF = CloseMetaFile(hdc); 00137 DeleteObject(font); 00138 if( !mfp.hMF ) 00139 return NULL; 00140 00141 hmem = GlobalAlloc( GMEM_MOVEABLE, sizeof(mfp) ); 00142 if( !hmem ) 00143 { 00144 DeleteMetaFile(mfp.hMF); 00145 return NULL; 00146 } 00147 00148 mfdata = GlobalLock( hmem ); 00149 if( !mfdata ) 00150 { 00151 GlobalFree( hmem ); 00152 DeleteMetaFile(mfp.hMF); 00153 return NULL; 00154 } 00155 00156 memcpy(mfdata,&mfp,sizeof(mfp)); 00157 GlobalUnlock( hmem ); 00158 00159 TRACE("returning %p\n",hmem); 00160 00161 return hmem; 00162 } Generated on Fri May 25 2012 04:23:47 for ReactOS by
1.7.6.1
|