青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

公告

<2025年9月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

統計

  • 隨筆 - 9
  • 文章 - 13
  • 評論 - 3
  • 引用 - 0

常用鏈接

留言簿(1)

隨筆分類

隨筆檔案

文章分類

文章檔案

搜索

  •  

最新評論

閱讀排行榜

評論排行榜

Getting an (ATL) ActiveX control to print from Office Applications
13 votes for this article.
Popularity: 4.73. Rating: 4.25 out of 5.

Introduction

Seeing as this is my first ever post to CodeProject, let me do a quick introduction as to who I am and what I do. I have been working in one form of C and C++ or another for as long as I can remember (among the other myriad of languages that I've run into). Nowadays, most of my development is focused on Microsoft Windows platforms, and is done in VC6, VC2002.NET. I am heavily entrenched in BI (Business Intelligence) development, and in my spare time develop little ActiveX controls and games etc...

The plot

Having learnt COM a while ago, I made the obvious progression to ATL to ease the development of boilerplate code, and to leverage off Microsoft's template library. As my experience grew, I ventured into creating ActiveX controls using the ATL framework ... and life was good. I could spew out a fairly useful (albeit not overly complex) control within a short period of time. Recently, I was asked to create a KPI (Key Performance Indicator) control that could be embedded in a web page and an Excel document. Obviously based on my experience (which was obviously not vast) I thought that this would be no problem and off I went, creating code that would meet the functional spec (we all work to these don't we :)).

A couple of days later the control was finished and the final tests were being run when someone asked me to print a hardcopy of an example spreadsheet with the embedded control. This is where my nightmares began. Not only did my control not print, but there was no clear indication as to why it didn't print. And so my exploration into this apparent mystery began.

Have you ever tried to include 3rd party ActiveX controls into an Office document? They sure seem to work fine, but most (apart from the Microsoft controls) don't seem to render themselves when you request a Print Preview or a simple Print of the worksheet or document. So, if any of you have ever had this problem, or have never dabbled with this, but think that you may be heading this way, take note of this, cos it might save you hours of frustration and frantic searching on MSDN and Google.

So what now?

The first thing one needs to realize is that even though we have been blessed with Office 2000 and Office XP, the printing architecture still uses the old Windows-format metafile for its printing operations. This metafile format was used in 16-bit Windows-based applications (thinks back to Win3.1). Now, this becomes a major problem for ActiveX developers who wish their controls to be printable from within Office applications, because this old metafile format only supported a limited set of GDI functionality. The list of supported GDI functions can be found here.

Now that you are armed with your limited function set, you cringe with the realization that you can no longer create memory DC's, you can no longer use your lovely DrawText() functions and you can definitely no longer call GetTextExtentPoint32() function. However, those realizations only hold true for the instance of when your control is being rendered to an old format metafile. So how do we empower our control to know that its being rendered to an old format metafile? Simple, we use the GetObjectType() function and check if the result is equal to OBJ_METADC (old metafile format):

HRESULT Cxxxxx::OnDraw(ATL_DRAWINFO& di)
{
    HDC hdc = di.hdcDraw;
    bool bMetaFile = false;

    //// lets check if we're drawing to an old// metafile format.. (like Office printing)//if ( GetObjectType(hdc) == OBJ_METADC )
        bOldMetaFile = true;

    //// the rest of your code...//
}

For interest, the opposite of OBJ_METADC is OBJ_ENHMETADC (refer to this MSDN document).

Now that we know if we're drawing to an old metafile format or not, we can write adaptive code to cater for each instance or we can just write all our drawing logic using the limited set of functionality that is supported by the old metafile DC.

What about fonts and text extents?

As any ATL ActiveX developer knows, using fonts in AX controls provides for limited amount of fun. The typical piece of code would probably look something like this:

																//
																// ... some code
																//
    CComQIPtr<IFont, &IID_IFont> pFont(m_pFont);
    TEXTMETRICOLE tm;if ( pFont != NULL )
    {
        pFont->get_hFont(&newFont);
        pFont->AddRefHfont(newFont);
        pFont->QueryTextMetrics(&tm);
        oldFont = (HFONT) SelectObject(dc, newFont);
    }

The Bolded lines of code are ones that I didn't use regularly, due to the fact that I didn't really need to know about the breakdown of my font's details because I had access to GetTextExtentPoint32() function. Unfortunately, in this scenario, we don't have access to that function to determine how wide (in pixels) our text is going to be. But there is another way to calculate this fairly accurately, as is demonstrated in the code below:

																//
																// assume that we have called QueryTextMetrics() and
																// have a filled TEXTMETRICOLE structure called tm
																//
CComBSTR strText(_T("Hello, world"));
SIZE sz;

sz.cx = strText.Length() * tm.tmAveCharWidth;
sz.cy = tm.tmHeight;

Having said this, there are many other functions that I use a lot that I can't use if I want my ActiveX control to be printable by Office, but as with GetTextExtentPoint32() and its respective replacement, there is always a way to replace these functions using Old-Metafile-Safe-Drawing-Code (OMSDC). *maybe that acronym will catch on*

Conclusion

When creating an ActiveX control that you know will be used inside Office applications, and will most probably be printed, remember to stick to these guidelines when developing your drawing logic. I was fairly shocked by how little information was available in the MSDN and online in general, while I was searching for information on how to enable my ActiveX control to print from within an Office application. There are hundreds of documents on ActiveX controls being printed from within Internet Explorer, but none address this particular issue. Perhaps I was looking in the wrong places. Hopefully this article will help one or more of you one day ;)

Acknowledgment

Many thanks to Igor Tandetnik for pointing me in the right direction on this.

About Peter Mares

posted on 2006-11-07 17:38 blues 閱讀(536) 評論(0)  編輯 收藏 引用

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            午夜在线不卡| 国产伦精品一区二区三区高清| 亚洲国产精品尤物yw在线观看 | 亚洲人午夜精品免费| 韩曰欧美视频免费观看| 影音先锋中文字幕一区二区| 一区在线观看视频| 亚洲日本va午夜在线电影| 亚洲精品看片| 亚洲一区二区三区视频| 亚洲欧美激情四射在线日| 欧美在线一二三区| 欧美成人视屏| 一区二区91| 久久xxxx| 欧美日韩国产精品一区二区亚洲 | 亚洲午夜未删减在线观看| 亚洲午夜在线视频| 久久久xxx| 欧美日韩精品一区二区三区| 国产精品亚洲аv天堂网| 精品999成人| 亚洲一区二区黄| 裸体一区二区| 亚洲毛片一区二区| 久久精品国产99国产精品| 欧美国产一区二区| 国产欧美精品一区| 日韩亚洲欧美成人| 久久久亚洲精品一区二区三区 | 欧美成人免费全部| 国产乱码精品一区二区三区av| 在线日韩成人| 久久成年人视频| 夜夜嗨av一区二区三区网页| 亚洲欧美日韩在线观看a三区| 亚洲女同性videos| 国产亚洲aⅴaaaaaa毛片| 亚洲国产精品黑人久久久| 一区二区三区蜜桃网| 久久免费视频观看| 亚洲视频在线看| 欧美精品二区| 亚洲国产片色| 免费毛片一区二区三区久久久| 一区二区三区国产在线| 男女激情视频一区| 在线观看欧美一区| 久久久综合精品| 亚洲男同1069视频| 国产精品mv在线观看| aa成人免费视频| 亚洲激情综合| 欧美精品1区2区3区| 亚洲国产影院| 欧美激情在线狂野欧美精品| 久久国产视频网站| 国产在线欧美日韩| 久久久久久噜噜噜久久久精品| 亚洲一区久久久| 国产精品色婷婷| 欧美一区二区三区另类 | 欧美激情视频一区二区三区免费 | 免费人成网站在线观看欧美高清| 国产中文一区二区三区| 久久精品九九| 久久xxxx精品视频| 一区二区亚洲精品| 欧美11—12娇小xxxx| 免费看av成人| 一区二区三区视频在线| 99在线精品视频| 国产精品欧美风情| 久久九九久精品国产免费直播| 久久国产色av| 亚洲看片一区| 一区二区三区视频在线观看 | 国产午夜精品理论片a级探花| 欧美一区亚洲二区| 久久国产一区二区三区| 亚洲高清不卡一区| 日韩一级免费观看| 国产午夜亚洲精品不卡| 欧美成人首页| 欧美三级在线视频| 久久久午夜电影| 欧美精品一二三| 欧美主播一区二区三区| 久久精品亚洲一区二区三区浴池| 久久久精品久久久久| 亚洲免费观看| 亚洲欧美一区二区视频| 一区二区视频免费完整版观看| 亚洲国产婷婷综合在线精品| 欧美日韩在线影院| 久久久噜噜噜久久中文字幕色伊伊 | 男人的天堂亚洲| 欧美日韩成人综合在线一区二区| 欧美亚洲在线播放| 蜜臀av国产精品久久久久| 亚洲私人影吧| 蜜臀久久久99精品久久久久久| 亚洲午夜久久久| 久久精品首页| 亚洲欧美清纯在线制服| 老司机67194精品线观看| 亚洲女女女同性video| 裸体丰满少妇做受久久99精品| 午夜免费久久久久| 欧美精品一区二区视频| 鲁大师影院一区二区三区| 国产精品久久久久久久久免费| 亚洲大片av| 伊甸园精品99久久久久久| 亚洲欧美国产不卡| 亚洲性线免费观看视频成熟| 麻豆av一区二区三区| 久久深夜福利| 国产日本精品| 亚洲视频高清| 在线视频精品一区| 欧美激情第10页| 欧美不卡在线视频| 黄色一区二区在线| 欧美一区二区三区啪啪| 午夜精品免费视频| 欧美手机在线视频| 日韩一级大片| 亚洲五月婷婷| 国产精品久久久久99| 亚洲精品免费一二三区| 最新亚洲电影| 欧美成人精品在线| 亚洲国产裸拍裸体视频在线观看乱了| 激情欧美一区二区三区| 久久精品论坛| 欧美1区2区视频| 亚洲欧洲精品一区二区三区 | 国产一区二区精品| 欧美一区久久| 美女图片一区二区| 亚洲国产91| 欧美精品日本| 中日韩美女免费视频网站在线观看| 一区二区三区三区在线| 欧美日韩在线播放一区| 一区二区三区.www| 国产亚洲网站| 欧美在线|欧美| 久久综合色88| 亚洲激情午夜| 欧美激情综合五月色丁香小说 | 亚洲免费黄色| 亚洲综合电影| 国产亚洲精品7777| 久久全国免费视频| 欧美大色视频| 亚洲一区二区三区四区五区午夜| 国产精品久久久久久久久搜平片| 亚洲一区二区三区高清| 久久国产色av| 亚洲欧洲午夜| 欧美三区美女| 久久精品国产91精品亚洲| 亚洲国产日韩一级| 亚洲欧美日韩综合国产aⅴ| 国产日韩精品一区| 欧美 日韩 国产精品免费观看| 亚洲美女黄色片| 久久精品国产99国产精品| 亚洲大黄网站| 国产精品国产三级国产aⅴ入口| 午夜精品视频在线| 亚洲黄色尤物视频| 欧美在线综合| 日韩午夜精品| 韩国精品在线观看| 欧美视频一区在线观看| 久久久久久久激情视频| 一本色道88久久加勒比精品| 久久久久国内| 亚洲一区一卡| 亚洲激情网址| 国产一区二区三区自拍| 欧美日韩国产成人| 久久一区二区视频| 午夜精品久久久久久久久久久| 亚洲国产精品999| 久久一日本道色综合久久| 亚洲午夜羞羞片| 亚洲精品中文字幕有码专区| 国产在线欧美| 国产欧美日韩免费| 欧美视频在线看| 欧美经典一区二区| 久久青青草综合| 久久av在线| 欧美一区二区成人6969| 亚洲视频999| 一区二区三区四区五区在线|