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

公告

<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 閱讀(537) 評論(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>
            亚洲精品欧美精品| 亚洲欧美日韩一区二区| 亚洲美女免费视频| 国语自产精品视频在线看8查询8| 国产精品大片| 国产精品网红福利| 国产免费成人| 国内精品久久国产| 亚洲全部视频| 亚洲一区二区三区在线看| 亚洲欧美日韩一区二区| 在线播放精品| av成人免费| 午夜精品久久| 免费欧美日韩国产三级电影| 亚洲国产精品小视频| 欧美国产日韩一区二区三区| 亚洲区在线播放| 亚洲国产成人午夜在线一区| 亚洲伦理在线| 一区二区三区导航| 日韩午夜在线视频| 亚洲日韩中文字幕在线播放| 一区二区高清视频在线观看| 午夜精品久久久久久久久久久久| 久久人人97超碰国产公开结果 | 99精品视频一区| 西西人体一区二区| 欧美电影在线播放| 国产精品久久午夜| 伊人影院久久| 欧美一区二区三区视频| 亚洲国产婷婷| 久久黄色影院| 国产精品日韩在线播放| 亚洲精品三级| 欧美激情一区二区三级高清视频| 国产日韩欧美在线播放不卡| 久久在线视频| 亚洲黄色在线| 久久国产欧美| 亚洲麻豆av| 久久av一区二区| 国产精品视频一| 一区二区三区www| 欧美国产一区视频在线观看| 午夜精品国产更新| 欧美无砖砖区免费| 99re66热这里只有精品4| 久久一区激情| 久久激情一区| 国产精品视频久久一区| 一本一本久久a久久精品综合麻豆| 久久综合网络一区二区| 欧美一区二区免费观在线| 国产精品日韩精品欧美精品| 亚洲视频观看| 亚洲免费av观看| 亚洲福利小视频| 99亚洲一区二区| 欧美日韩另类在线| 亚洲乱码精品一二三四区日韩在线| 欧美日韩精品免费看| 国产精品啊v在线| 亚洲无玛一区| 久久久久久久激情视频| 亚洲国产精品第一区二区| 亚洲一区中文字幕在线观看| 精品二区视频| 日韩一级裸体免费视频| 国产欧美一区在线| 性高湖久久久久久久久| 亚洲激情第一页| 亚洲大胆av| 影音先锋日韩精品| 欧美午夜一区二区| 一区二区三区www| 亚洲精品国产精品久久清纯直播 | 亚洲一区二区三区国产| 精品动漫3d一区二区三区| 亚洲欧美日韩一区二区| 国产精品男人爽免费视频1| 欧美一区二区三区在线观看视频| 亚洲欧洲日产国产综合网| 欧美在线观看天堂一区二区三区 | 国产免费成人av| 欧美激情一区二区三区成人| 久久久综合激的五月天| 亚洲一本大道在线| 一区二区三区黄色| 亚洲国产91| 欧美日韩99| 国产精品女人久久久久久| 一本色道久久88综合亚洲精品ⅰ| 久久视频一区| 欧美ed2k| av成人天堂| 激情视频亚洲| 国产精品一区二区在线观看网站| 亚洲欧美在线另类| 日韩视频永久免费| 欧美www在线| 久久精品五月| 香蕉久久一区二区不卡无毒影院| 亚洲欧洲一级| 在线播放日韩专区| 国产在线一区二区三区四区| 国产精品theporn| 亚洲第一精品福利| 亚洲精品一二区| 亚洲国产天堂久久国产91| 麻豆成人综合网| 久久国产夜色精品鲁鲁99| 欧美一区二区三区另类| 欧美在线免费观看亚洲| 狠狠色狠狠色综合日日91app| 免费成人在线视频网站| 亚洲欧美日韩国产综合精品二区| 亚洲综合不卡| 亚洲人成免费| 亚洲欧美另类久久久精品2019| 亚洲精品国产拍免费91在线| 欧美一区二区在线视频| 亚洲一级一区| 欧美精品一区三区在线观看| 欧美成年人视频| 激情一区二区| 性欧美大战久久久久久久免费观看 | 亚洲一区视频在线观看视频| 亚洲精品日韩久久| 欧美sm视频| 欧美国产综合| 影音先锋亚洲精品| 久久精品视频在线观看| 久久久久国产精品www| 国产日韩欧美一区二区三区在线观看| 亚洲天堂黄色| 欧美一区二区三区在| 国产欧美欧洲在线观看| 午夜精品一区二区在线观看| 欧美一站二站| 国产亚洲va综合人人澡精品| 欧美一区二区三区免费视| 久久久噜噜噜久噜久久 | 亚洲午夜在线| 欧美三区视频| 亚洲资源av| 久久人人97超碰国产公开结果| 国产嫩草一区二区三区在线观看| 午夜激情综合网| 麻豆精品精华液| 亚洲精选视频免费看| 欧美视频一区二区三区…| 亚洲一区二区在线视频| 性色一区二区| 精品成人在线视频| 欧美国产日本在线| 亚洲精品久久久久久久久久久久久 | 国产精品大片wwwwww| 亚洲视频免费看| 久久精品中文字幕免费mv| 在线看国产日韩| 欧美日韩高清区| 亚洲性色视频| 久久免费视频在线| 亚洲国产日韩综合一区| 欧美三级资源在线| 欧美+日本+国产+在线a∨观看| 亚洲国产天堂久久综合网| 你懂的国产精品| 亚洲精品日韩在线| 国产精品中文字幕在线观看| 久久国产精品久久精品国产| 老司机一区二区| 99精品黄色片免费大全| 国产欧美日韩三区| 蜜桃av久久久亚洲精品| 一本色道久久88综合日韩精品| 久久精品国产99| 亚洲精品乱码视频| 国产日本欧美视频| 欧美成人免费网站| 亚洲免费视频在线观看| 亚洲激情电影在线| 久久黄色网页| 亚洲综合色激情五月| 狠狠色伊人亚洲综合网站色| 欧美色中文字幕| 久久中文字幕一区| 亚洲视频在线免费观看| 亚洲国产精品一区制服丝袜| 欧美一区三区三区高中清蜜桃| 亚洲卡通欧美制服中文| 激情久久婷婷| 国产女人精品视频| 欧美三级午夜理伦三级中文幕 | 国产精品久久久久久久久免费桃花| 久久一二三区| 欧美一区二区啪啪| 亚洲免费人成在线视频观看|