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

公告

<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>
            国产精品一区=区| 蜜桃久久av一区| 亚洲图片欧洲图片av| 欧美一二三区精品| 日韩天堂在线视频| 亚洲黄色一区二区三区| 影音先锋久久| 亚洲人成7777| 亚洲免费电影在线观看| 日韩视频在线永久播放| 亚洲国产日韩欧美在线99 | 午夜国产不卡在线观看视频| 亚洲最新视频在线播放| 亚洲午夜精品一区二区| 久久精品国亚洲| 亚洲高清视频一区二区| 麻豆成人综合网| 亚洲免费电影在线| 亚洲福利视频一区| 亚洲国产精品va在线观看黑人| 在线成人激情| 欧美亚洲在线视频| 亚洲日韩第九十九页| 欧美一区二区免费观在线| 久久伊人一区二区| 国产精品国产福利国产秒拍 | 亚洲一区二区精品| 免费成人在线观看视频| 国产精品一区二区女厕厕| 在线欧美不卡| 久久久一二三| 欧美在线视频播放| 国产伦精品一区二区三区照片91 | 亚洲精品欧美精品| 久久久91精品| 国产亚洲综合精品| 亚洲欧美日韩另类| 日韩一区二区精品视频| 欧美黄色aa电影| 欧美精品一区二区三区四区| 91久久在线观看| 久久视频一区| 亚洲国产一区视频| 亚洲高清二区| 欧美精品一区二区三区高清aⅴ| 在线观看亚洲视频啊啊啊啊| 久久亚洲精品欧美| avtt综合网| 午夜激情综合网| 一区二区三区免费网站| 国产精品蜜臀在线观看| 久久se精品一区二区| 久久精品一区二区三区中文字幕| 国产欧美在线观看| 欧美韩日一区| 国产精品国产自产拍高清av王其 | 国产精品三区www17con| 久久av一区二区三区漫画| 久久综合九色九九| 亚洲欧美一区二区三区在线 | 一区二区三区.www| 国产精品一区二区久激情瑜伽| 欧美一区日本一区韩国一区| 玖玖玖国产精品| 欧美在线三级| 国产精品久久久久一区二区| 久久久亚洲影院你懂的| 欧美视频在线观看视频极品| 久久免费99精品久久久久久| 欧美日韩国产三级| 欧美激情精品久久久久久大尺度| 国产精品在线看| 亚洲午夜女主播在线直播| 影音先锋亚洲电影| 欧美一区三区三区高中清蜜桃| 一区二区三区四区国产| 欧美激情四色 | 国产欧美一级| aa日韩免费精品视频一| 亚洲欧美日韩精品一区二区| 欧美中文字幕在线视频| 久久先锋资源| 免费视频最近日韩| **欧美日韩vr在线| 欧美大片在线观看一区二区| 欧美成熟视频| 亚洲国产欧美一区二区三区同亚洲 | 一区二区高清在线观看| 美女视频黄免费的久久| 亚洲二区免费| 一区二区国产日产| 国产精品一区免费观看| 亚洲欧美日韩久久精品| 久久久久高清| 亚洲人体偷拍| 国产日韩欧美a| 欧美黄色一区| 久久不见久久见免费视频1| 欧美成人免费全部观看天天性色| 日韩亚洲精品视频| 国产日韩一级二级三级| 欧美久久婷婷综合色| 久久国内精品自在自线400部| 亚洲国产精品电影| 久久亚洲美女| 久久久久久一区二区| 亚洲午夜在线观看视频在线| 激情久久婷婷| 狠狠综合久久av一区二区老牛| 欧美成人免费大片| 欧美中文字幕在线| 99精品福利视频| 亚洲国产日韩欧美在线99| 狠狠色综合色区| 韩国一区二区三区美女美女秀| 欧美成人一区二区三区| 亚洲激情电影在线| 欧美激情一区二区三区四区| 久久久久国产精品午夜一区| 欧美伊久线香蕉线新在线| 亚洲欧美国产精品va在线观看| 亚洲精品一区二区三区不| 91久久视频| 夜夜嗨av色综合久久久综合网| 亚洲狠狠丁香婷婷综合久久久| 国产综合久久久久久鬼色| 国内免费精品永久在线视频| 国产一区二区三区免费不卡| 99视频精品全国免费| 亚洲特级片在线| 欧美一区二区三区四区在线观看地址 | 久久精品国产99| 久久精品亚洲乱码伦伦中文 | 性色av一区二区三区红粉影视| 香蕉成人久久| 久久资源在线| 国产精品你懂的在线欣赏| 国产女人水真多18毛片18精品视频| 国产精品揄拍500视频| 亚洲欧洲综合另类| 欧美视频一区二区三区| 国产精品一区二区视频| 亚洲人成网站777色婷婷| 欧美一区二区黄| 99精品视频网| 欧美精品v国产精品v日韩精品 | 欧美一区二区免费观在线| 噜噜噜噜噜久久久久久91| 国产精品久久久久久妇女6080| 国产三级精品在线不卡| 一区二区三区四区在线| 免费欧美高清视频| 久久久久久一区二区三区| 国产女主播一区二区三区| 亚洲一区二区视频| 亚洲午夜精品久久久久久浪潮| 欧美激情按摩| 一区二区三区av| 亚洲美女视频在线观看| 欧美精品在线免费观看| 一区二区三区 在线观看视频| 最新日韩在线| 欧美午夜a级限制福利片| 亚洲午夜av电影| 亚洲欧美激情精品一区二区| 国产精品视频一区二区高潮| 午夜精品视频在线观看| 久久99在线观看| 亚洲国产精品一区二区三区| 欧美成人精品在线| 欧美大片免费久久精品三p| 一本色道久久综合亚洲二区三区 | 亚洲国产精品免费| 另类激情亚洲| 欧美在线观看网站| 久久久夜夜夜| 午夜精品三级视频福利| 久久久久久九九九九| 亚洲图片欧洲图片日韩av| 久久99伊人| 欧美在线综合视频| 欧美视频一区二区在线观看| 国产一区二区黄| 亚洲国产91精品在线观看| 国产精品久久久久久久久免费| 另类成人小视频在线| 国产精品嫩草99a| 99精品国产福利在线观看免费| 韩国三级电影一区二区| 亚洲香蕉成视频在线观看| 日韩午夜电影av| 欧美黄色视屏| 亚洲精品中文字幕女同| 最新亚洲电影| 蜜桃av综合| 亚洲品质自拍| 制服丝袜亚洲播放| 欧美视频精品在线观看| 亚洲视频精选| 久久久另类综合|