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

公告

<2006年8月>
303112345
6789101112
13141516171819
20212223242526
272829303112
3456789

統計

  • 隨筆 - 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 閱讀(542) 評論(0)  編輯 收藏 引用


只有注冊用戶登錄后才能發表評論。
網站導航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            国产精品高精视频免费| 亚洲国产美女| 韩日精品视频一区| 国产伦精品一区二区三| 亚洲网站啪啪| 国产精品色一区二区三区| 欧美一二三视频| 欧美在线免费视屏| 久久九九精品99国产精品| 久久综合九色| 欧美日精品一区视频| 国产麻豆精品在线观看| 国内精品一区二区三区| 91久久国产综合久久91精品网站| 亚洲精品午夜精品| 欧美一二三视频| 欧美黄色aa电影| 亚洲午夜在线观看| 久久久免费精品| 欧美日韩精品高清| 国产午夜精品久久| 日韩视频―中文字幕| 欧美亚洲免费在线| 亚洲二区三区四区| 亚洲欧美视频在线| 男女av一区三区二区色多| 欧美亚洲不卡| 91久久线看在观草草青青| 亚洲免费中文| 亚洲高清不卡在线| 久久国产婷婷国产香蕉| 欧美午夜精品一区| 亚洲黄一区二区| 久久激情中文| 亚洲天堂av在线免费观看| 欧美成人精品三级在线观看| 国产日韩欧美亚洲| 亚洲尤物视频网| 亚洲激情视频网| 久久最新视频| 一区免费视频| 久久久精品动漫| 亚洲欧美日韩国产精品| 欧美色图五月天| 一本大道久久a久久精二百| 麻豆9191精品国产| 欧美亚洲三级| 国产欧美日韩亚洲一区二区三区| 在线视频亚洲一区| 亚洲经典自拍| 欧美成人首页| 91久久精品国产91性色| 欧美电影免费观看高清| 久久视频在线免费观看| 国内揄拍国内精品少妇国语| 欧美在线不卡| 亚洲一级二级| 国产偷国产偷精品高清尤物| 亚洲欧美亚洲| 亚洲欧美日韩一区二区三区在线| 欧美少妇一区二区| 亚洲一本大道在线| 亚洲视频在线二区| 久热爱精品视频线路一| 欧美chengren| 欧美va亚洲va香蕉在线| 亚洲国产精品精华液2区45| 女女同性女同一区二区三区91| 久久成人18免费观看| 国内精品福利| 欧美高清视频一区| 欧美激情1区| 在线亚洲伦理| 亚洲伊人一本大道中文字幕| 国产精品日韩久久久| 先锋影音网一区二区| 亚洲欧美日韩天堂| 在线日韩中文| 一区二区三区成人| 国产视频精品va久久久久久| 久久久青草婷婷精品综合日韩| 久久久久久夜| 一区二区日韩免费看| 亚洲一区二区三区乱码aⅴ| 国产日韩三区| 亚洲国产中文字幕在线观看| 欧美日韩综合精品| 久久嫩草精品久久久久| 欧美激情91| 久久精品国产综合精品| 欧美1区免费| 午夜在线精品偷拍| 欧美ed2k| 久久精品国产欧美亚洲人人爽| 麻豆freexxxx性91精品| 亚洲在线不卡| 欧美波霸影院| 欧美综合国产精品久久丁香| 欧美成人一二三| 久久精品视频va| 欧美日韩国产成人精品| 久久精品五月婷婷| 欧美色一级片| 亚洲国产视频a| 伊人久久男人天堂| 亚洲综合视频在线| 99国产精品久久久| 久久黄色网页| 性色av香蕉一区二区| 欧美成人激情在线| 久久综合九色综合网站| 国产精品久久久久影院色老大 | 亚洲福利久久| 亚洲欧美一区二区在线观看| 艳妇臀荡乳欲伦亚洲一区| 久久久久国产精品人| 欧美影院视频| 国产精品男gay被猛男狂揉视频| 亚洲大胆人体在线| 一区二区视频免费在线观看| 亚洲女ⅴideoshd黑人| 中文无字幕一区二区三区| 免费在线观看一区二区| 久久一区亚洲| 国产一区av在线| 午夜精品亚洲一区二区三区嫩草| 亚洲欧美一区二区三区久久 | 国产精品99久久久久久www| 久久中文字幕导航| 久久午夜精品| 狠狠爱综合网| 欧美一区二区三区免费视频| 亚洲天堂男人| 久久久久国产精品人| 久久久久久穴| 国产一区二区三区精品久久久| 一区二区三区波多野结衣在线观看| 最新成人av在线| 模特精品在线| 亚洲区国产区| 亚洲精品社区| 欧美日产国产成人免费图片| 91久久视频| 99精品视频免费在线观看| 欧美激情国产日韩| 亚洲精品影视在线观看| 国产精品一区二区三区久久久| 亚洲色图自拍| 久久成年人视频| 国产色婷婷国产综合在线理论片a| 亚洲综合精品一区二区| 久久精品一区中文字幕| 一区二区视频在线观看| 免费观看一区| 一本大道久久a久久综合婷婷| 午夜在线a亚洲v天堂网2018| 国产一区美女| 欧美精品午夜| 亚洲欧美在线磁力| 榴莲视频成人在线观看| 日韩一级二级三级| 国产欧美精品一区二区三区介绍 | 欧美三级午夜理伦三级中文幕| 亚洲图片在线| 蜜桃av噜噜一区| 在线视频亚洲| 狠狠v欧美v日韩v亚洲ⅴ| 欧美精彩视频一区二区三区| aa日韩免费精品视频一| 欧美在线免费视频| 亚洲经典在线| 国产精品看片资源| 久久久五月婷婷| 一本久道久久久| 狼狼综合久久久久综合网| 一本色道久久综合一区| 国产亚洲精品久久久久久| 美女精品视频一区| 亚洲影院在线| 亚洲欧洲一级| 久久久久在线| 亚洲午夜久久久久久久久电影网| 国产女人aaa级久久久级| 欧美激情一区二区三区在线视频| 中文av字幕一区| 欧美激情亚洲国产| 久久精品中文字幕免费mv| 亚洲天堂网站在线观看视频| 伊人久久大香线蕉综合热线| 国产精品欧美激情| 欧美母乳在线| 噜噜噜久久亚洲精品国产品小说| 一个色综合av| 久久人人看视频| 久久成人人人人精品欧| 亚洲精品一二三区| 欧美大片免费观看在线观看网站推荐| 亚洲欧美乱综合| 日韩网站免费观看| 亚洲精品免费看|